Free resources when dlclose is called

When the Thunk is initialized multiple times in the lifetime of a single process
, some global resources are leaked. This can happen when dlopen and dlclose are
 used to load the library at runtime, rather than linking the runtime against
the Thunk. This patch adds the destructor to release global resources when
dlclose is called.


Change-Id: Ia00da0d41f095d0b2706f98c0e75effedd596f49
This commit is contained in:
Amber Lin
2015-12-01 14:41:59 -05:00
parent 8f529e3c72
commit 582b70f9c3
2 changed files with 27 additions and 0 deletions
+14
View File
@@ -139,6 +139,7 @@ static void __fmm_release(void *address,
static int _fmm_unmap_from_gpu_scratch(uint32_t gpu_id,
manageble_aperture_t *aperture,
void *address);
void __attribute__ ((destructor)) fmm_release_global_resources(void);
static vm_area_t *vm_create_and_init_area(void *start, void *end)
{
@@ -1544,3 +1545,16 @@ bool fmm_get_handle(void *address, uint64_t *handle)
return found;
}
void fmm_release_global_resources(void)
{
uint64_t len;
if (dgpu_shared_aperture_base) {
len = (uint64_t)dgpu_shared_aperture_limit
- (uint64_t)dgpu_shared_aperture_base + 1;
munmap(dgpu_shared_aperture_base, len);
}
dgpu_shared_aperture_base = NULL;
dgpu_shared_aperture_limit = NULL;
}