Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Wind River Systems, Inc. |
| 3 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: Apache-2.0 |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 5 | */ |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 6 | |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 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 | |
Benjamin Walsh | f6ca7de | 2016-11-08 10:36:50 -0500 | [diff] [blame] | 15 | #include <kernel_structs.h> |
Andrew Boie | 7f4d006 | 2018-07-19 11:09:33 -0700 | [diff] [blame] | 16 | #include <syscall_handler.h> |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 17 | |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 18 | /* |
| 19 | * Define _k_neg_eagain for use in assembly files as errno.h is |
| 20 | * not assembly language safe. |
Andrew Boie | e51c4c2 | 2016-11-07 10:29:53 -0800 | [diff] [blame] | 21 | * FIXME: wastes 4 bytes |
Benjamin Walsh | 456c6da | 2016-09-02 18:55:39 -0400 | [diff] [blame] | 22 | */ |
| 23 | const int _k_neg_eagain = -EAGAIN; |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 24 | |
Benjamin Walsh | 48efb38 | 2016-10-06 16:24:09 -0400 | [diff] [blame] | 25 | #ifdef CONFIG_ERRNO |
Andrew Boie | 7f4d006 | 2018-07-19 11:09:33 -0700 | [diff] [blame] | 26 | #ifdef CONFIG_USERSPACE |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 27 | int *z_impl_z_errno(void) |
Andrew Boie | 7f4d006 | 2018-07-19 11:09:33 -0700 | [diff] [blame] | 28 | { |
| 29 | /* Initialized to the lowest address in the stack so the thread can |
| 30 | * directly read/write it |
| 31 | */ |
Daniel Leung | fc18243 | 2018-08-16 15:42:28 -0700 | [diff] [blame] | 32 | return &_current->userspace_local_data->errno_var; |
Andrew Boie | 7f4d006 | 2018-07-19 11:09:33 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | Z_SYSCALL_HANDLER0_SIMPLE(z_errno); |
| 36 | #else |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 37 | int *z_impl_z_errno(void) |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 38 | { |
Benjamin Walsh | f6ca7de | 2016-11-08 10:36:50 -0500 | [diff] [blame] | 39 | return &_current->errno_var; |
Kumar Gala | d12d8af | 2016-10-05 12:01:54 -0500 | [diff] [blame] | 40 | } |
Andrew Boie | 7f4d006 | 2018-07-19 11:09:33 -0700 | [diff] [blame] | 41 | #endif /* CONFIG_USERSPACE */ |
| 42 | #endif /* CONFIG_ERRNO */ |