mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-30 05:46:45 -04:00
windows: use go:linkname instead of assembly
This is a bit cleaner and makes it more explicit what's happening, along with a documenting comment. Change-Id: I30c92f8576c72b05ebdb4634c68023237bde3cbf Reviewed-on: https://go-review.googlesource.com/c/sys/+/199519 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
@@ -1,13 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
//
|
|
||||||
// System calls for 386, Windows are implemented in runtime/syscall_windows.goc
|
|
||||||
//
|
|
||||||
|
|
||||||
TEXT ·getprocaddress(SB), 7, $0-16
|
|
||||||
JMP syscall·getprocaddress(SB)
|
|
||||||
|
|
||||||
TEXT ·loadlibrary(SB), 7, $0-12
|
|
||||||
JMP syscall·loadlibrary(SB)
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
//
|
|
||||||
// System calls for amd64, Windows are implemented in runtime/syscall_windows.goc
|
|
||||||
//
|
|
||||||
|
|
||||||
TEXT ·getprocaddress(SB), 7, $0-32
|
|
||||||
JMP syscall·getprocaddress(SB)
|
|
||||||
|
|
||||||
TEXT ·loadlibrary(SB), 7, $0-24
|
|
||||||
JMP syscall·loadlibrary(SB)
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
// Copyright 2018 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.
|
|
||||||
|
|
||||||
#include "textflag.h"
|
|
||||||
|
|
||||||
TEXT ·getprocaddress(SB),NOSPLIT,$0
|
|
||||||
B syscall·getprocaddress(SB)
|
|
||||||
|
|
||||||
TEXT ·loadlibrary(SB),NOSPLIT,$0
|
|
||||||
B syscall·loadlibrary(SB)
|
|
||||||
+15
-7
@@ -11,6 +11,18 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// We need to use LoadLibrary and GetProcAddress from the Go runtime, because
|
||||||
|
// the these symbols are loaded by the system linker and are required to
|
||||||
|
// dynamically load additional symbols. Note that in the Go runtime, these
|
||||||
|
// return syscall.Handle and syscall.Errno, but these are the same, in fact,
|
||||||
|
// as windows.Handle and windows.Errno, and we intend to keep these the same.
|
||||||
|
|
||||||
|
//go:linkname syscall_loadlibrary syscall.loadlibrary
|
||||||
|
func syscall_loadlibrary(filename *uint16) (handle Handle, err Errno)
|
||||||
|
|
||||||
|
//go:linkname syscall_getprocaddress syscall.getprocaddress
|
||||||
|
func syscall_getprocaddress(handle Handle, procname *uint8) (proc uintptr, err Errno)
|
||||||
|
|
||||||
// DLLError describes reasons for DLL load failures.
|
// DLLError describes reasons for DLL load failures.
|
||||||
type DLLError struct {
|
type DLLError struct {
|
||||||
Err error
|
Err error
|
||||||
@@ -20,10 +32,6 @@ type DLLError struct {
|
|||||||
|
|
||||||
func (e *DLLError) Error() string { return e.Msg }
|
func (e *DLLError) Error() string { return e.Msg }
|
||||||
|
|
||||||
// Implemented in runtime/syscall_windows.goc; we provide jumps to them in our assembly file.
|
|
||||||
func loadlibrary(filename *uint16) (handle uintptr, err syscall.Errno)
|
|
||||||
func getprocaddress(handle uintptr, procname *uint8) (proc uintptr, err syscall.Errno)
|
|
||||||
|
|
||||||
// A DLL implements access to a single DLL.
|
// A DLL implements access to a single DLL.
|
||||||
type DLL struct {
|
type DLL struct {
|
||||||
Name string
|
Name string
|
||||||
@@ -40,7 +48,7 @@ func LoadDLL(name string) (dll *DLL, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
h, e := loadlibrary(namep)
|
h, e := syscall_loadlibrary(namep)
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
return nil, &DLLError{
|
return nil, &DLLError{
|
||||||
Err: e,
|
Err: e,
|
||||||
@@ -50,7 +58,7 @@ func LoadDLL(name string) (dll *DLL, err error) {
|
|||||||
}
|
}
|
||||||
d := &DLL{
|
d := &DLL{
|
||||||
Name: name,
|
Name: name,
|
||||||
Handle: Handle(h),
|
Handle: h,
|
||||||
}
|
}
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
@@ -71,7 +79,7 @@ func (d *DLL) FindProc(name string) (proc *Proc, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
a, e := getprocaddress(uintptr(d.Handle), namep)
|
a, e := syscall_getprocaddress(d.Handle, namep)
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
return nil, &DLLError{
|
return nil, &DLLError{
|
||||||
Err: e,
|
Err: e,
|
||||||
|
|||||||
Reference in New Issue
Block a user