Skip to content

Commit 76b4ec4

Browse files
committed
read only sdk version this way
1 parent e0fffd4 commit 76b4ec4

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

src/core/libraries/kernel/process.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ s32 PS4_SYSV_ABI sceKernelGetMainSocId() {
3636
}
3737

3838
s32 PS4_SYSV_ABI sceKernelGetCompiledSdkVersion(s32* ver) {
39-
auto* param = Core::Linker::GetProcParam();
40-
constexpr u64 min_size = offsetof(Core::OrbisProcParam, sdk_version) + sizeof(u64);
41-
if (!param || param->size < min_size || param->sdk_version == 0) {
39+
if (!ver) {
4240
return ORBIS_KERNEL_ERROR_EINVAL;
4341
}
44-
*ver = param->sdk_version;
42+
*ver = Core::Linker::GetCompiledSdkVersion();
4543
return ORBIS_OK;
4644
}
4745

@@ -65,7 +63,8 @@ s32 PS4_SYSV_ABI sceKernelGetCurrentCpu() {
6563
}
6664

6765
void* PS4_SYSV_ABI sceKernelGetProcParam() {
68-
return Core::Linker::GetProcParam();
66+
auto* linker = Common::Singleton<Core::Linker>::Instance();
67+
return linker->GetProcParam();
6968
}
7069

7170
s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, u64 args, const void* argp,

src/core/linker.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static PS4_SYSV_ABI void* RunMainEntry [[noreturn]] (EntryParams* params) {
5151
}
5252
#endif
5353

54-
OrbisProcParam Linker::s_proc_param{};
54+
s32 Linker::s_compiled_sdk_version{};
5555

5656
Linker::Linker() : memory{Memory::Instance()} {}
5757

@@ -182,7 +182,7 @@ s32 Linker::LoadAndStartModule(const std::filesystem::path& path, u64 args, cons
182182
}
183183

184184
// Retrieve and verify proc param according to libkernel.
185-
auto* param = GetProcParam();
185+
auto* param = module->GetProcParam<OrbisProcParam*>();
186186
ASSERT_MSG(!param || param->size >= 0x18, "Invalid module param size: {}", param->size);
187187
s32 ret = module->Start(args, argp, param);
188188
if (pRes) {
@@ -450,7 +450,7 @@ void Linker::DebugDump() {
450450
}
451451
}
452452

453-
void Linker::InitializeProcParams(const std::filesystem::path& file) {
453+
void Linker::ReadCompiledSdkVersion(const std::filesystem::path& file) {
454454
Core::Loader::Elf elf;
455455
elf.Open(file);
456456
if (!elf.IsElfFile()) {
@@ -462,7 +462,9 @@ void Linker::InitializeProcParams(const std::filesystem::path& file) {
462462

463463
if (it != elf_pheader.end()) {
464464
// Initialize Proc Param in Linker
465-
elf.LoadSegment(u64(Core::Linker::GetProcParam()), it->p_offset, it->p_filesz);
465+
Core::OrbisProcParam param{};
466+
elf.LoadSegment(u64(&param), it->p_offset, it->p_filesz);
467+
s_compiled_sdk_version = param.sdk_version;
466468
}
467469
}
468470

src/core/linker.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ class Linker {
7878
return m_hle_symbols;
7979
}
8080

81-
static OrbisProcParam* GetProcParam() {
82-
return &s_proc_param;
81+
static s32 GetCompiledSdkVersion() {
82+
return s_compiled_sdk_version;
83+
}
84+
85+
OrbisProcParam* GetProcParam() {
86+
return m_modules[0]->GetProcParam<OrbisProcParam*>();
8387
}
8488

8589
Module* GetModule(s32 index) const {
@@ -156,7 +160,7 @@ class Linker {
156160
void Execute(const std::vector<std::string>& args = {});
157161
void DebugDump();
158162

159-
static void InitializeProcParams(const std::filesystem::path& elf);
163+
static void ReadCompiledSdkVersion(const std::filesystem::path& elf);
160164

161165
private:
162166
const Module* FindExportedModule(const ModuleInfo& m, const LibraryInfo& l);
@@ -172,7 +176,7 @@ class Linker {
172176
std::vector<std::unique_ptr<Module>> m_modules;
173177
Loader::SymbolsResolver m_hle_symbols{};
174178

175-
static OrbisProcParam s_proc_param;
179+
static s32 s_compiled_sdk_version;
176180
};
177181

178182
} // namespace Core

src/core/module.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ void Module::LoadModuleToMemory(u32& max_tls_index) {
199199
LOG_INFO(Core_Linker, "TLS virtual address = {:#x}", tls.image_virtual_addr);
200200
LOG_INFO(Core_Linker, "TLS image size = {}", tls.image_size);
201201
break;
202+
case PT_SCE_PROCPARAM:
203+
proc_param_virtual_addr = elf_pheader[i].p_vaddr + base_virtual_addr;
204+
break;
202205
case PT_GNU_EH_FRAME: {
203206
eh_frame_hdr_addr = elf_pheader[i].p_vaddr;
204207
eh_frame_hdr_size = elf_pheader[i].p_memsz;

src/core/module.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ class Module {
164164
return elf.IsSharedLib();
165165
}
166166

167+
template <typename T = VAddr>
168+
T GetProcParam() const noexcept {
169+
return reinterpret_cast<T>(proc_param_virtual_addr);
170+
}
171+
167172
std::span<const ModuleInfo> GetImportModules() const {
168173
return dynamic_info.import_modules;
169174
}
@@ -215,6 +220,7 @@ class Module {
215220
Loader::Elf elf;
216221
u64 aligned_base_size{};
217222
VAddr base_virtual_addr{};
223+
VAddr proc_param_virtual_addr{};
218224
VAddr eh_frame_hdr_addr{};
219225
VAddr eh_frame_addr{};
220226
u32 eh_frame_hdr_size{};

src/emulator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void Emulator::Run(std::filesystem::path file, std::vector<std::string> args,
173173

174174
auto guest_eboot_path = "/app0/" + eboot_name.generic_string();
175175
const auto eboot_path = mnt->GetHostPath(guest_eboot_path);
176-
Linker::InitializeProcParams(eboot_path);
176+
Linker::ReadCompiledSdkVersion(eboot_path);
177177

178178
const auto pic1_path = mnt->GetHostPath("/app0/sce_sys/pic1.png");
179179
if (std::filesystem::exists(pic1_path)) {
@@ -244,8 +244,8 @@ void Emulator::Run(std::filesystem::path file, std::vector<std::string> args,
244244
if (param_sfo_exists) {
245245
LOG_INFO(Loader, "Game id: {} Title: {}", id, title);
246246
LOG_INFO(Loader, "Fw: {:#x} App Version: {}", fw_version, app_version);
247-
LOG_INFO(Loader, "params.sfo SDK version: {:#x}", sdk_version);
248-
LOG_INFO(Loader, "eboot SDK version: {:#x}", Linker::GetProcParam()->sdk_version);
247+
LOG_INFO(Loader, "param.sfo SDK version: {:#x}", sdk_version);
248+
LOG_INFO(Loader, "eboot SDK version: {:#x}", Linker::GetCompiledSdkVersion());
249249
LOG_INFO(Loader, "PSVR Supported: {}", (bool)psf_attributes.support_ps_vr.Value());
250250
LOG_INFO(Loader, "PSVR Required: {}", (bool)psf_attributes.require_ps_vr.Value());
251251
}

0 commit comments

Comments
 (0)