forked from includeos/IncludeOS
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified clone, removed thread children, musl 1.1.24 support
- Loading branch information
Showing
14 changed files
with
227 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <arch/x86/cpu.hpp> | ||
#include <kernel/threads.hpp> | ||
#include <os.hpp> | ||
#include <common> | ||
#include <kprint> | ||
|
||
extern "C" { | ||
long syscall_SYS_set_thread_area(void* u_info); | ||
void __clone_return(void* stack); | ||
} | ||
|
||
extern "C" | ||
long clone_helper( | ||
void* callback, | ||
void* stack, | ||
unsigned long flags, | ||
void* userdata, | ||
void* ptid, | ||
void* newtls, | ||
void* ctid, | ||
void* old_stack) | ||
{ | ||
// NOTE: using printf is completely forbidden in this function | ||
auto* parent = kernel::get_thread(); | ||
|
||
auto* thread = kernel::thread_create(parent, flags, ctid, ptid, stack); | ||
|
||
//#define VERBOSE_CLONE_FUNCTION | ||
#ifdef VERBOSE_CLONE_FUNCTION | ||
extern int __thread_list_lock; | ||
kprintf("clone syscall creating thread %d\n", thread->tid); | ||
kprintf("-> callback: %p\n", callback); | ||
kprintf("-> stack: %p\n", stack); | ||
kprintf("-> flags: %#lx\n", flags); | ||
kprintf("-> argument: %p\n", userdata); | ||
kprintf("-> ptid: %p\n", ptid); | ||
kprintf("-> ctid: %p vs %p\n", ctid, nullptr); | ||
kprintf("-> tls: %p vs %p\n", newtls, *(void**) newtls); | ||
kprintf("-> old thread: %p\n", parent); | ||
kprintf("-> old stack: %p\n", old_stack); | ||
kprintf("-> old tls: %p (%p)\n", kernel::get_thread_area(), parent->my_tls); | ||
#endif | ||
|
||
// write tid on the top of the old stack (for parent) | ||
*(uintptr_t*) old_stack = thread->tid; | ||
//*(int*) ctid = thread->tid; | ||
|
||
// set TLS location (and set self) | ||
thread->set_tls(newtls); | ||
|
||
auto& tman = kernel::ThreadManager::get(); | ||
if (tman.on_new_thread != nullptr) { | ||
// potentially get child stolen by migration callback | ||
thread = tman.on_new_thread(tman, thread); | ||
} | ||
|
||
if (thread) { | ||
THPRINT("Suspending parent thread %p tid=%d stack=%p and entering %d\n", | ||
parent, parent->tid, old_stack, thread->tid); | ||
// suspend parent thread (not yielded) | ||
parent->suspend(false, old_stack); | ||
// continue on child | ||
kernel::set_thread_area(thread->my_tls); | ||
return thread->tid; | ||
} | ||
THPRINT("Returning to parent thread stack=%p\n", old_stack); | ||
// continue with parent | ||
__clone_return(old_stack); | ||
__builtin_unreachable(); | ||
} |
Oops, something went wrong.