From c25d0804f0a9ae31a0559195a37955caa6c131b0 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 27 Sep 2023 10:49:28 +0000 Subject: [PATCH] syscall: rename z_object_find -> k_object_find Rename internal API to not use z_/Z_. Signed-off-by: Anas Nashif --- include/zephyr/internal/syscall_handler.h | 4 ++-- include/zephyr/linker/kobject-text.ld | 2 +- include/zephyr/sys/internal/kobject_internal.h | 2 +- kernel/dynamic.c | 2 +- kernel/futex.c | 2 +- kernel/sched.c | 2 +- kernel/thread.c | 6 +++--- kernel/userspace.c | 18 +++++++++--------- kernel/userspace_handler.c | 4 ++-- lib/os/mutex.c | 2 +- scripts/build/gen_kobject_list.py | 2 +- scripts/build/process_gperf.py | 2 +- .../mem_protect/mem_protect/src/kobject.c | 6 +++--- .../mem_protect/obj_validation/src/main.c | 6 +++--- tests/kernel/mem_protect/userspace/src/main.c | 6 +++--- tests/kernel/threads/thread_stack/src/main.c | 2 +- 16 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/zephyr/internal/syscall_handler.h b/include/zephyr/internal/syscall_handler.h index d26b950831..b2811d1615 100644 --- a/include/zephyr/internal/syscall_handler.h +++ b/include/zephyr/internal/syscall_handler.h @@ -102,7 +102,7 @@ void z_dump_object_error(int retval, const void *obj, * @return Kernel object's metadata, or NULL if the parameter wasn't the * memory address of a kernel object */ -struct k_object *z_object_find(const void *obj); +struct k_object *k_object_find(const void *obj); typedef void (*_wordlist_cb_func_t)(struct k_object *ko, void *context); @@ -448,7 +448,7 @@ static inline int k_object_validation_check(struct k_object *ko, #define K_SYSCALL_IS_OBJ(ptr, type, init) \ K_SYSCALL_VERIFY_MSG(k_object_validation_check( \ - z_object_find((const void *)ptr), \ + k_object_find((const void *)ptr), \ (const void *)ptr, \ type, init) == 0, "access denied") diff --git a/include/zephyr/linker/kobject-text.ld b/include/zephyr/linker/kobject-text.ld index ee93f4a214..b1c2b69e6d 100644 --- a/include/zephyr/linker/kobject-text.ld +++ b/include/zephyr/linker/kobject-text.ld @@ -18,7 +18,7 @@ PROVIDE(z_object_gperf_find = .); PROVIDE(z_object_gperf_wordlist_foreach = .); #else - PROVIDE(z_object_find = .); + PROVIDE(k_object_find = .); PROVIDE(k_object_wordlist_foreach = .); #endif #endif diff --git a/include/zephyr/sys/internal/kobject_internal.h b/include/zephyr/sys/internal/kobject_internal.h index 15bab175e0..b7bf816ad7 100644 --- a/include/zephyr/sys/internal/kobject_internal.h +++ b/include/zephyr/sys/internal/kobject_internal.h @@ -50,7 +50,7 @@ union k_object_data { }; /* Table generated by gperf, these objects are retrieved via - * z_object_find() */ + * k_object_find() */ struct k_object { void *name; uint8_t perms[CONFIG_MAX_THREAD_BYTES]; diff --git a/kernel/dynamic.c b/kernel/dynamic.c index 3fea6b68c5..d30dba8ac0 100644 --- a/kernel/dynamic.c +++ b/kernel/dynamic.c @@ -152,7 +152,7 @@ int z_impl_k_thread_stack_free(k_thread_stack_t *stack) if (IS_ENABLED(CONFIG_DYNAMIC_THREAD_ALLOC)) { #ifdef CONFIG_USERSPACE - if (z_object_find(stack)) { + if (k_object_find(stack)) { k_object_free(stack); } else { k_free(stack); diff --git a/kernel/futex.c b/kernel/futex.c index f0f5e5aecb..52584fb643 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -16,7 +16,7 @@ static struct z_futex_data *k_futex_find_data(struct k_futex *futex) { struct k_object *obj; - obj = z_object_find(futex); + obj = k_object_find(futex); if (obj == NULL || obj->type != K_OBJ_FUTEX) { return NULL; } diff --git a/kernel/sched.c b/kernel/sched.c index 381d94d116..653e680e44 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1878,7 +1878,7 @@ int z_impl_k_thread_join(struct k_thread *thread, k_timeout_t timeout) */ static bool thread_obj_validate(struct k_thread *thread) { - struct k_object *ko = z_object_find(thread); + struct k_object *ko = k_object_find(thread); int ret = z_object_validate(ko, K_OBJ_THREAD, _OBJ_INIT_TRUE); switch (ret) { diff --git a/kernel/thread.c b/kernel/thread.c index 543da99583..66d81a8247 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -360,7 +360,7 @@ static inline int z_vrfy_k_thread_name_copy(k_tid_t thread, { #ifdef CONFIG_THREAD_NAME size_t len; - struct k_object *ko = z_object_find(thread); + struct k_object *ko = k_object_find(thread); /* Special case: we allow reading the names of initialized threads * even if we don't have permission on them @@ -715,7 +715,7 @@ k_tid_t z_impl_k_thread_create(struct k_thread *new_thread, #ifdef CONFIG_USERSPACE bool z_stack_is_user_capable(k_thread_stack_t *stack) { - return z_object_find(stack) != NULL; + return k_object_find(stack) != NULL; } k_tid_t z_vrfy_k_thread_create(struct k_thread *new_thread, @@ -733,7 +733,7 @@ k_tid_t z_vrfy_k_thread_create(struct k_thread *new_thread, /* No need to check z_stack_is_user_capable(), it won't be in the * object table if it isn't */ - stack_object = z_object_find(stack); + stack_object = k_object_find(stack); Z_OOPS(K_SYSCALL_VERIFY_MSG(k_object_validation_check(stack_object, stack, K_OBJ_THREAD_STACK_ELEMENT, _OBJ_INIT_FALSE) == 0, diff --git a/kernel/userspace.c b/kernel/userspace.c index 7a0db0f117..f3e73eff57 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -119,7 +119,7 @@ struct perm_ctx { */ uint8_t *z_priv_stack_find(k_thread_stack_t *stack) { - struct k_object *obj = z_object_find(stack); + struct k_object *obj = k_object_find(stack); __ASSERT(obj != NULL, "stack object not found"); __ASSERT(obj->type == K_OBJ_THREAD_STACK_ELEMENT, @@ -475,7 +475,7 @@ void k_object_free(void *obj) } } -struct k_object *z_object_find(const void *obj) +struct k_object *k_object_find(const void *obj) { struct k_object *ret; @@ -516,7 +516,7 @@ static unsigned int thread_index_get(struct k_thread *thread) { struct k_object *ko; - ko = z_object_find(thread); + ko = k_object_find(thread); if (ko == NULL) { return -1; @@ -691,7 +691,7 @@ void z_dump_object_error(int retval, const void *obj, struct k_object *ko, void z_impl_k_object_access_grant(const void *object, struct k_thread *thread) { - struct k_object *ko = z_object_find(object); + struct k_object *ko = k_object_find(object); if (ko != NULL) { k_thread_perms_set(ko, thread); @@ -700,7 +700,7 @@ void z_impl_k_object_access_grant(const void *object, struct k_thread *thread) void k_object_access_revoke(const void *object, struct k_thread *thread) { - struct k_object *ko = z_object_find(object); + struct k_object *ko = k_object_find(object); if (ko != NULL) { k_thread_perms_clear(ko, thread); @@ -714,7 +714,7 @@ void z_impl_k_object_release(const void *object) void k_object_access_all_grant(const void *object) { - struct k_object *ko = z_object_find(object); + struct k_object *ko = k_object_find(object); if (ko != NULL) { ko->flags |= K_OBJ_FLAG_PUBLIC; @@ -766,7 +766,7 @@ void k_object_init(const void *obj) * finalizes it */ - ko = z_object_find(obj); + ko = k_object_find(obj); if (ko == NULL) { /* Supervisor threads can ignore rules about kernel objects * and may declare them on stacks, etc. Such objects will never @@ -781,7 +781,7 @@ void k_object_init(const void *obj) void k_object_recycle(const void *obj) { - struct k_object *ko = z_object_find(obj); + struct k_object *ko = k_object_find(obj); if (ko != NULL) { (void)memset(ko->perms, 0, sizeof(ko->perms)); @@ -795,7 +795,7 @@ void k_object_uninit(const void *obj) struct k_object *ko; /* See comments in k_object_init() */ - ko = z_object_find(obj); + ko = k_object_find(obj); if (ko == NULL) { return; } diff --git a/kernel/userspace_handler.c b/kernel/userspace_handler.c index bc8f1b3f39..e345b1c2b4 100644 --- a/kernel/userspace_handler.c +++ b/kernel/userspace_handler.c @@ -16,7 +16,7 @@ static struct k_object *validate_kernel_object(const void *obj, struct k_object *ko; int ret; - ko = z_object_find(obj); + ko = k_object_find(obj); /* This can be any kernel object and it doesn't have to be * initialized @@ -50,7 +50,7 @@ bool k_object_is_valid(const void *obj, enum k_objects otype) * syscall_dispatch.c declares weak handlers results in build errors if these * are located in userspace.c. Just put in a separate file. * - * To avoid double z_object_find() lookups, we don't call the implementation + * To avoid double k_object_find() lookups, we don't call the implementation * function, but call a level deeper. */ static inline void z_vrfy_k_object_access_grant(const void *object, diff --git a/lib/os/mutex.c b/lib/os/mutex.c index fb18c9650b..b74cda0ab6 100644 --- a/lib/os/mutex.c +++ b/lib/os/mutex.c @@ -13,7 +13,7 @@ static struct k_mutex *get_k_mutex(struct sys_mutex *mutex) { struct k_object *obj; - obj = z_object_find(mutex); + obj = k_object_find(mutex); if (obj == NULL || obj->type != K_OBJ_SYS_MUTEX) { return NULL; } diff --git a/scripts/build/gen_kobject_list.py b/scripts/build/gen_kobject_list.py index c3df9679b1..c64eacd986 100755 --- a/scripts/build/gen_kobject_list.py +++ b/scripts/build/gen_kobject_list.py @@ -752,7 +752,7 @@ void z_object_gperf_wordlist_foreach(_wordlist_cb_func_t func, void *context) } #ifndef CONFIG_DYNAMIC_OBJECTS -struct k_object *z_object_find(const void *obj) +struct k_object *k_object_find(const void *obj) ALIAS_OF(z_object_gperf_find); void k_object_wordlist_foreach(_wordlist_cb_func_t func, void *context) diff --git a/scripts/build/process_gperf.py b/scripts/build/process_gperf.py index 002cd9cc1e..95bbd244dc 100755 --- a/scripts/build/process_gperf.py +++ b/scripts/build/process_gperf.py @@ -83,7 +83,7 @@ def process_line(line, fp): return # Set the lookup function to static inline so it gets rolled into - # z_object_find(), nothing else will use it + # k_object_find(), nothing else will use it if re.search(args.pattern + " [*]$", line): fp.write("static inline " + line) return diff --git a/tests/kernel/mem_protect/mem_protect/src/kobject.c b/tests/kernel/mem_protect/mem_protect/src/kobject.c index 7deae8b31c..1a5029f363 100644 --- a/tests/kernel/mem_protect/mem_protect/src/kobject.c +++ b/tests/kernel/mem_protect/mem_protect/src/kobject.c @@ -481,7 +481,7 @@ ZTEST(mem_protect_kobj, test_thread_has_residual_permissions) * @ingroup kernel_memprotect_tests * * @see k_object_access_grant(), k_object_access_revoke(), - * z_object_find() + * k_object_find() */ ZTEST(mem_protect_kobj, test_kobject_access_grant_to_invalid_thread) { @@ -1069,12 +1069,12 @@ ZTEST(mem_protect_kobj, test_mark_thread_exit_uninitialized) k_thread_join(&child_thread, K_FOREVER); /* check thread is uninitialized after its exit */ - ko = z_object_find(&child_thread); + ko = k_object_find(&child_thread); ret = z_object_validate(ko, K_OBJ_ANY, _OBJ_INIT_FALSE); zassert_equal(ret, _OBJ_INIT_FALSE); /* check stack is uninitialized after thread exit */ - ko = z_object_find(child_stack); + ko = k_object_find(child_stack); ret = z_object_validate(ko, K_OBJ_ANY, _OBJ_INIT_FALSE); zassert_equal(ret, _OBJ_INIT_FALSE); } diff --git a/tests/kernel/mem_protect/obj_validation/src/main.c b/tests/kernel/mem_protect/obj_validation/src/main.c index 07c42ac510..2ca87a11ed 100644 --- a/tests/kernel/mem_protect/obj_validation/src/main.c +++ b/tests/kernel/mem_protect/obj_validation/src/main.c @@ -34,9 +34,9 @@ static int test_object(struct k_sem *sem, int retval) /* Expected to fail; bypass k_object_validation_check() so we don't * fill the logs with spam */ - ret = z_object_validate(z_object_find(sem), K_OBJ_SEM, 0); + ret = z_object_validate(k_object_find(sem), K_OBJ_SEM, 0); } else { - ret = k_object_validation_check(z_object_find(sem), sem, + ret = k_object_validation_check(k_object_find(sem), sem, K_OBJ_SEM, 0); } @@ -179,7 +179,7 @@ ZTEST(object_validation, test_no_ref_dyn_kobj_release_mem) k_object_access_revoke(test_dyn_mutex, thread); /* check object was released, when no threads have access to it */ - ret = z_object_validate(z_object_find(test_dyn_mutex), K_OBJ_MUTEX, 0); + ret = z_object_validate(k_object_find(test_dyn_mutex), K_OBJ_MUTEX, 0); zassert_true(ret == -EBADF, "Dynamic kernel object not released"); } diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c index 05516d1342..1c0e7d3ef2 100644 --- a/tests/kernel/mem_protect/userspace/src/main.c +++ b/tests/kernel/mem_protect/userspace/src/main.c @@ -861,7 +861,7 @@ static struct k_sem recycle_sem; * @details Test recycle valid/invalid kernel object, see if * perms_count changes as expected. * - * @see k_object_recycle(), z_object_find() + * @see k_object_recycle(), k_object_find() * * @ingroup kernel_memprotect_tests */ @@ -874,12 +874,12 @@ ZTEST(userspace, test_object_recycle) /* Validate recycle invalid objects, after recycling this invalid * object, perms_count should finally still be 1. */ - ko = z_object_find(&dummy); + ko = k_object_find(&dummy); zassert_true(ko == NULL, "not an invalid object"); k_object_recycle(&dummy); - ko = z_object_find(&recycle_sem); + ko = k_object_find(&recycle_sem); (void)memset(ko->perms, 0xFF, sizeof(ko->perms)); k_object_recycle(&recycle_sem); diff --git a/tests/kernel/threads/thread_stack/src/main.c b/tests/kernel/threads/thread_stack/src/main.c index 19c54a052e..0ab5193118 100644 --- a/tests/kernel/threads/thread_stack/src/main.c +++ b/tests/kernel/threads/thread_stack/src/main.c @@ -335,7 +335,7 @@ void scenario_entry(void *stack_obj, size_t obj_size, size_t reported_size, #ifdef CONFIG_USERSPACE struct k_object *zo; - zo = z_object_find(stack_obj); + zo = k_object_find(stack_obj); if (zo != NULL) { is_user = true; #ifdef CONFIG_GEN_PRIV_STACKS