@@ -52,22 +52,35 @@ %assign i i+1 %endrep ; valency >= 7. this is not valid, so - ; we set our return value to 0 and the + ; we set our return value to -1 and the ; error number to its maximum value in ; order to indicate that the syscall ; was invalid - mov qword [rbx], 0 + mov qword [rbx], -1 mov qword [r12], -1 ret ; we have a valency match - perform the ; requested syscall already store in rax .perform_call: sys.call + + ; check for an error - on x86, error is + ; returned as a negative value in %rax + test sys.reg.ret, sys.reg.ret + js .error ; jump if sign flag set ; move our return values into place and ; return to the caller (which should ; always be k_platform_syscall, btw) - mov [rbx], sys.reg.ret - mov [r12], sys.reg.err + mov [rbx], sys.reg.ret + mov qword [r12], 0 ; no error ret + + ; an error was returned - we need to set + ; the errno to its positive equivalent, + ; and store -1 in the return variable + .error: neg sys.reg.ret + mov qword [rbx], -1 + mov [r12], sys.reg.ret + ret