Merge pull request #3347 from overlordxrz-source/feat/libc-getprogname

feat(libSceLibcInternal): implement getprogname
This commit is contained in:
Adrià 2026-10-11 10:49:27 +02:00 committed by GitHub
commit f38dc53d0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 47 additions and 0 deletions

View File

@ -19,6 +19,16 @@ if(BUILD_TESTING)
set_tests_properties(guest_utime PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
endif()
add_test_executable(guest_program_name_tests ${LIBS_INCLUDE_DIR}/tests/GuestProgramName.cpp)
target_include_directories(guest_program_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_program_name_tests PRIVATE libSceLibcInternal libkernel libc)
configure_windows_unwind(guest_program_name_tests)
add_test(NAME guest_program_name COMMAND guest_program_name_tests)
set_tests_properties(guest_program_name PROPERTIES TIMEOUT 20)
if(WIN32)
set_tests_properties(guest_program_name PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
endif()
add_test_executable(guest_thread_atexit_tests ${LIBS_INCLUDE_DIR}/tests/GuestThreadAtexit.cpp)
target_include_directories(guest_thread_atexit_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_thread_atexit_tests PRIVATE libSceLibcInternal libkernel libc)

View File

@ -15,6 +15,7 @@
extern "C" void APS5_VABI sceKernelSetThreadDtors(thread_dtors_func_t dtors);
extern "C" int APS5_VABI sceKernelGetModuleInfoFromAddr(std::uint64_t address, int flags, ModuleInfoEx* info);
extern "C" const char* __progname_nid_postfix;
namespace {
@ -104,6 +105,10 @@ extern "C" {
int Need_sceLibcInternal_nid_postfix = 1;
const char* APS5_VABI getprogname_nid_postfix() {
return __progname_nid_postfix;
}
void APS5_VABI __cxa_finalize_nid_postfix(void* dsoHandle) {
CxaFinalize_nid_no_patch(dsoHandle);
}

View File

@ -0,0 +1,32 @@
#include "SceTypes.hpp"
#include <cstdlib>
#include <cstring>
extern "C" {
const char* APS5_VABI getprogname_nid_postfix();
extern const char* __progname_nid_postfix;
int* APS5_VABI __error_nid_postfix();
}
static void Require(bool value) { if (!value) std::abort(); }
int main() {
const char* const original = __progname_nid_postfix;
*__error_nid_postfix() = 45;
Require(getprogname_nid_postfix() == original);
Require(std::strcmp(getprogname_nid_postfix(), "eboot.bin") == 0);
Require(*__error_nid_postfix() == 45);
char renamed[] = "quake2";
__progname_nid_postfix = renamed;
Require(getprogname_nid_postfix() == renamed);
renamed[0] = 'Q';
Require(std::strcmp(getprogname_nid_postfix(), "Quake2") == 0);
__progname_nid_postfix = "";
Require(getprogname_nid_postfix()[0] == '\0');
__progname_nid_postfix = original;
Require(getprogname_nid_postfix() == original);
Require(*__error_nid_postfix() == 45);
}