Commit 6b648caf authored by Alex Brainman's avatar Alex Brainman

runtime: another attempt to allow stdcall to be used from both 386 and amd64 arch

R=rsc
CC=golang-dev, vcc.163
https://golang.org/cl/4627071
parent fe2ccb53
...@@ -24,7 +24,7 @@ void* ...@@ -24,7 +24,7 @@ void*
runtime·SysAlloc(uintptr n) runtime·SysAlloc(uintptr n)
{ {
mstats.sys += n; mstats.sys += n;
return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, (uintptr)(MEM_COMMIT|MEM_RESERVE), (uintptr)PAGE_EXECUTE_READWRITE);
} }
void void
...@@ -40,7 +40,7 @@ runtime·SysFree(void *v, uintptr n) ...@@ -40,7 +40,7 @@ runtime·SysFree(void *v, uintptr n)
uintptr r; uintptr r;
mstats.sys -= n; mstats.sys -= n;
r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, 0, MEM_RELEASE); r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, (uintptr)0, (uintptr)MEM_RELEASE);
if(r == 0) if(r == 0)
runtime·throw("runtime: failed to release pages"); runtime·throw("runtime: failed to release pages");
} }
...@@ -50,12 +50,12 @@ runtime·SysReserve(void *v, uintptr n) ...@@ -50,12 +50,12 @@ runtime·SysReserve(void *v, uintptr n)
{ {
// v is just a hint. // v is just a hint.
// First try at v. // First try at v.
v = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_RESERVE, PAGE_EXECUTE_READWRITE); v = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, (uintptr)MEM_RESERVE, (uintptr)PAGE_EXECUTE_READWRITE);
if(v != nil) if(v != nil)
return v; return v;
// Next let the kernel choose the address. // Next let the kernel choose the address.
return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_RESERVE, PAGE_EXECUTE_READWRITE); return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, (uintptr)MEM_RESERVE, (uintptr)PAGE_EXECUTE_READWRITE);
} }
void void
...@@ -64,7 +64,7 @@ runtime·SysMap(void *v, uintptr n) ...@@ -64,7 +64,7 @@ runtime·SysMap(void *v, uintptr n)
void *p; void *p;
mstats.sys += n; mstats.sys += n;
p = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, MEM_COMMIT, PAGE_EXECUTE_READWRITE); p = runtime·stdcall(runtime·VirtualAlloc, 4, v, n, (uintptr)MEM_COMMIT, (uintptr)PAGE_EXECUTE_READWRITE);
if(p != v) if(p != v)
runtime·throw("runtime: cannot map pages in arena address space"); runtime·throw("runtime: cannot map pages in arena address space");
} }
...@@ -7,6 +7,9 @@ extern void *runtime·GetProcAddress; ...@@ -7,6 +7,9 @@ extern void *runtime·GetProcAddress;
// Call a Windows function with stdcall conventions, // Call a Windows function with stdcall conventions,
// and switch to os stack during the call. // and switch to os stack during the call.
#pragma varargck countpos runtime·stdcall 2
#pragma varargck type runtime·stdcall void*
#pragma varargck type runtime·stdcall uintptr
void *runtime·stdcall_raw(void *fn, uintptr nargs, void *args); void *runtime·stdcall_raw(void *fn, uintptr nargs, void *args);
void *runtime·stdcall(void *fn, int32 count, ...); void *runtime·stdcall(void *fn, int32 count, ...);
uintptr runtime·syscall(void *fn, uintptr nargs, void *args, uintptr *err); uintptr runtime·syscall(void *fn, uintptr nargs, void *args, uintptr *err);
......
...@@ -45,7 +45,7 @@ void ...@@ -45,7 +45,7 @@ void
runtime·osinit(void) runtime·osinit(void)
{ {
runtime·stdcall(runtime·QueryPerformanceFrequency, 1, &timerfreq); runtime·stdcall(runtime·QueryPerformanceFrequency, 1, &timerfreq);
runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, 1); runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (uintptr)1);
} }
void void
...@@ -81,7 +81,7 @@ runtime·goenvs(void) ...@@ -81,7 +81,7 @@ runtime·goenvs(void)
void void
runtime·exit(int32 code) runtime·exit(int32 code)
{ {
runtime·stdcall(runtime·ExitProcess, 1, code); runtime·stdcall(runtime·ExitProcess, 1, (uintptr)code);
} }
int32 int32
...@@ -93,15 +93,15 @@ runtime·write(int32 fd, void *buf, int32 n) ...@@ -93,15 +93,15 @@ runtime·write(int32 fd, void *buf, int32 n)
written = 0; written = 0;
switch(fd) { switch(fd) {
case 1: case 1:
handle = runtime·stdcall(runtime·GetStdHandle, 1, -11); handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-11);
break; break;
case 2: case 2:
handle = runtime·stdcall(runtime·GetStdHandle, 1, -12); handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-12);
break; break;
default: default:
return -1; return -1;
} }
runtime·stdcall(runtime·WriteFile, 5, handle, buf, n, &written, 0); runtime·stdcall(runtime·WriteFile, 5, handle, buf, (uintptr)n, &written, (uintptr)0);
return written; return written;
} }
...@@ -111,7 +111,7 @@ initevent(void **pevent) ...@@ -111,7 +111,7 @@ initevent(void **pevent)
{ {
void *event; void *event;
event = runtime·stdcall(runtime·CreateEvent, 4, 0, 0, 0, 0); event = runtime·stdcall(runtime·CreateEvent, 4, (uintptr)0, (uintptr)0, (uintptr)0, (uintptr)0);
if(!runtime·casp(pevent, 0, event)) { if(!runtime·casp(pevent, 0, event)) {
// Someone else filled it in. Use theirs. // Someone else filled it in. Use theirs.
runtime·stdcall(runtime·CloseHandle, 1, event); runtime·stdcall(runtime·CloseHandle, 1, event);
...@@ -126,7 +126,7 @@ eventlock(Lock *l) ...@@ -126,7 +126,7 @@ eventlock(Lock *l)
initevent(&l->event); initevent(&l->event);
if(runtime·xadd(&l->key, 1) > 1) // someone else has it; wait if(runtime·xadd(&l->key, 1) > 1) // someone else has it; wait
runtime·stdcall(runtime·WaitForSingleObject, 2, l->event, -1); runtime·stdcall(runtime·WaitForSingleObject, 2, l->event, (uintptr)-1);
} }
static void static void
...@@ -190,7 +190,7 @@ runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void)) ...@@ -190,7 +190,7 @@ runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
USED(g); // assuming g = m->g0 USED(g); // assuming g = m->g0
USED(fn); // assuming fn = mstart USED(fn); // assuming fn = mstart
thandle = runtime·stdcall(runtime·CreateThread, 6, 0, 0, runtime·tstart_stdcall, m, 0, 0); thandle = runtime·stdcall(runtime·CreateThread, 6, (uintptr)0, (uintptr)0, runtime·tstart_stdcall, m, (uintptr)0, (uintptr)0);
if(thandle == 0) { if(thandle == 0) {
runtime·printf("runtime: failed to create new OS thread (have %d already; errno=%d)\n", runtime·mcount(), runtime·getlasterror()); runtime·printf("runtime: failed to create new OS thread (have %d already; errno=%d)\n", runtime·mcount(), runtime·getlasterror());
runtime·throw("runtime.newosproc"); runtime·throw("runtime.newosproc");
......
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