Changeset: bd266b130386 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bd266b130386
Modified Files:
gdk/gdk_posix.c
gdk/gdk_utils.c
Branch: Jun2016
Log Message:
Push valgrind macros down into MT_mmap and friends.
We need more control because at the higher level of GDKmmap we can't
properly deal with mremap and partial munmap.
diffs (170 lines):
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -42,6 +42,19 @@
# include <sys/user.h>
#endif
+#ifdef NDEBUG
+#ifndef NVALGRIND
+#define NVALGRIND NDEBUG
+#endif
+#endif
+
+#if defined(__GNUC__) && defined(HAVE_VALGRIND)
+#include <valgrind.h>
+#else
+#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed)
+#define VALGRIND_FREELIKE_BLOCK(addr, rzB)
+#endif
+
#ifndef MAP_NORESERVE
# define MAP_NORESERVE MAP_PRIVATE
#endif
@@ -356,6 +369,7 @@ MT_mmap(const char *path, int mode, size
ret = NULL;
}
close(fd);
+ VALGRIND_MALLOCLIKE_BLOCK(ret, len, 0, 1);
return ret;
}
@@ -367,6 +381,7 @@ MT_munmap(void *p, size_t len)
if (ret < 0)
GDKsyserror("MT_munmap: munmap(" PTRFMT "," SZFMT ") failed\n",
PTRFMTCAST p, len);
+ VALGRIND_FREELIKE_BLOCK(p, 0);
#ifdef MMAP_DEBUG
fprintf(stderr, "#munmap(" PTRFMT "," SZFMT ") = %d\n", PTRFMTCAST p,
len, ret);
#endif
@@ -394,6 +409,7 @@ MT_mremap(const char *path, int mode, vo
if (*new_size < old_size) {
#ifndef STATIC_CODE_ANALYSIS /* hide this from static code analyzer */
/* shrink */
+ VALGRIND_RESIZEINPLACE_BLOCK(old_address, old_size, *new_size,
0);
if (munmap((char *) old_address + *new_size,
old_size - *new_size) < 0) {
GDKsyserror("MT_mremap: munmap("PTRFMT","SZFMT")
failed\n",
@@ -442,6 +458,14 @@ MT_mremap(const char *path, int mode, vo
GDKsyserror("MT_mremap:
mremap("PTRFMT","SZFMT","SZFMT") failed\n",
PTRFMTCAST old_address, old_size,
*new_size);
+#ifdef HAVE_VALGRIND
+ if (p == old_address) {
+ VALGRIND_RESIZEINPLACE_BLOCK(old_address, old_size,
*new_size, 0);
+ } else {
+ VALGRIND_FREELIKE_BLOCK(old_address, 0);
+ VALGRIND_MALLOCLIKE_BLOCK(p, *new_size, 0, 1);
+ }
+#endif
#else
/* try to map extension at end of current map */
p = mmap((char *) old_address + old_size, *new_size - old_size,
@@ -453,6 +477,7 @@ MT_mremap(const char *path, int mode, vo
/* we got the requested address, make
* sure we return the correct (old)
* address */
+ VALGRIND_RESIZEINPLACE_BLOCK(old_address,
old_size, *new_size, 0);
p = old_address;
} else {
/* we got some other address: discard
@@ -464,8 +489,11 @@ MT_mremap(const char *path, int mode, vo
/* first create full mmap, then, if
* successful, remove old mmap */
p = mmap(NULL, *new_size, prot, flags, fd, 0);
- if (p != MAP_FAILED)
+ if (p != MAP_FAILED) {
+ VALGRIND_MALLOCLIKE_BLOCK(p, *new_size,
0, 1);
munmap(old_address, old_size);
+ VALGRIND_FREELIKE_BLOCK(old_address, 0);
+ }
}
}
if (p == MAP_FAILED)
@@ -494,6 +522,7 @@ MT_mremap(const char *path, int mode, vo
/* we got the requested address, make
* sure we return the correct (old)
* address */
+ VALGRIND_RESIZEINPLACE_BLOCK(old_address,
old_size, *new_size, 0);
p = old_address;
} else {
/* we got some other address: discard
@@ -517,6 +546,12 @@ MT_mremap(const char *path, int mode, vo
munmap(p, *new_size);
p = MAP_FAILED;
}
+#ifdef HAVE_VALGRIND
+ else {
+
VALGRIND_FREELIKE_BLOCK(old_size, 0);
+ VALGRIND_MALLOCLIKE_BLOCK(p,
*new_size, 0, 1);
+ }
+#endif
}
#else
p = MAP_FAILED;
@@ -529,9 +564,11 @@ MT_mremap(const char *path, int mode, vo
p = mmap(NULL, *new_size, prot, flags,
fd, 0);
if (p != MAP_FAILED) {
+ VALGRIND_MALLOCLIKE_BLOCK(p,
*new_size, 0, 0);
memcpy(p, old_address,
old_size);
munmap(old_address, old_size);
+
VALGRIND_FREELIKE_BLOCK(old_address, 0);
}
/* if it failed, try alternative */
}
@@ -603,8 +640,11 @@ MT_mremap(const char *path, int mode, vo
}
p = mmap(NULL, *new_size, prot, flags,
fd, 0);
- if (p != MAP_FAILED)
+ if (p != MAP_FAILED) {
+ VALGRIND_MALLOCLIKE_BLOCK(p,
*new_size, 0, 1);
munmap(old_address, old_size);
+
VALGRIND_FREELIKE_BLOCK(old_address, 0);
+ }
}
#endif /* HAVE_MREMAP */
}
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -49,19 +49,6 @@ static char THRprintbuf[BUFSIZ];
#define chdir _chdir
#endif
-#ifdef NDEBUG
-#ifndef NVALGRIND
-#define NVALGRIND NDEBUG
-#endif
-#endif
-
-#if defined(__GNUC__) && defined(HAVE_VALGRIND)
-#include <valgrind.h>
-#else
-#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed)
-#define VALGRIND_FREELIKE_BLOCK(addr, rzB)
-#endif
-
static volatile ATOMIC_FLAG GDKstopped = ATOMIC_FLAG_INIT;
static void GDKunlockHome(void);
@@ -939,9 +926,6 @@ GDKmmap(const char *path, int mode, size
}
}
if (ret != NULL) {
- /* since mmap directly have content we say it's zero-ed
- * memory */
- VALGRIND_MALLOCLIKE_BLOCK(ret, len, 0, 1);
meminc(len);
}
return ret;
@@ -954,7 +938,6 @@ GDKmunmap(void *addr, size_t size)
int ret;
ret = MT_munmap(addr, size);
- VALGRIND_FREELIKE_BLOCK(addr, 0);
if (ret == 0)
memdec(size);
return ret == 0 ? GDK_SUCCEED : GDK_FAIL;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list