Bug is not really fixed, instead the SHM_HUGETLB flag is ignored.
Note that it is not straightforward to properly fix this,
as this implies either to learn aspacemgr what huge pages are.
Also, the trick used in the fix for 333051 cannot be used easily,
because the SHM_HUGETLB flag is given in shmget, while the mmap
is done in shmat.
So, the easiest is to just ignore the SHM_HUGETLB flag.
SHM_HUGETLB is supposed to only give a performance impact.
Ignoring it should be benign.
Theoretically, the caller might expect a sucessful shmget(SHM_HUGETLB)+shmat
to give pages aligned on e.g. 1MB.
In this case, bad luck, the program will misbehave under valgrind.
To warn of this, a warning is given (once) when SHM_HUGETLB is seen.
The map_unmap.c test has been restructured somewaht to allow
TEST_SHM_HUGETLB to be tested independently (or not) of the TEST_MAP_HUGETLB.
Note also that by default, testing MAP_HUGETLB and SHM_HUGETLB
is disabled as usually, huge pages are not enabled.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14683
335440 arm64: ld1 (single structure) is not implemented
335713 arm64: unhanded instruction: prfm (immediate)
338731 ppc: Fix testuite build for toolchains not supporting -maltivec
+338995 shmat with hugepages (SHM_HUGETLB) fails with EINVAL
339020 ppc64: memcheck/tests/ppc64/power_ISA2_05 failing in nightly build
339156 gdbsrv not called for fatal signal
339442 Fix testsuite build failure on OS X 10.9
{
PRINT("shmget ( %ld, %ld, %ld )",ARG1,ARG2,ARG3);
PRE_REG_READ3(long, "shmget", vki_key_t, key, vki_size_t, size, int, shmflg);
+ if (ARG3 & VKI_SHM_HUGETLB) {
+ static Bool warning_given = False;
+ ARG3 &= ~VKI_SHM_HUGETLB;
+ if (!warning_given) {
+ warning_given = True;
+ VG_(umsg)(
+ "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
+ }
+ }
}
PRE(shm_open)
case VKI_SHMGET:
PRE_REG_READ4(int, "ipc",
vki_uint, call, int, first, int, second, int, third);
+ if (ARG4 & VKI_SHM_HUGETLB) {
+ static Bool warning_given = False;
+ ARG4 &= ~VKI_SHM_HUGETLB;
+ if (!warning_given) {
+ warning_given = True;
+ VG_(umsg)(
+ "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
+ }
+ }
break;
case VKI_SHMCTL: /* IPCOP_shmctl */
PRE_REG_READ5(int, "ipc",
{
PRINT("sys_shmget ( %ld, %ld, %ld )",ARG1,ARG2,ARG3);
PRE_REG_READ3(long, "shmget", vki_key_t, key, vki_size_t, size, int, shmflg);
+ if (ARG3 & VKI_SHM_HUGETLB) {
+ static Bool warning_given = False;
+ ARG3 &= ~VKI_SHM_HUGETLB;
+ if (!warning_given) {
+ warning_given = True;
+ VG_(umsg)(
+ "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
+ }
+ }
}
PRE(wrap_sys_shmat)
#define VKI_IPC_64 0x0100 /* New version (support 32-bit UIDs, bigger
message sizes, etc. */
+// From /usr/include/bits/shm.h
+# define VKI_SHM_HUGETLB 04000
+
//----------------------------------------------------------------------
// From linux-2.6.8.1/include/linux/sem.h
echo 20 > /proc/sys/vm/nr_hugepages
Once this is done, uncomment the below, and recompile.
*/
-// #define TEST_MAP_HUGETLB 1
+//#define TEST_MAP_HUGETLB 1
/* Similarly, testing SHM_HUGETLB huge pages is disabled by default.
To have shmget/shmat big pages working, do (as root)
where 500 is the groupid of the user that runs this test
Once this is done, uncomment the below, and recompile.
*/
-// #define TEST_SHM_HUGETLB 1
+//#define TEST_SHM_HUGETLB 1
-#ifdef TEST_MAP_HUGETLB
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/stat.h>
+// Size to use for huge pages
+#define HUGESZ (4 * 1024 * 1024)
+#ifdef TEST_MAP_HUGETLB
/* Ensure this compiles on pre 2.6 systems, or on glibc missing MAP_HUGETLB */
#ifndef MAP_HUGETLB
/* The below works for me on an f12/x86 linux */
#endif /* TEST_MAP_HUGETLB */
#ifdef TEST_SHM_HUGETLB
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
#ifndef SHM_HUGETLB
#define SHM_HUGETLB 04000
#endif
}
#ifdef TEST_MAP_HUGETLB
-#define HUGESZ (4 * 1024 * 1024)
{
void *expect3;
expect3 = domap(HUGESZ, MAP_HUGETLB);