From 7ce124e744a0c780025bd58e38b37d846bea6982 Mon Sep 17 00:00:00 2001 From: fincs Date: Tue, 17 May 2016 00:14:32 +0200 Subject: [PATCH] Add svcSetProcessAffinityMask, svcSetProcessIdealProcessor and svcRun --- libctru/include/3ds/svc.h | 37 +++++++++++++++++++++++++++++++++++-- libctru/source/svc.s | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/libctru/include/3ds/svc.h b/libctru/include/3ds/svc.h index 25dcc9b..9667963 100644 --- a/libctru/include/3ds/svc.h +++ b/libctru/include/3ds/svc.h @@ -263,6 +263,16 @@ typedef struct { u64 program_id; ///< Program ID } CodeSetInfo; +/// Information for the main thread of a process. +typedef struct +{ + int priority; ///< Priority of the main thread. + u32 stack_size; ///< Size of the stack of the main thread. + int argc; ///< Unused on retail kernel. + u16* argv; ///< Unused on retail kernel. + u16* envp; ///< Unused on retail kernel. +} StartupInfo; + ///@} /** @@ -529,7 +539,30 @@ Result svcCreateCodeSet(Handle* out, const CodeSetInfo *info, void* code_ptr, vo * @param arm11kernelcaps ARM11 Kernel Capabilities from exheader * @param arm11kernelcaps_num Number of kernel capabilities */ -Result svcCreateProcess(Handle* out, Handle codeset, u32 *arm11kernelcaps, u32 arm11kernelcaps_num); +Result svcCreateProcess(Handle* out, Handle codeset, const u32 *arm11kernelcaps, u32 arm11kernelcaps_num); + +/** + * @brief Sets a process's affinity mask. + * @param process Handle of the process. + * @param affinitymask Pointer to retrieve the affinity masks from. + * @param processorcount Number of processors. + */ +Result svcSetProcessAffinityMask(Handle process, const u8* affinitymask, s32 processorcount); + +/** + * Sets a process's ideal processor. + * @param process Handle of the process. + * @param processorid ID of the thread's ideal processor. + */ +Result svcSetProcessIdealProcessor(Handle process, s32 processorid); + +/** + * Launches the main thread of the process. + * @param process Handle of the process. + * @param info Pointer to a StartupInfo structure describing information for the main thread. + */ +Result svcRun(Handle process, const StartupInfo* info); + ///@} ///@name Multithreading @@ -602,7 +635,7 @@ Result svcGetThreadAffinityMask(u8* affinitymask, Handle thread, s32 processorco * @param affinitymask Pointer to retrieve the affinity masks from. * @param processorcount Number of processors. */ -Result svcSetThreadAffinityMask(Handle thread, u8* affinitymask, s32 processorcount); +Result svcSetThreadAffinityMask(Handle thread, const u8* affinitymask, s32 processorcount); /** * @brief Gets a thread's ideal processor. diff --git a/libctru/source/svc.s b/libctru/source/svc.s index 59560e5..309487b 100644 --- a/libctru/source/svc.s +++ b/libctru/source/svc.s @@ -37,6 +37,14 @@ SVC_BEGIN svcExitProcess svc 0x03 bx lr +SVC_BEGIN svcSetProcessAffinityMask + svc 0x05 + bx lr + +SVC_BEGIN svcSetProcessIdealProcessor + svc 0x07 + bx lr + SVC_BEGIN svcCreateThread push {r0, r4} ldr r0, [sp, #0x8] @@ -89,6 +97,17 @@ SVC_BEGIN svcGetProcessorID svc 0x11 bx lr +SVC_BEGIN svcRun + push {r4,r5} + ldr r2, [r1, #0x04] + ldr r3, [r1, #0x08] + ldr r4, [r1, #0x0C] + ldr r5, [r1, #0x10] + ldr r1, [r1, #0x00] + svc 0x12 + pop {r4,r5} + bx lr + SVC_BEGIN svcCreateMutex str r0, [sp, #-4]! svc 0x13