Zephyr Project API
3.3.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
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
148
__syscall
void
k_object_access_grant
(
const
void
*
object
,
149
struct
k_thread
*
thread
);
150
161
void
k_object_access_revoke
(
const
void
*
object
,
struct
k_thread
*
thread
);
162
172
__syscall
void
k_object_release
(
const
void
*
object
);
173
191
void
k_object_access_all_grant
(
const
void
*
object
);
192
193
#else
194
/* LCOV_EXCL_START */
195
#define K_THREAD_ACCESS_GRANT(thread, ...)
196
200
static
inline
void
z_object_init(
const
void
*obj)
201
{
202
ARG_UNUSED(obj);
203
}
204
208
static
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
218
static
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
228
static
inline
void
z_impl_k_object_release(
const
void
*
object
)
229
{
230
ARG_UNUSED(
object
);
231
}
232
233
static
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
277
struct
z_object *z_dynamic_object_aligned_create(
size_t
align,
size_t
size);
278
298
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
299
{
300
return
z_dynamic_object_aligned_create(0, size);
301
}
302
312
void
k_object_free
(
void
*obj);
313
#else
314
315
/* LCOV_EXCL_START */
316
static
inline
void
*z_impl_k_object_alloc(
enum
k_objects
otype)
317
{
318
ARG_UNUSED(otype);
319
320
return
NULL;
321
}
322
323
static
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
332
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
333
{
334
ARG_UNUSED(size);
335
336
return
NULL;
337
}
338
344
static
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
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:344
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:1321
flags
flags
Definition:
parser.h:96
stdint.h
uint8_t
__UINT8_TYPE__ uint8_t
Definition:
stdint.h:88
k_mutex
Definition:
kernel.h:2764
k_thread
Definition:
thread.h:245
kobject.h
data
static fdata_t data[2]
Definition:
test_fifo_contexts.c:15
include
zephyr
sys
kobject.h
Generated on Fri Jun 9 2023 14:09:43 for Zephyr Project API by
1.9.2