kernel: fix errno access for user mode

The errno "variable" is required to be thread-specific.
It gets defined to a macro which dereferences a pointer
returned by a kernel function.

In user mode, we cannot simply read/write the thread struct.
We do not have thread-local storage mechanism, so for now
use the lowest address of the thread stack to store this
value, since this is guaranteed to be read/writable by
a user thread.

The downside of this approach is potential stack corruption
if the stack pointer goes down this far but does not exceed
the location, since a fault won't be generated in this case.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2018-07-19 11:09:33 -07:00 committed by Andrew Boie
commit 7f4d006959
6 changed files with 69 additions and 5 deletions

View file

@ -11,6 +11,7 @@
#include <linker/linker-defs.h>
#include <misc/util.h>
#include <kernel_internal.h>
#include <misc/errno_private.h>
#define USED_RAM_END_ADDR POINTER_TO_UINT(&_end)
@ -178,3 +179,8 @@ void z_newlib_get_heap_bounds(void **base, size_t *size)
*base = heap_base;
*size = MAX_HEAP_SIZE;
}
int *__errno(void)
{
return z_errno();
}