]> git.proxmox.com Git - rustc.git/blob - library/backtrace/tests/sgx-image-base.rs
New upstream version 1.75.0+dfsg1
[rustc.git] / library / backtrace / tests / sgx-image-base.rs
1 #![cfg(all(target_env = "sgx", target_vendor = "fortanix"))]
2 #![feature(sgx_platform)]
3
4 #[cfg(feature = "std")]
5 #[test]
6 fn sgx_image_base_with_std() {
7 use backtrace::trace;
8
9 let image_base = std::os::fortanix_sgx::mem::image_base();
10
11 let mut frame_ips = Vec::new();
12 trace(|frame| {
13 frame_ips.push(frame.ip());
14 true
15 });
16
17 assert!(frame_ips.len() > 0);
18 for ip in frame_ips {
19 let ip: u64 = ip as _;
20 assert!(ip < image_base);
21 }
22 }
23
24 #[cfg(not(feature = "std"))]
25 #[test]
26 fn sgx_image_base_no_std() {
27 use backtrace::trace_unsynchronized;
28
29 fn guess_image_base() -> u64 {
30 let mut top_frame_ip = None;
31 unsafe {
32 trace_unsynchronized(|frame| {
33 top_frame_ip = Some(frame.ip());
34 false
35 });
36 }
37 top_frame_ip.unwrap() as u64 & 0xFFFFFF000000
38 }
39
40 let image_base = guess_image_base();
41 backtrace::set_image_base(image_base as _);
42
43 let mut frame_ips = Vec::new();
44 unsafe {
45 trace_unsynchronized(|frame| {
46 frame_ips.push(frame.ip());
47 true
48 });
49 }
50
51 assert!(frame_ips.len() > 0);
52 for ip in frame_ips {
53 let ip: u64 = ip as _;
54 assert!(ip < image_base);
55 }
56 }