aboutsummaryrefslogtreecommitdiff
path: root/std/os
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-25 04:50:51 -0400
committerGitHub <noreply@github.com>2018-08-25 04:50:51 -0400
commit4003cd4747019d79ff50aaa22415d2d3dfc15cf4 (patch)
tree1f77690a5fb7ccbef75bcab9c8c1e008ef3c5068 /std/os
parentbf1f91595d4d3b5911632c671ef16e44d70dc9a6 (diff)
parent815950996dcc92ac6ac285f2005dbac51b9cb6f8 (diff)
downloadzig-4003cd4747019d79ff50aaa22415d2d3dfc15cf4.tar.gz
zig-4003cd4747019d79ff50aaa22415d2d3dfc15cf4.zip
Merge pull request #1406 from ziglang/macos-stack-traces
MacOS stack traces closes #1365
Diffstat (limited to 'std/os')
-rw-r--r--std/os/index.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/std/os/index.zig b/std/os/index.zig
index a0b6e6bf45..29d887e214 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -635,6 +635,35 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
pub var linux_aux_raw = []usize{0} ** 38;
pub var posix_environ_raw: [][*]u8 = undefined;
+/// See std.elf for the constants.
+pub fn linuxGetAuxVal(index: usize) usize {
+ if (builtin.link_libc) {
+ return usize(std.c.getauxval(index));
+ } else {
+ return linux_aux_raw[index];
+ }
+}
+
+pub fn getBaseAddress() usize {
+ switch (builtin.os) {
+ builtin.Os.linux => {
+ const base = linuxGetAuxVal(std.elf.AT_BASE);
+ if (base != 0) {
+ return base;
+ }
+ const phdr = linuxGetAuxVal(std.elf.AT_PHDR);
+ const ElfHeader = switch (@sizeOf(usize)) {
+ 4 => std.elf.Elf32_Ehdr,
+ 8 => std.elf.Elf64_Ehdr,
+ else => @compileError("Unsupported architecture"),
+ };
+ return phdr - @sizeOf(ElfHeader);
+ },
+ builtin.Os.macosx => return @ptrToInt(&std.c._mh_execute_header),
+ else => @compileError("Unsupported OS"),
+ }
+}
+
/// Caller must free result when done.
/// TODO make this go through libc when we have it
pub fn getEnvMap(allocator: *Allocator) !BufMap {