This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC][PATCH 07/15] Fix mmap usage of MAP_FIXED for multiple pages.
- From: henrik dot wallin at windriver dot com
- To: gdb-patches at sourceware dot org
- Date: Wed, 14 Oct 2015 13:14:25 +0200
- Subject: [RFC][PATCH 07/15] Fix mmap usage of MAP_FIXED for multiple pages.
- Authentication-results: sourceware.org; auth=none
- References: <cover dot 1444820235 dot git dot henrik dot wallin at windriver dot com>
- References: <cover dot 1444820235 dot git dot henrik dot wallin at windriver dot com>
From: Henrik Wallin <henrik.wallin@windriver.com>
mmap using MAP_FIXED will overwrite mapped pages if multiple pages
are requested.
E.g. On ARM it will result in overwriting the main code pages.
Fix by not using MAP_FIXED and use mmunmap in case we
don't get the start address we asked for.
gdb/gdbserver/ChangeLog:
* tracepoint.c : Include stdint.h and sys/mman.h.
(initialize_tracepoint): Fix problem with
MAP_FIXED usage in mmap.
Signed-off-by: Henrik Wallin <henrik.wallin@windriver.com>
---
gdb/gdbserver/tracepoint.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index d2ad197e58ab..35a125c951d5 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -27,6 +27,9 @@
#include <unistd.h>
#include "gdb_sys_time.h"
#include <inttypes.h>
+#include <stdint.h>
+#include <sys/mman.h>
+
#include "ax.h"
#include "tdesc.h"
@@ -7392,10 +7395,12 @@ initialize_tracepoint (void)
= (char *) mmap ((void *) addr,
pagesize * SCRATCH_BUFFER_NPAGES,
PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+ MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
- if (gdb_jump_pad_buffer != MAP_FAILED)
+ if (gdb_jump_pad_buffer == (void *)addr)
break;
+ if (gdb_jump_pad_buffer != MAP_FAILED)
+ munmap(gdb_jump_pad_buffer, pagesize * SCRATCH_BUFFER_NPAGES);
}
if (addr == 0)
--
2.1.4