Zephyr Project API 4.3.2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
kobject.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_SYS_KOBJECT_H
7#define ZEPHYR_INCLUDE_SYS_KOBJECT_H
8
9#include <stdint.h>
10#include <stddef.h>
11
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct k_thread;
20struct k_mutex;
21struct z_futex_data;
22
33
40#include <zephyr/kobj-types-enum.h>
43
45};
46
51
52#ifdef CONFIG_USERSPACE
53
66#define K_THREAD_ACCESS_GRANT(name_, ...) \
67 static void * const _CONCAT(_object_list_, name_)[] = \
68 { __VA_ARGS__, NULL }; \
69 static const STRUCT_SECTION_ITERABLE(k_object_assignment, \
70 _CONCAT(_object_access_, name_)) = \
71 { (&_k_thread_obj_ ## name_), \
72 (_CONCAT(_object_list_, name_)) }
73
75#define K_OBJ_FLAG_INITIALIZED BIT(0)
77#define K_OBJ_FLAG_PUBLIC BIT(1)
79#define K_OBJ_FLAG_ALLOC BIT(2)
81#define K_OBJ_FLAG_DRIVER BIT(3)
82
93__syscall void k_object_access_grant(const void *object,
94 struct k_thread *thread);
95
106void k_object_access_revoke(const void *object, struct k_thread *thread);
107
117__syscall void k_object_release(const void *object);
118
136void k_object_access_all_grant(const void *object);
137
149bool k_object_is_valid(const void *obj, enum k_objects otype);
150
162__syscall int k_object_access_check(const void *object);
163#else
164/* LCOV_EXCL_START */
165#define K_THREAD_ACCESS_GRANT(thread, ...)
166
170static inline void z_impl_k_object_access_grant(const void *object,
171 struct k_thread *thread)
172{
173 ARG_UNUSED(object);
174 ARG_UNUSED(thread);
175}
176
180static inline void k_object_access_revoke(const void *object,
181 struct k_thread *thread)
182{
183 ARG_UNUSED(object);
184 ARG_UNUSED(thread);
185}
186
190static inline void z_impl_k_object_release(const void *object)
191{
192 ARG_UNUSED(object);
193}
194
195static inline void k_object_access_all_grant(const void *object)
196{
197 ARG_UNUSED(object);
198}
199
200static inline bool k_object_is_valid(const void *obj, enum k_objects otype)
201{
202 ARG_UNUSED(obj);
203 ARG_UNUSED(otype);
204
205 return true;
206}
207
211static inline int z_impl_k_object_access_check(const void *object)
212{
213 ARG_UNUSED(object);
214
215 return 0;
216}
217
218/* LCOV_EXCL_STOP */
219#endif /* !CONFIG_USERSPACE */
220
221#if defined(CONFIG_DYNAMIC_OBJECTS) || defined(__DOXYGEN__)
240__syscall void *k_object_alloc(enum k_objects otype);
241
261__syscall void *k_object_alloc_size(enum k_objects otype, size_t size);
262
275void k_object_free(void *obj);
276#else
277
278/* LCOV_EXCL_START */
279static inline void *z_impl_k_object_alloc(enum k_objects otype)
280{
281 ARG_UNUSED(otype);
282
283 return NULL;
284}
285
286static inline void *z_impl_k_object_alloc_size(enum k_objects otype,
287 size_t size)
288{
289 ARG_UNUSED(otype);
290 ARG_UNUSED(size);
291
292 return NULL;
293}
294
300static inline void k_object_free(void *obj)
301{
302 ARG_UNUSED(obj);
303}
304/* LCOV_EXCL_STOP */
305#endif /* CONFIG_DYNAMIC_OBJECTS */
306
308
309#include <zephyr/syscalls/kobject.h>
310#ifdef __cplusplus
311}
312#endif
313
314#endif
int k_object_access_check(const void *object)
Check if the current thread has access to an object.
void k_object_release(const void *object)
Release an object.
void * k_object_alloc(enum k_objects otype)
Allocate a kernel object of a designated type.
void k_object_access_grant(const void *object, struct k_thread *thread)
Grant a thread access to a kernel object.
void k_object_free(void *obj)
Free a kernel object previously allocated with k_object_alloc()
bool k_object_is_valid(const void *obj, enum k_objects otype)
Check if a kernel object is of certain type and is valid.
void k_object_access_revoke(const void *object, struct k_thread *thread)
Revoke a thread's access to a kernel object.
void * k_object_alloc_size(enum k_objects otype, size_t size)
Allocate a kernel object of a designated type and a given size.
void k_object_access_all_grant(const void *object)
Grant all present and future threads access to an object.
#define NULL
Definition iar_missing_defs.h:20
k_objects
Kernel Object Types.
Definition kobject.h:30
@ K_OBJ_ANY
Used for matching any object type.
Definition kobject.h:31
@ K_OBJ_LAST
Definition kobject.h:44
@ K_OBJ_DRIVER_ANY
Used for matching any driver object type.
Definition kobject.h:32
Mutex Structure.
Definition kernel.h:3232
Thread Structure.
Definition thread.h:252