Files
PariotandDean Galvin 7b2370120c feat(libkernel_sys): implement pthread_getstack_np (#15111)
* feat(libkernel_sys): implement pthread_getstack_np
* fix: drop duplicate merge leftovers

Co-authored-by: Dean Galvin <dean.galvin@live.com>
2026-11-19 02:27:29 +13:00

43 lines
1.5 KiB
C++

#include "prx/libkernel_sys/include/Api.hpp"
#include "prx/libc/include/General.hpp"
#include "prx/libkernel/KernelErrors.hpp"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include "prx/libc/include/general/VabiMacros.hpp"
#include "prx/libc/include/General.hpp"
#include "prx/libkernel/include/Api.hpp"
#include "prx/libkernel/Pthread/include/Pthread.hpp"
extern "C" {
bool IsInitialPthread_nid_no_patch();
bool LiveGuestThreadName_nid_no_patch(std::int64_t tid, char* name, std::size_t capacity);
int APS5_VABI pthread_main_np_nid_postfix() {
return IsInitialPthread_nid_no_patch() ? 1 : 0;
}
int APS5_VABI scePthreadMain(void) {
return pthread_main_np_nid_postfix();
}
int APS5_VABI pthread_getstack_np_nid_postfix(void** stackAddress, std::size_t* stackSize) {
const Pthread thread = pthread_self_nid_postfix();
const void* address = thread->stackAddress;
const std::size_t size = thread->stackSize;
if (!GuestCopyOut_nid_no_patch(stackAddress, &address, sizeof(address))) return 14;
if (!GuestCopyOut_nid_no_patch(stackSize, &size, sizeof(size))) return 14;
return static_cast<int>(size);
}
int APS5_VABI sceKernelGetThreadName(uint32_t id, char* name) {
constexpr std::size_t capacity = 32;
char found[capacity];
if (!LiveGuestThreadName_nid_no_patch(id, found, capacity)) return SCE_KERNEL_ERROR_ESRCH;
if (!GuestCopyOut_nid_no_patch(name, found, std::strlen(found) + 1)) return SCE_KERNEL_ERROR_EFAULT;
return 0;
}
}