blob: 3919600d5ff60c5fc070028247f58742a94e92ea [file] [log] [blame]
Kumar Galad12d8af2016-10-05 12:01:54 -05001/*
2 * Copyright (c) 2015 Wind River Systems, Inc.
3 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08004 * SPDX-License-Identifier: Apache-2.0
Kumar Galad12d8af2016-10-05 12:01:54 -05005 */
Benjamin Walsh456c6da2016-09-02 18:55:39 -04006
Kumar Galad12d8af2016-10-05 12:01:54 -05007/** @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
Benjamin Walshf6ca7de2016-11-08 10:36:50 -050015#include <kernel_structs.h>
Andrew Boie7f4d0062018-07-19 11:09:33 -070016#include <syscall_handler.h>
Kumar Galad12d8af2016-10-05 12:01:54 -050017
Benjamin Walsh456c6da2016-09-02 18:55:39 -040018/*
19 * Define _k_neg_eagain for use in assembly files as errno.h is
20 * not assembly language safe.
Andrew Boiee51c4c22016-11-07 10:29:53 -080021 * FIXME: wastes 4 bytes
Benjamin Walsh456c6da2016-09-02 18:55:39 -040022 */
23const int _k_neg_eagain = -EAGAIN;
Kumar Galad12d8af2016-10-05 12:01:54 -050024
Benjamin Walsh48efb382016-10-06 16:24:09 -040025#ifdef CONFIG_ERRNO
Andrew Boie7f4d0062018-07-19 11:09:33 -070026#ifdef CONFIG_USERSPACE
Patrik Flykt4344e272019-03-08 14:19:05 -070027int *z_impl_z_errno(void)
Andrew Boie7f4d0062018-07-19 11:09:33 -070028{
29 /* Initialized to the lowest address in the stack so the thread can
30 * directly read/write it
31 */
Daniel Leungfc182432018-08-16 15:42:28 -070032 return &_current->userspace_local_data->errno_var;
Andrew Boie7f4d0062018-07-19 11:09:33 -070033}
34
35Z_SYSCALL_HANDLER0_SIMPLE(z_errno);
36#else
Patrik Flykt4344e272019-03-08 14:19:05 -070037int *z_impl_z_errno(void)
Kumar Galad12d8af2016-10-05 12:01:54 -050038{
Benjamin Walshf6ca7de2016-11-08 10:36:50 -050039 return &_current->errno_var;
Kumar Galad12d8af2016-10-05 12:01:54 -050040}
Andrew Boie7f4d0062018-07-19 11:09:33 -070041#endif /* CONFIG_USERSPACE */
42#endif /* CONFIG_ERRNO */