mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-09-18 06:51:56 +00:00
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>
37 lines
698 B
C
37 lines
698 B
C
/*
|
|
* Copyright (c) 2018 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef _MISC_ERRNO_PRIVATE_H_
|
|
#define _MISC_ERRNO_PRIVATE_H_
|
|
|
|
#include <toolchain.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* NOTE: located here to avoid include dependency loops between errno.h
|
|
* and kernel.h
|
|
*/
|
|
|
|
/**
|
|
* return a pointer to a memory location containing errno
|
|
*
|
|
* errno is thread-specific, and can't just be a global. This pointer
|
|
* is guaranteed to be read/writable from user mode.
|
|
*
|
|
* @return Memory location of errno data for current thread
|
|
*/
|
|
__syscall int *z_errno(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#include <syscalls/errno_private.h>
|
|
|
|
#endif /* _MISC_ERRNO_PRIVATE_H */
|