Zephyr API Documentation 4.4.0-rc1
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
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
161__syscall int k_object_access_check(const void *object);
162#else
163/* LCOV_EXCL_START */
164#define K_THREAD_ACCESS_GRANT(thread, ...)
165
169static inline void z_impl_k_object_access_grant(const void *object,
170 struct k_thread *thread)
171{
172 ARG_UNUSED(object);
173 ARG_UNUSED(thread);
174}
175
179static inline void k_object_access_revoke(const void *object,
180 struct k_thread *thread)
181{
182 ARG_UNUSED(object);
183 ARG_UNUSED(thread);
184}
185
189static inline void z_impl_k_object_release(const void *object)
190{
191 ARG_UNUSED(object);
192}
193
194static inline void k_object_access_all_grant(const void *object)
195{
196 ARG_UNUSED(object);
197}
198
199static inline bool k_object_is_valid(const void *obj, enum k_objects otype)
200{
201 ARG_UNUSED(obj);
202 ARG_UNUSED(otype);
203
204 return true;
205}
206
210static inline int z_impl_k_object_access_check(const void *object)
211{
212 ARG_UNUSED(object);
213
214 return 0;
215}
216
217/* LCOV_EXCL_STOP */
218#endif /* !CONFIG_USERSPACE */
219
220#if defined(CONFIG_DYNAMIC_OBJECTS) || defined(__DOXYGEN__)
239__syscall void *k_object_alloc(enum k_objects otype);
240
260__syscall void *k_object_alloc_size(enum k_objects otype, size_t size);
261
274void k_object_free(void *obj);
275#else
276
277/* LCOV_EXCL_START */
278static inline void *z_impl_k_object_alloc(enum k_objects otype)
279{
280 ARG_UNUSED(otype);
281
282 return NULL;
283}
284
285static inline void *z_impl_k_object_alloc_size(enum k_objects otype,
286 size_t size)
287{
288 ARG_UNUSED(otype);
289 ARG_UNUSED(size);
290
291 return NULL;
292}
293
299static inline void k_object_free(void *obj)
300{
301 ARG_UNUSED(obj);
302}
303/* LCOV_EXCL_STOP */
304#endif /* CONFIG_DYNAMIC_OBJECTS */
305
307
308#include <zephyr/syscalls/kobject.h>
309#ifdef __cplusplus
310}
311#endif
312
313#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
Definition kobject.h:31
@ K_OBJ_LAST
Definition kobject.h:43
Kernel mutex structure.
Definition kernel.h:3437
Thread Structure.
Definition thread.h:259