Author: Armin Rigo <[email protected]>
Branch: reverse-debugger
Changeset: r85613:ff376ccacb36
Date: 2016-07-08 18:12 +0200
http://bitbucket.org/pypy/pypy/changeset/ff376ccacb36/
Log: Use personality() with ADDR_NO_RANDOMIZE, a linux-only way to ask
for fixed addresses. Thanks mjacob.
diff --git a/rpython/translator/revdb/src-revdb/revdb.c
b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -13,6 +13,13 @@
#include <signal.h>
#include <search.h>
+#ifdef __linux__
+# define HAVE_PERSONALITY
+#endif
+#ifdef HAVE_PERSONALITY
+# include <sys/personality.h>
+#endif
+
#include "structdef.h"
#include "forwarddecl.h"
#include "preimpl.h"
@@ -54,6 +61,42 @@
static void setup_replay_mode(int *argc_p, char **argv_p[]);
static void check_at_end(uint64_t stop_points);
+static void ensure_fixed_address_space(char *argv[])
+{
+#ifdef HAVE_PERSONALITY
+ int pers = personality(0xffffffff);
+ if (pers == -1) {
+ perror("personality");
+ exit(1);
+ }
+ if (!(pers & ADDR_NO_RANDOMIZE)) {
+ pers |= ADDR_NO_RANDOMIZE;
+ if (personality(pers) == -1) {
+ perror("personality");
+ exit(1);
+ }
+ pers = personality(0xffffffff);
+ if (pers == -1 || !(pers & ADDR_NO_RANDOMIZE)) {
+ fprintf(stderr, "cannot set ADDR_NO_RANDOMIZE\n");
+ exit(1);
+ }
+ /* After setting this personality(), we need to restart the
+ current process. It will then reload the libpypy-c.so at a
+ non-randomized address.
+
+ Potentially buggy to use argv[0] here, but good enough I
+ suppose. For this reason ensure_fixed_address_space() is
+ not called when running manually without any PYPYRDB
+ environment variable set.
+ */
+ execv(argv[0], argv);
+
+ perror("execv");
+ exit(1);
+ }
+#endif
+}
+
RPY_EXTERN
void rpy_reverse_db_setup(int *argc_p, char **argv_p[])
{
@@ -152,6 +195,8 @@
assert(RPY_RDB_REPLAY == 0);
if (filename && *filename) {
+ ensure_fixed_address_space(argv);
+
putenv("PYPYRDB=");
rpy_rev_fileno = open(filename, O_RDWR | O_CLOEXEC |
O_CREAT | O_NOCTTY | O_TRUNC, 0600);
@@ -651,6 +696,8 @@
argv[0]);
exit(2);
}
+ ensure_fixed_address_space(*argv_p);
+
rpy_rev_filename = argv[2];
reopen_revdb_file(rpy_rev_filename);
rpy_rev_sockfd = atoi(argv[3]);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit