/*********************************************************************** * CreateToolhelp32Snapshot (KERNEL32.@) */ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process ) { SYSTEM_PROCESS_INFORMATION* spi = NULL; LDR_MODULE* mod = NULL; ULONG num_pcs, num_thd, num_mod; HANDLE hSnapShot = 0; TRACE("%x,%x\n", flags, process ); if (!(flags & (TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD|TH32CS_SNAPMODULE))) { FIXME("flags %x not implemented\n", flags ); SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); return INVALID_HANDLE_VALUE; } if (fetch_module( process, flags, &mod, &num_mod ) && fetch_process_thread( flags, &spi, &num_pcs, &num_thd )) { ULONG sect_size; struct snapshot*snap; SECURITY_ATTRIBUTES sa; /* create & fill the snapshot section */ sect_size = sizeof(struct snapshot) - 1; /* for last data[1] */ if (flags & TH32CS_SNAPMODULE) sect_size += num_mod * sizeof(MODULEENTRY32W); if (flags & TH32CS_SNAPPROCESS) sect_size += num_pcs * sizeof(PROCESSENTRY32W); if (flags & TH32CS_SNAPTHREAD) sect_size += num_thd * sizeof(THREADENTRY32); if (flags & TH32CS_SNAPHEAPLIST)FIXME("Unimplemented: heap list snapshot\n"); sa.bInheritHandle = (flags & TH32CS_INHERIT) ? TRUE : FALSE; sa.lpSecurityDescriptor = NULL; hSnapShot = CreateFileMappingW( INVALID_HANDLE_VALUE, &sa, SEC_COMMIT | PAGE_READWRITE, 0, sect_size, NULL ); if (hSnapShot && (snap = MapViewOfFile( hSnapShot, FILE_MAP_ALL_ACCESS, 0, 0, 0 ))) { DWORD offset = 0; fill_module( snap, &offset, process, mod, num_mod ); fill_process( snap, &offset, spi, num_pcs ); fill_thread( snap, &offset, spi, num_thd ); UnmapViewOfFile( snap ); } } while (num_mod--) { HeapFree( GetProcessHeap(), 0, mod[num_mod].BaseDllName.Buffer ); HeapFree( GetProcessHeap(), 0, mod[num_mod].FullDllName.Buffer ); } HeapFree( GetProcessHeap(), 0, mod ); HeapFree( GetProcessHeap(), 0, spi ); if (!hSnapShot) return INVALID_HANDLE_VALUE; return hSnapShot; }
void check_id(t_champ *champ) { int i; int id; i = -1; id = -1; while (++i < champ->nbr_champ) { if (champ->id_champ[i] == -1) { while (is_id_taken(champ->id_champ, ++id, champ->nbr_champ)); champ->id_champ[i] = id; } } i = -1; while (++i < champ->nbr_champ) champ->process[i] = fill_process(MEM_SIZE / champ->nbr_champ * i, champ->id_champ[i]); }