|
From: <sv...@va...> - 2005-09-30 08:07:59
|
Author: tom
Date: 2005-09-30 09:07:53 +0100 (Fri, 30 Sep 2005)
New Revision: 4834
Log:
Rationalise the mmap system call handling - after examining the kernel
source it turns out that there are five different versions of mmap for
the three platforms we currently support:
- On x86-linux there is mmap (aka old_mmap) which takes the
arguments in a memory block and the offset in bytes; and
mmap2 (aka sys_mmap2) which takes the arguments in the normal
way and the offset in pages.
- On ppc32-linux there is mmap (aka sys_mmap) which takes the
arguments in the normal way and the offset in bytes; and
mmap2 (aka sys_mmap2) which takes the arguments in the normal
way and the offset in pages.
- On amd64-linux everything is simple and there is just the one
call, mmap (aka sys_mmap) which takes the arguments in the normal
way and the offset in bytes.
To reconcile all this I have created a generic handler and then
written five platform specific wrappers which normalise all the
arguments and then call the generic handler.
I have also modified the address space manager to use mmap2 rather
than mmap on x86 and ppc32 so that large offsets can be correctly
handled.
There is still an issue of OffT truncating offsets as we go through
the address space manager that will need to be addressed.
Modified:
trunk/coregrind/m_aspacemgr/aspacemgr.c
trunk/coregrind/m_syswrap/priv_syswrap-generic.h
trunk/coregrind/m_syswrap/priv_syswrap-linux.h
trunk/coregrind/m_syswrap/syswrap-amd64-linux.c
trunk/coregrind/m_syswrap/syswrap-generic.c
trunk/coregrind/m_syswrap/syswrap-linux.c
trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c
trunk/coregrind/m_syswrap/syswrap-x86-linux.c
Modified: trunk/coregrind/m_aspacemgr/aspacemgr.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-09-30 02:17:40 UTC (rev =
4833)
+++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-09-30 08:07:53 UTC (rev =
4834)
@@ -228,23 +228,12 @@
UInt flags, UInt fd, OffT offset)
{
SysRes res;
-# if defined(VGP_x86_linux)
- {=20
- UWord args[6];
- args[0] =3D (UWord)start;
- args[1] =3D length;
- args[2] =3D prot;
- args[3] =3D flags;
- args[4] =3D fd;
- args[5] =3D offset;
- res =3D VG_(do_syscall1)(__NR_mmap, (UWord)args );
- }
+# if defined(VGP_x86_linux) || defined(VGP_ppc32_linux)
+ res =3D VG_(do_syscall6)(__NR_mmap2, (UWord)start, length,
+ prot, flags, fd, offset / VKI_PAGE_SIZE));
# elif defined(VGP_amd64_linux)
res =3D VG_(do_syscall6)(__NR_mmap, (UWord)start, length,=20
prot, flags, fd, offset);
-# elif defined(VGP_ppc32_linux)
- res =3D VG_(do_syscall6)(__NR_mmap, (UWord)(start), (length),
- prot, flags, fd, offset);
# else
# error Unknown platform
# endif
Modified: trunk/coregrind/m_syswrap/priv_syswrap-generic.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/priv_syswrap-generic.h 2005-09-30 02:17:40 =
UTC (rev 4833)
+++ trunk/coregrind/m_syswrap/priv_syswrap-generic.h 2005-09-30 08:07:53 =
UTC (rev 4834)
@@ -242,6 +242,8 @@
extern void ML_(generic_PRE_sys_shmctl) ( TId, UW, UW, UW );
extern void ML_(generic_POST_sys_shmctl) ( TId, UW, UW, UW, UW );
=20
+extern SysRes ML_(generic_PRE_sys_mmap) ( TId, UW, UW, UW, UW, U=
W, UW );
+
#undef TId
#undef UW
#undef SR
Modified: trunk/coregrind/m_syswrap/priv_syswrap-linux.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/priv_syswrap-linux.h 2005-09-30 02:17:40 UT=
C (rev 4833)
+++ trunk/coregrind/m_syswrap/priv_syswrap-linux.h 2005-09-30 08:07:53 UT=
C (rev 4834)
@@ -66,7 +66,6 @@
DECL_TEMPLATE(linux, sys_sendfile);
DECL_TEMPLATE(linux, sys_sendfile64);
DECL_TEMPLATE(linux, sys_futex);
-DECL_TEMPLATE(linux, sys_mmap2);
=20
DECL_TEMPLATE(linux, sys_epoll_create);
DECL_TEMPLATE(linux, sys_epoll_ctl);
Modified: trunk/coregrind/m_syswrap/syswrap-amd64-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-amd64-linux.c 2005-09-30 02:17:40 U=
TC (rev 4833)
+++ trunk/coregrind/m_syswrap/syswrap-amd64-linux.c 2005-09-30 08:07:53 U=
TC (rev 4834)
@@ -569,6 +569,7 @@
DECL_TEMPLATE(amd64_linux, sys_pread64);
DECL_TEMPLATE(amd64_linux, sys_pwrite64);
DECL_TEMPLATE(amd64_linux, sys_fadvise64);
+DECL_TEMPLATE(amd64_linux, sys_mmap);
=20
=20
PRE(sys_clone)
@@ -1136,6 +1137,21 @@
int, fd, vki_loff_t, offset, vki_size_t, len, int, advi=
ce);
}
=20
+PRE(sys_mmap)
+{
+ SysRes r;
+
+ PRINT("sys_mmap ( %p, %llu, %d, %d, %d, %d )",
+ ARG1, (ULong)ARG2, ARG3, ARG4, ARG5, ARG6 );
+ PRE_REG_READ6(long, "mmap",
+ unsigned long, start, unsigned long, length,
+ unsigned long, prot, unsigned long, flags,
+ unsigned long, fd, unsigned long, offset);
+
+ r =3D ML_(generic_PRE_sys_mmap)( tid, ARG1, ARG2, ARG3, ARG4, ARG5, A=
RG6 );
+ SET_STATUS_from_SysRes(r);
+}
+
#undef PRE
#undef POST
=20
@@ -1167,7 +1183,7 @@
GENXY(__NR_lstat, sys_newlstat), // 6=20
GENXY(__NR_poll, sys_poll), // 7=20
LINX_(__NR_lseek, sys_lseek), // 8=20
- LINX_(__NR_mmap, sys_mmap2), // 9=20
+ PLAX_(__NR_mmap, sys_mmap), // 9=20
=20
GENXY(__NR_mprotect, sys_mprotect), // 10=20
GENXY(__NR_munmap, sys_munmap), // 11=20
Modified: trunk/coregrind/m_syswrap/syswrap-generic.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-generic.c 2005-09-30 02:17:40 UTC (=
rev 4833)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c 2005-09-30 08:07:53 UTC (=
rev 4834)
@@ -1710,6 +1710,79 @@
=20
=20
/* ---------------------------------------------------------------------
+ Generic handler for mmap
+ ------------------------------------------------------------------ */
+
+SysRes
+ML_(generic_PRE_sys_mmap) ( ThreadId tid,
+ UWord arg1, UWord arg2, UWord arg3,
+ UWord arg4, UWord arg5, UWord arg6 )
+{
+ Addr advised;
+ SysRes sres;
+ MapRequest mreq;
+ Bool mreq_ok;
+
+ if (arg2 =3D=3D 0) {
+ /* SuSV3 says: If len is zero, mmap() shall fail and no mapping
+ shall be established. */
+ return VG_(mk_SysRes_Error)( VKI_EINVAL );
+ }
+
+ if (!VG_IS_PAGE_ALIGNED(arg1)) {
+ /* zap any misaligned addresses. */
+ /* SuSV3 says misaligned addresses only cause the MAP_FIXED case
+ to fail. Here, we catch them all. */
+ return VG_(mk_SysRes_Error)( VKI_EINVAL );
+ }
+
+ /* Figure out what kind of allocation constraints there are
+ (fixed/hint/any), and ask aspacem what we should do. */
+ mreq.start =3D arg1;
+ mreq.len =3D arg2;
+ if (arg4 & VKI_MAP_FIXED) {
+ mreq.rkind =3D MFixed;
+ } else
+ if (arg1 !=3D 0) {
+ mreq.rkind =3D MHint;
+ } else {
+ mreq.rkind =3D MAny;
+ }
+
+ /* Enquire ... */
+ advised =3D VG_(am_get_advisory)( &mreq, True/*client*/, &mreq_ok );
+ if (!mreq_ok) {
+ /* Our request was bounced, so we'd better fail. */
+ return VG_(mk_SysRes_Error)( VKI_EINVAL );
+ }
+
+ /* Otherwise we're OK (so far). Install aspacem's choice of
+ address, and let the mmap go through. */
+ sres =3D VG_(am_do_mmap_NO_NOTIFY)(advised, arg2, arg3,
+ arg4 | VKI_MAP_FIXED,
+ arg5, arg6);
+
+ if (!sres.isError) {
+ /* Notify aspacem and the tool. */
+ ML_(notify_aspacem_and_tool_of_mmap)(=20
+ (Addr)sres.val, /* addr kernel actually assigned */
+ arg2, arg3,=20
+ arg4, /* the original flags value */
+ arg5, arg6=20
+ );
+ /* Load symbols? */
+ VG_(di_notify_mmap)( (Addr)sres.val );
+ }
+
+ /* Stay sane */
+ if (!sres.isError && (arg4 & VKI_MAP_FIXED))
+ vg_assert(sres.val =3D=3D arg1);
+
+ return sres;
+}
+
+
+/* ---------------------------------------------------------------------
The Main Entertainment ... syscall wrappers
------------------------------------------------------------------ */
=20
Modified: trunk/coregrind/m_syswrap/syswrap-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-linux.c 2005-09-30 02:17:40 UTC (re=
v 4833)
+++ trunk/coregrind/m_syswrap/syswrap-linux.c 2005-09-30 08:07:53 UTC (re=
v 4834)
@@ -548,98 +548,7 @@
}
}
=20
-PRE(sys_mmap2)
-{
- Addr advised;
- SysRes sres;
- OffT offset;
- MapRequest mreq;
- Bool mreq_ok;
=20
- // Exactly like old_mmap() in x86-linux except:
- // - all 6 args are passed in regs, rather than in a memory-block.
- // - on x86-linux, the file offset is specified in pagesize units
- // rather than bytes, so that it can be used for files bigger=20
- // than 2^32 bytes. On amd64-linux and ppc32-linux it appears
- // to be in bytes.
- PRINT("sys_mmap2 ( %p, %llu, %d, %d, %d, %d )",
- ARG1, (ULong)ARG2, ARG3, ARG4, ARG5, ARG6 );
- PRE_REG_READ6(long, "mmap2",
- unsigned long, start, unsigned long, length,
- unsigned long, prot, unsigned long, flags,
- unsigned long, fd, unsigned long, offset);
-
- if (ARG2 =3D=3D 0) {
- /* SuSV3 says: If len is zero, mmap() shall fail and no mapping
- shall be established. */
- SET_STATUS_Failure( VKI_EINVAL );
- return;
- }
-
- if (!VG_IS_PAGE_ALIGNED(ARG1)) {
- /* zap any misaligned addresses. */
- /* SuSV3 says misaligned addresses only cause the MAP_FIXED case
- to fail. Here, we catch them all. */
- SET_STATUS_Failure( VKI_EINVAL );
- return;
- }
-
- /* Figure out what kind of allocation constraints there are
- (fixed/hint/any), and ask aspacem what we should do. */
- mreq.start =3D ARG1;
- mreq.len =3D ARG2;
- if (ARG4 & VKI_MAP_FIXED) {
- mreq.rkind =3D MFixed;
- } else
- if (ARG1 !=3D 0) {
- mreq.rkind =3D MHint;
- } else {
- mreq.rkind =3D MAny;
- }
-
- /* Enquire ... */
- advised =3D VG_(am_get_advisory)( &mreq, True/*client*/, &mreq_ok );
- if (!mreq_ok) {
- /* Our request was bounced, so we'd better fail. */
- SET_STATUS_Failure( VKI_EINVAL );
- return;
- }
-
- vg_assert(! FAILURE);
-
-# if defined(VGP_x86_linux)
- offset =3D ARG6 * VKI_PAGE_SIZE;
-# elif defined(VGP_amd64_linux) || defined(VGP_ppc32_linux)
- offset =3D ARG6;
-# else
-# error Unknown platform
-# endif
-
- /* Otherwise we're OK (so far). Install aspacem's choice of
- address, and let the mmap go through. */
- sres =3D VG_(am_do_mmap_NO_NOTIFY)(advised, ARG2, ARG3,
- ARG4 | VKI_MAP_FIXED,
- ARG5, offset);
- SET_STATUS_from_SysRes(sres);
-
- if (!sres.isError) {
- /* Notify aspacem and the tool. */
- ML_(notify_aspacem_and_tool_of_mmap)(=20
- (Addr)sres.val, /* addr kernel actually assigned */
- ARG2, ARG3,=20
- ARG4, /* the original flags value */
- ARG5, offset
- );
- /* Load symbols? */
- VG_(di_notify_mmap)( (Addr)sres.val );
- }
-
- /* Stay sane */
- if (SUCCESS && (ARG4 & VKI_MAP_FIXED))
- vg_assert(RES =3D=3D ARG1);
-}
-
-
/* ---------------------------------------------------------------------
epoll_* wrappers
------------------------------------------------------------------ */
Modified: trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c 2005-09-30 02:17:40 U=
TC (rev 4833)
+++ trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c 2005-09-30 08:07:53 U=
TC (rev 4834)
@@ -592,6 +592,8 @@
magic. */
=20
DECL_TEMPLATE(ppc32_linux, sys_socketcall);
+DECL_TEMPLATE(ppc32_linux, sys_mmap);
+DECL_TEMPLATE(ppc32_linux, sys_mmap2);
DECL_TEMPLATE(ppc32_linux, sys_stat64);
DECL_TEMPLATE(ppc32_linux, sys_lstat64);
DECL_TEMPLATE(ppc32_linux, sys_fstat64);
@@ -856,6 +858,39 @@
# undef ARG2_5
}
=20
+PRE(sys_mmap)
+{
+ SysRes r;
+
+ PRINT("sys_mmap ( %p, %llu, %d, %d, %d, %d )",
+ ARG1, (ULong)ARG2, ARG3, ARG4, ARG5, ARG6 );
+ PRE_REG_READ6(long, "mmap",
+ unsigned long, start, unsigned long, length,
+ unsigned long, prot, unsigned long, flags,
+ unsigned long, fd, unsigned long, offset);
+
+ r =3D ML_(generic_PRE_sys_mmap)( tid, ARG1, ARG2, ARG3, ARG4, ARG5, A=
RG6 );
+ SET_STATUS_from_SysRes(r);
+}
+
+PRE(sys_mmap2)
+{
+ SysRes r;
+
+ // Exactly like old_mmap() except:
+ // - the file offset is specified in pagesize units rather than byte=
s,
+ // so that it can be used for files bigger than 2^32 bytes.
+ PRINT("sys_mmap2 ( %p, %llu, %d, %d, %d, %d )",
+ ARG1, (ULong)ARG2, ARG3, ARG4, ARG5, ARG6 );
+ PRE_REG_READ6(long, "mmap2",
+ unsigned long, start, unsigned long, length,
+ unsigned long, prot, unsigned long, flags,
+ unsigned long, fd, unsigned long, offset);
+
+ r =3D ML_(generic_PRE_sys_mmap)( tid, ARG1, ARG2, ARG3, ARG4, ARG5, A=
RG6 * VKI_PAGE_SIZE );
+ SET_STATUS_from_SysRes(r);
+}
+
// XXX: lstat64/fstat64/stat64 are generic, but not necessarily
// applicable to every architecture -- I think only to 32-bit archs.
// We're going to need something like linux/core_os32.h for such
@@ -1725,7 +1760,7 @@
//.. // (__NR_reboot, sys_reboot), // 88 */Li=
nux
//.. // (__NR_readdir, old_readdir), // 89 -- s=
uperseded
=20
- LINX_(__NR_mmap, sys_mmap2), // 90
+ PLAX_(__NR_mmap, sys_mmap), // 90
GENXY(__NR_munmap, sys_munmap), // 91
//.. GENX_(__NR_truncate, sys_truncate), // 92
GENX_(__NR_ftruncate, sys_ftruncate), // 93
@@ -1851,7 +1886,7 @@
GENX_(__NR_vfork, sys_fork), // 189
GENXY(__NR_ugetrlimit, sys_getrlimit), // 190
//__NR_readahead // 191 ppc/Linux only?
- LINX_(__NR_mmap2, sys_mmap2), // 192
+ PLAX_(__NR_mmap2, sys_mmap2), // 192
//.. GENX_(__NR_truncate64, sys_truncate64), // 193
//.. GENX_(__NR_ftruncate64, sys_ftruncate64), // 194
//.. =20
Modified: trunk/coregrind/m_syswrap/syswrap-x86-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-x86-linux.c 2005-09-30 02:17:40 UTC=
(rev 4833)
+++ trunk/coregrind/m_syswrap/syswrap-x86-linux.c 2005-09-30 08:07:53 UTC=
(rev 4834)
@@ -966,6 +966,7 @@
DECL_TEMPLATE(x86_linux, sys_lstat64);
DECL_TEMPLATE(x86_linux, sys_clone);
DECL_TEMPLATE(x86_linux, old_mmap);
+DECL_TEMPLATE(x86_linux, sys_mmap2);
DECL_TEMPLATE(x86_linux, sys_sigreturn);
DECL_TEMPLATE(x86_linux, sys_ipc);
DECL_TEMPLATE(x86_linux, sys_rt_sigreturn);
@@ -1466,10 +1467,7 @@
unsigned long offset;
}; */
UWord a1, a2, a3, a4, a5, a6;
- Addr advised;
- SysRes sres;
- MapRequest mreq;
- Bool mreq_ok;
+ SysRes r;
=20
UWord* args =3D (UWord*)ARG1;
PRE_REG_READ1(long, "old_mmap", struct mmap_arg_struct *, args);
@@ -1485,65 +1483,27 @@
PRINT("old_mmap ( %p, %llu, %d, %d, %d, %d )",
a1, (ULong)a2, a3, a4, a5, a6 );
=20
- if (a2 =3D=3D 0) {
- /* SuSV3 says: If len is zero, mmap() shall fail and no mapping
- shall be established. */
- SET_STATUS_Failure( VKI_EINVAL );
- return;
- }
+ r =3D ML_(generic_PRE_sys_mmap)( tid, a1, a2, a3, a4, a5, a6 );
+ SET_STATUS_from_SysRes(r);
+}
=20
- if (!VG_IS_PAGE_ALIGNED(a1)) {
- /* zap any misaligned addresses. */
- SET_STATUS_Failure( VKI_EINVAL );
- return;
- }
+PRE(sys_mmap2)
+{
+ SysRes r;
=20
- /* Figure out what kind of allocation constraints there are
- (fixed/hint/any), and ask aspacem what we should do. */
- mreq.start =3D a1;
- mreq.len =3D a2;
- if (a4 & VKI_MAP_FIXED) {
- mreq.rkind =3D MFixed;
- } else
- if (a1 !=3D 0) {
- mreq.rkind =3D MHint;
- } else {
- mreq.rkind =3D MAny;
- }
+ // Exactly like old_mmap() except:
+ // - all 6 args are passed in regs, rather than in a memory-block.
+ // - the file offset is specified in pagesize units rather than byte=
s,
+ // so that it can be used for files bigger than 2^32 bytes.
+ PRINT("sys_mmap2 ( %p, %llu, %d, %d, %d, %d )",
+ ARG1, (ULong)ARG2, ARG3, ARG4, ARG5, ARG6 );
+ PRE_REG_READ6(long, "mmap2",
+ unsigned long, start, unsigned long, length,
+ unsigned long, prot, unsigned long, flags,
+ unsigned long, fd, unsigned long, offset);
=20
- /* Enquire ... */
- advised =3D VG_(am_get_advisory)( &mreq, True/*client*/, &mreq_ok );
- if (!mreq_ok) {
- /* Our request was bounced, so we'd better fail. */
- SET_STATUS_Failure( VKI_EINVAL );
- return;
- }
-
- /* Otherwise we're OK (so far). Install aspacem's choice of
- address, and let the mmap go through. */
- a1 =3D advised;
- a4 |=3D VKI_MAP_FIXED;
-
- vg_assert(! FAILURE);
-
- sres =3D VG_(am_do_mmap_NO_NOTIFY)(a1, a2, a3, a4, a5, a6);
- SET_STATUS_from_SysRes(sres);
-
- if (!sres.isError) {
- /* Notify aspacem and the tool. */
- ML_(notify_aspacem_and_tool_of_mmap)(=20
- (Addr)sres.val, /* addr kernel actually assigned */
- a2, a3,=20
- args[4-1], /* the original flags value */
- a5, a6=20
- );
- /* Load symbols? */
- VG_(di_notify_mmap)( (Addr)sres.val );
- }
-
- /* Stay sane */
- if (SUCCESS && (args[4-1] & VKI_MAP_FIXED))
- vg_assert(RES =3D=3D args[0]);
+ r =3D ML_(generic_PRE_sys_mmap)( tid, ARG1, ARG2, ARG3, ARG4, ARG5, A=
RG6 * VKI_PAGE_SIZE );
+ SET_STATUS_from_SysRes(r);
}
=20
// XXX: lstat64/fstat64/stat64 are generic, but not necessarily
@@ -2170,7 +2130,7 @@
// Nb: we treat vfork as fork
GENX_(__NR_vfork, sys_fork), // 190
GENXY(__NR_ugetrlimit, sys_getrlimit), // 191
- LINX_(__NR_mmap2, sys_mmap2), // 192
+ PLAX_(__NR_mmap2, sys_mmap2), // 192
GENX_(__NR_truncate64, sys_truncate64), // 193
GENX_(__NR_ftruncate64, sys_ftruncate64), // 194
=20
|
|
From: Julian S. <js...@ac...> - 2005-09-30 09:36:05
|
> Rationalise the mmap system call handling Excellent. This is long overdue. > There is still an issue of OffT truncating offsets as we go through > the address space manager that will need to be addressed. How about this: store offsets consistently 64-bit throughout aspacem, and change the type of VG_(am_do_mmap_NO_NOTIFY)'s last arg accordingly. Then make VG_(am_do_mmap_NO_NOTIFY) examine that last arg: - on amd64, no change from now - on x86/ppc32, if < 2^32, do the obvious thing (sys_mmap/old_mmap) else if it's of the form 0xFFFFFFFF << PAGE_SHIFT then use mmap2 else return a failure SysRes, since we have no way to express that offset to the kernel. J |
|
From: Tom H. <to...@co...> - 2005-09-30 09:46:17
|
In message <200...@ac...>
Julian Seward <js...@ac...> wrote:
> How about this: store offsets consistently 64-bit throughout aspacem,
> and change the type of VG_(am_do_mmap_NO_NOTIFY)'s last arg accordingly.
>
> Then make VG_(am_do_mmap_NO_NOTIFY) examine that last arg:
>
> - on amd64, no change from now
>
> - on x86/ppc32, if < 2^32, do the obvious thing (sys_mmap/old_mmap)
> else if it's of the form 0xFFFFFFFF << PAGE_SHIFT then use
> mmap2
> else return a failure SysRes, since we have no way to express that
> offset to the kernel.
What is the point of this - offsets that are not page aligned are
always invalid (though we should probably check that in the generic
wrapper) and I think mmap2 has been around long enough that we're
not likely to encounter a kernel that doesn't have it - or do you
think we might?
Tom
--
Tom Hughes (to...@co...)
http://www.compton.nu/
|
|
From: Julian S. <js...@ac...> - 2005-09-30 10:26:34
|
> Julian Seward <js...@ac...> wrote: > > How about this: store offsets consistently 64-bit throughout aspacem, > > and change the type of VG_(am_do_mmap_NO_NOTIFY)'s last arg accordingly. > > > > Then make VG_(am_do_mmap_NO_NOTIFY) examine that last arg: > > > > - on amd64, no change from now > > > > - on x86/ppc32, if < 2^32, do the obvious thing (sys_mmap/old_mmap) > > else if it's of the form 0xFFFFFFFF << PAGE_SHIFT then use > > mmap2 > > else return a failure SysRes, since we have no way to express that > > offset to the kernel. > > What is the point of this - offsets that are not page aligned are > always invalid (though we should probably check that in the generic > wrapper) and I think mmap2 has been around long enough that we're > not likely to encounter a kernel that doesn't have it - or do you > think we might? Let me rephrase that. 64-bit offsets everywhere, including last arg to VG_(am_do_mmap_NO_NOTIFY). That fn then communicates the mmap to the kernel using whatever variant of sys_mmap it feels like. The important thing is that VG_(am_do_mmap_NO_NOTIFY) insulates the rest of aspacem from those details. I don't want to lose support for 2.4 kernels, so if mmap2 predates 2.4.0 then we may as well just use that. Do you know when it appeared? Ah, 2.3.31 according to man mmap2. J |
|
From: Tom H. <to...@co...> - 2005-09-30 13:37:51
|
In message <200...@ac...>
Julian Seward <js...@ac...> wrote:
>> > - on x86/ppc32, if < 2^32, do the obvious thing (sys_mmap/old_mmap)
>> > else if it's of the form 0xFFFFFFFF << PAGE_SHIFT then use
>> > mmap2
>> > else return a failure SysRes, since we have no way to express that
>> > offset to the kernel.
>>
>> What is the point of this - offsets that are not page aligned are
>> always invalid (though we should probably check that in the generic
>> wrapper) and I think mmap2 has been around long enough that we're
>> not likely to encounter a kernel that doesn't have it - or do you
>> think we might?
>
> Let me rephrase that. 64-bit offsets everywhere, including
> last arg to VG_(am_do_mmap_NO_NOTIFY). That fn then communicates
> the mmap to the kernel using whatever variant of sys_mmap it feels
> like. The important thing is that VG_(am_do_mmap_NO_NOTIFY) insulates
> the rest of aspacem from those details.
Absolutely, and that is the current situation, modulo changing the
type of the offset argument and the question of whether or not we want
to rely on mmap2.
> I don't want to lose support for 2.4 kernels, so if mmap2 predates
> 2.4.0 then we may as well just use that. Do you know when it
> appeared? Ah, 2.3.31 according to man mmap2.
Does that mean you're happy to assume that mmap2 exists or should we
add a fallback to use mmap if mmap2 fails?
Tom
--
Tom Hughes (to...@co...)
http://www.compton.nu/
|
|
From: Nicholas N. <nj...@cs...> - 2005-09-30 14:28:38
|
On Fri, 30 Sep 2005, Tom Hughes wrote: > Absolutely, and that is the current situation, modulo changing the > type of the offset argument and the question of whether or not we want > to rely on mmap2. I think OffT should stay as word-sized, since it's meant to be a drop-in replacement for off_t which is word-sized. We could introduce LOffT (in pub_core_basics.h) which would be 64 bits. Nick |
|
From: Julian S. <js...@ac...> - 2005-09-30 15:09:56
|
On Friday 30 September 2005 15:28, Nicholas Nethercote wrote: > On Fri, 30 Sep 2005, Tom Hughes wrote: > > Absolutely, and that is the current situation, modulo changing the > > type of the offset argument and the question of whether or not we want > > to rely on mmap2. Let's just do mmap2 .. if we get borkage it's easy to Plan-B it. > I think OffT should stay as word-sized, since it's meant to be a drop-in > replacement for off_t which is word-sized. Absolutely totally definitely. It'll all go to hell if OffT changes its meaning. > We could introduce LOffT (in pub_core_basics.h) which would be 64 bits. Ehm .. could we not just use ULong? We know that's reliably 64 bits; LOffT gives another type for which to remember the meaning and it took me long enough to get my head around SizeT, OffT, Addr, Word all being word-sized things. Alternatively .. if you really want to have a new type .. could we call it Off64T, to be more in accordance with eg Addr/Addr32/Addr64 conventions? I find the 'long' qualifier ambiguous (one long means "word sized", which isn't what you mean here) and try to avoid it as much as possible. J |
|
From: Nicholas N. <nj...@cs...> - 2005-09-30 15:15:48
|
On Fri, 30 Sep 2005, Julian Seward wrote: > Ehm .. could we not just use ULong? We know that's reliably 64 bits; > LOffT gives another type for which to remember the meaning and it > took me long enough to get my head around SizeT, OffT, Addr, Word > all being word-sized things. > > Alternatively .. if you really want to have a new type .. could we > call it Off64T, to be more in accordance with eg Addr/Addr32/Addr64 > conventions? I find the 'long' qualifier ambiguous (one long means "word > sized", which isn't what you mean here) and try to avoid it as much as > possible. Off64T is good, the kernel has off64_t also. N |
|
From: Greg P. <gp...@us...> - 2005-10-01 01:37:52
|
Nicholas Nethercote writes: > On Fri, 30 Sep 2005, Tom Hughes wrote: > > Absolutely, and that is the current situation, modulo changing the > > type of the offset argument and the question of whether or not we want > > to rely on mmap2. > > I think OffT should stay as word-sized, since it's meant to be a drop-in > replacement for off_t which is word-sized. We could introduce LOffT (in > pub_core_basics.h) which would be 64 bits. Note that some 32-bit platforms like Darwin and maybe FreeBSD use a 64-bit off_t. -- Greg Parker gp...@us... |
|
From: Doug R. <df...@nl...> - 2005-10-02 21:15:04
|
On Saturday 01 October 2005 02:09, Greg Parker wrote: > Nicholas Nethercote writes: > > On Fri, 30 Sep 2005, Tom Hughes wrote: > > > Absolutely, and that is the current situation, modulo changing > > > the type of the offset argument and the question of whether or > > > not we want to rely on mmap2. > > > > I think OffT should stay as word-sized, since it's meant to be a > > drop-in replacement for off_t which is word-sized. We could > > introduce LOffT (in pub_core_basics.h) which would be 64 bits. > > Note that some 32-bit platforms like Darwin and maybe FreeBSD > use a 64-bit off_t. All 4.4BSD derived systems (*BSD, Darwin) use 64-bit off_t on both 32-bit and 64-bit platforms. |
|
From: Nicholas N. <nj...@cs...> - 2005-10-02 21:17:12
|
On Fri, 30 Sep 2005, Greg Parker wrote: >> I think OffT should stay as word-sized, since it's meant to be a drop-in >> replacement for off_t which is word-sized. We could introduce LOffT (in >> pub_core_basics.h) which would be 64 bits. > > Note that some 32-bit platforms like Darwin and maybe FreeBSD > use a 64-bit off_t. Huh, interesting. Well, we use vki_off_t in syscall wrappers, and that definition comes from the appropriate vki-*.h header. OffT is more for our internal use, so hopefully it won't be a problem. I like the idea of SizeT and OffT being the same size. Nick |