Zephyr Project API  3.2.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
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16struct k_thread;
17struct k_mutex;
18struct z_futex_data;
19
29
36#include <kobj-types-enum.h>
41};
48#ifdef CONFIG_USERSPACE
49#ifdef CONFIG_GEN_PRIV_STACKS
50/* Metadata struct for K_OBJ_THREAD_STACK_ELEMENT */
51struct z_stack_data {
52 /* Size of the entire stack object, including reserved areas */
53 size_t size;
54
55 /* Stack buffer for privilege mode elevations */
56 uint8_t *priv;
57};
58#endif /* CONFIG_GEN_PRIV_STACKS */
59
60/* Object extra data. Only some objects use this, determined by object type */
61union z_object_data {
62 /* Backing mutex for K_OBJ_SYS_MUTEX */
63 struct k_mutex *mutex;
64
65 /* Numerical thread ID for K_OBJ_THREAD */
66 unsigned int thread_id;
67
68#ifdef CONFIG_GEN_PRIV_STACKS
69 /* Metadata for K_OBJ_THREAD_STACK_ELEMENT */
70 const struct z_stack_data *stack_data;
71#else
72 /* Stack buffer size for K_OBJ_THREAD_STACK_ELEMENT */
73 size_t stack_size;
74#endif /* CONFIG_GEN_PRIV_STACKS */
75
76 /* Futex wait queue and spinlock for K_OBJ_FUTEX */
77 struct z_futex_data *futex_data;
78
79 /* All other objects */
80 int unused;
81};
82
83/* Table generated by gperf, these objects are retrieved via
84 * z_object_find() */
85struct z_object {
86 void *name;
87 uint8_t perms[CONFIG_MAX_THREAD_BYTES];
88 uint8_t type;
90 union z_object_data data;
91} __packed __aligned(4);
92
93struct z_object_assignment {
94 struct k_thread *thread;
95 void * const *objects;
96};
97
110#define K_THREAD_ACCESS_GRANT(name_, ...) \
111 static void * const _CONCAT(_object_list_, name_)[] = \
112 { __VA_ARGS__, NULL }; \
113 static const STRUCT_SECTION_ITERABLE(z_object_assignment, \
114 _CONCAT(_object_access_, name_)) = \
115 { (&_k_thread_obj_ ## name_), \
116 (_CONCAT(_object_list_, name_)) }
117
119#define K_OBJ_FLAG_INITIALIZED BIT(0)
121#define K_OBJ_FLAG_PUBLIC BIT(1)
123#define K_OBJ_FLAG_ALLOC BIT(2)
125#define K_OBJ_FLAG_DRIVER BIT(3)
126
136void z_object_init(const void *obj);
137
148__syscall void k_object_access_grant(const void *object,
149 struct k_thread *thread);
150
161void k_object_access_revoke(const void *object, struct k_thread *thread);
162
172__syscall void k_object_release(const void *object);
173
191void k_object_access_all_grant(const void *object);
192
193#else
194/* LCOV_EXCL_START */
195#define K_THREAD_ACCESS_GRANT(thread, ...)
196
200static inline void z_object_init(const void *obj)
201{
202 ARG_UNUSED(obj);
203}
204
208static inline void z_impl_k_object_access_grant(const void *object,
209 struct k_thread *thread)
210{
211 ARG_UNUSED(object);
212 ARG_UNUSED(thread);
213}
214
218static inline void k_object_access_revoke(const void *object,
219 struct k_thread *thread)
220{
221 ARG_UNUSED(object);
222 ARG_UNUSED(thread);
223}
224
228static inline void z_impl_k_object_release(const void *object)
229{
230 ARG_UNUSED(object);
231}
232
233static inline void k_object_access_all_grant(const void *object)
234{
235 ARG_UNUSED(object);
236}
237/* LCOV_EXCL_STOP */
238#endif /* !CONFIG_USERSPACE */
239
240#ifdef CONFIG_DYNAMIC_OBJECTS
255__syscall void *k_object_alloc(enum k_objects otype);
256
277struct z_object *z_dynamic_object_aligned_create(size_t align, size_t size);
278
298static inline struct z_object *z_dynamic_object_create(size_t size)
299{
300 return z_dynamic_object_aligned_create(0, size);
301}
302
312void k_object_free(void *obj);
313#else
314
315/* LCOV_EXCL_START */
316static inline void *z_impl_k_object_alloc(enum k_objects otype)
317{
318 ARG_UNUSED(otype);
319
320 return NULL;
321}
322
323static inline struct z_object *z_dynamic_object_aligned_create(size_t align,
324 size_t size)
325{
326 ARG_UNUSED(align);
327 ARG_UNUSED(size);
328
329 return NULL;
330}
331
332static inline struct z_object *z_dynamic_object_create(size_t size)
333{
334 ARG_UNUSED(size);
335
336 return NULL;
337}
338
344static inline void k_object_free(void *obj)
345{
346 ARG_UNUSED(obj);
347}
348/* LCOV_EXCL_STOP */
349#endif /* CONFIG_DYNAMIC_OBJECTS */
350
353#include <syscalls/kobject.h>
354#ifdef __cplusplus
355}
356#endif
357
358#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:344
flags
Definition: http_parser.h:131
k_objects
Kernel Object Types.
Definition: kobject.h:27
@ K_OBJ_ANY
Definition: kobject.h:28
@ K_OBJ_LAST
Definition: kobject.h:40
struct k_mutex mutex
Definition: kobject.c:1321
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Definition: kernel.h:2721
Definition: thread.h:245
static fdata_t data[2]
Definition: test_fifo_contexts.c:15