2024-02-23 21:32:32 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-06-26 17:45:16 +00:00
|
|
|
#pragma once
|
2023-11-05 23:11:54 +00:00
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
#include <functional>
|
|
|
|
#include "common/logging/log.h"
|
2023-11-05 23:11:54 +00:00
|
|
|
#include "core/loader/elf.h"
|
|
|
|
#include "core/loader/symbols_resolver.h"
|
2023-07-13 09:56:36 +00:00
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
template <size_t N>
|
|
|
|
struct StringLiteral {
|
|
|
|
constexpr StringLiteral(const char (&str)[N]) {
|
|
|
|
std::copy_n(str, N, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
char value[N];
|
|
|
|
};
|
|
|
|
|
|
|
|
template <StringLiteral name, class F, F f>
|
|
|
|
struct wrapper_impl;
|
|
|
|
|
|
|
|
template <StringLiteral name, class R, class... Args, PS4_SYSV_ABI R (*f)(Args...)>
|
|
|
|
struct wrapper_impl<name, PS4_SYSV_ABI R (*)(Args...), f> {
|
|
|
|
static R PS4_SYSV_ABI wrap(Args... args) {
|
|
|
|
if (std::string_view(name.value) != "scePthreadEqual" &&
|
|
|
|
std::string_view(name.value) != "sceUserServiceGetEvent") {
|
2024-06-15 22:50:07 +00:00
|
|
|
// LOG_WARNING(Core_Linker, "Function {} called", name.value);
|
2024-06-15 11:36:07 +00:00
|
|
|
}
|
|
|
|
if constexpr (std::is_same_v<R, s32> || std::is_same_v<R, u32>) {
|
|
|
|
const u32 ret = f(args...);
|
|
|
|
if (ret != 0 && std::string_view(name.value) != "scePthreadEqual") {
|
|
|
|
LOG_WARNING(Core_Linker, "Function {} returned {:#x}", name.value, ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
// stuff
|
|
|
|
return f(args...);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <StringLiteral name, class F, F f>
|
|
|
|
constexpr auto wrapper = wrapper_impl<name, F, f>::wrap;
|
|
|
|
|
|
|
|
// #define W(foo) wrapper<#foo, decltype(&foo), foo>
|
|
|
|
#define W(foo) foo
|
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
|
|
|
{ \
|
2024-03-11 11:26:33 +00:00
|
|
|
Core::Loader::SymbolResolver sr{}; \
|
2024-02-23 20:57:57 +00:00
|
|
|
sr.name = nid; \
|
|
|
|
sr.library = lib; \
|
|
|
|
sr.library_version = libversion; \
|
|
|
|
sr.module = mod; \
|
|
|
|
sr.module_version_major = moduleVersionMajor; \
|
|
|
|
sr.module_version_minor = moduleVersionMinor; \
|
2024-03-11 11:26:33 +00:00
|
|
|
sr.type = Core::Loader::SymbolType::Function; \
|
2024-06-15 11:36:07 +00:00
|
|
|
auto func = reinterpret_cast<u64>(W(function)); \
|
2024-02-23 20:57:57 +00:00
|
|
|
sym->AddSymbol(sr, func); \
|
2023-07-17 10:53:27 +00:00
|
|
|
}
|
2023-07-27 14:56:57 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
#define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
|
|
|
{ \
|
2024-03-11 11:26:33 +00:00
|
|
|
Core::Loader::SymbolResolver sr{}; \
|
2024-02-23 20:57:57 +00:00
|
|
|
sr.name = nid; \
|
|
|
|
sr.library = lib; \
|
|
|
|
sr.library_version = libversion; \
|
|
|
|
sr.module = mod; \
|
|
|
|
sr.module_version_major = moduleVersionMajor; \
|
|
|
|
sr.module_version_minor = moduleVersionMinor; \
|
2024-03-11 11:26:33 +00:00
|
|
|
sr.type = Core::Loader::SymbolType::Object; \
|
2024-02-23 20:57:57 +00:00
|
|
|
auto func = reinterpret_cast<u64>(function); \
|
|
|
|
sym->AddSymbol(sr, func); \
|
2023-07-27 14:56:57 +00:00
|
|
|
}
|
|
|
|
|
2024-04-13 21:35:48 +00:00
|
|
|
namespace Libraries {
|
2023-11-05 23:11:54 +00:00
|
|
|
|
2024-03-14 12:18:16 +00:00
|
|
|
void InitHLELibs(Core::Loader::SymbolsResolver* sym);
|
2023-11-05 23:11:54 +00:00
|
|
|
|
2024-04-13 21:35:48 +00:00
|
|
|
} // namespace Libraries
|