OSGetUserStackPointer

Syntax

#include <cafe/os.h>

u32 OSGetUserStackPointer(OSThread* thread);

Parameters

thread Pointer to the thread that obtains the user stack pointer(*): The thread specified in this case must be in a suspended state.

* The user stack in this case means the one specified at the time of thread creation.

Return Values

If the specified thread is being suspended, return the user stack pointer. If not, return 0.

Description

This function obtains the user stack pointer for the specified thread. The user stack in this case indicates the one specified at the time of thread creation. Even if an API in SDK has switched stacks by OSSwitchStack or OSSwitchFiber, you can still obtain the latest stack pointer for using the user stack.

OSSwitchStack and OSSwitchFiber save the stack pointer into the OSThread structure of the current thread before switching stacks. In doing so, even when stacks have been switched, the user stack pointer can return.

However, OSCoroutine-related APIs do not save the pointer as described above. (OSCoroutine provides a mechanism to achieve high-speed context switching. For more information on OSCoroutine, see OSInitCoroutine.) It takes some time to obtain the current thread when saving. Because execution speed is especially important to OSCoroutine, it is exempt from saving the user stack pointer. With middleware using OSCoroutine, OSGetUserStackPointer may not function properly.

Even if the application intentionally switches stacks using OSSwitchStack or OSSwitchFiber, you cannot obtain the stack pointer by OSGetUserStackPointer after the switch.

The target thread needs to be in a suspended state.

Do Not Call From

None.

See Also

OSSuspendThread

Revision History

2015/03/10 Removed private note.
2013/05/08 Automated cleanup pass.
2012/07/31 Cleanup Pass
2011/10/14 Initial version.


CONFIDENTIAL