Zephyr Project API
3.5.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
206
bool
k_object_is_valid
(
const
void
*obj,
enum
k_objects
otype);
207
208
#else
209
/* LCOV_EXCL_START */
210
#define K_THREAD_ACCESS_GRANT(thread, ...)
211
215
static
inline
void
z_object_init(
const
void
*obj)
216
{
217
ARG_UNUSED(obj);
218
}
219
223
static
inline
void
z_impl_k_object_access_grant(
const
void
*
object
,
224
struct
k_thread
*
thread
)
225
{
226
ARG_UNUSED(
object
);
227
ARG_UNUSED(
thread
);
228
}
229
233
static
inline
void
k_object_access_revoke
(
const
void
*
object
,
234
struct
k_thread
*
thread
)
235
{
236
ARG_UNUSED(
object
);
237
ARG_UNUSED(
thread
);
238
}
239
243
static
inline
void
z_impl_k_object_release(
const
void
*
object
)
244
{
245
ARG_UNUSED(
object
);
246
}
247
248
static
inline
void
k_object_access_all_grant
(
const
void
*
object
)
249
{
250
ARG_UNUSED(
object
);
251
}
252
253
static
inline
bool
k_object_is_valid
(
const
void
*obj,
enum
k_objects
otype)
254
{
255
ARG_UNUSED(obj);
256
ARG_UNUSED(otype);
257
258
return
true
;
259
}
260
261
/* LCOV_EXCL_STOP */
262
#endif
/* !CONFIG_USERSPACE */
263
264
#ifdef CONFIG_DYNAMIC_OBJECTS
280
__syscall
void
*k_object_alloc(
enum
k_objects
otype);
281
298
__syscall
void
*k_object_alloc_size(
enum
k_objects
otype,
size_t
size);
299
320
struct
z_object *z_dynamic_object_aligned_create(
size_t
align,
size_t
size);
321
341
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
342
{
343
return
z_dynamic_object_aligned_create(0, size);
344
}
345
355
void
k_object_free
(
void
*obj);
356
#else
357
358
/* LCOV_EXCL_START */
359
static
inline
void
*z_impl_k_object_alloc(
enum
k_objects
otype)
360
{
361
ARG_UNUSED(otype);
362
363
return
NULL;
364
}
365
366
static
inline
void
*z_impl_k_object_alloc_size(
enum
k_objects
otype,
367
size_t
size)
368
{
369
ARG_UNUSED(otype);
370
ARG_UNUSED(size);
371
372
return
NULL;
373
}
374
375
static
inline
struct
z_object *z_dynamic_object_aligned_create(
size_t
align,
376
size_t
size)
377
{
378
ARG_UNUSED(align);
379
ARG_UNUSED(size);
380
381
return
NULL;
382
}
383
384
static
inline
struct
z_object *z_dynamic_object_create(
size_t
size)
385
{
386
ARG_UNUSED(size);
387
388
return
NULL;
389
}
390
396
static
inline
void
k_object_free
(
void
*obj)
397
{
398
ARG_UNUSED(obj);
399
}
400
/* LCOV_EXCL_STOP */
401
#endif
/* CONFIG_DYNAMIC_OBJECTS */
402
405
#include <
syscalls/kobject.h
>
406
#ifdef __cplusplus
407
}
408
#endif
409
410
#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)
Grant a thread access to a kernel object.
k_object_is_valid
bool k_object_is_valid(const void *obj, enum k_objects otype)
Check if a kernel object is of certain type and is valid.
k_object_access_revoke
void k_object_access_revoke(const void *object, struct k_thread *thread)
Revoke a thread's access to a kernel object.
k_object_access_all_grant
void k_object_access_all_grant(const void *object)
Grant all present and future threads access to an object.
k_object_free
static void k_object_free(void *obj)
Free an object.
Definition
kobject.h:396
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:1314
flags
flags
Definition
parser.h:96
stdint.h
uint8_t
__UINT8_TYPE__ uint8_t
Definition
stdint.h:88
k_mutex
Mutex Structure.
Definition
kernel.h:2911
k_thread
Thread Structure.
Definition
thread.h:250
kobject.h
iterable_sections.h
data
static fdata_t data[2]
Definition
test_fifo_contexts.c:15
include
zephyr
sys
kobject.h
Generated on Tue Mar 5 2024 08:42:07 for Zephyr Project API by
1.9.8