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
12
#include <
zephyr/sys/iterable_sections.h
>
13
14
#ifdef __cplusplus
15
extern
"C"
{
16
#endif
17
18
struct
k_thread
;
19
struct
k_mutex
;
20
struct
z_futex_data;
21
29
enum
k_objects
{
30
K_OBJ_ANY
,
31
38
#include <kobj-types-enum.h>
42
K_OBJ_LAST
43
};
50
#ifdef CONFIG_USERSPACE
51
#ifdef CONFIG_GEN_PRIV_STACKS
52
/* Metadata struct for K_OBJ_THREAD_STACK_ELEMENT */
53
struct
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 */
63
union
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() */
87
struct
z_object {
88
void
*name;
89
uint8_t
perms[CONFIG_MAX_THREAD_BYTES];
90
uint8_t
type;
91
uint8_t
flags
;
92
union
z_object_data
data
;
93
} __packed __aligned(4);
94
95
struct
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
138
void
z_object_init(
const
void
*obj);
139
150
__syscall
void
k_object_access_grant
(
const
void
*
object
,
151
struct
k_thread
*
thread
);
152
163
void
k_object_access_revoke
(
const
void
*
object
,
struct
k_thread
*
thread
);
164
174
__syscall
void
k_object_release
(
const
void
*
object
);
175
193
void
k_object_access_all_grant
(
const
void
*
object
);
194
195
#else
196
/* LCOV_EXCL_START */
197
#define K_THREAD_ACCESS_GRANT(thread, ...)
198
202
static
inline
void
z_object_init(
const
void
*obj)
203
{
204
ARG_UNUSED(obj);
205
}
206
210
static
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
220
static
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
230
static
inline
void
z_impl_k_object_release(
const
void
*
object
)
231
{
232
ARG_UNUSED(
object
);
233
}
234
235
static
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
279
struct
z_object *z_dynamic_object_aligned_create(
size_t
align,
size_t
size);
280
300
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
301
{
302
return
z_dynamic_object_aligned_create(0, size);
303
}
304
314
void
k_object_free
(
void
*obj);
315
#else
316
317
/* LCOV_EXCL_START */
318
static
inline
void
*z_impl_k_object_alloc(
enum
k_objects
otype)
319
{
320
ARG_UNUSED(otype);
321
322
return
NULL;
323
}
324
325
static
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
334
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
335
{
336
ARG_UNUSED(size);
337
338
return
NULL;
339
}
340
346
static
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
thread
static struct k_thread thread[2]
Definition:
atomic.c:26
k_object_release
void k_object_release(const void *object)
Release an object.
k_object_access_grant
void k_object_access_grant(const void *object, struct k_thread *thread)
k_object_access_revoke
void k_object_access_revoke(const void *object, struct k_thread *thread)
k_object_access_all_grant
void k_object_access_all_grant(const void *object)
k_object_free
static void k_object_free(void *obj)
Free an object.
Definition:
kobject.h:346
k_objects
k_objects
Kernel Object Types.
Definition:
kobject.h:29
K_OBJ_ANY
@ K_OBJ_ANY
Definition:
kobject.h:30
K_OBJ_LAST
@ K_OBJ_LAST
Definition:
kobject.h:42
mutex
struct k_mutex mutex
Definition:
kobject.c:1321
flags
flags
Definition:
parser.h:96
stdint.h
uint8_t
__UINT8_TYPE__ uint8_t
Definition:
stdint.h:88
k_mutex
Definition:
kernel.h:2822
k_thread
Definition:
thread.h:245
kobject.h
iterable_sections.h
data
static fdata_t data[2]
Definition:
test_fifo_contexts.c:15
include
zephyr
sys
kobject.h
Generated on Sat Jun 17 2023 07:48:28 for Zephyr Project API by
1.9.2