From: Nicholas Nethercote Date: Sun, 29 May 2005 18:46:38 +0000 (+0000) Subject: Eliminated VGP_DO_MMAP. Replaced it with VG_(mmap_native)(), which was X-Git-Tag: svn/VALGRIND_3_0_0~505 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9923039ae4b35139bb7babc68be1ff2f8595137;p=thirdparty%2Fvalgrind.git Eliminated VGP_DO_MMAP. Replaced it with VG_(mmap_native)(), which was derived from mmap_inner(). As a consequence, $PLATFORM/core_platform.h files are no longer necessary, hooray! git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3813 --- diff --git a/coregrind/amd64-linux/Makefile.am b/coregrind/amd64-linux/Makefile.am index 96f3688d63..c485764a82 100644 --- a/coregrind/amd64-linux/Makefile.am +++ b/coregrind/amd64-linux/Makefile.am @@ -2,5 +2,4 @@ include $(top_srcdir)/Makefile.all.am include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am noinst_HEADERS = \ - core_platform.h \ vki_unistd.h diff --git a/coregrind/amd64-linux/core_platform.h b/coregrind/amd64-linux/core_platform.h deleted file mode 100644 index 9ac384ca25..0000000000 --- a/coregrind/amd64-linux/core_platform.h +++ /dev/null @@ -1,48 +0,0 @@ - -/*--------------------------------------------------------------------*/ -/*--- Platform-specific stuff for the core. ---*/ -/*--- amd64-linux/core_platform.h ---*/ -/*--------------------------------------------------------------------*/ - -/* - This file is part of Valgrind, a dynamic binary instrumentation - framework. - - Copyright (C) 2000-2005 Nicholas Nethercote - njn@valgrind.org - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307, USA. - - The GNU General Public License is contained in the file COPYING. -*/ - -#ifndef __AMD64_LINUX_CORE_PLATFORM_H -#define __AMD64_LINUX_CORE_PLATFORM_H - -/* --------------------------------------------------------------------- - mmap() stuff - ------------------------------------------------------------------ */ - -#define VGP_DO_MMAP(ret, start, length, prot, flags, fd, offset) { \ - ret = VG_(do_syscall6)(__NR_mmap, (UWord)(start), (length), \ - (prot), (flags), (fd), (offset)); \ -} while (0) - -#endif // __AMD64_LINUX_CORE_PLATFORM_H - -/*--------------------------------------------------------------------*/ -/*--- end ---*/ -/*--------------------------------------------------------------------*/ diff --git a/coregrind/arm-linux/Makefile.am b/coregrind/arm-linux/Makefile.am index 96f3688d63..c485764a82 100644 --- a/coregrind/arm-linux/Makefile.am +++ b/coregrind/arm-linux/Makefile.am @@ -2,5 +2,4 @@ include $(top_srcdir)/Makefile.all.am include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am noinst_HEADERS = \ - core_platform.h \ vki_unistd.h diff --git a/coregrind/arm-linux/core_platform.h b/coregrind/arm-linux/core_platform.h deleted file mode 100644 index 8822c09237..0000000000 --- a/coregrind/arm-linux/core_platform.h +++ /dev/null @@ -1,47 +0,0 @@ - -/*--------------------------------------------------------------------*/ -/*--- Platform-specific stuff for the core. ---*/ -/*--- arm-linux/core_platform.h ---*/ -/*--------------------------------------------------------------------*/ - -/* - This file is part of Valgrind, a dynamic binary instrumentation - framework. - - Copyright (C) 2000-2005 Nicholas Nethercote - njn@valgrind.org - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307, USA. - - The GNU General Public License is contained in the file COPYING. -*/ - -#ifndef __ARM_LINUX_CORE_PLATFORM_H -#define __ARM_LINUX_CORE_PLATFORM_H - -/* --------------------------------------------------------------------- - mmap() stuff - ------------------------------------------------------------------ */ - -#define VGP_DO_MMAP(ret, start, length, prot, flags, fd, offset) { \ - I_die_here; \ -} while (0) - -#endif // __ARM_LINUX_CORE_PLATFORM_H - -/*--------------------------------------------------------------------*/ -/*--- end ---*/ -/*--------------------------------------------------------------------*/ diff --git a/coregrind/core.h b/coregrind/core.h index 104390cf96..0c7d2cec49 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -35,8 +35,6 @@ #include "tool.h" // tool stuff #include "core_arch.h" // arch-specific stuff, eg. x86/core_arch.h -#include "core_platform.h" // platform-specific stuff, - // eg. x86-linux/core_platform.h #include "core_os.h" // OS-specific stuff, eg. linux/core_os.h #include "pub_core_mallocfree.h" // for type 'ArenaId' @@ -442,10 +440,12 @@ extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg ); extern Int VG_(poll)( struct vki_pollfd *, UInt nfds, Int timeout); /* system/mman.h */ -extern void* VG_(mmap)( void* start, SizeT length, UInt prot, UInt flags, - UInt sf_flags, UInt fd, OffT offset ); -extern Int VG_(munmap)( void* start, SizeT length ); -extern Int VG_(mprotect)( void *start, SizeT length, UInt prot ); +extern void* VG_(mmap) ( void* start, SizeT length, UInt prot, UInt flags, + UInt sf_flags, UInt fd, OffT offset ); +extern void* VG_(mmap_native)( void* start, SizeT length, UInt prot, UInt flags, + UInt fd, OffT offset ); +extern Int VG_(munmap) ( void* start, SizeT length ); +extern Int VG_(mprotect) ( void *start, SizeT length, UInt prot ); extern Int VG_(mprotect_native)( void *start, SizeT length, UInt prot ); diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c index 26a969d317..eb34a0c21f 100644 --- a/coregrind/m_aspacemgr/aspacemgr.c +++ b/coregrind/m_aspacemgr/aspacemgr.c @@ -953,14 +953,14 @@ Addr VG_(find_map_space)(Addr addr, SizeT len, Bool for_client) void VG_(pad_address_space)(Addr start) { Addr addr = (start == 0) ? VG_(client_base) : start; - Addr ret; + void* ret; Int i = 0; Segment* s = i >= segments_used ? NULL : &segments[i]; while (s && addr <= VG_(valgrind_last)) { if (addr < s->addr) { - VGP_DO_MMAP(ret, addr, s->addr - addr, 0, + ret = VG_(mmap_native)((void*)addr, s->addr - addr, 0, VKI_MAP_FIXED | VKI_MAP_PRIVATE | VKI_MAP_ANONYMOUS, -1, 0); } @@ -970,7 +970,7 @@ void VG_(pad_address_space)(Addr start) } if (addr <= VG_(valgrind_last)) { - VGP_DO_MMAP(ret, addr, VG_(valgrind_last) - addr + 1, 0, + ret = VG_(mmap_native)((void*)addr, VG_(valgrind_last) - addr + 1, 0, VKI_MAP_FIXED | VKI_MAP_PRIVATE | VKI_MAP_ANONYMOUS, -1, 0); } diff --git a/coregrind/m_syscalls/syscalls.c b/coregrind/m_syscalls/syscalls.c index fd00df6f6f..b64b3e2d51 100644 --- a/coregrind/m_syscalls/syscalls.c +++ b/coregrind/m_syscalls/syscalls.c @@ -4533,8 +4533,7 @@ PRE(old_mmap, Special) } if (RES != -VKI_ENOMEM) { - int res; - VGP_DO_MMAP(res, a1, a2, a3, a4, a5, a6); + Int res = (Int)VG_(mmap_native)((void*)a1, a2, a3, a4, a5, a6); SET_RESULT(res); if (!VG_(is_kerror)(RES)) { diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c index 206f1e84b8..231dac6a3e 100644 --- a/coregrind/vg_mylibc.c +++ b/coregrind/vg_mylibc.c @@ -288,19 +288,28 @@ Int VG_(gettid)(void) mmap/munmap, exit, fcntl ------------------------------------------------------------------ */ -static Int munmap_inner(void *start, SizeT length) -{ - return VG_(do_syscall2)(__NR_munmap, (UWord)start, length ); -} - -static Addr mmap_inner(void *start, SizeT length, UInt prot, UInt flags, +void* VG_(mmap_native)(void *start, SizeT length, UInt prot, UInt flags, UInt fd, OffT offset) { - Word ret; - - VGP_DO_MMAP(ret, start, length, prot, - flags & ~(VKI_MAP_NOSYMS|VKI_MAP_CLIENT), fd, offset); - return ret; + UWord ret; +#if defined(VGP_x86_linux) + { + UWord args[6]; + args[0] = (UWord)start; + args[1] = length; + args[2] = prot; + args[3] = flags; + args[4] = fd; + args[5] = offset; + ret = VG_(do_syscall1)(__NR_mmap, (UWord)args ); + } +#elif defined(VGP_amd64_linux) + ret = VG_(do_syscall6)(__NR_mmap, (UWord)start, length, + prot, flags, fd, offset); +#else +# error Unknown platform +#endif + return VG_(is_kerror)(ret) ? (void*)-1 : (void*)ret; } /* Returns -1 on failure. */ @@ -317,10 +326,12 @@ void* VG_(mmap)( void* start, SizeT length, if (start == 0) return (void *)-1; - res = mmap_inner(start, length, prot, flags, fd, offset); + res = (Addr)VG_(mmap_native)(start, length, prot, + flags & ~(VKI_MAP_NOSYMS | VKI_MAP_CLIENT), + fd, offset); // Check it ended up in the right place. - if (!VG_(is_kerror)(res)) { + if (res != (Addr)-1) { if (flags & VKI_MAP_CLIENT) { vg_assert(VG_(client_base) <= res && res+length <= VG_(client_end)); } else { @@ -337,29 +348,36 @@ void* VG_(mmap)( void* start, SizeT length, VG_(map_fd_segment)(res, length, prot, sf_flags, fd, offset, NULL); } - return VG_(is_kerror)(res) ? ((void*)(-1)) : (void*)res; + return (void*)res; +} + +static Int munmap_native(void *start, SizeT length) +{ + Int res = VG_(do_syscall2)(__NR_munmap, (UWord)start, length ); + return VG_(is_kerror)(res) ? -1 : 0; } /* Returns -1 on failure. */ Int VG_(munmap)( void* start, SizeT length ) { - Int res = munmap_inner(start, length); - if (!VG_(is_kerror)(res)) + Int res = munmap_native(start, length); + if (0 == res) VG_(unmap_range)((Addr)start, length); - return VG_(is_kerror)(res) ? -1 : 0; + return res; } -Int VG_(mprotect)( void *start, SizeT length, UInt prot ) +Int VG_(mprotect_native)( void *start, SizeT length, UInt prot ) { Int res = VG_(do_syscall3)(__NR_mprotect, (UWord)start, length, prot ); - if (!VG_(is_kerror)(res)) - VG_(mprotect_range)((Addr)start, length, prot); return VG_(is_kerror)(res) ? -1 : 0; } -Int VG_(mprotect_native)( void *start, SizeT length, UInt prot ) + +Int VG_(mprotect)( void *start, SizeT length, UInt prot ) { - Int res = VG_(do_syscall3)(__NR_mprotect, (UWord)start, length, prot ); - return VG_(is_kerror)(res) ? -1 : 0; + Int res = VG_(mprotect_native)(start, length, prot); + if (0 == res) + VG_(mprotect_range)((Addr)start, length, prot); + return res; } /* Pull down the entire world */ diff --git a/coregrind/x86-linux/Makefile.am b/coregrind/x86-linux/Makefile.am index 96f3688d63..c485764a82 100644 --- a/coregrind/x86-linux/Makefile.am +++ b/coregrind/x86-linux/Makefile.am @@ -2,5 +2,4 @@ include $(top_srcdir)/Makefile.all.am include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am noinst_HEADERS = \ - core_platform.h \ vki_unistd.h diff --git a/coregrind/x86-linux/core_platform.h b/coregrind/x86-linux/core_platform.h deleted file mode 100644 index 408611dbd6..0000000000 --- a/coregrind/x86-linux/core_platform.h +++ /dev/null @@ -1,56 +0,0 @@ - -/*--------------------------------------------------------------------*/ -/*--- Platform-specific stuff for the core. ---*/ -/*--- x86-linux/core_platform.h ---*/ -/*--------------------------------------------------------------------*/ - -/* - This file is part of Valgrind, a dynamic binary instrumentation - framework. - - Copyright (C) 2000-2005 Nicholas Nethercote - njn@valgrind.org - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307, USA. - - The GNU General Public License is contained in the file COPYING. -*/ - -#ifndef __X86_LINUX_CORE_PLATFORM_H -#define __X86_LINUX_CORE_PLATFORM_H - -/* --------------------------------------------------------------------- - mmap() stuff - ------------------------------------------------------------------ */ - -#define VGP_DO_MMAP(ret, start, length, prot, flags, fd, offset) { \ - UWord __args[6]; \ - \ - __args[0] = (UWord)(start); \ - __args[1] = (length); \ - __args[2] = (prot); \ - __args[3] = (flags); \ - __args[4] = (fd); \ - __args[5] = (offset); \ - \ - ret = VG_(do_syscall1)(__NR_mmap, (UWord)(&(__args[0])) ); \ -} while (0) - -#endif // __X86_LINUX_CORE_PLATFORM_H - -/*--------------------------------------------------------------------*/ -/*--- end ---*/ -/*--------------------------------------------------------------------*/ diff --git a/docs/porting-HOWTO b/docs/porting-HOWTO index 22254055c8..80dd289235 100644 --- a/docs/porting-HOWTO +++ b/docs/porting-HOWTO @@ -1,6 +1,9 @@ This is a rough guide to porting Valgrind to a new architecture, or a new operating system. It's quite preliminary, but should get you started. +[29-May-2005: the stuff about the locations of files is now badly out of +date. --njn] + ----------------------------------------------------------------------------- Porting Valgrind to a new architecture -----------------------------------------------------------------------------