libk  Diff

Differences From Artifact [472ad3a7d3]:

To Artifact [9bf0ba9bf3]:

  • File mod/kcore/syscall.fn.x86.lin.64.s — part of check-in [e50a476efe] at 2019-08-22 02:52:20 on branch trunk — removed sneaky segfault in x86-64 syscall fn where %r8 (the register that contains the pointer to the syscall arguments from the C syscall wrapper, which need to be copied into the correct registers before the kernel is invoked) gets overwritten if the syscall valency > 5, because of overlapping ccall and syscall ABI argument registers - r8 is clobbered by argument 5 and any further attempts to use it as a ptr segfault at best. also modified the report function so that it immediate cancels compilation if a sub-process reports failure. changed allocator function signatures so they can return a condition code if the kernel reports an error; updated example code so it compiles and runs without fault. (user: lexi, size: 2358) [annotate] [blame] [check-ins using]

     7      7   ; altogether and access the error value of a
     8      8   ; syscall directly. invoke as:
     9      9   ;
    10     10   ; 	void k_platform_syscall_raw(s64* result, u64* errno,
    11     11   ;		syscall, u8 valency, s64[] args)
    12     12   
    13     13   bits 64
    14         -%include "../arch/posix/x86.lin.64.s"
    15         -%include "../arch/x86.cdecl.64.s"
           14  +%include "arch/posix/x86.lin.64.s"
           15  +%include "arch/x86.cdecl.64.s"
    16     16   ; vim: ft=nasm
    17     17   
    18     18   %macro handle_arg 1
    19     19   	%assign v %1+1
    20         -	mov sys.reg. %+ v, [ccall.reg.4 + 8 * %1]
           20  +	mov sys.reg. %+ v, [r15 + 8 * %1]
    21     21   	dec ccall.reg.3
    22     22   	jz .perform_call
    23     23   %endmacro
    24     24   
    25     25   global k_platform_syscall_raw:function
    26     26   k_platform_syscall_raw:
    27     27   	; locals: rbx = s64* result
................................................................................
    38     38   	; and popping back from the stack
    39     39   	mov rbx, ccall.reg.0
    40     40   	mov r12, ccall.reg.1
    41     41   
    42     42   	; this needs to go before the loop
    43     43   	; or it'll get clobbered
    44     44   	mov sys.reg.0, ccall.reg.2
           45  +
           46  +	; the fourth argument is in %r8, which
           47  +	; is also a syscall register, so we 
           48  +	; need to move it to a safe register
           49  +	; to keep it from getting clobbered
           50  +	; before we begin the "loop"
           51  +	mov r15, ccall.reg.4
    45     52   
    46     53   	; automatically generate the code
    47     54   	; needed to move the arguments into
    48     55   	; their correct registers. see above
    49     56   	%assign i 0
    50     57   	%rep 6
    51     58   		handle_arg i