1 /* 2 * Copyright (c) 2015 Wind River Systems, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** @file 8 * 9 * @brief Per-thread errno accessor function 10 * 11 * Allow accessing the errno for the current thread without involving the 12 * context switching. 13 */ 14 15 #include <kernel.h> 16 #include <syscall_handler.h> 17 18 /* 19 * Define _k_neg_eagain for use in assembly files as errno.h is 20 * not assembly language safe. 21 * FIXME: wastes 4 bytes 22 */ 23 const int _k_neg_eagain = -EAGAIN; 24 25 #ifdef CONFIG_ERRNO 26 27 #ifdef CONFIG_ERRNO_IN_TLS 28 __thread int z_errno_var; 29 #else 30 31 #ifdef CONFIG_USERSPACE z_impl_z_errno(void)32int *z_impl_z_errno(void) 33 { 34 /* Initialized to the lowest address in the stack so the thread can 35 * directly read/write it 36 */ 37 return &_current->userspace_local_data->errno_var; 38 } 39 z_vrfy_z_errno(void)40static inline int *z_vrfy_z_errno(void) 41 { 42 return z_impl_z_errno(); 43 } 44 #include <syscalls/z_errno_mrsh.c> 45 46 #else z_impl_z_errno(void)47int *z_impl_z_errno(void) 48 { 49 return &_current->errno_var; 50 } 51 #endif /* CONFIG_USERSPACE */ 52 53 #endif /* CONFIG_ERRNO_IN_TLS */ 54 55 #endif /* CONFIG_ERRNO */ 56