Skip to content

Commit

Permalink
correctly close module file handles on module unloading in new demon …
Browse files Browse the repository at this point in the history
…layer
  • Loading branch information
ryanfleury committed Mar 27, 2024
1 parent d73a3d4 commit 4899f18
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/dbgi/dbgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ dbgi_binary_close(String8 exe_path)
if(need_deletion) for(;;)
{
os_rw_mutex_drop_w(stripe->rw_mutex);
for(U64 start_t = os_now_microseconds();
os_now_microseconds() <= start_t + 250;);
for(U64 start_t = os_now_microseconds(); os_now_microseconds() <= start_t + 250;);
os_rw_mutex_take_w(stripe->rw_mutex);
if(binary->refcount == 0 && ins_atomic_u64_eval(&binary->scope_touch_count) == 0)
{
Expand Down
4 changes: 4 additions & 0 deletions src/demon/win32/demon_core_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ dmn_w32_entity_release(DMN_W32_Entity *entity)
// rjf: free entity
SLLStackPush(dmn_w32_shared->entities_first_free, t->e);
t->e->gen += 1;
if(t->e->kind == DMN_W32_EntityKind_Module)
{
CloseHandle(t->e->handle);
}

// rjf: remove from id -> entity map
if(t->e->id != 0)
Expand Down
9 changes: 6 additions & 3 deletions src/os/core/win32/os_core_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ os_file_close(OS_Handle file)
{
if(os_handle_match(file, os_handle_zero())) { return; }
HANDLE handle = (HANDLE)file.u64[0];
CloseHandle(handle);
BOOL result = CloseHandle(handle);
(void)result;
}

internal U64
Expand Down Expand Up @@ -896,7 +897,8 @@ internal void
os_file_map_close(OS_Handle map)
{
HANDLE handle = (HANDLE)map.u64[0];
CloseHandle(handle);
BOOL result = CloseHandle(handle);
(void)result;
}

internal void *
Expand Down Expand Up @@ -939,7 +941,8 @@ os_file_map_view_open(OS_Handle map, OS_AccessFlags flags, Rng1U64 range)
internal void
os_file_map_view_close(OS_Handle map, void *ptr)
{
UnmapViewOfFile(ptr);
BOOL result = UnmapViewOfFile(ptr);
(void)result;
}

//- rjf: directory iteration
Expand Down

0 comments on commit 4899f18

Please sign in to comment.