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 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /* NOTE: located here to avoid include dependency loops between errno.h
17  * and kernel.h
18  */
19 
20 #ifdef CONFIG_LIBC_ERRNO
21 #include <errno.h>
22 
z_errno(void)23 static inline int *z_errno(void)
24 {
25 	return &errno;
26 }
27 
28 #elif defined(CONFIG_ERRNO_IN_TLS)
29 extern __thread int z_errno_var;
30 
31 static inline int *z_errno(void)
32 {
33 	return &z_errno_var;
34 }
35 #else
36 /**
37  * return a pointer to a memory location containing errno
38  *
39  * errno is thread-specific, and can't just be a global. This pointer
40  * is guaranteed to be read/writable from user mode.
41  *
42  * @return Memory location of errno data for current thread
43  */
44 __syscall int *z_errno(void);
45 
46 #endif /* CONFIG_ERRNO_IN_TLS */
47 
48 #ifdef __cplusplus
49 }
50 #endif
51 
52 #if !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO)
53 #include <syscalls/errno_private.h>
54 #endif /* CONFIG_ERRNO_IN_TLS */
55 
56 #endif /* ZEPHYR_INCLUDE_SYS_ERRNO_PRIVATE_H_ */
57