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; if (MAP_FAILED != start && oldlen > 0) { opal_mem_hooks_release_hook (start, oldlen, true); } #if defined(MREMAP_FIXED) if (!(flags & MREMAP_FIXED)) { new_address = NULL; } #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; }
static void *intercept_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { OPAL_PATCHER_BEGIN; void *result = 0; if (prot == PROT_NONE) { opal_mem_hooks_release_hook (start, length, true); } if (!original_mmap) { #if OPAL_MEMORY_PATCHER_HAVE___MMAP /* the darwin syscall returns an int not a long so call the underlying __mmap function */ result = __mmap (start, length, prot, flags, fd, offset); #else result = (void*)(intptr_t) memory_patcher_syscall(SYS_mmap, start, length, prot, flags, fd, offset); #endif // I thought we had some issue in the past with the above line for IA32, // like maybe syscall() wouldn't handle that many arguments. But just now // I used gcc -m32 and it worked on a recent system. But there's a possibility // that older ia32 systems may need some other code to make the above syscall. } else { result = original_mmap (start, length, prot, flags, fd, offset); } OPAL_PATCHER_END; return result; }
static int intercept_shmdt (const void *shmaddr) { OPAL_PATCHER_BEGIN; int result; opal_mem_hooks_release_hook (shmaddr, memory_patcher_get_shm_seg_size (shmaddr), false); if (original_shmdt) { result = original_shmdt (shmaddr); } else { result = memory_patcher_syscall (SYS_shmdt, shmaddr); } OPAL_PATCHER_END; return result; }
static int intercept_munmap(void *start, size_t length) { OPAL_PATCHER_BEGIN; int result = 0; opal_mem_hooks_release_hook (start, length, false); if (!original_munmap) { result = memory_patcher_syscall(SYS_munmap, start, length); } else { result = original_munmap (start, length); } OPAL_PATCHER_END; return result; }
static int intercept_shmdt (const void *shmaddr) { OPAL_PATCHER_BEGIN; int result; /* opal_mem_hooks_release_hook should probably be updated to take a const void *. * for now just cast away the const */ opal_mem_hooks_release_hook ((void *) shmaddr, memory_patcher_get_shm_seg_size (shmaddr), false); if (original_shmdt) { result = original_shmdt (shmaddr); } else { result = memory_patcher_syscall (SYS_shmdt, shmaddr); } OPAL_PATCHER_END; return result; }
static int intercept_brk (void *addr) { OPAL_PATCHER_BEGIN; int result = 0; void *old_addr, *new_addr; #if OPAL_MEMORY_PATCHER_HAVE___CURBRK old_addr = __curbrk; #else old_addr = sbrk (0); #endif if (!original_brk) { /* get the current_addr */ new_addr = (void *) (intptr_t) memory_patcher_syscall(SYS_brk, addr); #if OPAL_MEMORY_PATCHER_HAVE___CURBRK /* * Note: if we were using glibc brk/sbrk, their __curbrk would get * updated, but since we're going straight to the syscall, we have * to update __curbrk or else glibc won't see it. */ __curbrk = new_addr; #endif } else { result = original_brk (addr); #if OPAL_MEMORY_PATCHER_HAVE___CURBRK new_addr = __curbrk; #else new_addr = sbrk (0); #endif } if (new_addr < addr) { errno = ENOMEM; result = -1; } else if (new_addr < old_addr) { opal_mem_hooks_release_hook (new_addr, (intptr_t) old_addr - (intptr_t) new_addr, true); } OPAL_PATCHER_END; return result; }
static int intercept_madvise (void *start, size_t length, int advice) { OPAL_PATCHER_BEGIN; int result = 0; if (advice == MADV_DONTNEED || #ifdef MADV_REMOVE advice == MADV_REMOVE || #endif advice == POSIX_MADV_DONTNEED) { opal_mem_hooks_release_hook (start, length, false); } if (!original_madvise) { result = memory_patcher_syscall(SYS_madvise, start, length, advice); } else { result = original_madvise (start, length, advice); } OPAL_PATCHER_END; return result; }