def get_handles ():
  system_handle_information = SYSTEM_HANDLE_INFORMATION ()
  size = DWORD (sizeof (system_handle_information))
  while True:
    result = ntdll.ZwQuerySystemInformation (
      SystemHandleInformation,
      byref (system_handle_information),
      size,
      byref (size)
    )
    result = signed_to_unsigned (result)
    if result == STATUS_SUCCESS:
      break
    elif result == STATUS_INFO_LENGTH_MISMATCH:
      size = DWORD (size.value * 4)
      resize (system_handle_information, size.value)
    else:
      raise x_file_handles ("ZwQuerySystemInformation", hex (result))

  pHandles = cast (
    system_handle_information.Handles,
    POINTER (SYSTEM_HANDLE_TABLE_ENTRY_INFO * system_handle_information.NumberOfHandles)
  )
  for handle in pHandles.contents:
    yield handle.UniqueProcessId, handle.HandleValue
dataset/ETHPy150Open tjguk/winsys/random/file_handles.py/get_handles/original