Zephyr Project API  3.4.0
A Scalable Open Source RTOS
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
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18struct k_thread;
19struct k_mutex;
20struct z_futex_data;
21
31
38#include <kobj-types-enum.h>
43};
50#ifdef CONFIG_USERSPACE
51#ifdef CONFIG_GEN_PRIV_STACKS
52/* Metadata struct for K_OBJ_THREAD_STACK_ELEMENT */
53struct z_stack_data {
54 /* Size of the entire stack object, including reserved areas */
55 size_t size;
56
57 /* Stack buffer for privilege mode elevations */
58 uint8_t *priv;
59};
60#endif /* CONFIG_GEN_PRIV_STACKS */
61
62/* Object extra data. Only some objects use this, determined by object type */
63union z_object_data {
64 /* Backing mutex for K_OBJ_SYS_MUTEX */
65 struct k_mutex *mutex;
66
67 /* Numerical thread ID for K_OBJ_THREAD */
68 unsigned int thread_id;
69
70#ifdef CONFIG_GEN_PRIV_STACKS
71 /* Metadata for K_OBJ_THREAD_STACK_ELEMENT */
72 const struct z_stack_data *stack_data;
73#else
74 /* Stack buffer size for K_OBJ_THREAD_STACK_ELEMENT */
75 size_t stack_size;
76#endif /* CONFIG_GEN_PRIV_STACKS */
77
78 /* Futex wait queue and spinlock for K_OBJ_FUTEX */
79 struct z_futex_data *futex_data;
80
81 /* All other objects */
82 int unused;
83};
84
85/* Table generated by gperf, these objects are retrieved via
86 * z_object_find() */
87struct z_object {
88 void *name;
89 uint8_t perms[CONFIG_MAX_THREAD_BYTES];
90 uint8_t type;
92 union z_object_data data;
93} __packed __aligned(4);
94
95struct z_object_assignment {
96 struct k_thread *thread;
97 void * const *objects;
98};
99
112#define K_THREAD_ACCESS_GRANT(name_, ...) \
113 static void * const _CONCAT(_object_list_, name_)[] = \
114 { __VA_ARGS__, NULL }; \
115 static const STRUCT_SECTION_ITERABLE(z_object_assignment, \
116 _CONCAT(_object_access_, name_)) = \
117 { (&_k_thread_obj_ ## name_), \
118 (_CONCAT(_object_list_, name_)) }
119
121#define K_OBJ_FLAG_INITIALIZED BIT(0)
123#define K_OBJ_FLAG_PUBLIC BIT(1)
125#define K_OBJ_FLAG_ALLOC BIT(2)
127#define K_OBJ_FLAG_DRIVER BIT(3)
128
138void z_object_init(const void *obj);
139
150__syscall void k_object_access_grant(const void *object,
151 struct k_thread *thread);
152
163void k_object_access_revoke(const void *object, struct k_thread *thread);
164
174__syscall void k_object_release(const void *object);
175
193void k_object_access_all_grant(const void *object);
194
195#else
196/* LCOV_EXCL_START */
197#define K_THREAD_ACCESS_GRANT(thread, ...)
198
202static inline void z_object_init(const void *obj)
203{
204 ARG_UNUSED(obj);
205}
206
210static inline void z_impl_k_object_access_grant(const void *object,
211 struct k_thread *thread)
212{
213 ARG_UNUSED(object);
214 ARG_UNUSED(thread);
215}
216
220static inline void k_object_access_revoke(const void *object,
221 struct k_thread *thread)
222{
223 ARG_UNUSED(object);
224 ARG_UNUSED(thread);
225}
226
230static inline void z_impl_k_object_release(const void *object)
231{
232 ARG_UNUSED(object);
233}
234
235static inline void k_object_access_all_grant(const void *object)
236{
237 ARG_UNUSED(object);
238}
239/* LCOV_EXCL_STOP */
240#endif /* !CONFIG_USERSPACE */
241
242#ifdef CONFIG_DYNAMIC_OBJECTS
257__syscall void *k_object_alloc(enum k_objects otype);
258
279struct z_object *z_dynamic_object_aligned_create(size_t align, size_t size);
280
300static inline struct z_object *z_dynamic_object_create(size_t size)
301{
302 return z_dynamic_object_aligned_create(0, size);
303}
304
314void k_object_free(void *obj);
315#else
316
317/* LCOV_EXCL_START */
318static inline void *z_impl_k_object_alloc(enum k_objects otype)
319{
320 ARG_UNUSED(otype);
321
322 return NULL;
323}
324
325static inline struct z_object *z_dynamic_object_aligned_create(size_t align,
326 size_t size)
327{
328 ARG_UNUSED(align);
329 ARG_UNUSED(size);
330
331 return NULL;
332}
333
334static inline struct z_object *z_dynamic_object_create(size_t size)
335{
336 ARG_UNUSED(size);
337
338 return NULL;
339}
340
346static inline void k_object_free(void *obj)
347{
348 ARG_UNUSED(obj);
349}
350/* LCOV_EXCL_STOP */
351#endif /* CONFIG_DYNAMIC_OBJECTS */
352
355#include <syscalls/kobject.h>
356#ifdef __cplusplus
357}
358#endif
359
360#endif
static struct k_thread thread[2]
Definition: atomic.c:26
void k_object_release(const void *object)
Release an object.
void k_object_access_grant(const void *object, struct k_thread *thread)
void k_object_access_revoke(const void *object, struct k_thread *thread)
void k_object_access_all_grant(const void *object)
static void k_object_free(void *obj)
Free an object.
Definition: kobject.h:346
k_objects
Kernel Object Types.
Definition: kobject.h:29
@ K_OBJ_ANY
Definition: kobject.h:30
@ K_OBJ_LAST
Definition: kobject.h:42
struct k_mutex mutex
Definition: kobject.c:1321
flags
Definition: parser.h:96
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Definition: kernel.h:2822
Definition: thread.h:245
static fdata_t data[2]
Definition: test_fifo_contexts.c:15