Zephyr API Documentation 4.4.99
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
128void k_object_access_revoke_others(const void *object);
129
139__syscall void k_object_release(const void *object);
140
159void k_object_access_all_grant(const void *object);
160
172bool k_object_is_valid(const void *obj, enum k_objects otype);
173
185__syscall int k_object_access_check(const void *object);
186#else
187/* LCOV_EXCL_START */
188#define K_THREAD_ACCESS_GRANT(thread, ...)
189
193static inline void z_impl_k_object_access_grant(const void *object,
194 struct k_thread *thread)
195{
196 ARG_UNUSED(object);
197 ARG_UNUSED(thread);
198}
199
203static inline void k_object_access_revoke(const void *object,
204 struct k_thread *thread)
205{
206 ARG_UNUSED(object);
207 ARG_UNUSED(thread);
208}
209
213static inline void k_object_access_revoke_others(const void *object)
214{
215 ARG_UNUSED(object);
216}
217
221static inline void z_impl_k_object_release(const void *object)
222{
223 ARG_UNUSED(object);
224}
225
226static inline void k_object_access_all_grant(const void *object)
227{
228 ARG_UNUSED(object);
229}
230
231static inline bool k_object_is_valid(const void *obj, enum k_objects otype)
232{
233 ARG_UNUSED(obj);
234 ARG_UNUSED(otype);
235
236 return true;
237}
238
242static inline int z_impl_k_object_access_check(const void *object)
243{
244 ARG_UNUSED(object);
245
246 return 0;
247}
248
249/* LCOV_EXCL_STOP */
250#endif /* !CONFIG_USERSPACE */
251
252#if defined(CONFIG_DYNAMIC_OBJECTS) || defined(__DOXYGEN__)
271__syscall void *k_object_alloc(enum k_objects otype);
272
292__syscall void *k_object_alloc_size(enum k_objects otype, size_t size);
293
306void k_object_free(void *obj);
307#else
308
309/* LCOV_EXCL_START */
310static inline void *z_impl_k_object_alloc(enum k_objects otype)
311{
312 ARG_UNUSED(otype);
313
314 return NULL;
315}
316
317static inline void *z_impl_k_object_alloc_size(enum k_objects otype,
318 size_t size)
319{
320 ARG_UNUSED(otype);
321 ARG_UNUSED(size);
322
323 return NULL;
324}
325
331static inline void k_object_free(void *obj)
332{
333 ARG_UNUSED(obj);
334}
335/* LCOV_EXCL_STOP */
336#endif /* CONFIG_DYNAMIC_OBJECTS */
337
339
340#include <zephyr/syscalls/kobject.h>
341#ifdef __cplusplus
342}
343#endif
344
345#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.
void k_object_access_revoke_others(const void *object)
Revoke access to a kernel object for all other threads.
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
Kernel mutex structure.
Definition kernel.h:3437
Thread Structure.
Definition thread.h:259