#import <pthread.h>
pthread_t currentThread = pthread_self();
uint8_t *endStack = pthread_get_stackaddr_np(currentThread);
size_t totalStackSize = pthread_get_stacksize_np(currentThread);
uint8_t *frameAddr = __builtin_frame_address(0);
size_t remainingStackSize = totalStackSize - (size_t)(endStack - frameAddr);