Skip to content

Fix and add error messages #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions src/provider/provider_file_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ static umf_result_t file_alloc_cb(void *provider, size_t size, size_t alignment,

file_memory_provider_t *file_provider = (file_memory_provider_t *)provider;

*resultPtr = NULL;

// alignment must be a power of two and a multiple or a divider of the page size
if (alignment && ((alignment & (alignment - 1)) ||
((alignment % file_provider->page_size) &&
Expand Down Expand Up @@ -517,8 +519,15 @@ static umf_result_t file_alloc_cb(void *provider, size_t size, size_t alignment,
LOG_ERR("inserting a value to the file descriptor offset map failed "
"(addr=%p, offset=%zu)",
addr, alloc_offset_fd);
// We cannot undo the file_alloc_aligned() call here,
// because the file memory provider does not support the free operation.
return UMF_RESULT_ERROR_UNKNOWN;
}

LOG_DEBUG("inserted a value to the file descriptor offset map (addr=%p, "
"offset=%zu)",
addr, alloc_offset_fd);

*resultPtr = addr;

return UMF_RESULT_SUCCESS;
Expand Down Expand Up @@ -623,23 +632,31 @@ static umf_result_t file_allocation_split_cb(void *provider, void *ptr,

void *value = critnib_get(file_provider->fd_offset_map, (uintptr_t)ptr);
if (value == NULL) {
LOG_ERR("file_allocation_split(): getting a value from the file "
"descriptor offset map failed (addr=%p)",
LOG_ERR("getting a value from the file descriptor offset map failed "
"(addr=%p)",
ptr);
return UMF_RESULT_ERROR_UNKNOWN;
}

LOG_DEBUG("split the value from the file descriptor offset map (addr=%p) "
"from size %zu to %zu + %zu",
ptr, totalSize, firstSize, totalSize - firstSize);

uintptr_t new_key = (uintptr_t)ptr + firstSize;
void *new_value = (void *)((uintptr_t)value + firstSize);
int ret = critnib_insert(file_provider->fd_offset_map, new_key, new_value,
0 /* update */);
if (ret) {
LOG_ERR("file_allocation_split(): inserting a value to the file "
"descriptor offset map failed (addr=%p, offset=%zu)",
LOG_ERR("inserting a value to the file descriptor offset map failed "
"(addr=%p, offset=%zu)",
(void *)new_key, (size_t)new_value - 1);
return UMF_RESULT_ERROR_UNKNOWN;
}

LOG_DEBUG("inserted a value to the file descriptor offset map (addr=%p, "
"offset=%zu)",
(void *)new_key, (size_t)new_value - 1);

return UMF_RESULT_SUCCESS;
}

Expand All @@ -662,12 +679,16 @@ static umf_result_t file_allocation_merge_cb(void *provider, void *lowPtr,
void *value =
critnib_remove(file_provider->fd_offset_map, (uintptr_t)highPtr);
if (value == NULL) {
LOG_ERR("file_allocation_merge(): removing a value from the file "
"descriptor offset map failed (addr=%p)",
LOG_ERR("removing a value from the file descriptor offset map failed "
"(addr=%p)",
highPtr);
return UMF_RESULT_ERROR_UNKNOWN;
}

LOG_DEBUG("removed a value from the file descriptor offset map (addr=%p) - "
"merged with %p",
highPtr, lowPtr);

return UMF_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -701,9 +722,7 @@ static umf_result_t file_get_ipc_handle(void *provider, const void *ptr,

void *value = critnib_get(file_provider->fd_offset_map, (uintptr_t)ptr);
if (value == NULL) {
LOG_ERR("file_get_ipc_handle(): getting a value from the IPC cache "
"failed (addr=%p)",
ptr);
LOG_ERR("getting a value from the IPC cache failed (addr=%p)", ptr);
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

Expand Down
4 changes: 1 addition & 3 deletions src/provider/provider_os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,9 +1286,7 @@ static umf_result_t os_get_ipc_handle(void *provider, const void *ptr,

void *value = critnib_get(os_provider->fd_offset_map, (uintptr_t)ptr);
if (value == NULL) {
LOG_ERR("os_get_ipc_handle(): getting a value from the IPC cache "
"failed (addr=%p)",
ptr);
LOG_ERR("getting a value from the IPC cache failed (addr=%p)", ptr);
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

Expand Down
Loading