feat(libkernel): export POSIX pthread_attr_setstack

This commit is contained in:
mrk1987
2026-10-08 09:21:14 +02:00
parent 6b57386237
commit 137a282d70
2 changed files with 23 additions and 0 deletions
@@ -9,6 +9,7 @@ extern "C" {
int APS5_VABI scePthreadAttrInit(PthreadAttr* attr);
int APS5_VABI scePthreadAttrDestroy(PthreadAttr* attr);
int APS5_VABI scePthreadAttrSetstacksize(PthreadAttr* attr, std::size_t stacksize);
int APS5_VABI scePthreadAttrSetstack(PthreadAttr* attr, void* addr, std::size_t size);
}
static bool Valid(const PthreadAttr* attr) {
@@ -110,6 +111,11 @@ int APS5_VABI pthread_attr_setstacksize_nid_postfix(PthreadAttr* attr, size_t st
return PosixThread::ToErrno(scePthreadAttrSetstacksize(attr, stack_size));
}
int APS5_VABI pthread_attr_setstack_nid_postfix(PthreadAttr* attr, void* stack_addr, size_t stack_size) {
if (!Valid(attr) || !stack_addr || stack_size < 16384) return PosixThread::GUEST_EINVAL;
return PosixThread::ToErrno(scePthreadAttrSetstack(attr, stack_addr, stack_size));
}
int APS5_VABI pthread_attr_setsolosched_np_nid_postfix() {
NotImplemented_nid_no_patch(__func__);
return 0;
+17
View File
@@ -19,6 +19,8 @@ int APS5_VABI scePthreadAttrGetschedparam(const PthreadAttr* attr, KernelSchedPa
int APS5_VABI scePthreadAttrGetaffinity(const PthreadAttr* attr, KernelCpumask* mask);
int APS5_VABI scePthreadAttrGetstacksize(const PthreadAttr* attr, std::size_t* stackSize);
int APS5_VABI scePthreadAttrGetdetachstate(const PthreadAttr* attr, int* state);
int APS5_VABI pthread_attr_setstack_nid_postfix(PthreadAttr* attr, void* addr, std::size_t size);
int APS5_VABI pthread_attr_getstack_nid_postfix(const PthreadAttr* attr, void** addr, std::size_t* size);
}
static constexpr int SCE_OK = 0;
@@ -61,6 +63,21 @@ static void* APS5_VABI Worker(void* arg) {
}
int main() {
PthreadAttr stackAttr = nullptr;
char stackMarker;
Require(pthread_attr_setstack_nid_postfix(nullptr, &stackMarker, STACK_SIZE) == 22);
Require(pthread_attr_setstack_nid_postfix(&stackAttr, &stackMarker, STACK_SIZE) == 22);
Require(scePthreadAttrInit(&stackAttr) == SCE_OK);
Require(pthread_attr_setstack_nid_postfix(&stackAttr, &stackMarker, STACK_SIZE) == 0);
Require(pthread_attr_setstack_nid_postfix(&stackAttr, nullptr, STACK_SIZE) == 22);
Require(pthread_attr_setstack_nid_postfix(&stackAttr, &stackMarker, 16383) == 22);
void* reportedAddress = nullptr;
std::size_t reportedSize = 0;
Require(pthread_attr_getstack_nid_postfix(&stackAttr, &reportedAddress, &reportedSize) == 0);
Require(reportedAddress == &stackMarker && reportedSize == STACK_SIZE);
Require(scePthreadAttrDestroy(&stackAttr) == SCE_OK);
Require(pthread_attr_setstack_nid_postfix(&stackAttr, &stackMarker, STACK_SIZE) == 22);
PthreadAttr attr = nullptr;
Require(scePthreadAttrInit(&attr) == SCE_OK);
Require(scePthreadAttrSetinheritsched(&attr, EXPLICIT_SCHED) == SCE_OK);