Skip to content

Commit 7585c00

Browse files
committed
IPC API of OS memory provider requires UMF_MEM_MAP_SHARED visibility
IPC API of OS memory provider requires the `UMF_MEM_MAP_SHARED` memory `visibility` mode (`UMF_RESULT_ERROR_INVALID_ARGUMENT` is returned otherwise). Signed-off-by: Lukasz Dorau <[email protected]>
1 parent ea53923 commit 7585c00

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ OS memory provider supports two types of memory mappings (set by the `visibility
143143
1) private memory mapping (`UMF_MEM_MAP_PRIVATE`)
144144
2) shared memory mapping (`UMF_MEM_MAP_SHARED` - supported on Linux only yet)
145145

146+
IPC API requires the `UMF_MEM_MAP_SHARED` memory `visibility` mode (`UMF_RESULT_ERROR_INVALID_ARGUMENT` is returned otherwise).
147+
146148
There are available two mechanisms for the shared memory mapping:
147149
1) a named shared memory object (used if the `shm_name` parameter is not NULL) or
148150
2) an anonymous file descriptor (used if the `shm_name` parameter is NULL)

src/provider/provider_os_memory.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ static umf_result_t os_allocation_split(void *provider, void *ptr,
10891089
(void)totalSize;
10901090

10911091
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
1092-
if (os_provider->fd <= 0) {
1092+
if (os_provider->fd < 0) {
10931093
return UMF_RESULT_SUCCESS;
10941094
}
10951095

@@ -1122,7 +1122,7 @@ static umf_result_t os_allocation_merge(void *provider, void *lowPtr,
11221122
(void)totalSize;
11231123

11241124
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
1125-
if (os_provider->fd <= 0) {
1125+
if (os_provider->fd < 0) {
11261126
return UMF_RESULT_SUCCESS;
11271127
}
11281128

@@ -1152,6 +1152,11 @@ static umf_result_t os_get_ipc_handle_size(void *provider, size_t *size) {
11521152
}
11531153

11541154
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
1155+
if (os_provider->fd < 0) {
1156+
// IPC API requires params->visibility == UMF_MEM_MAP_SHARED
1157+
LOG_ERR("memory visibility mode is not UMF_MEM_MAP_SHARED")
1158+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1159+
}
11551160

11561161
if (os_provider->shm_name[0]) {
11571162
// os_ipc_data_t->shm_name will be used
@@ -1171,7 +1176,9 @@ static umf_result_t os_get_ipc_handle(void *provider, const void *ptr,
11711176
}
11721177

11731178
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
1174-
if (os_provider->fd <= 0) {
1179+
if (os_provider->fd < 0) {
1180+
// IPC API requires params->visibility == UMF_MEM_MAP_SHARED
1181+
LOG_ERR("memory visibility mode is not UMF_MEM_MAP_SHARED")
11751182
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
11761183
}
11771184

@@ -1203,6 +1210,12 @@ static umf_result_t os_put_ipc_handle(void *provider, void *providerIpcData) {
12031210
}
12041211

12051212
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
1213+
if (os_provider->fd < 0) {
1214+
// IPC API requires params->visibility == UMF_MEM_MAP_SHARED
1215+
LOG_ERR("memory visibility mode is not UMF_MEM_MAP_SHARED")
1216+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1217+
}
1218+
12061219
os_ipc_data_t *os_ipc_data = (os_ipc_data_t *)providerIpcData;
12071220

12081221
if (os_ipc_data->pid != utils_getpid()) {
@@ -1229,6 +1242,12 @@ static umf_result_t os_open_ipc_handle(void *provider, void *providerIpcData,
12291242
}
12301243

12311244
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
1245+
if (os_provider->fd < 0) {
1246+
// IPC API requires params->visibility == UMF_MEM_MAP_SHARED
1247+
LOG_ERR("memory visibility mode is not UMF_MEM_MAP_SHARED")
1248+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1249+
}
1250+
12321251
os_ipc_data_t *os_ipc_data = (os_ipc_data_t *)providerIpcData;
12331252
umf_result_t ret = UMF_RESULT_SUCCESS;
12341253
int fd;

0 commit comments

Comments
 (0)