summaryrefslogtreecommitdiff
path: root/src/pkg/syscall/zsyscall_windows_386.go
blob: 2032c14a65074f01c879c5d72ae8f4842ff9637e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// mksyscall_mingw.sh -l32 syscall_mingw.go zsyscall_mingw_386.go
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT

package syscall

import "unsafe"

var (
	modKERNEL32                    = loadDll("kernel32.dll")
	procGetLastError               = getSysProcAddr(modKERNEL32, "GetLastError")
	procLoadLibraryW               = getSysProcAddr(modKERNEL32, "LoadLibraryW")
	procFreeLibrary                = getSysProcAddr(modKERNEL32, "FreeLibrary")
	procGetProcAddress             = getSysProcAddr(modKERNEL32, "GetProcAddress")
	procGetVersion                 = getSysProcAddr(modKERNEL32, "GetVersion")
	procFormatMessageW             = getSysProcAddr(modKERNEL32, "FormatMessageW")
	procExitProcess                = getSysProcAddr(modKERNEL32, "ExitProcess")
	procCreateFileW                = getSysProcAddr(modKERNEL32, "CreateFileW")
	procReadFile                   = getSysProcAddr(modKERNEL32, "ReadFile")
	procWriteFile                  = getSysProcAddr(modKERNEL32, "WriteFile")
	procSetFilePointer             = getSysProcAddr(modKERNEL32, "SetFilePointer")
	procCloseHandle                = getSysProcAddr(modKERNEL32, "CloseHandle")
	procGetStdHandle               = getSysProcAddr(modKERNEL32, "GetStdHandle")
	procFindFirstFileW             = getSysProcAddr(modKERNEL32, "FindFirstFileW")
	procFindNextFileW              = getSysProcAddr(modKERNEL32, "FindNextFileW")
	procFindClose                  = getSysProcAddr(modKERNEL32, "FindClose")
	procGetFileInformationByHandle = getSysProcAddr(modKERNEL32, "GetFileInformationByHandle")
	procGetCurrentDirectoryW       = getSysProcAddr(modKERNEL32, "GetCurrentDirectoryW")
	procSetCurrentDirectoryW       = getSysProcAddr(modKERNEL32, "SetCurrentDirectoryW")
	procCreateDirectoryW           = getSysProcAddr(modKERNEL32, "CreateDirectoryW")
	procRemoveDirectoryW           = getSysProcAddr(modKERNEL32, "RemoveDirectoryW")
	procDeleteFileW                = getSysProcAddr(modKERNEL32, "DeleteFileW")
	procMoveFileW                  = getSysProcAddr(modKERNEL32, "MoveFileW")
	procGetComputerNameW           = getSysProcAddr(modKERNEL32, "GetComputerNameW")
	procSetEndOfFile               = getSysProcAddr(modKERNEL32, "SetEndOfFile")
	procGetSystemTimeAsFileTime    = getSysProcAddr(modKERNEL32, "GetSystemTimeAsFileTime")
	procSleep                      = getSysProcAddr(modKERNEL32, "Sleep")
)

func GetLastError() (lasterrno int) {
	r0, _, _ := Syscall(procGetLastError, 0, 0, 0)
	lasterrno = int(r0)
	return
}

