zephyr/kernel/errno.c
Yong Cong Sin b1def7145f arch: deprecate _current
`_current` is now functionally equals to `arch_curr_thread()`, remove
its usage in-tree and deprecate it instead of removing it outright,
as it has been with us since forever.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-11-23 20:12:24 -05:00

57 lines
1.1 KiB
C

/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
*
* @brief Per-thread errno accessor function
*
* Allow accessing the errno for the current thread without involving the
* context switching.
*/
#include <zephyr/kernel.h>
#include <zephyr/internal/syscall_handler.h>
/*
* Define _k_neg_eagain for use in assembly files as errno.h is
* not assembly language safe.
* FIXME: wastes 4 bytes
*/
const int _k_neg_eagain = -EAGAIN;
#ifdef CONFIG_ERRNO
#if defined(CONFIG_LIBC_ERRNO)
/* nothing needed here */
#elif defined(CONFIG_ERRNO_IN_TLS)
Z_THREAD_LOCAL int z_errno_var;
#else
#ifdef CONFIG_USERSPACE
int *z_impl_z_errno(void)
{
/* Initialized to the lowest address in the stack so the thread can
* directly read/write it
*/
return &arch_current_thread()->userspace_local_data->errno_var;
}
static inline int *z_vrfy_z_errno(void)
{
return z_impl_z_errno();
}
#include <zephyr/syscalls/z_errno_mrsh.c>
#else
int *z_impl_z_errno(void)
{
return &arch_current_thread()->errno_var;
}
#endif /* CONFIG_USERSPACE */
#endif /* CONFIG_ERRNO_IN_TLS */
#endif /* CONFIG_ERRNO */