Skip to content

Commit b6c5c8d

Browse files
authored
Merge pull request #505 from vinser52/svinogra_ipc_api
Add pid to the umf_ipc_data_t structure
2 parents fa07c25 + 358171c commit b6c5c8d

9 files changed

+13
-8
lines changed

src/ipc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "ipc_internal.h"
1717
#include "memory_pool_internal.h"
1818
#include "provider/provider_tracking.h"
19+
#include "utils_common.h"
1920
#include "utils_log.h"
2021

2122
umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
@@ -56,6 +57,7 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
5657
return ret;
5758
}
5859

60+
ipcData->pid = utils_getpid();
5961
ipcData->baseSize = allocInfo.baseSize;
6062
ipcData->offset = (uintptr_t)ptr - (uintptr_t)allocInfo.base;
6163

src/ipc_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern "C" {
2121
// providerIpcData is a Flexible Array Member because its size varies
2222
// depending on the provider.
2323
typedef struct umf_ipc_data_t {
24+
int pid; // process ID of the process that allocated the memory
2425
size_t baseSize; // size of base (coarse-grain) allocation
2526
uint64_t offset;
2627
char providerIpcData[];

src/provider/provider_os_memory.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "base_alloc_global.h"
1818
#include "critnib.h"
1919
#include "provider_os_memory_internal.h"
20+
#include "utils_common.h"
2021
#include "utils_concurrency.h"
2122
#include "utils_log.h"
2223

@@ -854,7 +855,7 @@ static umf_result_t os_get_ipc_handle(void *provider, const void *ptr,
854855
}
855856

856857
os_ipc_data_t *os_ipc_data = (os_ipc_data_t *)providerIpcData;
857-
os_ipc_data->pid = os_getpid();
858+
os_ipc_data->pid = utils_getpid();
858859
os_ipc_data->fd = os_provider->fd;
859860
os_ipc_data->fd_offset = (size_t)value - 1;
860861
os_ipc_data->size = size;
@@ -870,7 +871,8 @@ static umf_result_t os_put_ipc_handle(void *provider, void *providerIpcData) {
870871
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
871872
os_ipc_data_t *os_ipc_data = (os_ipc_data_t *)providerIpcData;
872873

873-
if (os_ipc_data->fd != os_provider->fd || os_ipc_data->pid != os_getpid()) {
874+
if (os_ipc_data->fd != os_provider->fd ||
875+
os_ipc_data->pid != utils_getpid()) {
874876
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
875877
}
876878

src/provider/provider_os_memory_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ size_t os_get_page_size(void);
4848

4949
void os_strerror(int errnum, char *buf, size_t buflen);
5050

51-
int os_getpid(void);
52-
5351
umf_result_t os_duplicate_fd(int pid, int fd_in, int *fd_out);
5452

5553
umf_result_t os_close_fd(int fd);

src/provider/provider_os_memory_posix.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ void os_strerror(int errnum, char *buf, size_t buflen) {
9090
strerror_r(errnum, buf, buflen);
9191
}
9292

93-
int os_getpid(void) { return getpid(); }
94-
9593
umf_result_t os_duplicate_fd(int pid, int fd_in, int *fd_out) {
9694
// pidfd_getfd(2) is used to obtain a duplicate of another process's file descriptor.
9795
// Permission to duplicate another process's file descriptor

src/provider/provider_os_memory_windows.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ void os_strerror(int errnum, char *buf, size_t buflen) {
116116
strerror_s(buf, buflen, errnum);
117117
}
118118

119-
int os_getpid(void) { return GetCurrentProcessId(); }
120-
121119
umf_result_t os_duplicate_fd(int pid, int fd_in, int *fd_out) {
122120
(void)pid; // unused
123121
(void)fd_in; // unused

src/utils/utils_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ size_t util_get_page_size(void);
7171
// align a pointer and a size
7272
void util_align_ptr_size(void **ptr, size_t *size, size_t alignment);
7373

74+
// get the current process ID
75+
int utils_getpid(void);
76+
7477
#ifdef __cplusplus
7578
}
7679
#endif

src/utils/utils_posix_common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ size_t util_get_page_size(void) {
2323
util_init_once(&Page_size_is_initialized, _util_get_page_size);
2424
return Page_size;
2525
}
26+
27+
int utils_getpid(void) { return getpid(); }

src/utils/utils_windows_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ size_t util_get_page_size(void) {
2828
util_init_once(&Page_size_is_initialized, _util_get_page_size);
2929
return Page_size;
3030
}
31+
int utils_getpid(void) { return GetCurrentProcessId(); }

0 commit comments

Comments
 (0)