about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/backtrace.rs83
-rw-r--r--src/libstd/rt/mod.rs2
-rw-r--r--src/libstd/rt/util.rs16
3 files changed, 97 insertions, 4 deletions
diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs
index c3bf7a6d12a..85699cdfebc 100644
--- a/src/libstd/rt/backtrace.rs
+++ b/src/libstd/rt/backtrace.rs
@@ -665,6 +665,89 @@ mod imp {
         }
     }
 
+    #[cfg(target_arch = "x86_64")]
+    mod arch {
+        use libc::{c_longlong, c_ulonglong};
+        use libc::types::os::arch::extra::{WORD, DWORD, DWORDLONG};
+
+        pub struct CONTEXT {
+            P1Home: DWORDLONG,
+            P2Home: DWORDLONG,
+            P3Home: DWORDLONG,
+            P4Home: DWORDLONG,
+            P5Home: DWORDLONG,
+            P6Home: DWORDLONG,
+
+            ContextFlags: DWORD,
+            MxCsr: DWORD,
+
+            SegCs: WORD,
+            SegDs: WORD,
+            SegEs: WORD,
+            SegFs: WORD,
+            SegGs: WORD,
+            SegSs: WORD,
+            EFlags: DWORD,
+
+            Dr0: DWORDLONG,
+            Dr1: DWORDLONG,
+            Dr2: DWORDLONG,
+            Dr3: DWORDLONG,
+            Dr6: DWORDLONG,
+            Dr7: DWORDLONG,
+
+            Rax: DWORDLONG,
+            Rcx: DWORDLONG,
+            Rdx: DWORDLONG,
+            Rbx: DWORDLONG,
+            Rsp: DWORDLONG,
+            Rbp: DWORDLONG,
+            Rsi: DWORDLONG,
+            Rdi: DWORDLONG,
+            R8:  DWORDLONG,
+            R9:  DWORDLONG,
+            R10: DWORDLONG,
+            R11: DWORDLONG,
+            R12: DWORDLONG,
+            R13: DWORDLONG,
+            R14: DWORDLONG,
+            R15: DWORDLONG,
+
+            Rip: DWORDLONG,
+
+            FltSave: FLOATING_SAVE_AREA,
+
+            VectorRegister: [M128A, .. 26],
+            VectorControl: DWORDLONG,
+
+            DebugControl: DWORDLONG,
+            LastBranchToRip: DWORDLONG,
+            LastBranchFromRip: DWORDLONG,
+            LastExceptionToRip: DWORDLONG,
+            LastExceptionFromRip: DWORDLONG,
+        }
+
+        pub struct M128A {
+            Low:  c_ulonglong,
+            High: c_longlong
+        }
+
+        pub struct FLOATING_SAVE_AREA {
+            _Dummy: [u8, ..512] // FIXME: Fill this out
+        }
+
+        pub fn init_frame(frame: &mut super::STACKFRAME64,
+                          ctx: &CONTEXT) -> DWORD {
+            frame.AddrPC.Offset = ctx.Rip as u64;
+            frame.AddrPC.Mode = super::AddrModeFlat;
+            frame.AddrStack.Offset = ctx.Rsp as u64;
+            frame.AddrStack.Mode = super::AddrModeFlat;
+            frame.AddrFrame.Offset = ctx.Rbp as u64;
+            frame.AddrFrame.Mode = super::AddrModeFlat;
+            super::IMAGE_FILE_MACHINE_AMD64
+        }
+    }
+
     struct Cleanup {
         handle: libc::HANDLE,
         SymCleanup: SymCleanupFn,
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs
index f4a4fd9ab2e..a61443d335a 100644
--- a/src/libstd/rt/mod.rs
+++ b/src/libstd/rt/mod.rs
@@ -71,6 +71,8 @@ pub use self::util::default_sched_threads;
 // Export unwinding facilities used by the failure macros
 pub use self::unwind::{begin_unwind, begin_unwind_raw, begin_unwind_fmt};
 
+pub use self::util::{Stdio, Stdout, Stderr};
+
 // FIXME: these probably shouldn't be public...
 #[doc(hidden)]
 pub mod shouldnt_be_public {
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index 4c208a64ddf..84284ca1faf 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -71,14 +71,22 @@ pub fn default_sched_threads() -> uint {
     }
 }
 
-pub struct Stderr;
+pub struct Stdio(libc::c_int);
 
-impl io::Writer for Stderr {
+pub static Stdout: Stdio = Stdio(libc::STDOUT_FILENO);
+pub static Stderr: Stdio = Stdio(libc::STDERR_FILENO);
+
+impl io::Writer for Stdio {
     fn write(&mut self, data: &[u8]) -> IoResult<()> {
+        #[cfg(unix)]
+        type WriteLen = libc::size_t;
+        #[cfg(windows)]
+        type WriteLen = libc::c_uint;
         unsafe {
-            libc::write(libc::STDERR_FILENO,
+            let Stdio(fd) = *self;
+            libc::write(fd,
                         data.as_ptr() as *libc::c_void,
-                        data.len() as libc::size_t);
+                        data.len() as WriteLen);
         }
         Ok(()) // yes, we're lying
     }