pthread: Remove magic thread exit; pthread_exit() is just syscall_exit

This commit is contained in:
K. Lange 2022-03-12 18:04:54 +09:00
parent 4bcd1b4b89
commit 58a1b6e999
4 changed files with 9 additions and 31 deletions

View File

@ -297,12 +297,6 @@ void aarch64_sync_enter(struct regs * r) {
goto _resume_user;
}
/* Magic thread exit */
if (elr == 0xFFFFB00F && far == 0xFFFFB00F) {
task_exit(0);
__builtin_unreachable();
}
/* Magic signal return */
if (elr == 0x8DEADBEEF && far == 0x8DEADBEEF) {
return_from_signal_handler(r);

View File

@ -499,16 +499,6 @@ static void _page_fault(struct regs * r) {
uintptr_t faulting_address;
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
/* FFFFB00Fh is the magic thread exit address.
* XXX: This seems like it could be a perfectly valid address,
* should we move it to 0x8FFFFB00F, similar to what was
* done with the ret-from-sig address?
*/
if (faulting_address == 0xFFFFB00F) {
task_exit(0);
return;
}
/* 8DEADBEEFh is the magic ret-from-sig address. */
if (faulting_address == 0x8DEADBEEF) {
return_from_signal_handler(r);

View File

@ -1356,10 +1356,10 @@ pid_t clone(uintptr_t new_stack, uintptr_t thread_func, uintptr_t arg) {
/* different calling convention */
#if defined(__x86_64__)
r.rdi = arg;
PUSH(new_stack, uintptr_t, (uintptr_t)0xFFFFB00F);
PUSH(new_stack, uintptr_t, (uintptr_t)0);
#elif defined(__aarch64__)
r.x0 = arg;
r.x30 = 0xFFFFB00F;
r.x30 = 0;
#endif
PUSH(sp, struct regs, r);
new_proc->syscall_registers = (void*)sp;

View File

@ -49,11 +49,17 @@ void __make_tls(void) {
sysfunc(TOARU_SYS_FUNC_SETGSBASE, (char*[]){(char*)tlsSelf});
}
void pthread_exit(void * value) {
syscall_exit(0);
__builtin_unreachable();
}
void * __thread_start(void * thread) {
__make_tls();
struct pthread * me = ((pthread_t *)thread)->ret_val;
((pthread_t *)thread)->ret_val = 0;
return me->entry(me->arg);
pthread_exit(me->entry(me->arg));
return NULL;
}
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg) {
@ -73,18 +79,6 @@ int pthread_kill(pthread_t thread, int sig) {
__sets_errno(kill(thread.id, sig));
}
void pthread_exit(void * value) {
/* Perform nice cleanup */
#if 0
/* XXX: LOCK */
free(stack);
/* XXX: Return value!? */
#endif
uintptr_t magic_exit_target = 0xFFFFB00F;
void (*magic_exit_func)(void) = (void *)magic_exit_target;
magic_exit_func();
}
void pthread_cleanup_push(void (*routine)(void *), void *arg) {
/* do nothing */
}