Skip to content

Commit 1ec8cad

Browse files
authored
Fix unsafe uses of unsafe.Pointer (microsoft#1438)
Per rule 4 of unsafe.Pointer usage, conversion of a unsafe.Pointer to a uinptr to pass to the syscall.Syscall family should only be done in the argument list. We had a couple spots where we were passing it in as an argument to a small wrapper function until it reached the underlying syscall.Syscall*. https://pkg.go.dev/unsafe#Pointer Signed-off-by: Daniel Canter <[email protected]>
1 parent bc3b951 commit 1ec8cad

7 files changed

Lines changed: 15 additions & 15 deletions

File tree

internal/jobcontainers/jobcontainer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ func systemProcessInformation() ([]*winapi.SYSTEM_PROCESS_INFORMATION, error) {
731731
systemProcInfo = (*winapi.SYSTEM_PROCESS_INFORMATION)(unsafe.Pointer(&b[0]))
732732
status := winapi.NtQuerySystemInformation(
733733
winapi.SystemProcessInformation,
734-
uintptr(unsafe.Pointer(systemProcInfo)),
734+
unsafe.Pointer(systemProcInfo),
735735
size,
736736
&size,
737737
)

internal/jobobject/jobobject.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (job *JobObject) Pids() ([]uint32, error) {
344344
err := winapi.QueryInformationJobObject(
345345
job.handle,
346346
winapi.JobObjectBasicProcessIdList,
347-
uintptr(unsafe.Pointer(&info)),
347+
unsafe.Pointer(&info),
348348
uint32(unsafe.Sizeof(info)),
349349
nil,
350350
)
@@ -370,7 +370,7 @@ func (job *JobObject) Pids() ([]uint32, error) {
370370
if err = winapi.QueryInformationJobObject(
371371
job.handle,
372372
winapi.JobObjectBasicProcessIdList,
373-
uintptr(unsafe.Pointer(&buf[0])),
373+
unsafe.Pointer(&buf[0]),
374374
uint32(len(buf)),
375375
nil,
376376
); err != nil {
@@ -398,7 +398,7 @@ func (job *JobObject) QueryMemoryStats() (*winapi.JOBOBJECT_MEMORY_USAGE_INFORMA
398398
if err := winapi.QueryInformationJobObject(
399399
job.handle,
400400
winapi.JobObjectMemoryUsageInformation,
401-
uintptr(unsafe.Pointer(&info)),
401+
unsafe.Pointer(&info),
402402
uint32(unsafe.Sizeof(info)),
403403
nil,
404404
); err != nil {
@@ -420,7 +420,7 @@ func (job *JobObject) QueryProcessorStats() (*winapi.JOBOBJECT_BASIC_ACCOUNTING_
420420
if err := winapi.QueryInformationJobObject(
421421
job.handle,
422422
winapi.JobObjectBasicAccountingInformation,
423-
uintptr(unsafe.Pointer(&info)),
423+
unsafe.Pointer(&info),
424424
uint32(unsafe.Sizeof(info)),
425425
nil,
426426
); err != nil {
@@ -444,7 +444,7 @@ func (job *JobObject) QueryStorageStats() (*winapi.JOBOBJECT_IO_ATTRIBUTION_INFO
444444
if err := winapi.QueryInformationJobObject(
445445
job.handle,
446446
winapi.JobObjectIoAttribution,
447-
uintptr(unsafe.Pointer(&info)),
447+
unsafe.Pointer(&info),
448448
uint32(unsafe.Sizeof(info)),
449449
nil,
450450
); err != nil {
@@ -582,7 +582,7 @@ func (job *JobObject) QueryPrivateWorkingSet() (uint64, error) {
582582
status := winapi.NtQueryInformationProcess(
583583
h,
584584
winapi.ProcessVmCounters,
585-
uintptr(unsafe.Pointer(&vmCounters)),
585+
unsafe.Pointer(&vmCounters),
586586
uint32(unsafe.Sizeof(vmCounters)),
587587
nil,
588588
)

internal/jobobject/limits.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (job *JobObject) getExtendedInformation() (*windows.JOBOBJECT_EXTENDED_LIMI
204204
if err := winapi.QueryInformationJobObject(
205205
job.handle,
206206
windows.JobObjectExtendedLimitInformation,
207-
uintptr(unsafe.Pointer(&info)),
207+
unsafe.Pointer(&info),
208208
uint32(unsafe.Sizeof(info)),
209209
nil,
210210
); err != nil {
@@ -226,7 +226,7 @@ func (job *JobObject) getCPURateControlInformation() (*winapi.JOBOBJECT_CPU_RATE
226226
if err := winapi.QueryInformationJobObject(
227227
job.handle,
228228
windows.JobObjectCpuRateControlInformation,
229-
uintptr(unsafe.Pointer(&info)),
229+
unsafe.Pointer(&info),
230230
uint32(unsafe.Sizeof(info)),
231231
nil,
232232
); err != nil {

internal/winapi/jobobject.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ type JOBOBJECT_ASSOCIATE_COMPLETION_PORT struct {
178178
// LPDWORD lpReturnLength
179179
// );
180180
//
181-
//sys QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo uintptr, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error) = kernel32.QueryInformationJobObject
181+
//sys QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo unsafe.Pointer, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error) = kernel32.QueryInformationJobObject
182182

183183
// HANDLE OpenJobObjectW(
184184
// DWORD dwDesiredAccess,

internal/winapi/process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ProcessVmCounters = 3
1818
// [out, optional] PULONG ReturnLength
1919
// );
2020
//
21-
//sys NtQueryInformationProcess(processHandle windows.Handle, processInfoClass uint32, processInfo uintptr, processInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQueryInformationProcess
21+
//sys NtQueryInformationProcess(processHandle windows.Handle, processInfoClass uint32, processInfo unsafe.Pointer, processInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQueryInformationProcess
2222

2323
// typedef struct _VM_COUNTERS_EX
2424
// {

internal/winapi/system.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
1515
// PULONG ReturnLength
1616
// );
1717
//
18-
//sys NtQuerySystemInformation(systemInfoClass int, systemInformation uintptr, systemInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQuerySystemInformation
18+
//sys NtQuerySystemInformation(systemInfoClass int, systemInformation unsafe.Pointer, systemInfoLength uint32, returnLength *uint32) (status uint32) = ntdll.NtQuerySystemInformation
1919

2020
type SYSTEM_PROCESS_INFORMATION struct {
2121
NextEntryOffset uint32 // ULONG

internal/winapi/zsyscall_windows.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)