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
include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
noinst_HEADERS = \
- core_platform.h \
vki_unistd.h
+++ /dev/null
-
-/*--------------------------------------------------------------------*/
-/*--- 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 ---*/
-/*--------------------------------------------------------------------*/
include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
noinst_HEADERS = \
- core_platform.h \
vki_unistd.h
+++ /dev/null
-
-/*--------------------------------------------------------------------*/
-/*--- 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 ---*/
-/*--------------------------------------------------------------------*/
#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'
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 );
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);
}
}
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);
}
}
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)) {
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. */
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 {
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 */
include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
noinst_HEADERS = \
- core_platform.h \
vki_unistd.h
+++ /dev/null
-
-/*--------------------------------------------------------------------*/
-/*--- 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 ---*/
-/*--------------------------------------------------------------------*/
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
-----------------------------------------------------------------------------