Skip to content

Commit b1b05ab

Browse files
committed
WIP
1 parent a7a6d62 commit b1b05ab

File tree

7 files changed

+74
-22
lines changed

7 files changed

+74
-22
lines changed

unwind/Cargo.toml

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
[package]
2-
name = "unwind"
2+
name = "runwind"
33
version = "0.1.0"
44
authors = ["main() <[email protected]>"]
55

66
[dependencies]
7-
gimli = { git = 'https://github.com/main--/gimli.git', branch = 'unwind-patches' }
8-
libc = "0.2"
9-
fallible-iterator = "0.1"
10-
log = "0.3"
7+
gimli = { path = '../../gimli', default-features = false }
8+
libc = { git = "https://github.com/megatonhammer/libc", default-features = false }
9+
fallible-iterator = { version = "0.1", default-features = false }
10+
log = { version = "0.3", default-features = false }
1111

12-
[build-dependencies]
13-
gcc = "0.3.52"
12+
#[build-dependencies]
13+
#gcc = "0.3.52"
1414

15-
[dev-dependencies]
16-
backtrace = "0.3"
17-
env_logger = "0.4"
15+
#[dev-dependencies]
16+
#backtrace = "0.3"
17+
#env_logger = "0.4"
1818

1919
[features]
20-
nightly = []
20+
default = ["std"]
21+
std = ["gimli/std", "fallible-iterator/std", "libc/use_std"]
22+
nightly = ["gimli/alloc", "fallible-iterator/alloc"]

unwind/Cargo.toml.orig

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unwind/build.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
extern crate gcc;
1+
//extern crate gcc;
2+
23
use std::env;
34

45
fn main() {
56
match env::var("CARGO_FEATURE_NIGHTLY") {
6-
Err(env::VarError::NotPresent) => (),
7+
Err(env::VarError::NotPresent) => panic!("Meh"),
78
_ => return
89
}
910

10-
gcc::Build::new()
11-
.file(format!("src/glue/{}_helper.S", env::var("CARGO_CFG_TARGET_ARCH").expect("Didn't run with cargo")))
12-
.include("src/glue")
13-
.compile("unwind_helper");
11+
//gcc::Build::new()
12+
// .file(format!("src/glue/{}_helper.S", env::var("CARGO_CFG_TARGET_ARCH").expect("Didn't run with cargo")))
13+
// .include("src/glue")
14+
// .compile("unwind_helper");
1415
}

unwind/src/find_cfi/baremetal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use range::AddrRange;
22
use super::EhRef;
33

4+
use alloc::Vec;
5+
46
extern "C" {
57
static __text_start: usize;
68
static __text_end: usize;

unwind/src/find_cfi/ld.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(not(feature = "std"))]
2+
compiler_error!("LD backend requires std");
3+
14
use libc::{c_void, c_int, c_char};
25
use std::ffi::CStr;
36
use std::{slice, mem};

unwind/src/lib.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#![cfg_attr(feature = "nightly", feature(global_asm))]
1+
#![no_std]
2+
#![cfg_attr(feature = "nightly", feature(global_asm, alloc))]
3+
4+
#![cfg(all(not(feature = "std"), not(feature = "nightly")))]
5+
compiler_error!("One of std or nightly feature needs to be enabled");
26

37
extern crate gimli;
48
extern crate libc;
@@ -15,7 +19,18 @@ pub mod libunwind_shim;
1519
pub mod glue;
1620
use registers::{Registers, DwarfRegister};
1721
use find_cfi::EhRef;
18-
22+
//#[cfg(feature = "std")]
23+
//extern crate std;
24+
#[cfg(not(feature = "std"))]
25+
use core as std;
26+
27+
//#[cfg(feature = "std")]
28+
//mod alloc {
29+
// pub use std::*;
30+
// pub use std::prelude::v1::*;
31+
//}
32+
#[cfg(not(feature = "std"))]
33+
extern crate alloc;
1934

2035
pub struct StackFrames<'a> {
2136
unwinder: &'a mut DwarfUnwinder,
@@ -57,7 +72,7 @@ impl Default for DwarfUnwinder {
5772

5873
let eh_frame_hdr: &'static [u8] = std::slice::from_raw_parts(er.cfi.start as *const u8, er.cfi.len() as usize);
5974

60-
let eh_frame_hdr = EhFrameHdr::new(eh_frame_hdr, NativeEndian).parse(&bases, 8).unwrap();
75+
let eh_frame_hdr = EhFrameHdr::new(eh_frame_hdr, NativeEndian).parse(&bases, std::mem::size_of::<*mut ()>() as u8).unwrap();
6176

6277
let cfi_addr = deref_ptr(eh_frame_hdr.eh_frame_ptr());
6378
let cfi_sz = 0x10000000; // FIXME HACK
@@ -95,7 +110,6 @@ impl Unwinder for DwarfUnwinder {
95110
}
96111
}
97112

98-
99113
struct UnwindInfo<R: Reader> {
100114
row: UnwindTableRow<R>,
101115
personality: Option<Pointer>,
@@ -129,7 +143,7 @@ impl ObjectRecord {
129143

130144

131145
if let Some(fde) = target_fde {
132-
trace!("fde {:x} - {:x}", fde.initial_address(), fde.len());
146+
trace!("fde {:x} - {:x}, {:x}", fde.initial_address(), fde.len(), address);
133147
if !fde.contains(address) {
134148
return Err(gimli::Error::NoUnwindInfoForAddress);
135149
}

unwind/src/libunwind_shim.rs

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ unsafe fn unwind_tracer(mut frames: &mut ::StackFrames, exception: *mut _Unwind_
118118
if let Some(contptr) = (*exception).private_contptr {
119119
loop {
120120
if let Some(frame) = frames.next().unwrap() {
121+
trace!("SP = {:x?}", frames.registers()[DwarfRegister::SP]);
121122
if frames.registers()[DwarfRegister::SP].unwrap() == contptr {
122123
break;
123124
}
@@ -139,6 +140,7 @@ unsafe fn unwind_tracer(mut frames: &mut ::StackFrames, exception: *mut _Unwind_
139140
registers: frames.registers(),
140141
};
141142

143+
trace!("contptr = {:x?}", frames.registers()[DwarfRegister::SP]);
142144
(*exception).private_contptr = frames.registers()[DwarfRegister::SP];
143145

144146
// ABI specifies that phase 1 is optional, so we just run phase 2 (CLEANUP_PHASE)

0 commit comments

Comments
 (0)