1 /* 2 * Copyright (c) 2018 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_SYS_ERRNO_PRIVATE_H_ 8 #define ZEPHYR_INCLUDE_SYS_ERRNO_PRIVATE_H_ 9 10 #include <zephyr/toolchain.h> 11 #include <zephyr/types.h> /* For Z_THREAD_LOCAL */ 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /* NOTE: located here to avoid include dependency loops between errno.h 18 * and kernel.h 19 */ 20 21 #ifdef CONFIG_LIBC_ERRNO 22 #include <errno.h> 23 z_errno(void)24static inline int *z_errno(void) 25 { 26 return &errno; 27 } 28 29 #elif defined(CONFIG_ERRNO_IN_TLS) 30 extern Z_THREAD_LOCAL int z_errno_var; 31 32 static inline int *z_errno(void) 33 { 34 return &z_errno_var; 35 } 36 #else 37 /** 38 * return a pointer to a memory location containing errno 39 * 40 * errno is thread-specific, and can't just be a global. This pointer 41 * is guaranteed to be read/writable from user mode. 42 * 43 * @return Memory location of errno data for current thread 44 */ 45 __syscall int *z_errno(void); 46 47 #endif /* CONFIG_ERRNO_IN_TLS */ 48 49 #ifdef __cplusplus 50 } 51 #endif 52 53 #if !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO) 54 #include <zephyr/syscalls/errno_private.h> 55 #endif /* CONFIG_ERRNO_IN_TLS */ 56 57 #endif /* ZEPHYR_INCLUDE_SYS_ERRNO_PRIVATE_H_ */ 58