Skip to content

Commit eb14b34

Browse files
committed
memory/patcher: fix compilation on BSDs
The function signature of mremap on BSD (NetBSD, FreeBSD) differs from the linux version. Added support for the BSD style of mremap. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 52edb43 commit eb14b34

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

opal/mca/memory/patcher/memory_patcher_component.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,20 @@ static int intercept_munmap(void *start, size_t length)
166166

167167
#if defined (SYS_mremap)
168168

169+
#if defined(__linux__)
169170
/* on linux this function has an optional extra argument but ... can not be used here because it
170171
* causes issues when intercepting a 4-argument mremap call */
171172
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
172177

178+
#if defined(__linux__)
173179
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
174183
{
175184
OPAL_PATCHER_BEGIN;
176185
void *result = MAP_FAILED;
@@ -185,11 +194,19 @@ static void *intercept_mremap (void *start, size_t oldlen, size_t newlen, int fl
185194
}
186195
#endif
187196

197+
#if defined(__linux__)
188198
if (!original_mremap) {
189199
result = (void *)(intptr_t) memory_patcher_syscall (SYS_mremap, start, oldlen, newlen, flags, new_address);
190200
} else {
191201
result = original_mremap (start, oldlen, newlen, flags, new_address);
192202
}
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
193210

194211
OPAL_PATCHER_END;
195212
return result;

0 commit comments

Comments
 (0)