|
From: <sv...@va...> - 2005-11-09 14:52:04
|
Author: sewardj
Date: 2005-11-09 14:51:59 +0000 (Wed, 09 Nov 2005)
New Revision: 5057
Log:
Add comments from email discussion re mprotect.
Modified:
trunk/coregrind/m_syswrap/syswrap-generic.c
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-11-09 14:43:03 UTC (=
rev 5056)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c 2005-11-09 14:51:59 UTC (=
rev 5057)
@@ -4554,7 +4554,23 @@
=20
if (!ML_(valid_client_addr)(ARG1, ARG2, tid, "mprotect")) {
SET_STATUS_Failure( VKI_ENOMEM );
- } else if (ARG3 & (VKI_PROT_GROWSDOWN|VKI_PROT_GROWSUP)) {
+ }=20
+ else=20
+ if (ARG3 & (VKI_PROT_GROWSDOWN|VKI_PROT_GROWSUP)) {
+ /* Deal with mprotects on growable stack areas.
+
+ The critical files to understand all this are mm/mprotect.c
+ in the kernel and sysdeps/unix/sysv/linux/dl-execstack.c in
+ glibc.
+
+ The kernel provides PROT_GROWSDOWN and PROT_GROWSUP which
+ round the start/end address of mprotect to the start/end of
+ the underlying vma and glibc uses that as an easy way to
+ change the protection of the stack by calling mprotect on the
+ last page of the stack with PROT_GROWSDOWN set.
+
+ The sanity check provided by the kernel is that the vma must
+ have the VM_GROWSDOWN/VM_GROWSUP flag set as appropriate. */
UInt grows =3D ARG3 & (VKI_PROT_GROWSDOWN|VKI_PROT_GROWSUP);
NSegment *aseg =3D VG_(am_find_nsegment)(ARG1);
NSegment *rseg;
@@ -4586,6 +4602,7 @@
SET_STATUS_Failure( VKI_EINVAL );
}
} else {
+ /* both GROWSUP and GROWSDOWN */
SET_STATUS_Failure( VKI_EINVAL );
}
}
|