kobject: move internal functions to own header
Move all internal kobject APIs to own header and do not expose them with the rest of the public API. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
3cf254434d
commit
ae265ea96e
167
include/zephyr/sys/internal/kobject_internal.h
Normal file
167
include/zephyr/sys/internal/kobject_internal.h
Normal file
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ZEPHYR_INCLUDE_SYS_INTERNAL_KOBJECT_INTERNAL_H
|
||||
#define ZEPHYR_INCLUDE_SYS_INTERNAL_KOBJECT_INTERNAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @cond INTERNAL
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#ifdef CONFIG_GEN_PRIV_STACKS
|
||||
/* Metadata struct for K_OBJ_THREAD_STACK_ELEMENT */
|
||||
struct z_stack_data {
|
||||
/* Size of the entire stack object, including reserved areas */
|
||||
size_t size;
|
||||
|
||||
/* Stack buffer for privilege mode elevations */
|
||||
uint8_t *priv;
|
||||
};
|
||||
#endif /* CONFIG_GEN_PRIV_STACKS */
|
||||
|
||||
/* Object extra data. Only some objects use this, determined by object type */
|
||||
union z_object_data {
|
||||
/* Backing mutex for K_OBJ_SYS_MUTEX */
|
||||
struct k_mutex *mutex;
|
||||
|
||||
/* Numerical thread ID for K_OBJ_THREAD */
|
||||
unsigned int thread_id;
|
||||
|
||||
#ifdef CONFIG_GEN_PRIV_STACKS
|
||||
/* Metadata for K_OBJ_THREAD_STACK_ELEMENT */
|
||||
const struct z_stack_data *stack_data;
|
||||
#else
|
||||
/* Stack buffer size for K_OBJ_THREAD_STACK_ELEMENT */
|
||||
size_t stack_size;
|
||||
#endif /* CONFIG_GEN_PRIV_STACKS */
|
||||
|
||||
/* Futex wait queue and spinlock for K_OBJ_FUTEX */
|
||||
struct z_futex_data *futex_data;
|
||||
|
||||
/* All other objects */
|
||||
int unused;
|
||||
};
|
||||
|
||||
/* Table generated by gperf, these objects are retrieved via
|
||||
* z_object_find() */
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Lookup a kernel object and init its metadata if it exists
|
||||
*
|
||||
* Calling this on an object will make it usable from userspace.
|
||||
* Intended to be called as the last statement in kernel object init
|
||||
* functions.
|
||||
*
|
||||
* @param obj Address of the kernel object
|
||||
*/
|
||||
void z_object_init(const void *obj);
|
||||
|
||||
|
||||
#else
|
||||
static inline void z_object_init(const void *obj)
|
||||
{
|
||||
ARG_UNUSED(obj);
|
||||
}
|
||||
/* LCOV_EXCL_STOP */
|
||||
#endif /* !CONFIG_USERSPACE */
|
||||
|
||||
#ifdef CONFIG_DYNAMIC_OBJECTS
|
||||
/**
|
||||
* Allocate memory and install as a generic kernel object
|
||||
*
|
||||
* This is a low-level function to allocate some memory, and register that
|
||||
* allocated memory in the kernel object lookup tables with type K_OBJ_ANY.
|
||||
* Initialization state and thread permissions will be cleared. The
|
||||
* returned z_object's data value will be uninitialized.
|
||||
*
|
||||
* Most users will want to use k_object_alloc() instead.
|
||||
*
|
||||
* Memory allocated will be drawn from the calling thread's reasource pool
|
||||
* and may be freed later by passing the actual object pointer (found
|
||||
* in the returned z_object's 'name' member) to k_object_free().
|
||||
*
|
||||
* @param align Required memory alignment for the allocated object
|
||||
* @param size Size of the allocated object
|
||||
* @return NULL on insufficient memory
|
||||
* @return A pointer to the associated z_object that is installed in the
|
||||
* kernel object tables
|
||||
*/
|
||||
struct z_object *z_dynamic_object_aligned_create(size_t align, size_t size);
|
||||
|
||||
/**
|
||||
* Allocate memory and install as a generic kernel object
|
||||
*
|
||||
* This is a low-level function to allocate some memory, and register that
|
||||
* allocated memory in the kernel object lookup tables with type K_OBJ_ANY.
|
||||
* Initialization state and thread permissions will be cleared. The
|
||||
* returned z_object's data value will be uninitialized.
|
||||
*
|
||||
* Most users will want to use k_object_alloc() instead.
|
||||
*
|
||||
* Memory allocated will be drawn from the calling thread's reasource pool
|
||||
* and may be freed later by passing the actual object pointer (found
|
||||
* in the returned z_object's 'name' member) to k_object_free().
|
||||
*
|
||||
* @param size Size of the allocated object
|
||||
* @return NULL on insufficient memory
|
||||
* @return A pointer to the associated z_object that is installed in the
|
||||
* kernel object tables
|
||||
*/
|
||||
static inline struct z_object *z_dynamic_object_create(size_t size)
|
||||
{
|
||||
return z_dynamic_object_aligned_create(0, size);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* LCOV_EXCL_START */
|
||||
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;
|
||||
}
|
||||
|
||||
/* LCOV_EXCL_STOP */
|
||||
#endif /* CONFIG_DYNAMIC_OBJECTS */
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @endcond INTERNAL
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -10,6 +10,7 @@
|
|||
#include <stddef.h>
|
||||
|
||||
#include <zephyr/sys/iterable_sections.h>
|
||||
#include <zephyr/sys/internal/kobject_internal.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -48,54 +49,6 @@ enum k_objects {
|
|||
*/
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#ifdef CONFIG_GEN_PRIV_STACKS
|
||||
/* Metadata struct for K_OBJ_THREAD_STACK_ELEMENT */
|
||||
struct z_stack_data {
|
||||
/* Size of the entire stack object, including reserved areas */
|
||||
size_t size;
|
||||
|
||||
/* Stack buffer for privilege mode elevations */
|
||||
uint8_t *priv;
|
||||
};
|
||||
#endif /* CONFIG_GEN_PRIV_STACKS */
|
||||
|
||||
/* Object extra data. Only some objects use this, determined by object type */
|
||||
union z_object_data {
|
||||
/* Backing mutex for K_OBJ_SYS_MUTEX */
|
||||
struct k_mutex *mutex;
|
||||
|
||||
/* Numerical thread ID for K_OBJ_THREAD */
|
||||
unsigned int thread_id;
|
||||
|
||||
#ifdef CONFIG_GEN_PRIV_STACKS
|
||||
/* Metadata for K_OBJ_THREAD_STACK_ELEMENT */
|
||||
const struct z_stack_data *stack_data;
|
||||
#else
|
||||
/* Stack buffer size for K_OBJ_THREAD_STACK_ELEMENT */
|
||||
size_t stack_size;
|
||||
#endif /* CONFIG_GEN_PRIV_STACKS */
|
||||
|
||||
/* Futex wait queue and spinlock for K_OBJ_FUTEX */
|
||||
struct z_futex_data *futex_data;
|
||||
|
||||
/* All other objects */
|
||||
int unused;
|
||||
};
|
||||
|
||||
/* Table generated by gperf, these objects are retrieved via
|
||||
* z_object_find() */
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Grant a static thread access to a list of kernel objects
|
||||
|
@ -126,17 +79,6 @@ struct z_object_assignment {
|
|||
/** Driver Object */
|
||||
#define K_OBJ_FLAG_DRIVER BIT(3)
|
||||
|
||||
/**
|
||||
* Lookup a kernel object and init its metadata if it exists
|
||||
*
|
||||
* Calling this on an object will make it usable from userspace.
|
||||
* Intended to be called as the last statement in kernel object init
|
||||
* functions.
|
||||
*
|
||||
* @param obj Address of the kernel object
|
||||
*/
|
||||
void z_object_init(const void *obj);
|
||||
|
||||
/**
|
||||
* Grant a thread access to a kernel object
|
||||
*
|
||||
|
@ -209,14 +151,6 @@ bool k_object_is_valid(const void *obj, enum k_objects otype);
|
|||
/* LCOV_EXCL_START */
|
||||
#define K_THREAD_ACCESS_GRANT(thread, ...)
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
static inline void z_object_init(const void *obj)
|
||||
{
|
||||
ARG_UNUSED(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
@ -297,52 +231,6 @@ __syscall void *k_object_alloc(enum k_objects otype);
|
|||
*/
|
||||
__syscall void *k_object_alloc_size(enum k_objects otype, size_t size);
|
||||
|
||||
/**
|
||||
* Allocate memory and install as a generic kernel object
|
||||
*
|
||||
* This is a low-level function to allocate some memory, and register that
|
||||
* allocated memory in the kernel object lookup tables with type K_OBJ_ANY.
|
||||
* Initialization state and thread permissions will be cleared. The
|
||||
* returned z_object's data value will be uninitialized.
|
||||
*
|
||||
* Most users will want to use k_object_alloc() instead.
|
||||
*
|
||||
* Memory allocated will be drawn from the calling thread's reasource pool
|
||||
* and may be freed later by passing the actual object pointer (found
|
||||
* in the returned z_object's 'name' member) to k_object_free().
|
||||
*
|
||||
* @param align Required memory alignment for the allocated object
|
||||
* @param size Size of the allocated object
|
||||
* @return NULL on insufficient memory
|
||||
* @return A pointer to the associated z_object that is installed in the
|
||||
* kernel object tables
|
||||
*/
|
||||
struct z_object *z_dynamic_object_aligned_create(size_t align, size_t size);
|
||||
|
||||
/**
|
||||
* Allocate memory and install as a generic kernel object
|
||||
*
|
||||
* This is a low-level function to allocate some memory, and register that
|
||||
* allocated memory in the kernel object lookup tables with type K_OBJ_ANY.
|
||||
* Initialization state and thread permissions will be cleared. The
|
||||
* returned z_object's data value will be uninitialized.
|
||||
*
|
||||
* Most users will want to use k_object_alloc() instead.
|
||||
*
|
||||
* Memory allocated will be drawn from the calling thread's reasource pool
|
||||
* and may be freed later by passing the actual object pointer (found
|
||||
* in the returned z_object's 'name' member) to k_object_free().
|
||||
*
|
||||
* @param size Size of the allocated object
|
||||
* @return NULL on insufficient memory
|
||||
* @return A pointer to the associated z_object that is installed in the
|
||||
* kernel object tables
|
||||
*/
|
||||
static inline struct z_object *z_dynamic_object_create(size_t size)
|
||||
{
|
||||
return z_dynamic_object_aligned_create(0, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a kernel object previously allocated with k_object_alloc()
|
||||
*
|
||||
|
@ -372,22 +260,6 @@ static inline void *z_impl_k_object_alloc_size(enum k_objects 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Free an object
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue