kernel: return error instead of misaligned k_thread object

k_object_alloc(K_OBJ_THREAD) returns a usable struct k_thread pointer.
This pointer is 4 byte aligned. On x86 and x86_64 struct _thread_arch
has a member which requires alignment. Since this is currently not
supported k_object_alloc(K_OBJ_THREAD) now returns an error instead of
a misaligned pointer.

Signed-off-by: Maximilian Bachmann <m.bachmann@acontis.com>
This commit is contained in:
Maximilian Bachmann 2020-11-04 10:13:46 +01:00 committed by Andrew Boie
commit b3c5fe6720

View file

@ -289,6 +289,13 @@ void *z_impl_k_object_alloc(enum k_objects otype)
switch (otype) {
case K_OBJ_THREAD:
/* aligned allocator required for X86 and X86_64 */
if (IS_ENABLED(CONFIG_X86) || IS_ENABLED(CONFIG_X86_64)) {
LOG_ERR("object type '%s' forbidden on x86 and x86_64",
otype_to_str(otype));
return NULL;
}
if (!thread_idx_alloc(&tidx)) {
LOG_ERR("out of free thread indexes");
return NULL;