Skip to content

Commit 0b1963f

Browse files
committed
---
yaml --- r: 5485 b: refs/heads/master c: aabff48 h: refs/heads/master i: 5483: 6bcc403 v: v3
1 parent 9d79925 commit 0b1963f

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: d10d23f0ad4763642619d2d3e42f8150f7d91af3
2+
refs/heads/master: aabff480c92d7c72f8a8ff6652d328e6624585d5

trunk/src/rt/rust_abi.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
// ABI-specific routines.
2+
3+
#include <vector>
14
#include <cstdlib>
25
#include <stdint.h>
36
#include "rust_abi.h"
47

8+
#define END_OF_STACK_RA (void (*)())0xdeadbeef
9+
510
weak_symbol<uint32_t> abi_version("rust_abi_version");
611

712
uint32_t get_abi_version() {
813
return (*abi_version == NULL) ? 0 : **abi_version;
914
}
1015

16+
namespace stack_walk {
17+
18+
std::vector<frame>
19+
backtrace() {
20+
std::vector<frame> frames;
21+
22+
// Ideally we would use the current value of EIP here, but there's no
23+
// portable way to get that and there are never any GC roots in our C++
24+
// frames anyhow.
25+
frame f(__builtin_frame_address(0), (void (*)())NULL);
26+
27+
while (f.ra != END_OF_STACK_RA) {
28+
frames.push_back(f);
29+
f.next();
30+
}
31+
return frames;
32+
}
33+
34+
} // end namespace stack_walk
35+

trunk/src/rt/rust_abi.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// ABI-specific routines.
2+
13
#ifndef RUST_ABI_H
24
#define RUST_ABI_H
35

46
#include <cstdlib>
7+
#include <vector>
58

69
#ifdef __WIN32__
710
#include <windows.h>
@@ -36,6 +39,25 @@ class weak_symbol {
3639
T *&operator*() { fill(); return data; }
3740
};
3841

42+
namespace stack_walk {
43+
44+
struct frame {
45+
uint8_t *bp; // The frame pointer.
46+
void (*ra)(); // The return address.
47+
48+
frame(void *in_bp, void (*in_ra)()) : bp((uint8_t *)in_bp), ra(in_ra) {}
49+
50+
inline void next() {
51+
ra = *(void (**)())(bp + sizeof(void *));
52+
bp = *(uint8_t **)bp;
53+
}
54+
};
55+
56+
std::vector<frame> backtrace();
57+
58+
} // end namespace stack_walk
59+
60+
3961
uint32_t get_abi_version();
4062

4163
#endif

trunk/src/rt/rust_gc.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,12 @@
1818
#include <dlfcn.h>
1919
#endif
2020

21-
#define END_OF_STACK_RA (void (*)())0xdeadbeef
21+
using namespace stack_walk;
2222

2323
namespace gc {
2424

2525
weak_symbol<const uintptr_t> safe_point_data("rust_gc_safe_points");
2626

27-
struct frame {
28-
uint8_t *bp; // The frame pointer.
29-
void (*ra)(); // The return address.
30-
31-
frame(void *in_bp, void (*in_ra)()) : bp((uint8_t *)in_bp), ra(in_ra) {}
32-
33-
inline void next() {
34-
ra = *(void (**)())(bp + sizeof(void *));
35-
bp = *(uint8_t **)bp;
36-
}
37-
};
38-
3927
struct root_info {
4028
intptr_t frame_offset;
4129
uintptr_t dynamic; // 0 = static, 1 = dynamic
@@ -98,9 +86,7 @@ class gc {
9886

9987
public:
10088
gc(rust_task *in_task) : task(in_task) {}
101-
10289
void run();
103-
std::vector<frame> backtrace();
10490
};
10591

10692
const safe_point *
@@ -135,22 +121,6 @@ gc::sweep() {
135121
// TODO
136122
}
137123

138-
std::vector<frame>
139-
gc::backtrace() {
140-
std::vector<frame> frames;
141-
142-
// Ideally we would use the current value of EIP here, but there's no
143-
// portable way to get that and there are never any GC roots in our C++
144-
// frames anyhow.
145-
frame f(__builtin_frame_address(0), (void (*)())NULL);
146-
147-
while (f.ra != END_OF_STACK_RA) {
148-
frames.push_back(f);
149-
f.next();
150-
}
151-
return frames;
152-
}
153-
154124
void
155125
gc::run() {
156126
safe_point_map map;

0 commit comments

Comments
 (0)