Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sceKernelGetModuleList #806

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/core/libraries/kernel/libkernel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include <algorithm>
#include <chrono>
#include <thread>

Expand Down Expand Up @@ -398,6 +399,23 @@ int PS4_SYSV_ABI posix_getpagesize() {
return 4096;
}

int PS4_SYSV_ABI sceKernelGetModuleList(Core::Module** pArray, size_t numArray,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core::Module is our structure, not sure it matches what guest expects

size_t* pActualNum) {
auto* linker = Common::Singleton<Core::Linker>::Instance();
int numModules = linker->GetNumberModules();
for (int i = 0; i < std::min(static_cast<int>(numArray), numModules); ++i) {
auto m = linker->GetModule(i);
if (!m) {
*pActualNum = i;
break;
}

pArray[i] = m;
}

return ORBIS_OK;
}

void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
service_thread = std::jthread{KernelServiceThread};

Expand Down Expand Up @@ -443,6 +461,8 @@ void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("kBJzF8x4SyE", "libkernel", 1, "libkernel", 1, 1, sceKernelBatchMap2);
LIB_FUNCTION("DGMG3JshrZU", "libkernel", 1, "libkernel", 1, 1, sceKernelSetVirtualRangeName);

LIB_FUNCTION("IuxnUuXk6Bg", "libkernel", 1, "libkernel", 1, 1, sceKernelGetModuleList);

// equeue
LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue);
LIB_FUNCTION("jpFjmgAC5AE", "libkernel", 1, "libkernel", 1, 1, sceKernelDeleteEqueue);
Expand Down
2 changes: 2 additions & 0 deletions src/core/libraries/kernel/libkernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sys/types.h>

#include "common/types.h"
#include "core/module.h"

namespace Core::Loader {
class SymbolsResolver;
Expand Down Expand Up @@ -34,6 +35,7 @@ typedef struct {

int* PS4_SYSV_ABI __Error();
int PS4_SYSV_ABI sceKernelGetCompiledSdkVersion(int* ver);
int PS4_SYSV_ABI sceKernelGetModuleList(Core::Module** pArray, size_t numArray, size_t* pActualNum);

void LibKernel_Register(Core::Loader::SymbolsResolver* sym);

Expand Down
4 changes: 4 additions & 0 deletions src/core/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,8 @@ void Linker::DebugDump() {
}
}

int Linker::GetNumberModules() const {
return m_modules.size();
}

} // namespace Core
2 changes: 2 additions & 0 deletions src/core/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Linker {
return m_modules.at(index).get();
}

int GetNumberModules() const;

void RelocateAnyImports(Module* m) {
Relocate(m);
for (auto& module : m_modules) {
Expand Down
9 changes: 9 additions & 0 deletions src/core/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ Module::Module(Core::MemoryManager* memory_, const std::filesystem::path& file_,

Module::~Module() = default;

void* Module::FindByName(std::string_view name) {
const auto symbols = export_sym.GetSymbols();
const auto it = std::ranges::find(symbols, name, &Loader::SymbolRecord::nid_name);
if (it != symbols.end()) {
return reinterpret_cast<void*>(it->virtual_address);
}
return nullptr;
}

s32 Module::Start(size_t args, const void* argp, void* param) {
LOG_INFO(Core_Linker, "Module started : {}", name);
const VAddr addr = dynamic_info.init_virtual_addr + GetBaseAddress();
Expand Down
9 changes: 1 addition & 8 deletions src/core/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,7 @@ class Module {
return elf.IsSharedLib();
}

void* FindByName(std::string_view name) {
const auto symbols = export_sym.GetSymbols();
const auto it = std::ranges::find(symbols, name, &Loader::SymbolRecord::nid_name);
if (it != symbols.end()) {
return reinterpret_cast<void*>(it->virtual_address);
}
return nullptr;
}
void* FindByName(std::string_view name);

template <typename T = VAddr>
T GetProcParam() const noexcept {
Expand Down
Loading