File tree Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change 17
17
#include "oshmem/util/oshmem_util.h"
18
18
19
19
#include <stdio.h>
20
+ #include <limits.h>
21
+ #include <stdlib.h>
22
+ #include <pthread.h>
20
23
21
24
struct map_segment_desc {
22
25
void * start ;
@@ -127,7 +130,41 @@ static int _check_address(struct map_segment_desc *seg)
127
130
128
131
static int _check_pathname (struct map_segment_desc * seg )
129
132
{
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
131
168
* To press check coverity issue following code is disabled
132
169
*/
133
170
#if 0
You can’t perform that action at this time.
0 commit comments