[sys] windows: add NewLazySystemDLL and use it in zsyscall_windows.go

188 views
Skip to first unread message

Alex Brainman (Gerrit)

unread,
Apr 6, 2016, 2:29:11 AM4/6/16
to Brad Fitzpatrick, Ian Lance Taylor, Rob Pike, golang-co...@googlegroups.com
Reviewers: Brad Fitzpatrick

Alex Brainman uploaded a change:
https://go-review.googlesource.com/21592

windows: add NewLazySystemDLL and use it in zsyscall_windows.go

If we want new secure DLL approach to be adopted, we should make
conversion as simple as possible to explain and implement.
I think that replacing

syscall.NewLazyDLL(...) -> windows.NewLazySystemDLL(...)

is easier than

syscall.NewLazyDLL(...) -> &windows.LazyDLL{Name: ..., System: true}

So I propose we introduce convenience function NewLazySystemDLL.

$GOROOT/src/mksyscall_windows.go changes in the following CL.

Change-Id: If3432aff301c347cb355e4e837834696191b2219
---
M windows/dll_windows.go
M windows/registry/zsyscall_windows.go
M windows/zsyscall_windows.go
3 files changed, 20 insertions(+), 13 deletions(-)



diff --git a/windows/dll_windows.go b/windows/dll_windows.go
index 157d07e..5f11067 100644
--- a/windows/dll_windows.go
+++ b/windows/dll_windows.go
@@ -235,6 +235,13 @@
return &LazyDLL{Name: name}
}

+// NewLazySystemDLL is like NewLazyDLL, but will only
+// search Windows System directory for the DLL if name is
+// a base name (like "advapi32.dll").
+func NewLazySystemDLL(name string) *LazyDLL {
+ return &LazyDLL{Name: name, System: true}
+}
+
// A LazyProc implements access to a procedure inside a LazyDLL.
// It delays the lookup until the Addr method is called.
type LazyProc struct {
diff --git a/windows/registry/zsyscall_windows.go
b/windows/registry/zsyscall_windows.go
index f281a80..0fa24c6 100644
--- a/windows/registry/zsyscall_windows.go
+++ b/windows/registry/zsyscall_windows.go
@@ -11,8 +11,8 @@
var _ unsafe.Pointer

var (
- modadvapi32 = &windows.LazyDLL{Name: "advapi32.dll", System: true}
- modkernel32 = &windows.LazyDLL{Name: "kernel32.dll", System: true}
+ modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
+ modkernel32 = windows.NewLazySystemDLL("kernel32.dll")

procRegCreateKeyExW = modadvapi32.NewProc("RegCreateKeyExW")
procRegDeleteKeyW = modadvapi32.NewProc("RegDeleteKeyW")
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index d038831..3ff8f52 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -10,17 +10,17 @@
var _ unsafe.Pointer

var (
- modadvapi32 = &LazyDLL{Name: "advapi32.dll", System: true}
- modkernel32 = &LazyDLL{Name: "kernel32.dll", System: true}
- modshell32 = &LazyDLL{Name: "shell32.dll", System: true}
- modmswsock = &LazyDLL{Name: "mswsock.dll", System: true}
- modcrypt32 = &LazyDLL{Name: "crypt32.dll", System: true}
- modws2_32 = &LazyDLL{Name: "ws2_32.dll", System: true}
- moddnsapi = &LazyDLL{Name: "dnsapi.dll", System: true}
- modiphlpapi = &LazyDLL{Name: "iphlpapi.dll", System: true}
- modsecur32 = &LazyDLL{Name: "secur32.dll", System: true}
- modnetapi32 = &LazyDLL{Name: "netapi32.dll", System: true}
- moduserenv = &LazyDLL{Name: "userenv.dll", System: true}
+ modadvapi32 = NewLazySystemDLL("advapi32.dll")
+ modkernel32 = NewLazySystemDLL("kernel32.dll")
+ modshell32 = NewLazySystemDLL("shell32.dll")
+ modmswsock = NewLazySystemDLL("mswsock.dll")
+ modcrypt32 = NewLazySystemDLL("crypt32.dll")
+ modws2_32 = NewLazySystemDLL("ws2_32.dll")
+ moddnsapi = NewLazySystemDLL("dnsapi.dll")
+ modiphlpapi = NewLazySystemDLL("iphlpapi.dll")
+ modsecur32 = NewLazySystemDLL("secur32.dll")
+ modnetapi32 = NewLazySystemDLL("netapi32.dll")
+ moduserenv = NewLazySystemDLL("userenv.dll")

procRegisterEventSourceW =
modadvapi32.NewProc("RegisterEventSourceW")
procDeregisterEventSource =
modadvapi32.NewProc("DeregisterEventSource")

--
https://go-review.googlesource.com/21592
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>

Brad Fitzpatrick (Gerrit)

unread,
Apr 6, 2016, 2:31:51 AM4/6/16
to Alex Brainman, Brad Fitzpatrick, golang-co...@googlegroups.com
Brad Fitzpatrick has posted comments on this change.

windows: add NewLazySystemDLL and use it in zsyscall_windows.go

Patch Set 1: Code-Review+2

Doesn't seem much cleaner, but I won't object.

--
https://go-review.googlesource.com/21592
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-HasComments: No

Alex Brainman (Gerrit)

unread,
Apr 6, 2016, 2:33:51 AM4/6/16
to golang-...@googlegroups.com, Brad Fitzpatrick, golang-co...@googlegroups.com
Alex Brainman has submitted this change and it was merged.

windows: add NewLazySystemDLL and use it in zsyscall_windows.go

If we want new secure DLL approach to be adopted, we should make
conversion as simple as possible to explain and implement.
I think that replacing

syscall.NewLazyDLL(...) -> windows.NewLazySystemDLL(...)

is easier than

syscall.NewLazyDLL(...) -> &windows.LazyDLL{Name: ..., System: true}

So I propose we introduce convenience function NewLazySystemDLL.

$GOROOT/src/mksyscall_windows.go changes in the following CL.

Change-Id: If3432aff301c347cb355e4e837834696191b2219
Reviewed-on: https://go-review.googlesource.com/21592
Reviewed-by: Brad Fitzpatrick <brad...@golang.org>
---
M windows/dll_windows.go
M windows/registry/zsyscall_windows.go
M windows/zsyscall_windows.go
3 files changed, 20 insertions(+), 13 deletions(-)

Approvals:
Brad Fitzpatrick: Looks good to me, approved


--
https://go-review.googlesource.com/21592
Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Reply all
Reply to author
Forward
0 new messages