Skip to content

Commit 16968c6

Browse files
authored
Merge pull request #8703 from hoopoepg/topic/oshmem-start-proc-segment-filter
OSHMEM/SEGMENT-REGISTRATION: added segment filtering
2 parents d1c71ec + b22e275 commit 16968c6

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

oshmem/mca/memheap/base/memheap_base_static.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "oshmem/util/oshmem_util.h"
1818

1919
#include <stdio.h>
20+
#include <limits.h>
21+
#include <stdlib.h>
22+
#include <pthread.h>
2023

2124
struct map_segment_desc {
2225
void* start;
@@ -127,7 +130,41 @@ static int _check_address(struct map_segment_desc *seg)
127130

128131
static int _check_pathname(struct map_segment_desc *seg)
129132
{
130-
/* Probably we need to check found path but
133+
static const char *proc_self_exe = "/proc/self/exe";
134+
static int warned = 0;
135+
char exe_path[PATH_MAX];
136+
char module_path[PATH_MAX];
137+
char *path;
138+
139+
if (0 == seg->inode) {
140+
/* segment is not mapped to file, allow sharing it */
141+
return OSHMEM_SUCCESS;
142+
}
143+
144+
path = realpath(proc_self_exe, exe_path);
145+
if (NULL == path) {
146+
if (0 == warned) {
147+
MEMHEAP_VERBOSE(100, "failed to read link %s: %m", proc_self_exe);
148+
MEMHEAP_VERBOSE(100, "all segments will be registered");
149+
warned = 1;
150+
}
151+
152+
return OSHMEM_SUCCESS;
153+
}
154+
155+
/* for file-mapped segments allow segments from start process only */
156+
path = realpath(seg->pathname, module_path);
157+
if (NULL == path) {
158+
return OSHMEM_ERROR;
159+
}
160+
161+
if (!strncmp(exe_path, module_path, sizeof(exe_path))) {
162+
return OSHMEM_SUCCESS;
163+
}
164+
165+
return OSHMEM_ERROR;
166+
167+
/* Probably we need more accurate path check
131168
* To press check coverity issue following code is disabled
132169
*/
133170
#if 0

0 commit comments

Comments
 (0)