Author: Armin Rigo <[email protected]>
Branch:
Changeset: r95753:45e0519a5fe6
Date: 2019-01-30 23:52 +0100
http://bitbucket.org/pypy/pypy/changeset/45e0519a5fe6/
Log: Tentative fix for cpyext with revdb
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -507,6 +507,7 @@
header = DEFAULT_HEADER
if func.__name__ in FUNCTIONS_BY_HEADER[header]:
raise ValueError("%s already registered" % func.__name__)
+ func._revdb_c_only_ = True # hack for revdb
api_function = COnlyApiFunction(argtypes, restype, func)
FUNCTIONS_BY_HEADER[header][func.__name__] = api_function
return api_function
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -67,7 +67,7 @@
"""Returns True if we have a "split GC address space", i.e. if
we are translating with an option that doesn't support taking raw
addresses inside GC objects and "hacking" at them. This is
- notably the case with --reversedb."""
+ notably the case with --revdb."""
return False
# for test purposes we allow objects to be pinned and use
diff --git a/rpython/translator/revdb/gencsupp.py
b/rpython/translator/revdb/gencsupp.py
--- a/rpython/translator/revdb/gencsupp.py
+++ b/rpython/translator/revdb/gencsupp.py
@@ -51,6 +51,10 @@
## return False
def prepare_function(funcgen):
+ if getattr(getattr(funcgen.graph, 'func', None), '_revdb_c_only_', False):
+ extra_enter_text = 'RPY_REVDB_C_ONLY_ENTER'
+ extra_return_text = 'RPY_REVDB_C_ONLY_LEAVE'
+ return extra_enter_text, extra_return_text
stack_bottom = False
for block in funcgen.graph.iterblocks():
for op in block.operations:
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
@@ -253,7 +253,10 @@
"(use REVDB=logfile)\n", (int)getpid());
}
- rpy_revdb.buf_p = rpy_rev_buffer + sizeof(int16_t);
+ if (rpy_rev_fileno >= 0)
+ rpy_revdb.buf_p = rpy_rev_buffer + sizeof(int16_t);
+ else
+ rpy_revdb.buf_p = NULL;
rpy_revdb.buf_limit = rpy_rev_buffer + sizeof(rpy_rev_buffer) - 32;
rpy_revdb.unique_id_seen = 1;
@@ -269,17 +272,23 @@
ssize_t full_size;
assert(rpy_revdb.lock);
+ if (rpy_revdb.buf_p == NULL)
+ return;
+ assert(rpy_rev_fileno >= 0);
+
/* write the current buffer content to the OS */
full_size = rpy_revdb.buf_p - rpy_rev_buffer;
rpy_revdb.buf_p = rpy_rev_buffer + sizeof(int16_t);
- if (rpy_rev_fileno >= 0)
- write_all(rpy_rev_buffer, full_size);
+ write_all(rpy_rev_buffer, full_size);
}
static ssize_t current_packet_size(void)
{
/* must be called with the lock held */
- return rpy_revdb.buf_p - (rpy_rev_buffer + sizeof(int16_t));
+ if (rpy_revdb.buf_p != NULL)
+ return rpy_revdb.buf_p - (rpy_rev_buffer + sizeof(int16_t));
+ else
+ return 0;
}
RPY_EXTERN
@@ -327,6 +336,11 @@
rpy_reverse_db_flush();
assert(current_packet_size() == 0);
+ if (rpy_rev_fileno < 0)
+ return;
+ /* should not be here from the middle of a @c_only function */
+ assert(rpy_revdb.buf_p != NULL);
+
*(int16_t *)p = async_code;
memcpy(rpy_revdb.buf_p, &content, sizeof(uint64_t));
rpy_revdb.buf_p += sizeof(uint64_t);
@@ -472,6 +486,9 @@
if (rpy_rev_fileno < 0)
return 1;
+ /* should not be here from the middle of a @c_only function */
+ assert(rpy_revdb.buf_p != NULL);
+
base_offset = lseek(rpy_rev_fileno, 0, SEEK_CUR);
if (base_offset < 0) {
perror("lseek");
@@ -488,6 +505,9 @@
if (rpy_rev_fileno < 0)
return;
+ /* should not be here from the middle of a @c_only function */
+ assert(rpy_revdb.buf_p != NULL);
+
base_offset = lseek(rpy_rev_fileno, 0, SEEK_CUR);
if (base_offset < 0) {
perror("lseek");
@@ -1033,9 +1053,9 @@
" echo 0 | sudo tee /proc/sys/kernel/randomize_va_space\n"
"\n"
"It has been reported that on Linux kernel 4.12.4-1-ARCH,\n"
- "ASLR cannot be disabled at all for libpypy-c.so. For now\n"
- "there is no good solution. Either you downgrade the\n"
- "kernel, or you translate with --no-shared (and you loose\n"
+ "ASLR cannot be disabled at all for libpypy-c.so. It works\n"
+ "again in kernel 4.19 (and maybe sooner). Either change\n"
+ "kernels, or translate with --no-shared (but then you loose\n"
"PyPy's cpyext ability).\n"
"\n", argv[0]);
exit(1);
diff --git a/rpython/translator/revdb/src-revdb/revdb_include.h
b/rpython/translator/revdb/src-revdb/revdb_include.h
--- a/rpython/translator/revdb/src-revdb/revdb_include.h
+++ b/rpython/translator/revdb/src-revdb/revdb_include.h
@@ -16,7 +16,8 @@
#endif
bool_t watch_enabled;
int lock;
- char *buf_p, *buf_limit, *buf_readend;
+ char *buf_p; /* NULL during recording if recording is actually disabled */
+ char *buf_limit, *buf_readend;
uint64_t stop_point_seen, stop_point_break;
uint64_t unique_id_seen, unique_id_break;
} rpy_revdb_t;
@@ -85,9 +86,13 @@
{ \
decl_e = variable; \
_RPY_REVDB_PRINT("[ wr ]", _e); \
- memcpy(rpy_revdb.buf_p, &_e, sizeof(_e)); \
- if ((rpy_revdb.buf_p += sizeof(_e)) > rpy_revdb.buf_limit) \
- rpy_reverse_db_flush(); \
+ char *_dst = rpy_revdb.buf_p; \
+ if (_dst) { \
+ memcpy(_dst, &_e, sizeof(_e)); \
+ if ((rpy_revdb.buf_p = _dst + sizeof(_e)) \
+ > rpy_revdb.buf_limit) \
+ rpy_reverse_db_flush(); \
+ } \
}
#define _RPY_REVDB_EMIT_REPLAY(decl_e, variable) \
@@ -179,6 +184,13 @@
rpy_reverse_db_bad_acquire_gil("release"); \
}
+#define RPY_REVDB_C_ONLY_ENTER \
+ char *saved_bufp = rpy_revdb.buf_p; \
+ rpy_revdb.buf_p = NULL;
+
+#define RPY_REVDB_C_ONLY_LEAVE \
+ rpy_revdb.buf_p = saved_bufp;
+
#define RPY_REVDB_CALLBACKLOC(locnum) \
rpy_reverse_db_callback_loc(locnum)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit