zephyr/kernel/userspace_handler.c
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00

72 lines
1.7 KiB
C

/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <syscall_handler.h>
#include <kernel_structs.h>
static struct _k_object *validate_any_object(void *obj)
{
struct _k_object *ko;
int ret;
ko = z_object_find(obj);
/* This can be any kernel object and it doesn't have to be
* initialized
*/
ret = z_object_validate(ko, K_OBJ_ANY, _OBJ_INIT_ANY);
if (ret != 0) {
#ifdef CONFIG_PRINTK
z_dump_object_error(ret, obj, ko, K_OBJ_ANY);
#endif
return NULL;
}
return ko;
}
/* Normally these would be included in userspace.c, but the way
* 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
* function, but call a level deeper.
*/
Z_SYSCALL_HANDLER(k_object_access_grant, object, thread)
{
struct _k_object *ko;
Z_OOPS(Z_SYSCALL_OBJ_INIT(thread, K_OBJ_THREAD));
ko = validate_any_object((void *)object);
Z_OOPS(Z_SYSCALL_VERIFY_MSG(ko != NULL, "object %p access denied",
(void *)object));
z_thread_perms_set(ko, (struct k_thread *)thread);
return 0;
}
Z_SYSCALL_HANDLER(k_object_release, object)
{
struct _k_object *ko;
ko = validate_any_object((void *)object);
Z_OOPS(Z_SYSCALL_VERIFY_MSG(ko != NULL, "object %p access denied",
(void *)object));
z_thread_perms_clear(ko, _current);
return 0;
}
Z_SYSCALL_HANDLER(k_object_alloc, otype)
{
Z_OOPS(Z_SYSCALL_VERIFY_MSG(otype > K_OBJ_ANY && otype < K_OBJ_LAST &&
otype != K_OBJ__THREAD_STACK_ELEMENT,
"bad object type %d requested", otype));
return (u32_t)z_impl_k_object_alloc(otype);
}