Zephyr API Documentation 4.0.0
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>
44};
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
116__syscall void k_object_release(const void *object);
117
135void k_object_access_all_grant(const void *object);
136
148bool k_object_is_valid(const void *obj, enum k_objects otype);
149
150#else
151/* LCOV_EXCL_START */
152#define K_THREAD_ACCESS_GRANT(thread, ...)
153
157static inline void z_impl_k_object_access_grant(const void *object,
158 struct k_thread *thread)
159{
160 ARG_UNUSED(object);
161 ARG_UNUSED(thread);
162}
163
167static inline void k_object_access_revoke(const void *object,
168 struct k_thread *thread)
169{
170 ARG_UNUSED(object);
171 ARG_UNUSED(thread);
172}
173
177static inline void z_impl_k_object_release(const void *object)
178{
179 ARG_UNUSED(object);
180}
181
182static inline void k_object_access_all_grant(const void *object)
183{
184 ARG_UNUSED(object);
185}
186
187static inline bool k_object_is_valid(const void *obj, enum k_objects otype)
188{
189 ARG_UNUSED(obj);
190 ARG_UNUSED(otype);
191
192 return true;
193}
194
195/* LCOV_EXCL_STOP */
196#endif /* !CONFIG_USERSPACE */
197
198#if defined(CONFIG_DYNAMIC_OBJECTS) || defined(__DOXYGEN__)
217__syscall void *k_object_alloc(enum k_objects otype);
218
238__syscall void *k_object_alloc_size(enum k_objects otype, size_t size);
239
252void k_object_free(void *obj);
253#else
254
255/* LCOV_EXCL_START */
256static inline void *z_impl_k_object_alloc(enum k_objects otype)
257{
258 ARG_UNUSED(otype);
259
260 return NULL;
261}
262
263static inline void *z_impl_k_object_alloc_size(enum k_objects otype,
264 size_t size)
265{
266 ARG_UNUSED(otype);
267 ARG_UNUSED(size);
268
269 return NULL;
270}
271
277static inline void k_object_free(void *obj)
278{
279 ARG_UNUSED(obj);
280}
281/* LCOV_EXCL_STOP */
282#endif /* CONFIG_DYNAMIC_OBJECTS */
283
286#include <zephyr/syscalls/kobject.h>
287#ifdef __cplusplus
288}
289#endif
290
291#endif
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.
k_objects
Kernel Object Types.
Definition kobject.h:30
@ K_OBJ_ANY
Definition kobject.h:31
@ K_OBJ_LAST
Definition kobject.h:43
Mutex Structure.
Definition kernel.h:2994
Thread Structure.
Definition thread.h:259