blob: 6531e83791cec88c2bd7a6217abb86d18e1d7c13 [file] [log] [blame]
Andrew Boie743e4682017-10-04 12:25:50 -07001/*
2 * Copyright (c) 2017 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
Gerard Marull-Paretascffefc82022-05-06 11:04:23 +02007#include <zephyr/kernel.h>
8#include <zephyr/syscall_handler.h>
9#include <zephyr/kernel_structs.h>
Andrew Boie743e4682017-10-04 12:25:50 -070010
Peter Bigot2fcf7622020-05-14 05:06:08 -050011static struct z_object *validate_any_object(const void *obj)
Andrew Boie7e3d3d72017-10-10 09:31:32 -070012{
Andrew Boie2dc2ecf2020-03-11 07:13:07 -070013 struct z_object *ko;
Andrew Boie7e3d3d72017-10-10 09:31:32 -070014 int ret;
15
Patrik Flykt4344e272019-03-08 14:19:05 -070016 ko = z_object_find(obj);
Andrew Boie7e3d3d72017-10-10 09:31:32 -070017
18 /* This can be any kernel object and it doesn't have to be
19 * initialized
20 */
Patrik Flykt4344e272019-03-08 14:19:05 -070021 ret = z_object_validate(ko, K_OBJ_ANY, _OBJ_INIT_ANY);
Flavio Ceolin76b35182018-12-16 12:48:29 -080022 if (ret != 0) {
Andrew Boiecb1dd742019-10-01 10:28:32 -070023#ifdef CONFIG_LOG
Patrik Flykt4344e272019-03-08 14:19:05 -070024 z_dump_object_error(ret, obj, ko, K_OBJ_ANY);
Andrew Boie7e3d3d72017-10-10 09:31:32 -070025#endif
26 return NULL;
27 }
28
29 return ko;
30}
31
Andrew Boie743e4682017-10-04 12:25:50 -070032/* Normally these would be included in userspace.c, but the way
33 * syscall_dispatch.c declares weak handlers results in build errors if these
34 * are located in userspace.c. Just put in a separate file.
Andrew Boie7e3d3d72017-10-10 09:31:32 -070035 *
Patrik Flykt4344e272019-03-08 14:19:05 -070036 * To avoid double z_object_find() lookups, we don't call the implementation
Andrew Boie7e3d3d72017-10-10 09:31:32 -070037 * function, but call a level deeper.
Andrew Boie743e4682017-10-04 12:25:50 -070038 */
Peter Bigot2fcf7622020-05-14 05:06:08 -050039static inline void z_vrfy_k_object_access_grant(const void *object,
Andy Ross643701a2019-08-13 12:58:38 -070040 struct k_thread *thread)
Andrew Boie743e4682017-10-04 12:25:50 -070041{
Andrew Boie2dc2ecf2020-03-11 07:13:07 -070042 struct z_object *ko;
Andrew Boie743e4682017-10-04 12:25:50 -070043
Andrew Boie8345e5e2018-05-04 15:57:57 -070044 Z_OOPS(Z_SYSCALL_OBJ_INIT(thread, K_OBJ_THREAD));
Andy Ross65649742019-08-06 13:34:31 -070045 ko = validate_any_object(object);
Flavio Ceolin92ea2f92018-09-20 16:14:57 -070046 Z_OOPS(Z_SYSCALL_VERIFY_MSG(ko != NULL, "object %p access denied",
Andy Ross65649742019-08-06 13:34:31 -070047 object));
48 z_thread_perms_set(ko, thread);
Andrew Boie743e4682017-10-04 12:25:50 -070049}
Andy Ross65649742019-08-06 13:34:31 -070050#include <syscalls/k_object_access_grant_mrsh.c>
Andrew Boie743e4682017-10-04 12:25:50 -070051
Peter Bigot2fcf7622020-05-14 05:06:08 -050052static inline void z_vrfy_k_object_release(const void *object)
Andrew Boiea89bf012017-10-09 14:47:55 -070053{
Andrew Boie2dc2ecf2020-03-11 07:13:07 -070054 struct z_object *ko;
Andrew Boiea89bf012017-10-09 14:47:55 -070055
Andrew Boiea89bf012017-10-09 14:47:55 -070056 ko = validate_any_object((void *)object);
Flavio Ceolin92ea2f92018-09-20 16:14:57 -070057 Z_OOPS(Z_SYSCALL_VERIFY_MSG(ko != NULL, "object %p access denied",
Andrew Boie8345e5e2018-05-04 15:57:57 -070058 (void *)object));
Patrik Flykt4344e272019-03-08 14:19:05 -070059 z_thread_perms_clear(ko, _current);
Andrew Boiea89bf012017-10-09 14:47:55 -070060}
Andy Ross65649742019-08-06 13:34:31 -070061#include <syscalls/k_object_release_mrsh.c>
Andrew Boie97bf0012018-04-24 17:01:37 -070062
Andy Ross65649742019-08-06 13:34:31 -070063static inline void *z_vrfy_k_object_alloc(enum k_objects otype)
Andrew Boie97bf0012018-04-24 17:01:37 -070064{
Andy Ross65649742019-08-06 13:34:31 -070065 return z_impl_k_object_alloc(otype);
Andrew Boie97bf0012018-04-24 17:01:37 -070066}
Andy Ross65649742019-08-06 13:34:31 -070067#include <syscalls/k_object_alloc_mrsh.c>