func LoadLibrary(libname string) (handle uint32, errno int) {
	r0, _, e1 := Syscall(procLoadLibraryW, uintptr(unsafe.Pointer(StringToUTF16Ptr(libname))), 0, 0)
	handle = uint32(r0)
	if handle == 0 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func FreeLibrary(handle uint32) (ok bool, errno int) {
	r0, _, e1 := Syscall(procFreeLibrary, uintptr(handle), 0, 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func GetProcAddress(module uint32, procname string) (proc uint32, errno int) {
	r0, _, e1 := Syscall(procGetProcAddress, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0)
	proc = uint32(r0)
	if proc == 0 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func GetVersion() (ver uint32, errno int) {
	r0, _, e1 := Syscall(procGetVersion, 0, 0, 0)
	ver = uint32(r0)
	if ver == 0 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, errno int) {
	var _p0 *uint16
	if len(buf) > 0 {
		_p0 = &buf[0]
	}
	r0, _, e1 := Syscall9(procFormatMessageW, uintptr(flags), uintptr(msgsrc), uintptr(msgid), uintptr(langid), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(args)), 0, 0)
	n = uint32(r0)
	if n == 0 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func ExitProcess(exitcode uint32) {
	Syscall(procExitProcess, uintptr(exitcode), 0, 0)
	return
}

func CreateFile(name *uint16, access uint32, mode uint32, sa *byte, createmode uint32, attrs uint32, templatefile int32) (handle int32, errno int) {
	r0, _, e1 := Syscall9(procCreateFileW, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
	handle = int32(r0)
	if handle == -1 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func ReadFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (ok bool, errno int) {
	var _p0 *byte
	if len(buf) > 0 {
		_p0 = &buf[0]
	}
	r0, _, e1 := Syscall6(procReadFile, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func WriteFile(handle int32, buf []byte, done *uint32, overlapped *Overlapped) (ok bool, errno int) {
	var _p0 *byte
	if len(buf) > 0 {
		_p0 = &buf[0]
	}
	r0, _, e1 := Syscall6(procWriteFile, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func SetFilePointer(handle int32, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, errno int) {
	r0, _, e1 := Syscall6(procSetFilePointer, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
	newlowoffset = uint32(r0)
	if newlowoffset == 0xffffffff {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func CloseHandle(handle int32) (ok bool, errno int) {
	r0, _, e1 := Syscall(procCloseHandle, uintptr(handle), 0, 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func GetStdHandle(stdhandle int32) (handle int32, errno int) {
	r0, _, e1 := Syscall(procGetStdHandle, uintptr(stdhandle), 0, 0)
	handle = int32(r0)
	if handle == -1 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func FindFirstFile(name *uint16, data *Win32finddata) (handle int32, errno int) {
	r0, _, e1 := Syscall(procFindFirstFileW, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
	handle = int32(r0)
	if handle == -1 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func FindNextFile(handle int32, data *Win32finddata) (ok bool, errno int) {
	r0, _, e1 := Syscall(procFindNextFileW, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func FindClose(handle int32) (ok bool, errno int) {
	r0, _, e1 := Syscall(procFindClose, uintptr(handle), 0, 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func GetFileInformationByHandle(handle int32, data *ByHandleFileInformation) (ok bool, errno int) {
	r0, _, e1 := Syscall(procGetFileInformationByHandle, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, errno int) {
	r0, _, e1 := Syscall(procGetCurrentDirectoryW, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
	n = uint32(r0)
	if n == 0 {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func SetCurrentDirectory(path *uint16) (ok bool, errno int) {
	r0, _, e1 := Syscall(procSetCurrentDirectoryW, uintptr(unsafe.Pointer(path)), 0, 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func CreateDirectory(path *uint16, sa *byte) (ok bool, errno int) {
	r0, _, e1 := Syscall(procCreateDirectoryW, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func RemoveDirectory(path *uint16) (ok bool, errno int) {
	r0, _, e1 := Syscall(procRemoveDirectoryW, uintptr(unsafe.Pointer(path)), 0, 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func DeleteFile(path *uint16) (ok bool, errno int) {
	r0, _, e1 := Syscall(procDeleteFileW, uintptr(unsafe.Pointer(path)), 0, 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func MoveFile(from *uint16, to *uint16) (ok bool, errno int) {
	r0, _, e1 := Syscall(procMoveFileW, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func GetComputerName(buf *uint16, n *uint32) (ok bool, errno int) {
	r0, _, e1 := Syscall(procGetComputerNameW, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func SetEndOfFile(handle int32) (ok bool, errno int) {
	r0, _, e1 := Syscall(procSetEndOfFile, uintptr(handle), 0, 0)
	ok = bool(r0 != 0)
	if !ok {
		errno = int(e1)
	} else {
		errno = 0
	}
	return
}

func GetSystemTimeAsFileTime(time *Filetime) {
	Syscall(procGetSystemTimeAsFileTime, uintptr(unsafe.Pointer(time)), 0, 0)
	return
}

func sleep(msec uint32) {
	Syscall(procSleep, uintptr(msec), 0, 0)
	return
}