Skip to content

Commit 119c30e

Browse files
committed
internal/syscall/windows: add GetModuleFileName
For os.Executable. Updates #12773. Change-Id: Iff6593514b7453b6c5e1f20079e35cb4992cc74a Reviewed-on: https://go-review.googlesource.com/32877 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent a9a1d02 commit 119c30e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/internal/syscall/windows/syscall_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const (
110110
//sys GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) = iphlpapi.GetAdaptersAddresses
111111
//sys GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
112112
//sys MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) = MoveFileExW
113+
//sys GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) = kernel32.GetModuleFileNameW
113114

114115
const (
115116
ComputerNameNetBIOS = 0

src/internal/syscall/windows/zsyscall_windows.go

+14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
4545
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
4646
procMoveFileExW = modkernel32.NewProc("MoveFileExW")
47+
procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
4748
procGetACP = modkernel32.NewProc("GetACP")
4849
procGetConsoleCP = modkernel32.NewProc("GetConsoleCP")
4950
procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
@@ -89,6 +90,19 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
8990
return
9091
}
9192

93+
func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) {
94+
r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(fn)), uintptr(len))
95+
n = uint32(r0)
96+
if n == 0 {
97+
if e1 != 0 {
98+
err = errnoErr(e1)
99+
} else {
100+
err = syscall.EINVAL
101+
}
102+
}
103+
return
104+
}
105+
92106
func GetACP() (acp uint32) {
93107
r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
94108
acp = uint32(r0)

0 commit comments

Comments
 (0)