Author: fijal
Branch: vmprof-newstack
Changeset: r80572:0e7edf95c3c5
Date: 2015-11-07 13:18 +0000
http://bitbucket.org/pypy/pypy/changeset/0e7edf95c3c5/
Log: progress
diff --git a/rpython/memory/gctransform/shadowstack.py
b/rpython/memory/gctransform/shadowstack.py
--- a/rpython/memory/gctransform/shadowstack.py
+++ b/rpython/memory/gctransform/shadowstack.py
@@ -74,14 +74,12 @@
self.decr_stack = decr_stack
def walk_stack_root(callback, start, end):
- # shadowstack[0] contains the vmprof stack
gc = self.gc
addr = end
- addr -= sizeofaddr
while addr != start:
+ addr -= sizeofaddr
if gc.points_to_valid_gc_object(addr):
callback(gc, addr)
- addr -= sizeofaddr
self.rootstackhook = walk_stack_root
self.shadow_stack_pool = ShadowStackPool(gcdata)
@@ -284,8 +282,7 @@
def start_fresh_new_state(self):
self.gcdata.root_stack_base = self.unused_full_stack
- # shadowstack[0] contains the vmprof stack
- self.gcdata.root_stack_top = self.unused_full_stack + sizeofaddr
+ self.gcdata.root_stack_top = self.unused_full_stack
self.unused_full_stack = llmemory.NULL
def _cleanup(self, shadowstackref):
@@ -312,14 +309,12 @@
SHADOWSTACKREFPTR.TO.become(SHADOWSTACKREF)
def customtrace(gc, obj, callback, arg):
- # we intentionally don't read shadowstack[0]
obj = llmemory.cast_adr_to_ptr(obj, SHADOWSTACKREFPTR)
addr = obj.top
start = obj.base
- addr -= sizeofaddr
while addr != start:
+ addr -= sizeofaddr
gc._trace_callback(callback, arg, addr)
- addr -= sizeofaddr
gc = gctransformer.gcdata.gc
assert not hasattr(gc, 'custom_trace_dispatcher')
diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py
--- a/rpython/rlib/rvmprof/cintf.py
+++ b/rpython/rlib/rvmprof/cintf.py
@@ -103,28 +103,25 @@
argnames = ", ".join(["arg%d" % i for i in range(len(token))])
target = target.join('trampoline_%s_%s.vmprof.c' % (name, token))
target.write("""
-typedef struct vmprof_stack {
- struct vmprof_stack* next;
- long value;
-};
+#include "vmprof_stack.h"
%(type)s %(cont_name)s(%(llargs)s);
-%(type)s %(tramp_name)s(%(llargs)s, long unique_id, void** shadowstack_base)
+%(type)s %(tramp_name)s(%(llargs)s, long unique_id)
{
%(type)s result;
struct vmprof_stack node;
node.value = unique_id;
- node.next = (struct vmprof_stack*)shadowstack_base[0];
- shadowstack_base[0] = (void*)(&node);
+ node.next = vmprof_global_stack;
+ vmprof_global_stack = &node;
result = %(cont_name)s(%(argnames)s);
- shadowstack_base[0] = node.next;
+ vmprof_global_stack = node.next;
return result;
}
""" % locals())
return finish_ll_trampoline(tramp_name, tramp_name, target, token,
- restok, True)
+ restok)
def make_trampoline_function(name, func, token, restok):
from rpython.jit.backend import detect_cpu
@@ -191,14 +188,11 @@
%(size_decl)s
""" % locals())
return finish_ll_trampoline(orig_tramp_name, tramp_name, target, token,
- restok, False)
+ restok)
-def finish_ll_trampoline(orig_tramp_name, tramp_name, target, token, restok,
- accepts_shadowstack):
+def finish_ll_trampoline(orig_tramp_name, tramp_name, target, token, restok):
extra_args = ['long']
- if accepts_shadowstack:
- extra_args.append("void*")
header = 'RPY_EXTERN %s %s(%s);\n' % (
token2ctype(restok),
orig_tramp_name,
@@ -223,8 +217,6 @@
)
ARGS = [token2lltype(tok) for tok in token] + [lltype.Signed]
- if accepts_shadowstack:
- ARGS.append(llmemory.Address)
return rffi.llexternal(
orig_tramp_name, ARGS,
token2lltype(restok),
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -202,10 +202,9 @@
else: # this is the case of the stack
if we_are_translated() and not jit.we_are_jitted():
unique_id = get_code_fn(*args)._vmprof_unique_id
- shadowstack_0 =
llop.gc_adr_of_root_stack_base(llmemory.Address)
ll_args, token = lower(*args)
ll_trampoline = get_ll_trampoline(token, True)
- ll_result = ll_trampoline(*ll_args + (unique_id,
shadowstack_0))
+ ll_result = ll_trampoline(*ll_args + (unique_id,))
else:
return func(*args)
if result_class is not None:
diff --git a/rpython/rlib/rvmprof/src/vmprof_main.h
b/rpython/rlib/rvmprof/src/vmprof_main.h
--- a/rpython/rlib/rvmprof/src/vmprof_main.h
+++ b/rpython/rlib/rvmprof/src/vmprof_main.h
@@ -37,7 +37,7 @@
#include "vmprof_unwind.h"
#endif
#include "vmprof_mt.h"
-
+#include "vmprof_stack.h"
/************************************************************/
@@ -144,6 +144,8 @@
#define VERSION_BASE '\x00'
#define VERSION_THREAD_ID '\x01'
+vmprof_stack* vmprof_global_stack = NULL;
+
struct prof_stacktrace_s {
char padding[sizeof(long) - 1];
char marker;
@@ -211,7 +213,13 @@
static int get_stack_trace(void **result, int max_depth, ucontext_t *ucontext)
{
- return 0;
+ // read the first slot of shadowstack
+ struct vmprof_stack* stack = vmprof_global_stack;
+ if (!stack) {
+ return 0;
+ }
+ result[0] = (void*)stack->value;
+ return 1;
}
static int xxx_get_stack_trace(void** result, int max_depth, ucontext_t
*ucontext)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit