123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- #ifndef ZEPHYR_INCLUDE_SYS_KOBJECT_H
- #define ZEPHYR_INCLUDE_SYS_KOBJECT_H
- #include <stdint.h>
- #include <stddef.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct k_thread;
- struct k_mutex;
- struct z_futex_data;
- enum k_objects {
- K_OBJ_ANY,
-
- #include <kobj-types-enum.h>
-
- K_OBJ_LAST
- };
- #ifdef CONFIG_USERSPACE
- #ifdef CONFIG_GEN_PRIV_STACKS
- struct z_stack_data {
-
- size_t size;
-
- uint8_t *priv;
- };
- #endif
- union z_object_data {
-
- struct k_mutex *mutex;
-
- unsigned int thread_id;
- #ifdef CONFIG_GEN_PRIV_STACKS
-
- const struct z_stack_data *stack_data;
- #else
-
- size_t stack_size;
- #endif
-
- struct z_futex_data *futex_data;
-
- int unused;
- };
- struct z_object {
- void *name;
- uint8_t perms[CONFIG_MAX_THREAD_BYTES];
- uint8_t type;
- uint8_t flags;
- union z_object_data data;
- } __packed __aligned(4);
- struct z_object_assignment {
- struct k_thread *thread;
- void * const *objects;
- };
- #define K_THREAD_ACCESS_GRANT(name_, ...) \
- static void * const _CONCAT(_object_list_, name_)[] = \
- { __VA_ARGS__, NULL }; \
- static const STRUCT_SECTION_ITERABLE(z_object_assignment, \
- _CONCAT(_object_access_, name_)) = \
- { (&_k_thread_obj_ ## name_), \
- (_CONCAT(_object_list_, name_)) }
- #define K_OBJ_FLAG_INITIALIZED BIT(0)
- #define K_OBJ_FLAG_PUBLIC BIT(1)
- #define K_OBJ_FLAG_ALLOC BIT(2)
- #define K_OBJ_FLAG_DRIVER BIT(3)
- void z_object_init(const void *obj);
- #else
- #define K_THREAD_ACCESS_GRANT(thread, ...)
- static inline void z_object_init(const void *obj)
- {
- ARG_UNUSED(obj);
- }
- static inline void z_impl_k_object_access_grant(const void *object,
- struct k_thread *thread)
- {
- ARG_UNUSED(object);
- ARG_UNUSED(thread);
- }
- static inline void k_object_access_revoke(const void *object,
- struct k_thread *thread)
- {
- ARG_UNUSED(object);
- ARG_UNUSED(thread);
- }
- static inline void z_impl_k_object_release(const void *object)
- {
- ARG_UNUSED(object);
- }
- static inline void k_object_access_all_grant(const void *object)
- {
- ARG_UNUSED(object);
- }
- #endif
- __syscall void k_object_access_grant(const void *object,
- struct k_thread *thread);
- void k_object_access_revoke(const void *object, struct k_thread *thread);
- __syscall void k_object_release(const void *object);
- void k_object_access_all_grant(const void *object);
- __syscall void *k_object_alloc(enum k_objects otype);
- #ifdef CONFIG_DYNAMIC_OBJECTS
- struct z_object *z_dynamic_object_aligned_create(size_t align, size_t size);
- static inline struct z_object *z_dynamic_object_create(size_t size)
- {
- return z_dynamic_object_aligned_create(0, size);
- }
- void k_object_free(void *obj);
- #else
- static inline void *z_impl_k_object_alloc(enum k_objects otype)
- {
- ARG_UNUSED(otype);
- return NULL;
- }
- static inline struct z_object *z_dynamic_object_aligned_create(size_t align,
- size_t size)
- {
- ARG_UNUSED(align);
- ARG_UNUSED(size);
- return NULL;
- }
- static inline struct z_object *z_dynamic_object_create(size_t size)
- {
- ARG_UNUSED(size);
- return NULL;
- }
- static inline void k_object_free(void *obj)
- {
- ARG_UNUSED(obj);
- }
- #endif
- #include <syscalls/kobject.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
|