From 7231a21b00028a52d7938131bfeca4d663d09071 Mon Sep 17 00:00:00 2001 From: Prefetch Date: Sat, 22 Jul 2023 19:22:06 +0200 Subject: Add locks, with some minor improvements to threads --- lib/thread_create.asm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'lib/thread_create.asm') diff --git a/lib/thread_create.asm b/lib/thread_create.asm index 2ccd1fa..9a6fe78 100644 --- a/lib/thread_create.asm +++ b/lib/thread_create.asm @@ -3,9 +3,9 @@ ; Cheat sheet for Linux' x86_64 calling convention: ; -; - free to overwrite; the caller should save them: +; - free to overwrite (caller should save them): ; rax, rcx, rdx, rsi, rdi, r8-r11, xmm0-xmm15 -; - caller expects no change; callee should save them: +; - caller expects be kept (callee should save them): ; rbx, rbp, r12-r15 ; ; - for passing paramters to functions: @@ -63,9 +63,9 @@ section .text ; Create a new thread executing a given function. Arguments: -; rdi: u32** = where to put the thread handle -; rsi: void* (*)(void*) = function to make the child run -; rdx: void* = single argument for function +; rdi: struct{u32,u32}** = where to put the thread handle +; rsi: void* (*)(void*) = function to make the child run +; rdx: void* = single argument for function ; Returns zero on success, or a standard error code. global linen_thread_create linen_thread_create: @@ -79,9 +79,9 @@ linen_thread_create: ; Return EINVAL if any argument is NULL mov eax, -22 ; (EINVAL = -22) test rdi, rdi - jz create_end ; Nowhere to store the thread handle + jz create_return ; Nowhere to store the thread handle test rsi, rsi - jz create_end ; No function for the thread to run + jz create_return ; No function for the thread to run ; Note: we allow rdx to be NULL; in that case the worst that can happen ; is a segmentation fault in the user's code (not really our problem). @@ -104,7 +104,7 @@ linen_thread_create: mov esi, (STACK_SIZE + GUARD_PAGE) ; mmap: rdx = prot: mprotect-style access permissions mov edx, (PROT_WRITE | PROT_READ) - ; mmap: r10 = flags: settings for mapping + ; mmap: r10 = flags: configuration flags for mapping: ; - MAP_ANONYMOUS: there is no file backing this buffer ; - MAP_PRIVATE: only this process can see thread's stack ; - MAP_STACK: no-op; inform kernel that this is a stack @@ -126,7 +126,7 @@ linen_thread_create: ; Check result of mmap: negative means failure, ; otherwise rax is the address of the new mapping. test rax, rax - js create_end + js create_return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Revoke guard page's R/W permissions ;;;; @@ -151,7 +151,7 @@ linen_thread_create: ; Check result of mprotect: nonzero means failure test rax, rax - jnz create_end + jnz create_return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Spawn a thread with the new stack ;;;; @@ -202,7 +202,7 @@ linen_thread_create: ; Check result of clone: test rax, rax - js create_end ; Negative means failure + js create_return ; Negative means failure jnz create_success ; Positive means we're in the parent thread ; Zero means we're in the child thread @@ -256,7 +256,7 @@ linen_thread_create: ; Return 0 for success xor eax, eax - create_end: + create_return: ; Restore callee-save registers pop rbx -- cgit v1.2.3