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
32
39#include <zephyr/kobj-types-enum.h>
42
44};
45
50
51#ifdef CONFIG_USERSPACE
52
65#define K_THREAD_ACCESS_GRANT(name_, ...) \
66 static void * const _CONCAT(_object_list_, name_)[] = \
67 { __VA_ARGS__, NULL }; \
68 static const STRUCT_SECTION_ITERABLE(k_object_assignment, \
69 _CONCAT(_object_access_, name_)) = \
70 { (&_k_thread_obj_ ## name_), \
71 (_CONCAT(_object_list_, name_)) }
72
74#define K_OBJ_FLAG_INITIALIZED BIT(0)
76#define K_OBJ_FLAG_PUBLIC BIT(1)
78#define K_OBJ_FLAG_ALLOC BIT(2)
80#define K_OBJ_FLAG_DRIVER BIT(3)
81
92__syscall void k_object_access_grant(const void *object,
93 struct k_thread *thread);
94
105void k_object_access_revoke(const void *object, struct k_thread *thread);
106
127void k_object_access_revoke_others(const void *object);
128
138__syscall void k_object_release(const void *object);
139
158void k_object_access_all_grant(const void *object);
159
171bool k_object_is_valid(const void *obj, enum k_objects otype);
172
184__syscall int k_object_access_check(const void *object);
185#else
186/* LCOV_EXCL_START */
187#define K_THREAD_ACCESS_GRANT(thread, ...)
188
192static inline void z_impl_k_object_access_grant(const void *object,
193 struct k_thread *thread)
194{
195 ARG_UNUSED(object);
196 ARG_UNUSED(thread);
197}
198
202static inline void k_object_access_revoke(const void *object,
203 struct k_thread *thread)
204{
205 ARG_UNUSED(object);
206 ARG_UNUSED(thread);
207}
208
212static inline void k_object_access_revoke_others(const void *object)
213{
214 ARG_UNUSED(object);
215}
216
220static inline void z_impl_k_object_release(const void *object)
221{
222 ARG_UNUSED(object);
223}
224
225static inline void k_object_access_all_grant(const void *object)
226{
227 ARG_UNUSED(object);
228}
229
230static inline bool k_object_is_valid(const void *obj, enum k_objects otype)
231{
232 ARG_UNUSED(obj);
233 ARG_UNUSED(otype);
234
235 return true;
236}
237
241static inline int z_impl_k_object_access_check(const void *object)
242{
243 ARG_UNUSED(object);
244
245 return 0;
246}
247
248/* LCOV_EXCL_STOP */
249#endif /* !CONFIG_USERSPACE */
250
251#if defined(CONFIG_DYNAMIC_OBJECTS) || defined(__DOXYGEN__)
270__syscall void *k_object_alloc(enum k_objects otype);
271
291__syscall void *k_object_alloc_size(enum k_objects otype, size_t size);
292
305void k_object_free(void *obj);
306#else
307
308/* LCOV_EXCL_START */
309static inline void *z_impl_k_object_alloc(enum k_objects otype)
310{
311 ARG_UNUSED(otype);
312
313 return NULL;
314}
315
316static inline void *z_impl_k_object_alloc_size(enum k_objects otype,
317 size_t size)
318{
319 ARG_UNUSED(otype);
320 ARG_UNUSED(size);
321
322 return NULL;
323}
324
330static inline void k_object_free(void *obj)
331{
332 ARG_UNUSED(obj);
333}
334/* LCOV_EXCL_STOP */
335#endif /* CONFIG_DYNAMIC_OBJECTS */
336
338
339#include <zephyr/syscalls/kobject.h>
340#ifdef __cplusplus
341}
342#endif
343
344#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.
#define NULL
Definition iar_missing_defs.h:20
k_objects
Kernel Object Types.
Definition kobject.h:30
@ K_OBJ_ANY
Definition kobject.h:31
@ K_OBJ_LAST
Definition kobject.h:43
Kernel mutex structure.
Definition kernel.h:3437
Thread Structure.
Definition thread.h:259