Skip to content
Closed
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
10 changes: 10 additions & 0 deletions core/libs/prx/libSceLibcInternal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ target_link_libraries(libSceLibcInternal PRIVATE ${CMAKE_DL_LIBS})
configure_windows_unwind(libSceLibcInternal)

if(BUILD_TESTING)
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 10)
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)
Expand Down
5 changes: 5 additions & 0 deletions core/libs/prx/libSceLibcInternal/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
Expand Down
30 changes: 30 additions & 0 deletions core/libs/tests/GuestProgramName.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#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 auto* original = __progname_nid_postfix;
const auto savedError = *__error_nid_postfix();
*__error_nid_postfix() = 45;
Require(getprogname_nid_postfix() == original);
Require(std::strcmp(getprogname_nid_postfix(), "eboot.bin") == 0);
char name[] = "guest-program";
__progname_nid_postfix = name;
Require(getprogname_nid_postfix() == name);
name[0] = 'G';
Require(std::strcmp(getprogname_nid_postfix(), "Guest-program") == 0);
__progname_nid_postfix = "";
Require(getprogname_nid_postfix() == __progname_nid_postfix);
Require(*getprogname_nid_postfix() == '\0');
Require(*__error_nid_postfix() == 45);
__progname_nid_postfix = original;
*__error_nid_postfix() = savedError;
}
Loading