Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Intel Corporation |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | |
| 7 | |
Gerard Marull-Paretas | cffefc8 | 2022-05-06 11:04:23 +0200 | [diff] [blame] | 8 | #include <zephyr/kernel.h> |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 9 | #include <string.h> |
Gerard Marull-Paretas | cffefc8 | 2022-05-06 11:04:23 +0200 | [diff] [blame] | 10 | #include <zephyr/sys/math_extras.h> |
| 11 | #include <zephyr/sys/rb.h> |
| 12 | #include <zephyr/kernel_structs.h> |
| 13 | #include <zephyr/sys/sys_io.h> |
Andrew Boie | 5cfa5dc | 2017-08-30 14:17:44 -0700 | [diff] [blame] | 14 | #include <ksched.h> |
Gerard Marull-Paretas | cffefc8 | 2022-05-06 11:04:23 +0200 | [diff] [blame] | 15 | #include <zephyr/syscall.h> |
Anas Nashif | 4e39617 | 2023-09-26 22:46:01 +0000 | [diff] [blame] | 16 | #include <zephyr/internal/syscall_handler.h> |
Gerard Marull-Paretas | cffefc8 | 2022-05-06 11:04:23 +0200 | [diff] [blame] | 17 | #include <zephyr/device.h> |
| 18 | #include <zephyr/init.h> |
Flavio Ceolin | 8a14817 | 2018-12-16 12:39:44 -0800 | [diff] [blame] | 19 | #include <stdbool.h> |
Gerard Marull-Paretas | cffefc8 | 2022-05-06 11:04:23 +0200 | [diff] [blame] | 20 | #include <zephyr/app_memory/app_memdomain.h> |
| 21 | #include <zephyr/sys/libc-hooks.h> |
| 22 | #include <zephyr/sys/mutex.h> |
Andrew Boie | 800b35f | 2019-11-05 09:27:18 -0800 | [diff] [blame] | 23 | #include <inttypes.h> |
Gerard Marull-Paretas | cffefc8 | 2022-05-06 11:04:23 +0200 | [diff] [blame] | 24 | #include <zephyr/linker/linker-defs.h> |
Andrew Boie | 17ce822 | 2019-02-21 13:44:54 -0800 | [diff] [blame] | 25 | |
Andrew Boie | 7707060 | 2019-02-27 20:12:40 -0800 | [diff] [blame] | 26 | #ifdef Z_LIBC_PARTITION_EXISTS |
Andrew Boie | 17ce822 | 2019-02-21 13:44:54 -0800 | [diff] [blame] | 27 | K_APPMEM_PARTITION_DEFINE(z_libc_partition); |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 28 | #endif /* Z_LIBC_PARTITION_EXISTS */ |
Anas Nashif | 0a0c8c8 | 2018-09-17 06:58:09 -0500 | [diff] [blame] | 29 | |
Andrew Boie | e686aef | 2019-02-27 14:41:45 -0800 | [diff] [blame] | 30 | /* TODO: Find a better place to put this. Since we pull the entire |
Anas Nashif | 6e27d6d | 2019-05-09 08:43:30 -0400 | [diff] [blame] | 31 | * lib..__modules__crypto__mbedtls.a globals into app shared memory |
| 32 | * section, we can't put this in zephyr_init.c of the mbedtls module. |
Andrew Boie | e686aef | 2019-02-27 14:41:45 -0800 | [diff] [blame] | 33 | */ |
| 34 | #ifdef CONFIG_MBEDTLS |
| 35 | K_APPMEM_PARTITION_DEFINE(k_mbedtls_partition); |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 36 | #endif /* CONFIG_MBEDTLS */ |
Andrew Boie | e686aef | 2019-02-27 14:41:45 -0800 | [diff] [blame] | 37 | |
Gerard Marull-Paretas | cffefc8 | 2022-05-06 11:04:23 +0200 | [diff] [blame] | 38 | #include <zephyr/logging/log.h> |
Krzysztof Chruscinski | 3ed8083 | 2020-11-26 19:32:34 +0100 | [diff] [blame] | 39 | LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); |
Anas Nashif | 0a0c8c8 | 2018-09-17 06:58:09 -0500 | [diff] [blame] | 40 | |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 41 | /* The originally synchronization strategy made heavy use of recursive |
| 42 | * irq_locking, which ports poorly to spinlocks which are |
| 43 | * non-recursive. Rather than try to redesign as part of |
| 44 | * spinlockification, this uses multiple locks to preserve the |
| 45 | * original semantics exactly. The locks are named for the data they |
| 46 | * protect where possible, or just for the code that uses them where |
| 47 | * not. |
| 48 | */ |
| 49 | #ifdef CONFIG_DYNAMIC_OBJECTS |
Flavio Ceolin | 2b1106a | 2023-07-14 12:24:33 -0700 | [diff] [blame] | 50 | static struct k_spinlock lists_lock; /* kobj dlist */ |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 51 | static struct k_spinlock objfree_lock; /* k_object_free */ |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 52 | |
| 53 | #ifdef CONFIG_GEN_PRIV_STACKS |
Nikolay Agishev | baeda6a | 2023-09-20 15:35:58 +0300 | [diff] [blame] | 54 | /* On ARM & ARC MPU we may have two different alignment requirement |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 55 | * when dynamically allocating thread stacks, one for the privileged |
| 56 | * stack and other for the user stack, so we need to account the |
| 57 | * worst alignment scenario and reserve space for that. |
| 58 | */ |
Nikolay Agishev | baeda6a | 2023-09-20 15:35:58 +0300 | [diff] [blame] | 59 | #if defined(CONFIG_ARM_MPU) || defined(CONFIG_ARC_MPU) |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 60 | #define STACK_ELEMENT_DATA_SIZE(size) \ |
| 61 | (sizeof(struct z_stack_data) + CONFIG_PRIVILEGED_STACK_SIZE + \ |
Daniel Leung | d34351d | 2024-03-22 14:11:49 -0700 | [diff] [blame] | 62 | Z_THREAD_STACK_OBJ_ALIGN(size) + K_THREAD_STACK_LEN(size)) |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 63 | #else |
| 64 | #define STACK_ELEMENT_DATA_SIZE(size) (sizeof(struct z_stack_data) + \ |
Daniel Leung | d34351d | 2024-03-22 14:11:49 -0700 | [diff] [blame] | 65 | K_THREAD_STACK_LEN(size)) |
Nikolay Agishev | baeda6a | 2023-09-20 15:35:58 +0300 | [diff] [blame] | 66 | #endif /* CONFIG_ARM_MPU || CONFIG_ARC_MPU */ |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 67 | #else |
Daniel Leung | d34351d | 2024-03-22 14:11:49 -0700 | [diff] [blame] | 68 | #define STACK_ELEMENT_DATA_SIZE(size) K_THREAD_STACK_LEN(size) |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 69 | #endif /* CONFIG_GEN_PRIV_STACKS */ |
| 70 | |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 71 | #endif /* CONFIG_DYNAMIC_OBJECTS */ |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 72 | static struct k_spinlock obj_lock; /* kobj struct data */ |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 73 | |
Andrew Boie | 2574219 | 2017-10-16 15:29:30 -0700 | [diff] [blame] | 74 | #define MAX_THREAD_BITS (CONFIG_MAX_THREAD_BYTES * 8) |
| 75 | |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 76 | #ifdef CONFIG_DYNAMIC_OBJECTS |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 77 | extern uint8_t _thread_idx_map[CONFIG_MAX_THREAD_BYTES]; |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 78 | #endif /* CONFIG_DYNAMIC_OBJECTS */ |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 79 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 80 | static void clear_perms_cb(struct k_object *ko, void *ctx_ptr); |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 81 | |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 82 | const char *otype_to_str(enum k_objects otype) |
| 83 | { |
Flavio Ceolin | 3259ac0 | 2018-09-11 13:14:21 -0700 | [diff] [blame] | 84 | const char *ret; |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 85 | /* -fdata-sections doesn't work right except in very very recent |
| 86 | * GCC and these literal strings would appear in the binary even if |
| 87 | * otype_to_str was omitted by the linker |
| 88 | */ |
Andrew Boie | cb1dd74 | 2019-10-01 10:28:32 -0700 | [diff] [blame] | 89 | #ifdef CONFIG_LOG |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 90 | switch (otype) { |
Leandro Pereira | 39dc7d0 | 2018-04-05 13:59:33 -0700 | [diff] [blame] | 91 | /* otype-to-str.h is generated automatically during build by |
| 92 | * gen_kobject_list.py |
| 93 | */ |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 94 | case K_OBJ_ANY: |
| 95 | ret = "generic"; |
| 96 | break; |
Yong Cong Sin | bbe5e1e | 2024-01-24 17:35:04 +0800 | [diff] [blame] | 97 | #include <zephyr/otype-to-str.h> |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 98 | default: |
Flavio Ceolin | 3259ac0 | 2018-09-11 13:14:21 -0700 | [diff] [blame] | 99 | ret = "?"; |
| 100 | break; |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 101 | } |
| 102 | #else |
| 103 | ARG_UNUSED(otype); |
Maksim Masalski | d6c9d40 | 2021-05-24 16:30:32 +0800 | [diff] [blame] | 104 | ret = NULL; |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 105 | #endif /* CONFIG_LOG */ |
Flavio Ceolin | 3259ac0 | 2018-09-11 13:14:21 -0700 | [diff] [blame] | 106 | return ret; |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Andrew Boie | 47f8fd1 | 2017-10-05 11:11:02 -0700 | [diff] [blame] | 109 | struct perm_ctx { |
| 110 | int parent_id; |
| 111 | int child_id; |
| 112 | struct k_thread *parent; |
| 113 | }; |
| 114 | |
Andrew Boie | 28be793 | 2020-03-11 10:56:19 -0700 | [diff] [blame] | 115 | #ifdef CONFIG_GEN_PRIV_STACKS |
Anas Nashif | efbadbb | 2022-07-11 10:53:29 -0400 | [diff] [blame] | 116 | /* See write_gperf_table() in scripts/build/gen_kobject_list.py. The privilege |
Andrew Boie | 28be793 | 2020-03-11 10:56:19 -0700 | [diff] [blame] | 117 | * mode stacks are allocated as an array. The base of the array is |
| 118 | * aligned to Z_PRIVILEGE_STACK_ALIGN, and all members must be as well. |
| 119 | */ |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 120 | uint8_t *z_priv_stack_find(k_thread_stack_t *stack) |
Andrew Boie | 28be793 | 2020-03-11 10:56:19 -0700 | [diff] [blame] | 121 | { |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 122 | struct k_object *obj = k_object_find(stack); |
Andrew Boie | 28be793 | 2020-03-11 10:56:19 -0700 | [diff] [blame] | 123 | |
| 124 | __ASSERT(obj != NULL, "stack object not found"); |
| 125 | __ASSERT(obj->type == K_OBJ_THREAD_STACK_ELEMENT, |
| 126 | "bad stack object"); |
| 127 | |
| 128 | return obj->data.stack_data->priv; |
| 129 | } |
| 130 | #endif /* CONFIG_GEN_PRIV_STACKS */ |
| 131 | |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 132 | #ifdef CONFIG_DYNAMIC_OBJECTS |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * Note that dyn_obj->data is where the kernel object resides |
| 136 | * so it is the one that actually needs to be aligned. |
Jordan Yates | 0787093 | 2024-06-21 18:37:21 +1000 | [diff] [blame] | 137 | * Due to the need to get the fields inside struct dyn_obj |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 138 | * from kernel object pointers (i.e. from data[]), the offset |
| 139 | * from data[] needs to be fixed at build time. Therefore, |
| 140 | * data[] is declared with __aligned(), such that when dyn_obj |
| 141 | * is allocated with alignment, data[] is also aligned. |
| 142 | * Due to this requirement, data[] needs to be aligned with |
| 143 | * the maximum alignment needed for all kernel objects |
| 144 | * (hence the following DYN_OBJ_DATA_ALIGN). |
| 145 | */ |
Peter Mitsis | 48f5164 | 2021-12-16 12:47:32 -0500 | [diff] [blame] | 146 | #ifdef ARCH_DYNAMIC_OBJ_K_THREAD_ALIGNMENT |
| 147 | #define DYN_OBJ_DATA_ALIGN_K_THREAD (ARCH_DYNAMIC_OBJ_K_THREAD_ALIGNMENT) |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 148 | #else |
| 149 | #define DYN_OBJ_DATA_ALIGN_K_THREAD (sizeof(void *)) |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 150 | #endif /* ARCH_DYNAMIC_OBJ_K_THREAD_ALIGNMENT */ |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 151 | |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 152 | #ifdef CONFIG_DYNAMIC_THREAD_STACK_SIZE |
| 153 | #ifndef CONFIG_MPU_STACK_GUARD |
| 154 | #define DYN_OBJ_DATA_ALIGN_K_THREAD_STACK \ |
| 155 | Z_THREAD_STACK_OBJ_ALIGN(CONFIG_PRIVILEGED_STACK_SIZE) |
| 156 | #else |
| 157 | #define DYN_OBJ_DATA_ALIGN_K_THREAD_STACK \ |
| 158 | Z_THREAD_STACK_OBJ_ALIGN(CONFIG_DYNAMIC_THREAD_STACK_SIZE) |
| 159 | #endif /* !CONFIG_MPU_STACK_GUARD */ |
| 160 | #else |
| 161 | #define DYN_OBJ_DATA_ALIGN_K_THREAD_STACK \ |
| 162 | Z_THREAD_STACK_OBJ_ALIGN(ARCH_STACK_PTR_ALIGN) |
| 163 | #endif /* CONFIG_DYNAMIC_THREAD_STACK_SIZE */ |
| 164 | |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 165 | #define DYN_OBJ_DATA_ALIGN \ |
| 166 | MAX(DYN_OBJ_DATA_ALIGN_K_THREAD, (sizeof(void *))) |
| 167 | |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 168 | struct dyn_obj { |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 169 | struct k_object kobj; |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 170 | sys_dnode_t dobj_list; |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 171 | |
| 172 | /* The object itself */ |
| 173 | void *data; |
| 174 | }; |
| 175 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 176 | extern struct k_object *z_object_gperf_find(const void *obj); |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 177 | extern void z_object_gperf_wordlist_foreach(_wordlist_cb_func_t func, |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 178 | void *context); |
| 179 | |
Andrew Boie | 97bf001 | 2018-04-24 17:01:37 -0700 | [diff] [blame] | 180 | /* |
| 181 | * Linked list of allocated kernel objects, for iteration over all allocated |
| 182 | * objects (and potentially deleting them during iteration). |
| 183 | */ |
| 184 | static sys_dlist_t obj_list = SYS_DLIST_STATIC_INIT(&obj_list); |
| 185 | |
| 186 | /* |
Flavio Ceolin | 2b1106a | 2023-07-14 12:24:33 -0700 | [diff] [blame] | 187 | * TODO: Write some hash table code that will replace obj_list. |
Andrew Boie | 97bf001 | 2018-04-24 17:01:37 -0700 | [diff] [blame] | 188 | */ |
| 189 | |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 190 | static size_t obj_size_get(enum k_objects otype) |
| 191 | { |
Flavio Ceolin | 3259ac0 | 2018-09-11 13:14:21 -0700 | [diff] [blame] | 192 | size_t ret; |
| 193 | |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 194 | switch (otype) { |
Yong Cong Sin | bbe5e1e | 2024-01-24 17:35:04 +0800 | [diff] [blame] | 195 | #include <zephyr/otype-to-size.h> |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 196 | default: |
Tomasz Bursztyka | e18fcbb | 2020-04-30 20:33:38 +0200 | [diff] [blame] | 197 | ret = sizeof(const struct device); |
Flavio Ceolin | 3259ac0 | 2018-09-11 13:14:21 -0700 | [diff] [blame] | 198 | break; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 199 | } |
Flavio Ceolin | 3259ac0 | 2018-09-11 13:14:21 -0700 | [diff] [blame] | 200 | |
| 201 | return ret; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 204 | static size_t obj_align_get(enum k_objects otype) |
| 205 | { |
| 206 | size_t ret; |
| 207 | |
| 208 | switch (otype) { |
| 209 | case K_OBJ_THREAD: |
Peter Mitsis | 48f5164 | 2021-12-16 12:47:32 -0500 | [diff] [blame] | 210 | #ifdef ARCH_DYNAMIC_OBJ_K_THREAD_ALIGNMENT |
| 211 | ret = ARCH_DYNAMIC_OBJ_K_THREAD_ALIGNMENT; |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 212 | #else |
Daniel Leung | b6dd960 | 2021-12-13 14:54:51 -0800 | [diff] [blame] | 213 | ret = __alignof(struct dyn_obj); |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 214 | #endif /* ARCH_DYNAMIC_OBJ_K_THREAD_ALIGNMENT */ |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 215 | break; |
| 216 | default: |
Daniel Leung | b6dd960 | 2021-12-13 14:54:51 -0800 | [diff] [blame] | 217 | ret = __alignof(struct dyn_obj); |
Daniel Leung | fe477ea | 2020-12-15 13:50:48 -0800 | [diff] [blame] | 218 | break; |
| 219 | } |
| 220 | |
| 221 | return ret; |
| 222 | } |
| 223 | |
Hess Nathan | e05c4a8 | 2024-05-07 13:22:50 +0200 | [diff] [blame] | 224 | static struct dyn_obj *dyn_object_find(const void *obj) |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 225 | { |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 226 | struct dyn_obj *node; |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 227 | k_spinlock_key_t key; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 228 | |
| 229 | /* For any dynamically allocated kernel object, the object |
Naiyuan Tian | bc3fda4 | 2021-08-23 23:32:58 +0800 | [diff] [blame] | 230 | * pointer is just a member of the containing struct dyn_obj, |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 231 | * so just a little arithmetic is necessary to locate the |
| 232 | * corresponding struct rbnode |
| 233 | */ |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 234 | key = k_spin_lock(&lists_lock); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 235 | |
Flavio Ceolin | 2b1106a | 2023-07-14 12:24:33 -0700 | [diff] [blame] | 236 | SYS_DLIST_FOR_EACH_CONTAINER(&obj_list, node, dobj_list) { |
| 237 | if (node->kobj.name == obj) { |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 238 | goto end; |
| 239 | } |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 240 | } |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 241 | |
| 242 | /* No object found */ |
Flavio Ceolin | 2b1106a | 2023-07-14 12:24:33 -0700 | [diff] [blame] | 243 | node = NULL; |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 244 | |
| 245 | end: |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 246 | k_spin_unlock(&lists_lock, key); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 247 | |
Flavio Ceolin | 2b1106a | 2023-07-14 12:24:33 -0700 | [diff] [blame] | 248 | return node; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 251 | /** |
| 252 | * @internal |
| 253 | * |
| 254 | * @brief Allocate a new thread index for a new thread. |
| 255 | * |
| 256 | * This finds an unused thread index that can be assigned to a new |
| 257 | * thread. If too many threads have been allocated, the kernel will |
| 258 | * run out of indexes and this function will fail. |
| 259 | * |
| 260 | * Note that if an unused index is found, that index will be marked as |
| 261 | * used after return of this function. |
| 262 | * |
| 263 | * @param tidx The new thread index if successful |
| 264 | * |
Flavio Ceolin | 8a14817 | 2018-12-16 12:39:44 -0800 | [diff] [blame] | 265 | * @return true if successful, false if failed |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 266 | **/ |
Andrew Boie | 428afe5 | 2019-11-18 10:20:16 -0800 | [diff] [blame] | 267 | static bool thread_idx_alloc(uintptr_t *tidx) |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 268 | { |
| 269 | int i; |
| 270 | int idx; |
| 271 | int base; |
| 272 | |
| 273 | base = 0; |
| 274 | for (i = 0; i < CONFIG_MAX_THREAD_BYTES; i++) { |
| 275 | idx = find_lsb_set(_thread_idx_map[i]); |
| 276 | |
Flavio Ceolin | 76b3518 | 2018-12-16 12:48:29 -0800 | [diff] [blame] | 277 | if (idx != 0) { |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 278 | *tidx = base + (idx - 1); |
| 279 | |
Daniel Leung | 2ad265c | 2024-05-14 16:16:10 -0700 | [diff] [blame] | 280 | /* Clear the bit. We already know the array index, |
| 281 | * and the bit to be cleared. |
| 282 | */ |
| 283 | _thread_idx_map[i] &= ~(BIT(idx - 1)); |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 284 | |
| 285 | /* Clear permission from all objects */ |
Anas Nashif | 27d74e9 | 2023-09-27 10:48:38 +0000 | [diff] [blame] | 286 | k_object_wordlist_foreach(clear_perms_cb, |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 287 | (void *)*tidx); |
| 288 | |
Flavio Ceolin | 8a14817 | 2018-12-16 12:39:44 -0800 | [diff] [blame] | 289 | return true; |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | base += 8; |
| 293 | } |
| 294 | |
Flavio Ceolin | 8a14817 | 2018-12-16 12:39:44 -0800 | [diff] [blame] | 295 | return false; |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /** |
| 299 | * @internal |
| 300 | * |
| 301 | * @brief Free a thread index. |
| 302 | * |
| 303 | * This frees a thread index so it can be used by another |
| 304 | * thread. |
| 305 | * |
| 306 | * @param tidx The thread index to be freed |
| 307 | **/ |
Andrew Boie | 428afe5 | 2019-11-18 10:20:16 -0800 | [diff] [blame] | 308 | static void thread_idx_free(uintptr_t tidx) |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 309 | { |
| 310 | /* To prevent leaked permission when index is recycled */ |
Anas Nashif | 27d74e9 | 2023-09-27 10:48:38 +0000 | [diff] [blame] | 311 | k_object_wordlist_foreach(clear_perms_cb, (void *)tidx); |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 312 | |
Daniel Leung | 2ad265c | 2024-05-14 16:16:10 -0700 | [diff] [blame] | 313 | /* Figure out which bits to set in _thread_idx_map[] and set it. */ |
| 314 | int base = tidx / NUM_BITS(_thread_idx_map[0]); |
| 315 | int offset = tidx % NUM_BITS(_thread_idx_map[0]); |
| 316 | |
| 317 | _thread_idx_map[base] |= BIT(offset); |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 320 | static struct k_object *dynamic_object_create(enum k_objects otype, size_t align, |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 321 | size_t size) |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 322 | { |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 323 | struct dyn_obj *dyn; |
| 324 | |
| 325 | dyn = z_thread_aligned_alloc(align, sizeof(struct dyn_obj)); |
| 326 | if (dyn == NULL) { |
| 327 | return NULL; |
| 328 | } |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 329 | |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 330 | if (otype == K_OBJ_THREAD_STACK_ELEMENT) { |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 331 | size_t adjusted_size; |
| 332 | |
| 333 | if (size == 0) { |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 334 | k_free(dyn); |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 335 | return NULL; |
| 336 | } |
| 337 | |
| 338 | adjusted_size = STACK_ELEMENT_DATA_SIZE(size); |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 339 | dyn->data = z_thread_aligned_alloc(DYN_OBJ_DATA_ALIGN_K_THREAD_STACK, |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 340 | adjusted_size); |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 341 | if (dyn->data == NULL) { |
| 342 | k_free(dyn); |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 343 | return NULL; |
| 344 | } |
| 345 | |
| 346 | #ifdef CONFIG_GEN_PRIV_STACKS |
| 347 | struct z_stack_data *stack_data = (struct z_stack_data *) |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 348 | ((uint8_t *)dyn->data + adjusted_size - sizeof(*stack_data)); |
| 349 | stack_data->priv = (uint8_t *)dyn->data; |
Ederson de Souza | 4440d6a | 2024-02-15 20:31:50 -0800 | [diff] [blame] | 350 | stack_data->size = adjusted_size; |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 351 | dyn->kobj.data.stack_data = stack_data; |
Nikolay Agishev | baeda6a | 2023-09-20 15:35:58 +0300 | [diff] [blame] | 352 | #if defined(CONFIG_ARM_MPU) || defined(CONFIG_ARC_MPU) |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 353 | dyn->kobj.name = (void *)ROUND_UP( |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 354 | ((uint8_t *)dyn->data + CONFIG_PRIVILEGED_STACK_SIZE), |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 355 | Z_THREAD_STACK_OBJ_ALIGN(size)); |
| 356 | #else |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 357 | dyn->kobj.name = dyn->data; |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 358 | #endif /* CONFIG_ARM_MPU || CONFIG_ARC_MPU */ |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 359 | #else |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 360 | dyn->kobj.name = dyn->data; |
Ederson de Souza | 4440d6a | 2024-02-15 20:31:50 -0800 | [diff] [blame] | 361 | dyn->kobj.data.stack_size = adjusted_size; |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 362 | #endif /* CONFIG_GEN_PRIV_STACKS */ |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 363 | } else { |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 364 | dyn->data = z_thread_aligned_alloc(align, obj_size_get(otype) + size); |
| 365 | if (dyn->data == NULL) { |
| 366 | k_free(dyn->data); |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 367 | return NULL; |
| 368 | } |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 369 | dyn->kobj.name = dyn->data; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 372 | dyn->kobj.type = otype; |
Spoorthy Priya Yerabolu | 9247e8b | 2020-08-25 03:11:16 -0700 | [diff] [blame] | 373 | dyn->kobj.flags = 0; |
| 374 | (void)memset(dyn->kobj.perms, 0, CONFIG_MAX_THREAD_BYTES); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 375 | |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 376 | k_spinlock_key_t key = k_spin_lock(&lists_lock); |
| 377 | |
Daniel Leung | abfe045 | 2021-04-27 11:49:30 -0700 | [diff] [blame] | 378 | sys_dlist_append(&obj_list, &dyn->dobj_list); |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 379 | k_spin_unlock(&lists_lock, key); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 380 | |
Spoorthy Priya Yerabolu | 9247e8b | 2020-08-25 03:11:16 -0700 | [diff] [blame] | 381 | return &dyn->kobj; |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 384 | struct k_object *k_object_create_dynamic_aligned(size_t align, size_t size) |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 385 | { |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 386 | struct k_object *obj = dynamic_object_create(K_OBJ_ANY, align, size); |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 387 | |
| 388 | if (obj == NULL) { |
| 389 | LOG_ERR("could not allocate kernel object, out of memory"); |
| 390 | } |
| 391 | |
| 392 | return obj; |
| 393 | } |
| 394 | |
| 395 | static void *z_object_alloc(enum k_objects otype, size_t size) |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 396 | { |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 397 | struct k_object *zo; |
Ioannis Glaropoulos | 8ada29e | 2020-06-11 09:53:01 +0200 | [diff] [blame] | 398 | uintptr_t tidx = 0; |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 399 | |
Hess Nathan | 6d417d5 | 2024-04-30 13:26:35 +0200 | [diff] [blame] | 400 | if ((otype <= K_OBJ_ANY) || (otype >= K_OBJ_LAST)) { |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 401 | LOG_ERR("bad object type %d requested", otype); |
| 402 | return NULL; |
| 403 | } |
| 404 | |
| 405 | switch (otype) { |
| 406 | case K_OBJ_THREAD: |
| 407 | if (!thread_idx_alloc(&tidx)) { |
| 408 | LOG_ERR("out of free thread indexes"); |
| 409 | return NULL; |
| 410 | } |
| 411 | break; |
| 412 | /* The following are currently not allowed at all */ |
| 413 | case K_OBJ_FUTEX: /* Lives in user memory */ |
| 414 | case K_OBJ_SYS_MUTEX: /* Lives in user memory */ |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 415 | case K_OBJ_NET_SOCKET: /* Indeterminate size */ |
| 416 | LOG_ERR("forbidden object type '%s' requested", |
| 417 | otype_to_str(otype)); |
| 418 | return NULL; |
| 419 | default: |
| 420 | /* Remainder within bounds are permitted */ |
| 421 | break; |
| 422 | } |
| 423 | |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 424 | zo = dynamic_object_create(otype, obj_align_get(otype), size); |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 425 | if (zo == NULL) { |
Nicolas Pitre | 962b374 | 2022-03-13 18:28:59 -0400 | [diff] [blame] | 426 | if (otype == K_OBJ_THREAD) { |
| 427 | thread_idx_free(tidx); |
| 428 | } |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 429 | return NULL; |
| 430 | } |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 431 | |
| 432 | if (otype == K_OBJ_THREAD) { |
| 433 | zo->data.thread_id = tidx; |
| 434 | } |
| 435 | |
| 436 | /* The allocating thread implicitly gets permission on kernel objects |
| 437 | * that it allocates |
| 438 | */ |
Anas Nashif | 993f903 | 2023-09-27 10:47:01 +0000 | [diff] [blame] | 439 | k_thread_perms_set(zo, _current); |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 440 | |
| 441 | /* Activates reference counting logic for automatic disposal when |
| 442 | * all permissions have been revoked |
| 443 | */ |
| 444 | zo->flags |= K_OBJ_FLAG_ALLOC; |
| 445 | |
| 446 | return zo->name; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Flavio Ceolin | 67e66e4 | 2023-06-22 06:27:28 +0000 | [diff] [blame] | 449 | void *z_impl_k_object_alloc(enum k_objects otype) |
| 450 | { |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 451 | return z_object_alloc(otype, 0); |
Flavio Ceolin | 67e66e4 | 2023-06-22 06:27:28 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | void *z_impl_k_object_alloc_size(enum k_objects otype, size_t size) |
| 455 | { |
| 456 | return z_object_alloc(otype, size); |
| 457 | } |
| 458 | |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 459 | void k_object_free(void *obj) |
| 460 | { |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 461 | struct dyn_obj *dyn; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 462 | |
| 463 | /* This function is intentionally not exposed to user mode. |
| 464 | * There's currently no robust way to track that an object isn't |
| 465 | * being used by some other thread |
| 466 | */ |
| 467 | |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 468 | k_spinlock_key_t key = k_spin_lock(&objfree_lock); |
| 469 | |
Spoorthy Priya Yerabolu | 9247e8b | 2020-08-25 03:11:16 -0700 | [diff] [blame] | 470 | dyn = dyn_object_find(obj); |
| 471 | if (dyn != NULL) { |
Daniel Leung | abfe045 | 2021-04-27 11:49:30 -0700 | [diff] [blame] | 472 | sys_dlist_remove(&dyn->dobj_list); |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 473 | |
Spoorthy Priya Yerabolu | 9247e8b | 2020-08-25 03:11:16 -0700 | [diff] [blame] | 474 | if (dyn->kobj.type == K_OBJ_THREAD) { |
| 475 | thread_idx_free(dyn->kobj.data.thread_id); |
Daniel Leung | e58b654 | 2018-08-08 11:23:16 -0700 | [diff] [blame] | 476 | } |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 477 | } |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 478 | k_spin_unlock(&objfree_lock, key); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 479 | |
Spoorthy Priya Yerabolu | 9247e8b | 2020-08-25 03:11:16 -0700 | [diff] [blame] | 480 | if (dyn != NULL) { |
Flavio Ceolin | ed8355a | 2023-07-18 21:00:07 +0000 | [diff] [blame] | 481 | k_free(dyn->data); |
Spoorthy Priya Yerabolu | 9247e8b | 2020-08-25 03:11:16 -0700 | [diff] [blame] | 482 | k_free(dyn); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 486 | struct k_object *k_object_find(const void *obj) |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 487 | { |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 488 | struct k_object *ret; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 489 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 490 | ret = z_object_gperf_find(obj); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 491 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 492 | if (ret == NULL) { |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 493 | struct dyn_obj *dyn; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 494 | |
Peter Bigot | 2fcf762 | 2020-05-14 05:06:08 -0500 | [diff] [blame] | 495 | /* The cast to pointer-to-non-const violates MISRA |
| 496 | * 11.8 but is justified since we know dynamic objects |
| 497 | * were not declared with a const qualifier. |
| 498 | */ |
Hess Nathan | e05c4a8 | 2024-05-07 13:22:50 +0200 | [diff] [blame] | 499 | dyn = dyn_object_find(obj); |
Flavio Ceolin | 3b7e0b6 | 2023-06-23 09:34:14 -0700 | [diff] [blame] | 500 | if (dyn != NULL) { |
| 501 | ret = &dyn->kobj; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
| 505 | return ret; |
| 506 | } |
| 507 | |
Anas Nashif | 27d74e9 | 2023-09-27 10:48:38 +0000 | [diff] [blame] | 508 | void k_object_wordlist_foreach(_wordlist_cb_func_t func, void *context) |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 509 | { |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 510 | struct dyn_obj *obj, *next; |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 511 | |
Patrik Flykt | 4344e27 | 2019-03-08 14:19:05 -0700 | [diff] [blame] | 512 | z_object_gperf_wordlist_foreach(func, context); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 513 | |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 514 | k_spinlock_key_t key = k_spin_lock(&lists_lock); |
| 515 | |
Daniel Leung | abfe045 | 2021-04-27 11:49:30 -0700 | [diff] [blame] | 516 | SYS_DLIST_FOR_EACH_CONTAINER_SAFE(&obj_list, obj, next, dobj_list) { |
Andrew Boie | 97bf001 | 2018-04-24 17:01:37 -0700 | [diff] [blame] | 517 | func(&obj->kobj, context); |
| 518 | } |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 519 | k_spin_unlock(&lists_lock, key); |
Andrew Boie | 31bdfc0 | 2017-11-08 16:38:03 -0800 | [diff] [blame] | 520 | } |
| 521 | #endif /* CONFIG_DYNAMIC_OBJECTS */ |
| 522 | |
Andrew Boie | f2734ab | 2020-03-11 06:37:42 -0700 | [diff] [blame] | 523 | static unsigned int thread_index_get(struct k_thread *thread) |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 524 | { |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 525 | struct k_object *ko; |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 526 | |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 527 | ko = k_object_find(thread); |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 528 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 529 | if (ko == NULL) { |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 530 | return -1; |
| 531 | } |
| 532 | |
Andrew Boie | f2734ab | 2020-03-11 06:37:42 -0700 | [diff] [blame] | 533 | return ko->data.thread_id; |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 536 | static void unref_check(struct k_object *ko, uintptr_t index) |
Andrew Boie | 337e743 | 2018-04-13 14:44:00 -0700 | [diff] [blame] | 537 | { |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 538 | k_spinlock_key_t key = k_spin_lock(&obj_lock); |
Andrew Boie | 7ecc359 | 2019-01-31 12:09:06 -0800 | [diff] [blame] | 539 | |
| 540 | sys_bitfield_clear_bit((mem_addr_t)&ko->perms, index); |
| 541 | |
| 542 | #ifdef CONFIG_DYNAMIC_OBJECTS |
Daniel Leung | b6dd960 | 2021-12-13 14:54:51 -0800 | [diff] [blame] | 543 | if ((ko->flags & K_OBJ_FLAG_ALLOC) == 0U) { |
| 544 | /* skip unref check for static kernel object */ |
| 545 | goto out; |
| 546 | } |
| 547 | |
Carles Cufi | 55350a9 | 2021-12-04 19:57:03 +0100 | [diff] [blame] | 548 | void *vko = ko; |
| 549 | |
Flavio Ceolin | cbbe6d2 | 2023-07-18 13:11:07 -0700 | [diff] [blame] | 550 | struct dyn_obj *dyn = CONTAINER_OF(vko, struct dyn_obj, kobj); |
Andrew Boie | 7ecc359 | 2019-01-31 12:09:06 -0800 | [diff] [blame] | 551 | |
Daniel Leung | b6dd960 | 2021-12-13 14:54:51 -0800 | [diff] [blame] | 552 | __ASSERT(IS_PTR_ALIGNED(dyn, struct dyn_obj), "unaligned z_object"); |
Andrew Boie | 7ecc359 | 2019-01-31 12:09:06 -0800 | [diff] [blame] | 553 | |
Andrew Boie | 337e743 | 2018-04-13 14:44:00 -0700 | [diff] [blame] | 554 | for (int i = 0; i < CONFIG_MAX_THREAD_BYTES; i++) { |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 555 | if (ko->perms[i] != 0U) { |
Andrew Boie | 7ecc359 | 2019-01-31 12:09:06 -0800 | [diff] [blame] | 556 | goto out; |
Andrew Boie | 337e743 | 2018-04-13 14:44:00 -0700 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
| 560 | /* This object has no more references. Some objects may have |
| 561 | * dynamically allocated resources, require cleanup, or need to be |
Nguyen Minh Thien | 8188be5 | 2024-02-19 13:16:58 +0100 | [diff] [blame] | 562 | * marked as uninitialized when all references are gone. What |
Andrew Boie | 337e743 | 2018-04-13 14:44:00 -0700 | [diff] [blame] | 563 | * specifically needs to happen depends on the object type. |
| 564 | */ |
| 565 | switch (ko->type) { |
Peter Mitsis | f86027f | 2022-07-08 11:27:09 -0400 | [diff] [blame] | 566 | #ifdef CONFIG_PIPES |
Andrew Boie | 44fe812 | 2018-04-12 17:38:12 -0700 | [diff] [blame] | 567 | case K_OBJ_PIPE: |
| 568 | k_pipe_cleanup((struct k_pipe *)ko->name); |
| 569 | break; |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 570 | #endif /* CONFIG_PIPES */ |
Andrew Boie | 0fe789f | 2018-04-12 18:35:56 -0700 | [diff] [blame] | 571 | case K_OBJ_MSGQ: |
| 572 | k_msgq_cleanup((struct k_msgq *)ko->name); |
| 573 | break; |
Andrew Boie | f3bee95 | 2018-05-02 17:44:39 -0700 | [diff] [blame] | 574 | case K_OBJ_STACK: |
| 575 | k_stack_cleanup((struct k_stack *)ko->name); |
| 576 | break; |
Andrew Boie | 337e743 | 2018-04-13 14:44:00 -0700 | [diff] [blame] | 577 | default: |
Flavio Ceolin | 3259ac0 | 2018-09-11 13:14:21 -0700 | [diff] [blame] | 578 | /* Nothing to do */ |
Andrew Boie | 337e743 | 2018-04-13 14:44:00 -0700 | [diff] [blame] | 579 | break; |
| 580 | } |
Andrew Boie | 97bf001 | 2018-04-24 17:01:37 -0700 | [diff] [blame] | 581 | |
Daniel Leung | abfe045 | 2021-04-27 11:49:30 -0700 | [diff] [blame] | 582 | sys_dlist_remove(&dyn->dobj_list); |
Flavio Ceolin | ed8355a | 2023-07-18 21:00:07 +0000 | [diff] [blame] | 583 | k_free(dyn->data); |
Spoorthy Priya Yerabolu | 9247e8b | 2020-08-25 03:11:16 -0700 | [diff] [blame] | 584 | k_free(dyn); |
Andrew Boie | 7ecc359 | 2019-01-31 12:09:06 -0800 | [diff] [blame] | 585 | out: |
Simon Hein | bcd1d19 | 2024-03-08 12:00:10 +0100 | [diff] [blame] | 586 | #endif /* CONFIG_DYNAMIC_OBJECTS */ |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 587 | k_spin_unlock(&obj_lock, key); |
Andrew Boie | 337e743 | 2018-04-13 14:44:00 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 590 | static void wordlist_cb(struct k_object *ko, void *ctx_ptr) |
Andrew Boie | 47f8fd1 | 2017-10-05 11:11:02 -0700 | [diff] [blame] | 591 | { |
| 592 | struct perm_ctx *ctx = (struct perm_ctx *)ctx_ptr; |
| 593 | |
| 594 | if (sys_bitfield_test_bit((mem_addr_t)&ko->perms, ctx->parent_id) && |
Hess Nathan | 6d417d5 | 2024-04-30 13:26:35 +0200 | [diff] [blame] | 595 | ((struct k_thread *)ko->name != ctx->parent)) { |
Andrew Boie | 47f8fd1 | 2017-10-05 11:11:02 -0700 | [diff] [blame] | 596 | sys_bitfield_set_bit((mem_addr_t)&ko->perms, ctx->child_id); |
| 597 | } |
| 598 | } |
| 599 | |
Anas Nashif | a5b4945 | 2023-09-27 10:47:50 +0000 | [diff] [blame] | 600 | void k_thread_perms_inherit(struct k_thread *parent, struct k_thread *child) |
Andrew Boie | 47f8fd1 | 2017-10-05 11:11:02 -0700 | [diff] [blame] | 601 | { |
| 602 | struct perm_ctx ctx = { |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 603 | thread_index_get(parent), |
| 604 | thread_index_get(child), |
Andrew Boie | 47f8fd1 | 2017-10-05 11:11:02 -0700 | [diff] [blame] | 605 | parent |
| 606 | }; |
| 607 | |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 608 | if ((ctx.parent_id != -1) && (ctx.child_id != -1)) { |
Anas Nashif | 27d74e9 | 2023-09-27 10:48:38 +0000 | [diff] [blame] | 609 | k_object_wordlist_foreach(wordlist_cb, &ctx); |
Andrew Boie | 47f8fd1 | 2017-10-05 11:11:02 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
Anas Nashif | 993f903 | 2023-09-27 10:47:01 +0000 | [diff] [blame] | 613 | void k_thread_perms_set(struct k_object *ko, struct k_thread *thread) |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 614 | { |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 615 | int index = thread_index_get(thread); |
| 616 | |
| 617 | if (index != -1) { |
| 618 | sys_bitfield_set_bit((mem_addr_t)&ko->perms, index); |
Andrew Boie | 2acfcd6 | 2017-08-30 14:31:03 -0700 | [diff] [blame] | 619 | } |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Anas Nashif | e2a9d01 | 2023-09-27 10:46:26 +0000 | [diff] [blame] | 622 | void k_thread_perms_clear(struct k_object *ko, struct k_thread *thread) |
Andrew Boie | a89bf01 | 2017-10-09 14:47:55 -0700 | [diff] [blame] | 623 | { |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 624 | int index = thread_index_get(thread); |
| 625 | |
| 626 | if (index != -1) { |
Andy Ross | 8a3d57b | 2019-02-06 09:10:36 -0800 | [diff] [blame] | 627 | sys_bitfield_clear_bit((mem_addr_t)&ko->perms, index); |
Andrew Boie | 7ecc359 | 2019-01-31 12:09:06 -0800 | [diff] [blame] | 628 | unref_check(ko, index); |
Andrew Boie | a89bf01 | 2017-10-09 14:47:55 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 632 | static void clear_perms_cb(struct k_object *ko, void *ctx_ptr) |
Andrew Boie | 04caa67 | 2017-10-13 13:57:07 -0700 | [diff] [blame] | 633 | { |
Andrew Boie | 428afe5 | 2019-11-18 10:20:16 -0800 | [diff] [blame] | 634 | uintptr_t id = (uintptr_t)ctx_ptr; |
Andrew Boie | 04caa67 | 2017-10-13 13:57:07 -0700 | [diff] [blame] | 635 | |
Andrew Boie | 7ecc359 | 2019-01-31 12:09:06 -0800 | [diff] [blame] | 636 | unref_check(ko, id); |
Andrew Boie | 04caa67 | 2017-10-13 13:57:07 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Anas Nashif | 70cf96b | 2023-09-27 10:45:48 +0000 | [diff] [blame] | 639 | void k_thread_perms_all_clear(struct k_thread *thread) |
Andrew Boie | 04caa67 | 2017-10-13 13:57:07 -0700 | [diff] [blame] | 640 | { |
Andrew Boie | 428afe5 | 2019-11-18 10:20:16 -0800 | [diff] [blame] | 641 | uintptr_t index = thread_index_get(thread); |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 642 | |
Carlo Caione | f161223 | 2020-10-12 12:10:45 +0200 | [diff] [blame] | 643 | if ((int)index != -1) { |
Anas Nashif | 27d74e9 | 2023-09-27 10:48:38 +0000 | [diff] [blame] | 644 | k_object_wordlist_foreach(clear_perms_cb, (void *)index); |
Andrew Boie | 04caa67 | 2017-10-13 13:57:07 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 648 | static int thread_perms_test(struct k_object *ko) |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 649 | { |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 650 | int index; |
| 651 | |
Patrik Flykt | 24d7143 | 2019-03-26 19:57:45 -0600 | [diff] [blame] | 652 | if ((ko->flags & K_OBJ_FLAG_PUBLIC) != 0U) { |
Andrew Boie | 04caa67 | 2017-10-13 13:57:07 -0700 | [diff] [blame] | 653 | return 1; |
| 654 | } |
| 655 | |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 656 | index = thread_index_get(_current); |
| 657 | if (index != -1) { |
| 658 | return sys_bitfield_test_bit((mem_addr_t)&ko->perms, index); |
Andrew Boie | 2acfcd6 | 2017-08-30 14:31:03 -0700 | [diff] [blame] | 659 | } |
| 660 | return 0; |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 663 | static void dump_permission_error(struct k_object *ko) |
Andrew Boie | 7e3d3d7 | 2017-10-10 09:31:32 -0700 | [diff] [blame] | 664 | { |
Andrew Boie | 818a96d | 2017-11-03 09:00:35 -0700 | [diff] [blame] | 665 | int index = thread_index_get(_current); |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 666 | LOG_ERR("thread %p (%d) does not have permission on %s %p", |
| 667 | _current, index, |
| 668 | otype_to_str(ko->type), ko->name); |
| 669 | LOG_HEXDUMP_ERR(ko->perms, sizeof(ko->perms), "permission bitmap"); |
Andrew Boie | 7e3d3d7 | 2017-10-10 09:31:32 -0700 | [diff] [blame] | 670 | } |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 671 | |
Anas Nashif | 3ab3566 | 2023-09-27 10:51:23 +0000 | [diff] [blame] | 672 | void k_object_dump_error(int retval, const void *obj, struct k_object *ko, |
Andrew Boie | 7e3d3d7 | 2017-10-10 09:31:32 -0700 | [diff] [blame] | 673 | enum k_objects otype) |
| 674 | { |
| 675 | switch (retval) { |
| 676 | case -EBADF: |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 677 | LOG_ERR("%p is not a valid %s", obj, otype_to_str(otype)); |
Andrew Boie | be919d3 | 2020-05-29 17:49:02 -0700 | [diff] [blame] | 678 | if (ko == NULL) { |
| 679 | LOG_ERR("address is not a known kernel object"); |
| 680 | } else { |
| 681 | LOG_ERR("address is actually a %s", |
| 682 | otype_to_str(ko->type)); |
| 683 | } |
Andrew Boie | 7e3d3d7 | 2017-10-10 09:31:32 -0700 | [diff] [blame] | 684 | break; |
| 685 | case -EPERM: |
| 686 | dump_permission_error(ko); |
| 687 | break; |
| 688 | case -EINVAL: |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 689 | LOG_ERR("%p used before initialization", obj); |
Andrew Boie | 7e3d3d7 | 2017-10-10 09:31:32 -0700 | [diff] [blame] | 690 | break; |
Andrew Boie | a2b40ec | 2017-10-15 14:22:08 -0700 | [diff] [blame] | 691 | case -EADDRINUSE: |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 692 | LOG_ERR("%p %s in use", obj, otype_to_str(otype)); |
Flavio Ceolin | a3cea50 | 2018-09-10 22:54:55 -0700 | [diff] [blame] | 693 | break; |
| 694 | default: |
| 695 | /* Not handled error */ |
| 696 | break; |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 697 | } |
Andrew Boie | 3b5ae80 | 2017-10-04 12:10:32 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Peter Bigot | 2fcf762 | 2020-05-14 05:06:08 -0500 | [diff] [blame] | 700 | void z_impl_k_object_access_grant(const void *object, struct k_thread *thread) |
Andrew Boie | 3b5ae80 | 2017-10-04 12:10:32 -0700 | [diff] [blame] | 701 | { |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 702 | struct k_object *ko = k_object_find(object); |
Andrew Boie | 3b5ae80 | 2017-10-04 12:10:32 -0700 | [diff] [blame] | 703 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 704 | if (ko != NULL) { |
Anas Nashif | 993f903 | 2023-09-27 10:47:01 +0000 | [diff] [blame] | 705 | k_thread_perms_set(ko, thread); |
Andrew Boie | 3b5ae80 | 2017-10-04 12:10:32 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Peter Bigot | 2fcf762 | 2020-05-14 05:06:08 -0500 | [diff] [blame] | 709 | void k_object_access_revoke(const void *object, struct k_thread *thread) |
Andrew Boie | a89bf01 | 2017-10-09 14:47:55 -0700 | [diff] [blame] | 710 | { |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 711 | struct k_object *ko = k_object_find(object); |
Andrew Boie | a89bf01 | 2017-10-09 14:47:55 -0700 | [diff] [blame] | 712 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 713 | if (ko != NULL) { |
Anas Nashif | e2a9d01 | 2023-09-27 10:46:26 +0000 | [diff] [blame] | 714 | k_thread_perms_clear(ko, thread); |
Andrew Boie | a89bf01 | 2017-10-09 14:47:55 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
Peter Bigot | 2fcf762 | 2020-05-14 05:06:08 -0500 | [diff] [blame] | 718 | void z_impl_k_object_release(const void *object) |
Andrew Boie | e9cfc54 | 2018-04-13 13:15:28 -0700 | [diff] [blame] | 719 | { |
| 720 | k_object_access_revoke(object, _current); |
| 721 | } |
| 722 | |
Peter Bigot | 2fcf762 | 2020-05-14 05:06:08 -0500 | [diff] [blame] | 723 | void k_object_access_all_grant(const void *object) |
Andrew Boie | 3b5ae80 | 2017-10-04 12:10:32 -0700 | [diff] [blame] | 724 | { |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 725 | struct k_object *ko = k_object_find(object); |
Andrew Boie | 3b5ae80 | 2017-10-04 12:10:32 -0700 | [diff] [blame] | 726 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 727 | if (ko != NULL) { |
Andrew Boie | 04caa67 | 2017-10-13 13:57:07 -0700 | [diff] [blame] | 728 | ko->flags |= K_OBJ_FLAG_PUBLIC; |
Andrew Boie | 3b5ae80 | 2017-10-04 12:10:32 -0700 | [diff] [blame] | 729 | } |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Anas Nashif | 21254b2 | 2023-09-27 10:50:26 +0000 | [diff] [blame] | 732 | int k_object_validate(struct k_object *ko, enum k_objects otype, |
Andrew Boie | a2b40ec | 2017-10-15 14:22:08 -0700 | [diff] [blame] | 733 | enum _obj_init_check init) |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 734 | { |
Flavio Ceolin | ea716bf | 2018-09-20 16:30:45 -0700 | [diff] [blame] | 735 | if (unlikely((ko == NULL) || |
Hess Nathan | 6d417d5 | 2024-04-30 13:26:35 +0200 | [diff] [blame] | 736 | ((otype != K_OBJ_ANY) && (ko->type != otype)))) { |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 737 | return -EBADF; |
| 738 | } |
| 739 | |
Andrew Boie | 3a0f684 | 2017-10-09 12:46:25 -0700 | [diff] [blame] | 740 | /* Manipulation of any kernel objects by a user thread requires that |
| 741 | * thread be granted access first, even for uninitialized objects |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 742 | */ |
Flavio Ceolin | 2df02cc | 2019-03-14 14:32:45 -0700 | [diff] [blame] | 743 | if (unlikely(thread_perms_test(ko) == 0)) { |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 744 | return -EPERM; |
| 745 | } |
| 746 | |
Andrew Boie | a2b40ec | 2017-10-15 14:22:08 -0700 | [diff] [blame] | 747 | /* Initialization state checks. _OBJ_INIT_ANY, we don't care */ |
| 748 | if (likely(init == _OBJ_INIT_TRUE)) { |
Naiyuan Tian | bc3fda4 | 2021-08-23 23:32:58 +0800 | [diff] [blame] | 749 | /* Object MUST be initialized */ |
Patrik Flykt | 21358ba | 2019-03-28 14:57:54 -0600 | [diff] [blame] | 750 | if (unlikely((ko->flags & K_OBJ_FLAG_INITIALIZED) == 0U)) { |
Andrew Boie | a2b40ec | 2017-10-15 14:22:08 -0700 | [diff] [blame] | 751 | return -EINVAL; |
| 752 | } |
Maksim Masalski | 929956d | 2021-05-17 16:58:20 +0800 | [diff] [blame] | 753 | } else if (init == _OBJ_INIT_FALSE) { /* _OBJ_INIT_FALSE case */ |
Andrew Boie | a2b40ec | 2017-10-15 14:22:08 -0700 | [diff] [blame] | 754 | /* Object MUST NOT be initialized */ |
Patrik Flykt | 21358ba | 2019-03-28 14:57:54 -0600 | [diff] [blame] | 755 | if (unlikely((ko->flags & K_OBJ_FLAG_INITIALIZED) != 0U)) { |
Andrew Boie | a2b40ec | 2017-10-15 14:22:08 -0700 | [diff] [blame] | 756 | return -EADDRINUSE; |
| 757 | } |
Flavio Ceolin | 3e97acc | 2018-09-25 11:24:28 -0700 | [diff] [blame] | 758 | } else { |
| 759 | /* _OBJ_INIT_ANY */ |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | return 0; |
| 763 | } |
| 764 | |
Anas Nashif | c91cad7 | 2023-09-26 21:32:13 +0000 | [diff] [blame] | 765 | void k_object_init(const void *obj) |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 766 | { |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 767 | struct k_object *ko; |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 768 | |
| 769 | /* By the time we get here, if the caller was from userspace, all the |
Anas Nashif | 21254b2 | 2023-09-27 10:50:26 +0000 | [diff] [blame] | 770 | * necessary checks have been done in k_object_validate(), which takes |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 771 | * place before the object is initialized. |
| 772 | * |
| 773 | * This function runs after the object has been initialized and |
| 774 | * finalizes it |
| 775 | */ |
| 776 | |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 777 | ko = k_object_find(obj); |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 778 | if (ko == NULL) { |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 779 | /* Supervisor threads can ignore rules about kernel objects |
| 780 | * and may declare them on stacks, etc. Such objects will never |
| 781 | * be usable from userspace, but we shouldn't explode. |
| 782 | */ |
| 783 | return; |
| 784 | } |
| 785 | |
Andrew Boie | 7e3d3d7 | 2017-10-10 09:31:32 -0700 | [diff] [blame] | 786 | /* Allows non-initialization system calls to be made on this object */ |
Andrew Boie | 945af95 | 2017-08-22 13:15:23 -0700 | [diff] [blame] | 787 | ko->flags |= K_OBJ_FLAG_INITIALIZED; |
| 788 | } |
| 789 | |
Anas Nashif | 43a7402 | 2023-09-27 10:44:47 +0000 | [diff] [blame] | 790 | void k_object_recycle(const void *obj) |
Andrew Boie | 83fda7c | 2018-07-31 14:39:11 -0700 | [diff] [blame] | 791 | { |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 792 | struct k_object *ko = k_object_find(obj); |
Andrew Boie | 83fda7c | 2018-07-31 14:39:11 -0700 | [diff] [blame] | 793 | |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 794 | if (ko != NULL) { |
Flavio Ceolin | da49f2e | 2018-09-11 19:09:03 -0700 | [diff] [blame] | 795 | (void)memset(ko->perms, 0, sizeof(ko->perms)); |
Anas Nashif | 993f903 | 2023-09-27 10:47:01 +0000 | [diff] [blame] | 796 | k_thread_perms_set(ko, _current); |
Andrew Boie | 83fda7c | 2018-07-31 14:39:11 -0700 | [diff] [blame] | 797 | ko->flags |= K_OBJ_FLAG_INITIALIZED; |
| 798 | } |
| 799 | } |
| 800 | |
Anas Nashif | 7a18c2b | 2023-09-27 10:45:18 +0000 | [diff] [blame] | 801 | void k_object_uninit(const void *obj) |
Andrew Boie | 4a9a424 | 2017-10-05 12:21:36 -0700 | [diff] [blame] | 802 | { |
Anas Nashif | a6b4900 | 2023-09-26 21:37:25 +0000 | [diff] [blame] | 803 | struct k_object *ko; |
Andrew Boie | 4a9a424 | 2017-10-05 12:21:36 -0700 | [diff] [blame] | 804 | |
Anas Nashif | c91cad7 | 2023-09-26 21:32:13 +0000 | [diff] [blame] | 805 | /* See comments in k_object_init() */ |
Anas Nashif | c25d080 | 2023-09-27 10:49:28 +0000 | [diff] [blame] | 806 | ko = k_object_find(obj); |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 807 | if (ko == NULL) { |
Andrew Boie | 4a9a424 | 2017-10-05 12:21:36 -0700 | [diff] [blame] | 808 | return; |
| 809 | } |
| 810 | |
| 811 | ko->flags &= ~K_OBJ_FLAG_INITIALIZED; |
| 812 | } |
| 813 | |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 814 | /* |
| 815 | * Copy to/from helper functions used in syscall handlers |
| 816 | */ |
Anas Nashif | 6ba8176 | 2023-09-27 10:54:24 +0000 | [diff] [blame] | 817 | void *k_usermode_alloc_from_copy(const void *src, size_t size) |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 818 | { |
| 819 | void *dst = NULL; |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 820 | |
| 821 | /* Does the caller in user mode have access to read this memory? */ |
Anas Nashif | 9c4d881 | 2023-09-27 11:09:45 +0000 | [diff] [blame] | 822 | if (K_SYSCALL_MEMORY_READ(src, size)) { |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 823 | goto out_err; |
| 824 | } |
| 825 | |
| 826 | dst = z_thread_malloc(size); |
Flavio Ceolin | 4218d5f | 2018-09-17 09:39:51 -0700 | [diff] [blame] | 827 | if (dst == NULL) { |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 828 | LOG_ERR("out of thread resource pool memory (%zu)", size); |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 829 | goto out_err; |
| 830 | } |
| 831 | |
Flavio Ceolin | 6699423 | 2018-08-13 15:17:04 -0700 | [diff] [blame] | 832 | (void)memcpy(dst, src, size); |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 833 | out_err: |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 834 | return dst; |
| 835 | } |
| 836 | |
Andrew Boie | 526807c | 2019-03-28 15:17:31 -0700 | [diff] [blame] | 837 | static int user_copy(void *dst, const void *src, size_t size, bool to_user) |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 838 | { |
| 839 | int ret = EFAULT; |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 840 | |
| 841 | /* Does the caller in user mode have access to this memory? */ |
Anas Nashif | 9c4d881 | 2023-09-27 11:09:45 +0000 | [diff] [blame] | 842 | if (to_user ? K_SYSCALL_MEMORY_WRITE(dst, size) : |
| 843 | K_SYSCALL_MEMORY_READ(src, size)) { |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 844 | goto out_err; |
| 845 | } |
| 846 | |
Flavio Ceolin | 6699423 | 2018-08-13 15:17:04 -0700 | [diff] [blame] | 847 | (void)memcpy(dst, src, size); |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 848 | ret = 0; |
| 849 | out_err: |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 850 | return ret; |
| 851 | } |
| 852 | |
Anas Nashif | 56fddd8 | 2023-09-27 10:54:56 +0000 | [diff] [blame] | 853 | int k_usermode_from_copy(void *dst, const void *src, size_t size) |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 854 | { |
| 855 | return user_copy(dst, src, size, false); |
| 856 | } |
| 857 | |
Anas Nashif | 9c1aeb5 | 2023-09-27 10:56:59 +0000 | [diff] [blame] | 858 | int k_usermode_to_copy(void *dst, const void *src, size_t size) |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 859 | { |
| 860 | return user_copy(dst, src, size, true); |
| 861 | } |
| 862 | |
Anas Nashif | 9c1aeb5 | 2023-09-27 10:56:59 +0000 | [diff] [blame] | 863 | char *k_usermode_string_alloc_copy(const char *src, size_t maxlen) |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 864 | { |
Jakob Olesen | c8708d9 | 2019-05-07 10:17:35 -0700 | [diff] [blame] | 865 | size_t actual_len; |
Flavio Ceolin | 0866d18 | 2018-08-14 17:57:08 -0700 | [diff] [blame] | 866 | int err; |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 867 | char *ret = NULL; |
| 868 | |
Anas Nashif | 70e7919 | 2023-09-27 10:53:39 +0000 | [diff] [blame] | 869 | actual_len = k_usermode_string_nlen(src, maxlen, &err); |
Flavio Ceolin | 76b3518 | 2018-12-16 12:48:29 -0800 | [diff] [blame] | 870 | if (err != 0) { |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 871 | goto out; |
| 872 | } |
| 873 | if (actual_len == maxlen) { |
| 874 | /* Not NULL terminated */ |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 875 | LOG_ERR("string too long %p (%zu)", src, actual_len); |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 876 | goto out; |
| 877 | } |
Jakob Olesen | c8708d9 | 2019-05-07 10:17:35 -0700 | [diff] [blame] | 878 | if (size_add_overflow(actual_len, 1, &actual_len)) { |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 879 | LOG_ERR("overflow"); |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 880 | goto out; |
| 881 | } |
| 882 | |
Anas Nashif | 6ba8176 | 2023-09-27 10:54:24 +0000 | [diff] [blame] | 883 | ret = k_usermode_alloc_from_copy(src, actual_len); |
Andrew Boie | 09dc929 | 2019-04-12 12:32:34 -0700 | [diff] [blame] | 884 | |
| 885 | /* Someone may have modified the source string during the above |
| 886 | * checks. Ensure what we actually copied is still terminated |
| 887 | * properly. |
| 888 | */ |
| 889 | if (ret != NULL) { |
Anas Nashif | bbbc38b | 2021-03-29 10:03:49 -0400 | [diff] [blame] | 890 | ret[actual_len - 1U] = '\0'; |
Andrew Boie | 09dc929 | 2019-04-12 12:32:34 -0700 | [diff] [blame] | 891 | } |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 892 | out: |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 893 | return ret; |
| 894 | } |
| 895 | |
Anas Nashif | 9c1aeb5 | 2023-09-27 10:56:59 +0000 | [diff] [blame] | 896 | int k_usermode_string_copy(char *dst, const char *src, size_t maxlen) |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 897 | { |
Jakob Olesen | c8708d9 | 2019-05-07 10:17:35 -0700 | [diff] [blame] | 898 | size_t actual_len; |
Flavio Ceolin | 0866d18 | 2018-08-14 17:57:08 -0700 | [diff] [blame] | 899 | int ret, err; |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 900 | |
Anas Nashif | 70e7919 | 2023-09-27 10:53:39 +0000 | [diff] [blame] | 901 | actual_len = k_usermode_string_nlen(src, maxlen, &err); |
Flavio Ceolin | 76b3518 | 2018-12-16 12:48:29 -0800 | [diff] [blame] | 902 | if (err != 0) { |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 903 | ret = EFAULT; |
| 904 | goto out; |
| 905 | } |
| 906 | if (actual_len == maxlen) { |
| 907 | /* Not NULL terminated */ |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 908 | LOG_ERR("string too long %p (%zu)", src, actual_len); |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 909 | ret = EINVAL; |
| 910 | goto out; |
| 911 | } |
Jakob Olesen | c8708d9 | 2019-05-07 10:17:35 -0700 | [diff] [blame] | 912 | if (size_add_overflow(actual_len, 1, &actual_len)) { |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 913 | LOG_ERR("overflow"); |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 914 | ret = EINVAL; |
| 915 | goto out; |
| 916 | } |
| 917 | |
Anas Nashif | 56fddd8 | 2023-09-27 10:54:56 +0000 | [diff] [blame] | 918 | ret = k_usermode_from_copy(dst, src, actual_len); |
Andrew Boie | 09dc929 | 2019-04-12 12:32:34 -0700 | [diff] [blame] | 919 | |
Anas Nashif | 9c1aeb5 | 2023-09-27 10:56:59 +0000 | [diff] [blame] | 920 | /* See comment above in k_usermode_string_alloc_copy() */ |
Andrew Boie | 09dc929 | 2019-04-12 12:32:34 -0700 | [diff] [blame] | 921 | dst[actual_len - 1] = '\0'; |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 922 | out: |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 923 | return ret; |
| 924 | } |
| 925 | |
| 926 | /* |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 927 | * Application memory region initialization |
| 928 | */ |
| 929 | |
| 930 | extern char __app_shmem_regions_start[]; |
| 931 | extern char __app_shmem_regions_end[]; |
| 932 | |
Gerard Marull-Paretas | a5fd0d1 | 2022-10-19 09:33:44 +0200 | [diff] [blame] | 933 | static int app_shmem_bss_zero(void) |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 934 | { |
| 935 | struct z_app_region *region, *end; |
| 936 | |
Andrew Boie | fb1c294 | 2020-03-16 11:20:08 -0700 | [diff] [blame] | 937 | |
Hess Nathan | 32af724 | 2024-04-26 10:23:56 +0200 | [diff] [blame] | 938 | end = (struct z_app_region *)&__app_shmem_regions_end[0]; |
| 939 | region = (struct z_app_region *)&__app_shmem_regions_start[0]; |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 940 | |
| 941 | for ( ; region < end; region++) { |
Daniel Leung | 2117a2a | 2021-07-12 13:33:32 -0700 | [diff] [blame] | 942 | #if defined(CONFIG_DEMAND_PAGING) && !defined(CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT) |
| 943 | /* When BSS sections are not present at boot, we need to wait for |
| 944 | * paging mechanism to be initialized before we can zero out BSS. |
| 945 | */ |
| 946 | extern bool z_sys_post_kernel; |
| 947 | bool do_clear = z_sys_post_kernel; |
| 948 | |
| 949 | /* During pre-kernel init, z_sys_post_kernel == false, but |
| 950 | * with pinned rodata region, so clear. Otherwise skip. |
| 951 | * In post-kernel init, z_sys_post_kernel == true, |
| 952 | * skip those in pinned rodata region as they have already |
| 953 | * been cleared and possibly already in use. Otherwise clear. |
| 954 | */ |
| 955 | if (((uint8_t *)region->bss_start >= (uint8_t *)_app_smem_pinned_start) && |
| 956 | ((uint8_t *)region->bss_start < (uint8_t *)_app_smem_pinned_end)) { |
| 957 | do_clear = !do_clear; |
| 958 | } |
| 959 | |
| 960 | if (do_clear) |
| 961 | #endif /* CONFIG_DEMAND_PAGING && !CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT */ |
| 962 | { |
| 963 | (void)memset(region->bss_start, 0, region->bss_size); |
| 964 | } |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 965 | } |
Andrew Boie | fb1c294 | 2020-03-16 11:20:08 -0700 | [diff] [blame] | 966 | |
| 967 | return 0; |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 968 | } |
| 969 | |
Jordan Yates | 6f41d52 | 2022-07-02 12:06:55 +1000 | [diff] [blame] | 970 | SYS_INIT_NAMED(app_shmem_bss_zero_pre, app_shmem_bss_zero, |
| 971 | PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); |
Andrew Boie | fb1c294 | 2020-03-16 11:20:08 -0700 | [diff] [blame] | 972 | |
Daniel Leung | 2117a2a | 2021-07-12 13:33:32 -0700 | [diff] [blame] | 973 | #if defined(CONFIG_DEMAND_PAGING) && !defined(CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT) |
| 974 | /* When BSS sections are not present at boot, we need to wait for |
| 975 | * paging mechanism to be initialized before we can zero out BSS. |
| 976 | */ |
Jordan Yates | 6f41d52 | 2022-07-02 12:06:55 +1000 | [diff] [blame] | 977 | SYS_INIT_NAMED(app_shmem_bss_zero_post, app_shmem_bss_zero, |
| 978 | POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); |
Daniel Leung | 2117a2a | 2021-07-12 13:33:32 -0700 | [diff] [blame] | 979 | #endif /* CONFIG_DEMAND_PAGING && !CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT */ |
| 980 | |
Andrew Boie | 4ce652e | 2019-02-22 16:08:44 -0800 | [diff] [blame] | 981 | /* |
Andrew Boie | c8188f6 | 2018-06-22 14:31:51 -0700 | [diff] [blame] | 982 | * Default handlers if otherwise unimplemented |
| 983 | */ |
| 984 | |
Andrew Boie | 800b35f | 2019-11-05 09:27:18 -0800 | [diff] [blame] | 985 | static uintptr_t handler_bad_syscall(uintptr_t bad_id, uintptr_t arg2, |
| 986 | uintptr_t arg3, uintptr_t arg4, |
| 987 | uintptr_t arg5, uintptr_t arg6, |
| 988 | void *ssf) |
Andrew Boie | f564986 | 2017-09-08 12:10:12 -0700 | [diff] [blame] | 989 | { |
frei tycho | fe38c70 | 2024-05-02 13:33:43 +0000 | [diff] [blame] | 990 | ARG_UNUSED(arg2); |
| 991 | ARG_UNUSED(arg3); |
| 992 | ARG_UNUSED(arg4); |
| 993 | ARG_UNUSED(arg5); |
| 994 | ARG_UNUSED(arg6); |
| 995 | |
Andrew Boie | 800b35f | 2019-11-05 09:27:18 -0800 | [diff] [blame] | 996 | LOG_ERR("Bad system call id %" PRIuPTR " invoked", bad_id); |
Andrew Boie | 64c8189 | 2020-05-28 16:24:09 -0700 | [diff] [blame] | 997 | arch_syscall_oops(ssf); |
Andrew Boie | 777336e | 2019-06-24 09:35:55 -0700 | [diff] [blame] | 998 | CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ |
Andrew Boie | f564986 | 2017-09-08 12:10:12 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
Andrew Boie | 800b35f | 2019-11-05 09:27:18 -0800 | [diff] [blame] | 1001 | static uintptr_t handler_no_syscall(uintptr_t arg1, uintptr_t arg2, |
| 1002 | uintptr_t arg3, uintptr_t arg4, |
| 1003 | uintptr_t arg5, uintptr_t arg6, void *ssf) |
Andrew Boie | fa94ee7 | 2017-09-28 16:54:35 -0700 | [diff] [blame] | 1004 | { |
frei tycho | fe38c70 | 2024-05-02 13:33:43 +0000 | [diff] [blame] | 1005 | ARG_UNUSED(arg1); |
| 1006 | ARG_UNUSED(arg2); |
| 1007 | ARG_UNUSED(arg3); |
| 1008 | ARG_UNUSED(arg4); |
| 1009 | ARG_UNUSED(arg5); |
| 1010 | ARG_UNUSED(arg6); |
| 1011 | |
Andrew Boie | 99b3f86 | 2019-09-30 14:25:23 -0700 | [diff] [blame] | 1012 | LOG_ERR("Unimplemented system call"); |
Andrew Boie | 64c8189 | 2020-05-28 16:24:09 -0700 | [diff] [blame] | 1013 | arch_syscall_oops(ssf); |
Andrew Boie | 777336e | 2019-06-24 09:35:55 -0700 | [diff] [blame] | 1014 | CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ |
Andrew Boie | fa94ee7 | 2017-09-28 16:54:35 -0700 | [diff] [blame] | 1015 | } |
Andrew Boie | fc273c0 | 2017-09-23 12:51:23 -0700 | [diff] [blame] | 1016 | |
Yong Cong Sin | 3570408 | 2024-05-24 22:09:31 +0800 | [diff] [blame] | 1017 | #include <zephyr/syscall_dispatch.c> |