Zephyr API Documentation  2.7.0-rc2
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#else
138/* LCOV_EXCL_START */
139#define K_THREAD_ACCESS_GRANT(thread, ...)
140
144static inline void z_object_init(const void *obj)
145{
146 ARG_UNUSED(obj);
147}
148
152static inline void z_impl_k_object_access_grant(const void *object,
153 struct k_thread *thread)
154{
155 ARG_UNUSED(object);
156 ARG_UNUSED(thread);
157}
158
162static inline void k_object_access_revoke(const void *object,
163 struct k_thread *thread)
164{
165 ARG_UNUSED(object);
166 ARG_UNUSED(thread);
167}
168
172static inline void z_impl_k_object_release(const void *object)
173{
174 ARG_UNUSED(object);
175}
176
177static inline void k_object_access_all_grant(const void *object)
178{
179 ARG_UNUSED(object);
180}
181/* LCOV_EXCL_STOP */
182#endif /* !CONFIG_USERSPACE */
183
194__syscall void k_object_access_grant(const void *object,
195 struct k_thread *thread);
196
207void k_object_access_revoke(const void *object, struct k_thread *thread);
208
218__syscall void k_object_release(const void *object);
219
237void k_object_access_all_grant(const void *object);
238
253__syscall void *k_object_alloc(enum k_objects otype);
254
255#ifdef CONFIG_DYNAMIC_OBJECTS
276struct z_object *z_dynamic_object_aligned_create(size_t align, size_t size);
277
297static inline struct z_object *z_dynamic_object_create(size_t size)
298{
299 return z_dynamic_object_aligned_create(0, size);
300}
301
311void k_object_free(void *obj);
312#else
313/* LCOV_EXCL_START */
314static inline void *z_impl_k_object_alloc(enum k_objects otype)
315{
316 ARG_UNUSED(otype);
317
318 return NULL;
319}
320
321static inline struct z_object *z_dynamic_object_aligned_create(size_t align,
322 size_t size)
323{
324 ARG_UNUSED(align);
325 ARG_UNUSED(size);
326
327 return NULL;
328}
329
330static inline struct z_object *z_dynamic_object_create(size_t size)
331{
332 ARG_UNUSED(size);
333
334 return NULL;
335}
336
342static inline void k_object_free(void *obj)
343{
344 ARG_UNUSED(obj);
345}
346/* LCOV_EXCL_STOP */
347#endif /* CONFIG_DYNAMIC_OBJECTS */
348
351#include <syscalls/kobject.h>
352#ifdef __cplusplus
353}
354#endif
355
356#endif
static struct k_thread thread[2]
Definition: atomic.c:22
void k_object_release(const void *object)
Release an object.
void * k_object_alloc(enum k_objects otype)
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:342
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:1310
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Definition: kernel.h:2680
Definition: thread.h:201
static fdata_t data[2]
Definition: test_fifo_contexts.c:15