kernel: userspace: fix dynamic kernel object alignment
Previous commit55350a93e9
fixing address-of-packed-mem warnings uncovered an issue with the alignment of dynamic kernel objects. On 64-bit platforms, the alignment is 16 bytes instead of 4/8 bytes (as in pointer, void *). This changes the function of mapping between kernel object types and alignments to use the dynamic object struct as basis for alignment instead of simply using pointers. This also uncomments the assertion added in the previous commit55350a93e9
so that we can keep an eye on the alignment in the future. Note that the assertion is moved after checking if the incoming kernel object is dynamically allocated. Static kernel objects are not subjected to this alignment requirement. Fixes #41062 Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
1e32d44729
commit
b6dd960be8
1 changed files with 8 additions and 7 deletions
|
@ -190,11 +190,11 @@ static size_t obj_align_get(enum k_objects otype)
|
|||
#ifdef ARCH_DYMANIC_OBJ_K_THREAD_ALIGNMENT
|
||||
ret = ARCH_DYMANIC_OBJ_K_THREAD_ALIGNMENT;
|
||||
#else
|
||||
ret = sizeof(void *);
|
||||
ret = __alignof(struct dyn_obj);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
ret = sizeof(void *);
|
||||
ret = __alignof(struct dyn_obj);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -466,15 +466,16 @@ static void unref_check(struct z_object *ko, uintptr_t index)
|
|||
sys_bitfield_clear_bit((mem_addr_t)&ko->perms, index);
|
||||
|
||||
#ifdef CONFIG_DYNAMIC_OBJECTS
|
||||
if ((ko->flags & K_OBJ_FLAG_ALLOC) == 0U) {
|
||||
/* skip unref check for static kernel object */
|
||||
goto out;
|
||||
}
|
||||
|
||||
void *vko = ko;
|
||||
|
||||
struct dyn_obj *dyn = CONTAINER_OF(vko, struct dyn_obj, kobj);
|
||||
/* TODO: check why this assert hits */
|
||||
/*__ASSERT(IS_PTR_ALIGNED(dyn, struct dyn_obj), "unaligned z_object");*/
|
||||
|
||||
if ((ko->flags & K_OBJ_FLAG_ALLOC) == 0U) {
|
||||
goto out;
|
||||
}
|
||||
__ASSERT(IS_PTR_ALIGNED(dyn, struct dyn_obj), "unaligned z_object");
|
||||
|
||||
for (int i = 0; i < CONFIG_MAX_THREAD_BYTES; i++) {
|
||||
if (ko->perms[i] != 0U) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue