Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,37 @@ func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitche
}

func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
return 0, common.ErrNotImplementedError
buffer := make([]byte, 1024)
var size uint32

st := common.CallWithExpandingBuffer(
func() common.NtStatus {
return common.NtQuerySystemInformation(
common.SystemExtendedHandleInformationClass,
&buffer[0],
uint32(len(buffer)),
&size,
)
},
&buffer,
&size,
)
if st.IsError() {
return 0, st.Error()
}

handlesList := (*common.SystemExtendedHandleInformation)(unsafe.Pointer(&buffer[0]))
handles := make([]common.SystemExtendedHandleTableEntryInformation, int(handlesList.NumberOfHandles))
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&handles))
hdr.Data = uintptr(unsafe.Pointer(&handlesList.Handles[0]))

var handleCount int32
for _, handle := range handles {
if int32(handle.UniqueProcessId) == p.Pid {
handleCount++
}
}
return handleCount, nil
}

func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
Expand Down