Skip to content

Add pid to the umf_ipc_data_t structure #505

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
May 20, 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
2 changes: 2 additions & 0 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ipc_internal.h"
#include "memory_pool_internal.h"
#include "provider/provider_tracking.h"
#include "utils_common.h"
#include "utils_log.h"

umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
Expand Down Expand Up @@ -56,6 +57,7 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
return ret;
}

ipcData->pid = utils_getpid();
ipcData->baseSize = allocInfo.baseSize;
ipcData->offset = (uintptr_t)ptr - (uintptr_t)allocInfo.base;

Expand Down
1 change: 1 addition & 0 deletions src/ipc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C" {
// providerIpcData is a Flexible Array Member because its size varies
// depending on the provider.
typedef struct umf_ipc_data_t {
int pid; // process ID of the process that allocated the memory
size_t baseSize; // size of base (coarse-grain) allocation
uint64_t offset;
char providerIpcData[];
Expand Down
6 changes: 4 additions & 2 deletions src/provider/provider_os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base_alloc_global.h"
#include "critnib.h"
#include "provider_os_memory_internal.h"
#include "utils_common.h"
#include "utils_concurrency.h"
#include "utils_log.h"

Expand Down Expand Up @@ -854,7 +855,7 @@ static umf_result_t os_get_ipc_handle(void *provider, const void *ptr,
}

os_ipc_data_t *os_ipc_data = (os_ipc_data_t *)providerIpcData;
os_ipc_data->pid = os_getpid();
os_ipc_data->pid = utils_getpid();
os_ipc_data->fd = os_provider->fd;
os_ipc_data->fd_offset = (size_t)value - 1;
os_ipc_data->size = size;
Expand All @@ -870,7 +871,8 @@ static umf_result_t os_put_ipc_handle(void *provider, void *providerIpcData) {
os_memory_provider_t *os_provider = (os_memory_provider_t *)provider;
os_ipc_data_t *os_ipc_data = (os_ipc_data_t *)providerIpcData;

if (os_ipc_data->fd != os_provider->fd || os_ipc_data->pid != os_getpid()) {
if (os_ipc_data->fd != os_provider->fd ||
os_ipc_data->pid != utils_getpid()) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

Expand Down
2 changes: 0 additions & 2 deletions src/provider/provider_os_memory_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ size_t os_get_page_size(void);

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

int os_getpid(void);

umf_result_t os_duplicate_fd(int pid, int fd_in, int *fd_out);

umf_result_t os_close_fd(int fd);
Expand Down
2 changes: 0 additions & 2 deletions src/provider/provider_os_memory_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ void os_strerror(int errnum, char *buf, size_t buflen) {
strerror_r(errnum, buf, buflen);
}

int os_getpid(void) { return getpid(); }

umf_result_t os_duplicate_fd(int pid, int fd_in, int *fd_out) {
// pidfd_getfd(2) is used to obtain a duplicate of another process's file descriptor.
// Permission to duplicate another process's file descriptor
Expand Down
2 changes: 0 additions & 2 deletions src/provider/provider_os_memory_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ void os_strerror(int errnum, char *buf, size_t buflen) {
strerror_s(buf, buflen, errnum);
}

int os_getpid(void) { return GetCurrentProcessId(); }

umf_result_t os_duplicate_fd(int pid, int fd_in, int *fd_out) {
(void)pid; // unused
(void)fd_in; // unused
Expand Down
3 changes: 3 additions & 0 deletions src/utils/utils_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ size_t util_get_page_size(void);
// align a pointer and a size
void util_align_ptr_size(void **ptr, size_t *size, size_t alignment);

// get the current process ID
int utils_getpid(void);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/utils/utils_posix_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ size_t util_get_page_size(void) {
util_init_once(&Page_size_is_initialized, _util_get_page_size);
return Page_size;
}

int utils_getpid(void) { return getpid(); }
1 change: 1 addition & 0 deletions src/utils/utils_windows_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ size_t util_get_page_size(void) {
util_init_once(&Page_size_is_initialized, _util_get_page_size);
return Page_size;
}
int utils_getpid(void) { return GetCurrentProcessId(); }