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
13
extern
"C"
{
14
#endif
15
16
struct
k_thread
;
17
struct
k_mutex
;
18
struct
z_futex_data;
19
27
enum
k_objects
{
28
K_OBJ_ANY
,
29
36
#include <kobj-types-enum.h>
40
K_OBJ_LAST
41
};
48
#ifdef CONFIG_USERSPACE
49
#ifdef CONFIG_GEN_PRIV_STACKS
50
/* Metadata struct for K_OBJ_THREAD_STACK_ELEMENT */
51
struct
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 */
61
union
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() */
85
struct
z_object {
86
void
*name;
87
uint8_t
perms[CONFIG_MAX_THREAD_BYTES];
88
uint8_t
type;
89
uint8_t
flags
;
90
union
z_object_data
data
;
91
} __packed __aligned(4);
92
93
struct
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
136
void
z_object_init(
const
void
*obj);
137
#else
138
/* LCOV_EXCL_START */
139
#define K_THREAD_ACCESS_GRANT(thread, ...)
140
144
static
inline
void
z_object_init(
const
void
*obj)
145
{
146
ARG_UNUSED(obj);
147
}
148
152
static
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
162
static
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
172
static
inline
void
z_impl_k_object_release(
const
void
*
object
)
173
{
174
ARG_UNUSED(
object
);
175
}
176
177
static
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
207
void
k_object_access_revoke
(
const
void
*
object
,
struct
k_thread
*
thread
);
208
218
__syscall
void
k_object_release
(
const
void
*
object
);
219
237
void
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
276
struct
z_object *z_dynamic_object_aligned_create(
size_t
align,
size_t
size);
277
297
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
298
{
299
return
z_dynamic_object_aligned_create(0, size);
300
}
301
311
void
k_object_free
(
void
*obj);
312
#else
313
/* LCOV_EXCL_START */
314
static
inline
void
*z_impl_k_object_alloc(
enum
k_objects
otype)
315
{
316
ARG_UNUSED(otype);
317
318
return
NULL;
319
}
320
321
static
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
330
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
331
{
332
ARG_UNUSED(size);
333
334
return
NULL;
335
}
336
342
static
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
thread
static struct k_thread thread[2]
Definition:
atomic.c:22
k_object_release
void k_object_release(const void *object)
Release an object.
k_object_alloc
void * k_object_alloc(enum k_objects otype)
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:342
flags
flags
Definition:
http_parser.h:131
k_objects
k_objects
Kernel Object Types.
Definition:
kobject.h:27
K_OBJ_ANY
@ K_OBJ_ANY
Definition:
kobject.h:28
K_OBJ_LAST
@ K_OBJ_LAST
Definition:
kobject.h:40
mutex
struct k_mutex mutex
Definition:
kobject.c:1310
stdint.h
uint8_t
__UINT8_TYPE__ uint8_t
Definition:
stdint.h:58
k_mutex
Definition:
kernel.h:2680
k_thread
Definition:
thread.h:201
kobject.h
data
static fdata_t data[2]
Definition:
test_fifo_contexts.c:15
include
sys
kobject.h
Generated on Sun Oct 9 2022 09:21:57 for Zephyr API Documentation by
1.9.4