2017-10-05 03:25:50 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <syscall_handler.h>
|
2018-04-14 04:15:28 +08:00
|
|
|
#include <kernel_structs.h>
|
2017-10-05 03:25:50 +08:00
|
|
|
|
2017-10-11 00:31:32 +08:00
|
|
|
static struct _k_object *validate_any_object(void *obj)
|
|
|
|
{
|
|
|
|
struct _k_object *ko;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ko = _k_object_find(obj);
|
|
|
|
|
|
|
|
/* This can be any kernel object and it doesn't have to be
|
|
|
|
* initialized
|
|
|
|
*/
|
2017-10-16 05:22:08 +08:00
|
|
|
ret = _k_object_validate(ko, K_OBJ_ANY, _OBJ_INIT_ANY);
|
2018-12-17 04:48:29 +08:00
|
|
|
if (ret != 0) {
|
2017-10-11 00:31:32 +08:00
|
|
|
#ifdef CONFIG_PRINTK
|
|
|
|
_dump_object_error(ret, obj, ko, K_OBJ_ANY);
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ko;
|
|
|
|
}
|
|
|
|
|
2017-10-05 03:25:50 +08:00
|
|
|
/* 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.
|
2017-10-11 00:31:32 +08:00
|
|
|
*
|
|
|
|
* To avoid double _k_object_find() lookups, we don't call the implementation
|
|
|
|
* function, but call a level deeper.
|
2017-10-05 03:25:50 +08:00
|
|
|
*/
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_SYSCALL_HANDLER(k_object_access_grant, object, thread)
|
2017-10-05 03:25:50 +08:00
|
|
|
{
|
2017-10-11 00:31:32 +08:00
|
|
|
struct _k_object *ko;
|
2017-10-05 03:25:50 +08:00
|
|
|
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_OBJ_INIT(thread, K_OBJ_THREAD));
|
2017-10-11 00:31:32 +08:00
|
|
|
ko = validate_any_object((void *)object);
|
2018-09-21 07:14:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(ko != NULL, "object %p access denied",
|
2018-05-05 06:57:57 +08:00
|
|
|
(void *)object));
|
2017-10-11 00:31:32 +08:00
|
|
|
_thread_perms_set(ko, (struct k_thread *)thread);
|
|
|
|
|
2017-10-05 03:25:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_SYSCALL_HANDLER(k_object_release, object)
|
2017-10-10 05:47:55 +08:00
|
|
|
{
|
|
|
|
struct _k_object *ko;
|
|
|
|
|
|
|
|
ko = validate_any_object((void *)object);
|
2018-09-21 07:14:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(ko != NULL, "object %p access denied",
|
2018-05-05 06:57:57 +08:00
|
|
|
(void *)object));
|
2018-04-14 04:15:28 +08:00
|
|
|
_thread_perms_clear(ko, _current);
|
2017-10-10 05:47:55 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-04-25 08:01:37 +08:00
|
|
|
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_SYSCALL_HANDLER(k_object_alloc, otype)
|
2018-04-25 08:01:37 +08:00
|
|
|
{
|
2018-05-05 06:57:57 +08:00
|
|
|
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));
|
2018-04-25 08:01:37 +08:00
|
|
|
|
|
|
|
return (u32_t)_impl_k_object_alloc(otype);
|
|
|
|
}
|