allow custom OS entrypoint
Also: * Expose `std.start.callMain`. * Other fixes added to fix issues found in development.master
parent
81f1f72197
commit
b37acc4d68
|
@ -424,6 +424,10 @@ pub const panic: PanicFn = if (@hasDecl(root, "panic")) root.panic else default_
|
||||||
/// therefore must be kept in sync with the compiler implementation.
|
/// therefore must be kept in sync with the compiler implementation.
|
||||||
pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn {
|
pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn {
|
||||||
@setCold(true);
|
@setCold(true);
|
||||||
|
if (@hasDecl(root, "os") and @hasDecl(root.os, "panic")) {
|
||||||
|
root.os.panic(msg, error_return_trace);
|
||||||
|
unreachable;
|
||||||
|
}
|
||||||
switch (os) {
|
switch (os) {
|
||||||
.freestanding => {
|
.freestanding => {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -187,19 +187,23 @@ pub fn abort() noreturn {
|
||||||
}
|
}
|
||||||
windows.kernel32.ExitProcess(3);
|
windows.kernel32.ExitProcess(3);
|
||||||
}
|
}
|
||||||
if (builtin.link_libc) {
|
if (!builtin.link_libc and builtin.os == .linux) {
|
||||||
system.abort();
|
raise(SIGABRT) catch {};
|
||||||
|
|
||||||
|
// TODO the rest of the implementation of abort() from musl libc here
|
||||||
|
|
||||||
|
raise(SIGKILL) catch {};
|
||||||
|
exit(127);
|
||||||
}
|
}
|
||||||
if (builtin.os == .uefi) {
|
if (builtin.os == .uefi) {
|
||||||
exit(0); // TODO choose appropriate exit code
|
exit(0); // TODO choose appropriate exit code
|
||||||
}
|
}
|
||||||
|
if (builtin.os == .wasi) {
|
||||||
|
@breakpoint();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
raise(SIGABRT) catch {};
|
system.abort();
|
||||||
|
|
||||||
// TODO the rest of the implementation of abort() from musl libc here
|
|
||||||
|
|
||||||
raise(SIGKILL) catch {};
|
|
||||||
exit(127);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const RaiseError = UnexpectedError;
|
pub const RaiseError = UnexpectedError;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
pub const start = @import("special/start.zig");
|
|
@ -83,7 +83,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
|
||||||
@setCold(true);
|
@setCold(true);
|
||||||
std.debug.panic("{}", msg);
|
std.debug.panic("{}", msg);
|
||||||
}
|
}
|
||||||
if (builtin.os != .freestanding) {
|
if (builtin.os != .freestanding and builtin.os != .other) {
|
||||||
std.os.abort();
|
std.os.abort();
|
||||||
}
|
}
|
||||||
while (true) {}
|
while (true) {}
|
||||||
|
|
|
@ -17,6 +17,7 @@ const is_mips = switch (builtin.arch) {
|
||||||
.mips, .mipsel, .mips64, .mips64el => true,
|
.mips, .mipsel, .mips64, .mips64el => true,
|
||||||
else => false,
|
else => false,
|
||||||
};
|
};
|
||||||
|
const start_sym_name = if (is_mips) "__start" else "_start";
|
||||||
|
|
||||||
comptime {
|
comptime {
|
||||||
if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
|
if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
|
||||||
|
@ -34,14 +35,10 @@ comptime {
|
||||||
}
|
}
|
||||||
} else if (builtin.os == .uefi) {
|
} else if (builtin.os == .uefi) {
|
||||||
if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
|
if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
|
||||||
} else if (builtin.os != .freestanding) {
|
} else if (is_wasm and builtin.os == .freestanding) {
|
||||||
if (is_mips) {
|
if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, wasm_freestanding_start, .Strong);
|
||||||
if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong);
|
} else if (builtin.os != .other and builtin.os != .freestanding) {
|
||||||
} else {
|
if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, _start, .Strong);
|
||||||
if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong);
|
|
||||||
}
|
|
||||||
} else if (is_wasm) {
|
|
||||||
if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +244,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 {
|
||||||
|
|
||||||
// This is not marked inline because it is called with @asyncCall when
|
// This is not marked inline because it is called with @asyncCall when
|
||||||
// there is an event loop.
|
// there is an event loop.
|
||||||
fn callMain() u8 {
|
pub fn callMain() u8 {
|
||||||
switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
|
switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
|
||||||
.NoReturn => {
|
.NoReturn => {
|
||||||
root.main();
|
root.main();
|
||||||
|
|
|
@ -65,6 +65,7 @@ pub const time = @import("time.zig");
|
||||||
pub const unicode = @import("unicode.zig");
|
pub const unicode = @import("unicode.zig");
|
||||||
pub const valgrind = @import("valgrind.zig");
|
pub const valgrind = @import("valgrind.zig");
|
||||||
pub const zig = @import("zig.zig");
|
pub const zig = @import("zig.zig");
|
||||||
|
pub const special = @import("special.zig");
|
||||||
|
|
||||||
test "" {
|
test "" {
|
||||||
meta.refAllDecls(@This());
|
meta.refAllDecls(@This());
|
||||||
|
|
Loading…
Reference in New Issue