vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: 143a28340bdc4536a904140577c247d99337f731
Parent: 54be90c3fc475444f115e8d5c87f4b743f775c35
Author: Randy Palamar
Date:   Sun,  1 Dec 2024 21:44:39 -0700

cleanup render thread's starting call stack

probably not critical but it aids in debugging and was good for
learning more about naked functions and system v abi

Diffstat:
Mplatform_linux_amd64.c | 17+++++++++++------
Mplatform_linux_x11.c | 2+-
2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/platform_linux_amd64.c b/platform_linux_amd64.c @@ -113,17 +113,22 @@ syscall6(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5, i64 a6) return result; } -/* NOTE: graciously taken from nullprogram (Chris Wellons) */ +/* NOTE: based on code from nullprogram (Chris Wellons) */ __attribute__((naked)) -static i64 clone_thread(void *stack_base) +static i64 +new_thread(void *stack_base) { asm volatile ( - "mov %%rdi, %%rsi\n" // arg2 = stack + "mov %%rdi, %%rsi\n" // arg2 = new stack "mov $0x50F00, %%edi\n" // arg1 = clone flags (VM|FS|FILES|SIGHAND|THREAD|SYSVMEM) - "mov $56, %%eax\n" // SYS_clone + "mov $56, %%eax\n" // SYS_clone "syscall\n" - "mov %%rsp, %%rdi\n" // entry point argument - "ret\n" + "test %%eax, %%eax\n" // don't mess with the calling thread's stack + "jne 1f\n" + "mov %%rsp, %%rdi\n" + "sub $8, %%rsp\n" // place a 0 return branch pointer on the child's stack + "push (%%rdi)\n" // push the entry point back onto the stack for use by ret + "1: ret\n" : : : "rax", "rcx", "rsi", "rdi", "r11", "memory" ); } diff --git a/platform_linux_x11.c b/platform_linux_x11.c @@ -405,7 +405,7 @@ main(i32 argc, char *argv[], char *envp[]) struct stack_base *render_stack = new_stack(KB(256)); render_stack->entry = linux_render_thread_entry; - clone_thread(render_stack); + new_thread(render_stack); { MemoryBlock terminal_memory = linux_block_alloc(MB(32));