From eb14b34f04f52acd17e1ad261ec8c6831c051304 Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Mon, 2 May 2016 14:54:08 -0600 Subject: [PATCH] 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 --- .../memory/patcher/memory_patcher_component.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/opal/mca/memory/patcher/memory_patcher_component.c b/opal/mca/memory/patcher/memory_patcher_component.c index 265529746d..6e317c919e 100644 --- a/opal/mca/memory/patcher/memory_patcher_component.c +++ b/opal/mca/memory/patcher/memory_patcher_component.c @@ -166,11 +166,20 @@ static int intercept_munmap(void *start, size_t length) #if defined (SYS_mremap) +#if defined(__linux__) /* on linux this function has an optional extra argument but ... can not be used here because it * causes issues when intercepting a 4-argument mremap call */ static void *(*original_mremap) (void *, size_t, size_t, int, void *); +#else +/* mremap has a different signature on BSD systems */ +static void *(*original_mremap) (void *, size_t, void *, size_t, int); +#endif +#if defined(__linux__) static void *intercept_mremap (void *start, size_t oldlen, size_t newlen, int flags, void *new_address) +#else +static void *intercept_mremap (void *start, size_t oldlen, void *new_address, size_t newlen, int flags) +#endif { OPAL_PATCHER_BEGIN; void *result = MAP_FAILED; @@ -185,11 +194,19 @@ static void *intercept_mremap (void *start, size_t oldlen, size_t newlen, int fl } #endif +#if defined(__linux__) if (!original_mremap) { result = (void *)(intptr_t) memory_patcher_syscall (SYS_mremap, start, oldlen, newlen, flags, new_address); } else { result = original_mremap (start, oldlen, newlen, flags, new_address); } +#else + if (!original_mremap) { + result = (void *)(intptr_t) memory_patcher_syscall (SYS_mremap, start, oldlen, new_address, newlen, flags); + } else { + result = original_mremap (start, oldlen, new_address, newlen, flags); + } +#endif OPAL_PATCHER_END; return result;