diff options
author | Alex Brainman <alex.brainman@gmail.com> | 2010-03-09 15:09:09 -0800 |
---|---|---|
committer | Alex Brainman <alex.brainman@gmail.com> | 2010-03-09 15:09:09 -0800 |
commit | 4c80ee5969a17e5a1fde0d65d71aa514fca87e26 (patch) | |
tree | 35dc6c152df37a913dd2552cfb399c85c4e18036 /src/pkg/runtime | |
parent | 82ed533b5e7fc9c2b260f831fd5437dbc436835c (diff) | |
download | golang-4c80ee5969a17e5a1fde0d65d71aa514fca87e26.tar.gz |
syscall: minimal mingw version of syscall to call windows dlls
lots of missing parts, but builds and can call dlls, see a sample code in syscall_mingw.go
R=rsc
CC=golang-dev
http://codereview.appspot.com/218042
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r-- | src/pkg/runtime/Makefile | 3 | ||||
-rw-r--r-- | src/pkg/runtime/mingw/os.h | 3 | ||||
-rw-r--r-- | src/pkg/runtime/mingw/syscall.cgo | 37 | ||||
-rw-r--r-- | src/pkg/runtime/mingw/thread.c | 6 |
4 files changed, 47 insertions, 2 deletions
diff --git a/src/pkg/runtime/Makefile b/src/pkg/runtime/Makefile index 103515c13..bc8a2d8bf 100644 --- a/src/pkg/runtime/Makefile +++ b/src/pkg/runtime/Makefile @@ -27,6 +27,9 @@ GOFILES=\ GOFILES_pchw=\ pchw/io.go\ +OFILES_mingw=\ + syscall.$O\ + # 386-specific object files OFILES_386=\ vlop.$O\ diff --git a/src/pkg/runtime/mingw/os.h b/src/pkg/runtime/mingw/os.h index 3864dbf8f..0de388524 100644 --- a/src/pkg/runtime/mingw/os.h +++ b/src/pkg/runtime/mingw/os.h @@ -12,6 +12,9 @@ void *stdcall(void *fn, ...); void *stdcall_raw(void *fn, ...); extern void *VirtualAlloc; +extern void *LoadLibraryEx; +extern void *GetProcAddress; +extern void *GetLastError; #define goargs mingw_goargs void mingw_goargs(void); diff --git a/src/pkg/runtime/mingw/syscall.cgo b/src/pkg/runtime/mingw/syscall.cgo new file mode 100644 index 000000000..1553c6131 --- /dev/null +++ b/src/pkg/runtime/mingw/syscall.cgo @@ -0,0 +1,37 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package syscall +#include "runtime.h" +#include "os.h" + +func loadlibraryex(filename uintptr) (handle uint32) { + handle = (uint32)stdcall(LoadLibraryEx, filename, 0, 0); +} + +func getprocaddress(handle uint32, procname uintptr) (proc uintptr) { + proc = (uintptr)stdcall(GetProcAddress, handle, procname); +} + +func Syscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr) (r1 uintptr, r2 uintptr, err uintptr) { + ·entersyscall(); + r1 = (uintptr)stdcall_raw((void*)trap, a1, a2, a3); + r2 = 0; + err = (uintptr)stdcall_raw(GetLastError); + ·exitsyscall(); +} + +func Syscall6(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr) (r1 uintptr, r2 uintptr, err uintptr) { + ·entersyscall(); + r1 = (uintptr)stdcall_raw((void*)trap, a1, a2, a3, a4, a5, a6); + r2 = 0; + err = (uintptr)stdcall_raw(GetLastError); + ·exitsyscall(); +} + +func RawSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr) (r1 uintptr, r2 uintptr, err uintptr) { + r1 = (uintptr)stdcall_raw((void*)trap, a1, a2, a3); + r2 = 0; + err = (uintptr)stdcall_raw(GetLastError); +} diff --git a/src/pkg/runtime/mingw/thread.c b/src/pkg/runtime/mingw/thread.c index 89f33f8a4..94ffc2752 100644 --- a/src/pkg/runtime/mingw/thread.c +++ b/src/pkg/runtime/mingw/thread.c @@ -16,12 +16,13 @@ void *GetStdHandle; void *SetEvent; void *WriteFile; void *VirtualAlloc; +void *LoadLibraryEx; +void *GetProcAddress; +void *GetLastError; static void *CreateEvent; static void *CreateThread; static void *GetModuleHandle; -static void *GetProcAddress; -static void *LoadLibraryEx; static void *WaitForSingleObject; static void* @@ -65,6 +66,7 @@ osinit(void) VirtualAlloc = get_proc_addr("kernel32.dll", "VirtualAlloc"); WaitForSingleObject = get_proc_addr("kernel32.dll", "WaitForSingleObject"); WriteFile = get_proc_addr("kernel32.dll", "WriteFile"); + GetLastError = get_proc_addr("kernel32.dll", "GetLastError"); } // The arguments are strings. |