Commit eee09539 authored by Alex Brainman's avatar Alex Brainman

syscall: improve windows errno handling

R=rsc, Joe Poirier, PeterGo
CC=golang-dev
https://golang.org/cl/1872045
parent aa4639fa
...@@ -17,6 +17,7 @@ void *VirtualAlloc; ...@@ -17,6 +17,7 @@ void *VirtualAlloc;
void *LoadLibraryEx; void *LoadLibraryEx;
void *GetProcAddress; void *GetProcAddress;
void *GetLastError; void *GetLastError;
void *SetLastError;
static void *CreateEvent; static void *CreateEvent;
static void *CreateThread; static void *CreateThread;
...@@ -65,6 +66,7 @@ osinit(void) ...@@ -65,6 +66,7 @@ osinit(void)
WaitForSingleObject = get_proc_addr("kernel32.dll", "WaitForSingleObject"); WaitForSingleObject = get_proc_addr("kernel32.dll", "WaitForSingleObject");
WriteFile = get_proc_addr("kernel32.dll", "WriteFile"); WriteFile = get_proc_addr("kernel32.dll", "WriteFile");
GetLastError = get_proc_addr("kernel32.dll", "GetLastError"); GetLastError = get_proc_addr("kernel32.dll", "GetLastError");
SetLastError = get_proc_addr("kernel32.dll", "SetLastError");
} }
// The arguments are strings. // The arguments are strings.
...@@ -285,6 +287,7 @@ void ...@@ -285,6 +287,7 @@ void
call_syscall(void *args) call_syscall(void *args)
{ {
StdcallParams *p = (StdcallParams*)args; StdcallParams *p = (StdcallParams*)args;
stdcall_raw(SetLastError, 1, 0);
p->r = (uintptr)stdcall_raw((void*)p->fn, p->args[0], p->args[1], p->args[2], p->args[3], p->args[4], p->args[5], p->args[6], p->args[7], p->args[8], p->args[9], p->args[10], p->args[11]); p->r = (uintptr)stdcall_raw((void*)p->fn, p->args[0], p->args[1], p->args[2], p->args[3], p->args[4], p->args[5], p->args[6], p->args[7], p->args[8], p->args[9], p->args[10], p->args[11]);
p->err = (uintptr)stdcall_raw(GetLastError); p->err = (uintptr)stdcall_raw(GetLastError);
return; return;
......
...@@ -229,7 +229,11 @@ while(<>) { ...@@ -229,7 +229,11 @@ while(<>) {
if($name eq "errno") { if($name eq "errno") {
# Set errno to "last error" only if returned value indicate failure # Set errno to "last error" only if returned value indicate failure
$body .= "\tif $failexpr {\n"; $body .= "\tif $failexpr {\n";
$body .= "\t\t$name = $type($reg);\n"; $body .= "\t\tif $reg != 0 {\n";
$body .= "\t\t\t$name = $type($reg);\n";
$body .= "\t\t} else {\n";
$body .= "\t\t\t$name = EINVAL;\n";
$body .= "\t\t}\n";
$body .= "\t} else {\n"; $body .= "\t} else {\n";
$body .= "\t\t$name = 0;\n"; $body .= "\t\t$name = 0;\n";
$body .= "\t}\n"; $body .= "\t}\n";
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment