Remove kernel thread alignment since malloc is already 16-byte aligned.

This commit is contained in:
Jonas 'Sortie' Termansen 2022-04-26 00:09:06 +02:00
parent 0f0c6a3232
commit 22f4fd859e
4 changed files with 7 additions and 39 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2016, 2018, 2021 Jonas 'Sortie' Termansen.
* Copyright (c) 2011-2016, 2018, 2021-2022 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -75,7 +75,6 @@ public:
uintptr_t system_tid;
uintptr_t yield_to_tid;
struct thread_registers registers;
uint8_t* self_allocation;
size_t id;
Process* process;
Thread* prevsibling;
@ -115,9 +114,6 @@ public:
};
Thread* AllocateThread();
void FreeThread(Thread* thread);
Thread* CurrentThread();
} // namespace Sortix

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2018, 2021 Jonas 'Sortie' Termansen.
* Copyright (c) 2011-2018, 2021-2022 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -373,7 +373,7 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo_p)
// create a kernel thread that is the current thread and isn't put into the
// scheduler's set of runnable threads, but rather run whenever there is
// _nothing_ else to run on this CPU.
Thread* idlethread = AllocateThread();
Thread* idlethread = new Thread();
idlethread->name = "idle";
idlethread->process = system;
idlethread->kernelstackpos = (addr_t) stack;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2014, 2021 Jonas 'Sortie' Termansen.
* Copyright (c) 2012, 2014, 2021, 2022 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -224,7 +224,7 @@ static void kthread_do_kill_thread(void* user)
Thread* thread = (Thread*) user;
while ( thread->state != ThreadState::DEAD )
kthread_yield();
FreeThread(thread);
delete thread;
}
void kthread_exit()

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2016, 2018, 2021 Jonas 'Sortie' Termansen.
* Copyright (c) 2011-2016, 2018, 2021-2022 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -49,36 +49,8 @@
#include "x86-family/float.h"
#endif
void* operator new (size_t /*size*/, void* address) throw()
{
return address;
}
namespace Sortix {
Thread* AllocateThread()
{
uint8_t* allocation = (uint8_t*) malloc(sizeof(class Thread) + 16);
if ( !allocation )
return NULL;
uint8_t* aligned = allocation;
if ( ((uintptr_t) aligned & 0xFUL) )
aligned = (uint8_t*) (((uintptr_t) aligned + 16) & ~0xFUL);
assert(!((uintptr_t) aligned & 0xFUL));
Thread* thread = new (aligned) Thread;
assert(!((uintptr_t) thread->registers.fpuenv & 0xFUL));
return thread->self_allocation = allocation, thread;
}
void FreeThread(Thread* thread)
{
uint8_t* allocation = thread->self_allocation;
thread->~Thread();
free(allocation);
}
Thread::Thread()
{
assert(!((uintptr_t) registers.fpuenv & 0xFUL));
@ -152,7 +124,7 @@ Thread* CreateKernelThread(Process* process,
process == CurrentProcess() ||
process == Scheduler::GetKernelProcess());
Thread* thread = AllocateThread();
Thread* thread = new Thread();
if ( !thread )
return NULL;
thread->name = name;