| ... | ... | @@ -623,22 +623,33 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [:null]?[*:0]u8) |
| 623 | 623 | return callMain(argv[0..argc], envp); |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | | fn main(c_argc: c_int, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.c) c_int { |
| 626 | fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.c) c_int { |
| 627 | 627 | var env_count: usize = 0; |
| 628 | 628 | while (c_envp[env_count] != null) : (env_count += 1) {} |
| 629 | 629 | const envp = c_envp[0..env_count :null]; |
| 630 | 630 | |
| 631 | | if (builtin.os.tag == .linux) { |
| 632 | | const at_phdr = std.c.getauxval(elf.AT_PHDR); |
| 633 | | const at_phnum = std.c.getauxval(elf.AT_PHNUM); |
| 634 | | const phdrs = (@as([*]elf.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum]; |
| 635 | | expandStackSize(phdrs); |
| 631 | switch (builtin.os.tag) { |
| 632 | .linux => { |
| 633 | const at_phdr = std.c.getauxval(elf.AT_PHDR); |
| 634 | const at_phnum = std.c.getauxval(elf.AT_PHNUM); |
| 635 | const phdrs = (@as([*]elf.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum]; |
| 636 | expandStackSize(phdrs); |
| 637 | }, |
| 638 | .windows => { |
| 639 | // On Windows, we ignore libc environment and argv and get those |
| 640 | // values in their intended encoding from the PEB instead. |
| 641 | std.debug.maybeEnableSegfaultHandler(); |
| 642 | const cmd_line = std.os.windows.peb().ProcessParameters.CommandLine; |
| 643 | const cmd_line_w = cmd_line.Buffer.?[0..@divExact(cmd_line.Length, 2)]; |
| 644 | return callMain(cmd_line_w, {}); |
| 645 | }, |
| 646 | else => {}, |
| 636 | 647 | } |
| 637 | 648 | |
| 638 | | return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), envp); |
| 649 | return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), @ptrCast(envp)); |
| 639 | 650 | } |
| 640 | 651 | |
| 641 | | fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]u8) callconv(.c) c_int { |
| 652 | fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { |
| 642 | 653 | const argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)]; |
| 643 | 654 | if (@sizeOf(std.Io.Threaded.Argv0) != 0) { |
| 644 | 655 | if (std.Options.debug_threaded_io) |t| t.argv0.value = argv[0]; |