diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-18 01:38:58 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-18 12:22:46 -0700 |
| commit | 2b8dcc76eba92ad44bd88756218de8d2bd8a1c10 (patch) | |
| tree | f4528dccdeed3278ef60a96f7340d184a78743e4 /lib/std/start.zig | |
| parent | d9368d70125abd70be380f7af38b75c152f307aa (diff) | |
| download | zig-2b8dcc76eba92ad44bd88756218de8d2bd8a1c10.tar.gz zig-2b8dcc76eba92ad44bd88756218de8d2bd8a1c10.zip | |
take advantage of std.os.linux.getauxval
Diffstat (limited to 'lib/std/start.zig')
| -rw-r--r-- | lib/std/start.zig | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig index 25c578c0ef..8d5eda6105 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -219,17 +219,7 @@ fn posixCallMainAndExit() noreturn { if (!@hasDecl(root, "use_AT_RANDOM_auxval") or root.use_AT_RANDOM_auxval) { // Initialize the per-thread CSPRNG since Linux gave us the handy-dandy // AT_RANDOM. This depends on the TLS initialization above. - var i: usize = 0; - while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { - switch (auxv[i].a_type) { - std.elf.AT_RANDOM => { - // "The address of sixteen bytes containing a random value." - initCryptoSeedFromAuxVal(auxv[i].a_un.a_val); - break; - }, - else => continue, - } - } + initCryptoSeedFromAuxVal(std.os.linux.getauxval(std.elf.AT_RANDOM)); } // TODO This is disabled because what should we do when linking libc and this code @@ -284,6 +274,7 @@ fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.C) fn initCryptoSeedFromAuxVal(addr: usize) void { if (addr == 0) return; + // "The address of sixteen bytes containing a random value." const ptr = @intToPtr(*[16]u8, addr); tlcsprng.init(ptr.*); // Clear AT_RANDOM after we use it, otherwise our secure |
