Skip to content

Commit b91149c

Browse files
committed
Add free() op to the file provider
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 8ccac0f commit b91149c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/provider/provider_file_memory.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,11 @@ static umf_result_t file_alloc(void *provider, size_t size, size_t alignment,
764764
return coarse_alloc(file_provider->coarse, size, alignment, resultPtr);
765765
}
766766

767+
static umf_result_t file_free(void *provider, void *ptr, size_t size) {
768+
file_memory_provider_t *file_provider = (file_memory_provider_t *)provider;
769+
return coarse_free(file_provider->coarse, ptr, size);
770+
}
771+
767772
static umf_result_t file_allocation_split(void *provider, void *ptr,
768773
size_t totalSize, size_t firstSize) {
769774
file_memory_provider_t *file_provider = (file_memory_provider_t *)provider;
@@ -785,6 +790,7 @@ static umf_memory_provider_ops_t UMF_FILE_MEMORY_PROVIDER_OPS = {
785790
.get_recommended_page_size = file_get_recommended_page_size,
786791
.get_min_page_size = file_get_min_page_size,
787792
.get_name = file_get_name,
793+
.ext.free = file_free,
788794
.ext.purge_lazy = file_purge_lazy,
789795
.ext.purge_force = file_purge_force,
790796
.ext.allocation_merge = file_allocation_merge,

test/provider_file_memory.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void test_alloc_free_success(umf_memory_provider_handle_t provider,
9898
}
9999

100100
umf_result = umfMemoryProviderFree(provider, ptr, size);
101-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
101+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
102102
}
103103

104104
static void verify_last_native_error(umf_memory_provider_handle_t provider,
@@ -153,7 +153,7 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
153153
bool flag_found = is_mapped_with_MAP_SYNC(path, buf, size);
154154

155155
umf_result = umfMemoryProviderFree(hProvider, buf, size);
156-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
156+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
157157

158158
umfMemoryProviderDestroy(hProvider);
159159

@@ -209,10 +209,10 @@ TEST_P(FileProviderParamsDefault, two_allocations) {
209209
memset(ptr2, 0x22, size);
210210

211211
umf_result = umfMemoryProviderFree(provider.get(), ptr1, size);
212-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
212+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
213213

214214
umf_result = umfMemoryProviderFree(provider.get(), ptr2, size);
215-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
215+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
216216
}
217217

218218
TEST_P(FileProviderParamsDefault, alloc_page64_align_0) {
@@ -331,12 +331,12 @@ TEST_P(FileProviderParamsDefault, get_name) {
331331
TEST_P(FileProviderParamsDefault, free_size_0_ptr_not_null) {
332332
umf_result_t umf_result =
333333
umfMemoryProviderFree(provider.get(), INVALID_PTR, 0);
334-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
334+
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
335335
}
336336

337337
TEST_P(FileProviderParamsDefault, free_NULL) {
338338
umf_result_t umf_result = umfMemoryProviderFree(provider.get(), nullptr, 0);
339-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
339+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
340340
}
341341

342342
// other negative tests
@@ -354,7 +354,7 @@ TEST_F(test, create_empty_path) {
354354
TEST_P(FileProviderParamsDefault, free_INVALID_POINTER_SIZE_GT_0) {
355355
umf_result_t umf_result =
356356
umfMemoryProviderFree(provider.get(), INVALID_PTR, page_plus_64);
357-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
357+
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_INVALID_ARGUMENT);
358358
}
359359

360360
TEST_P(FileProviderParamsDefault, purge_lazy_INVALID_POINTER) {
@@ -416,7 +416,7 @@ TEST_P(FileProviderParamsShared, IPC_base_success_test) {
416416
ASSERT_EQ(ret, 0);
417417

418418
umf_result = umfMemoryProviderFree(provider.get(), ptr, size);
419-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
419+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
420420
}
421421

422422
TEST_P(FileProviderParamsShared, IPC_file_not_exist) {
@@ -456,5 +456,5 @@ TEST_P(FileProviderParamsShared, IPC_file_not_exist) {
456456
ASSERT_EQ(new_ptr, nullptr);
457457

458458
umf_result = umfMemoryProviderFree(provider.get(), ptr, size);
459-
ASSERT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED);
459+
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);
460460
}

0 commit comments

Comments
 (0)