Skip to content

Commit 67fd6fa

Browse files
committed
Merge pull request #1615 from hjelmn/new_hooks_update
memory/patcher: add #if check for MREMAP_FIXED
2 parents f3e3b80 + eb14b34 commit 67fd6fa

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

opal/mca/memory/patcher/configure.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ AC_DEFUN([MCA_opal_memory_patcher_CONFIG],[
8484
AC_DEFINE_UNQUOTED([OPAL_MEMORY_PATCHER_HAVE___SYSCALL], [$memory_patcher_have___syscall],
8585
[Whether the internal __syscall call exists])
8686

87+
AC_CHECK_HEADERS([linux/mman.h])
88+
8789
[$1]
8890

8991
OPAL_VAR_SCOPE_POP

opal/mca/memory/patcher/memory_patcher_component.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include <sys/time.h>
4444
#include <sys/syscall.h>
4545

46+
#if defined(HAVE_LINUX_MMAN_H)
47+
#include <linux/mman.h>
48+
#endif
49+
4650
#include "memory_patcher.h"
4751
#undef opal_memory_changed
4852

@@ -162,11 +166,20 @@ static int intercept_munmap(void *start, size_t length)
162166

163167
#if defined (SYS_mremap)
164168

169+
#if defined(__linux__)
165170
/* on linux this function has an optional extra argument but ... can not be used here because it
166171
* causes issues when intercepting a 4-argument mremap call */
167172
static void *(*original_mremap) (void *, size_t, size_t, int, void *);
173+
#else
174+
/* mremap has a different signature on BSD systems */
175+
static void *(*original_mremap) (void *, size_t, void *, size_t, int);
176+
#endif
168177

178+
#if defined(__linux__)
169179
static void *intercept_mremap (void *start, size_t oldlen, size_t newlen, int flags, void *new_address)
180+
#else
181+
static void *intercept_mremap (void *start, size_t oldlen, void *new_address, size_t newlen, int flags)
182+
#endif
170183
{
171184
OPAL_PATCHER_BEGIN;
172185
void *result = MAP_FAILED;
@@ -175,15 +188,25 @@ static void *intercept_mremap (void *start, size_t oldlen, size_t newlen, int fl
175188
opal_mem_hooks_release_hook (start, oldlen, true);
176189
}
177190

191+
#if defined(MREMAP_FIXED)
178192
if (!(flags & MREMAP_FIXED)) {
179193
new_address = NULL;
180194
}
195+
#endif
181196

197+
#if defined(__linux__)
182198
if (!original_mremap) {
183199
result = (void *)(intptr_t) memory_patcher_syscall (SYS_mremap, start, oldlen, newlen, flags, new_address);
184200
} else {
185201
result = original_mremap (start, oldlen, newlen, flags, new_address);
186202
}
203+
#else
204+
if (!original_mremap) {
205+
result = (void *)(intptr_t) memory_patcher_syscall (SYS_mremap, start, oldlen, new_address, newlen, flags);
206+
} else {
207+
result = original_mremap (start, oldlen, new_address, newlen, flags);
208+
}
209+
#endif
187210

188211
OPAL_PATCHER_END;
189212
return result;

opal/mca/patcher/overwrite/patcher_overwrite_module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch)
105105
* imm64 = i << 63 | imm41 << 22 | ic << 21 | imm5c << 16 | imm9d << 7 | imm7b
106106
*/
107107
unsigned char buf[16];
108-
unsigned long long imm64 = func_new_addr - func_old_addr - 16;
108+
unsigned long long imm64 = func_new_addr - patch->patch_orig - 16;
109109
register unsigned long long glb_ptr __asm__("r1");
110110
unsigned long long nop =
111111
(0x0ULL<<37) | /* O */
@@ -133,7 +133,7 @@ static int mca_patcher_overwrite_apply_patch (mca_patcher_base_patch_t *patch)
133133
(1ULL << 6) |
134134
(0x0ULL << 0);
135135

136-
patch->data_size = 32;
136+
patch->patch_data_size = 32;
137137

138138
make_ia64_bundle(buf, movl, (glb_ptr>>22)&0x1FFFFFFFFFFULL, nop, 5);
139139
for (int i = 0 ; i < 16 ; ++i) {

0 commit comments

Comments
 (0)