zig/std/special/builtin.zig
Andrew Kelley a32b5929cc add stack protector safety when linking libc
* introduce zigrt file. it contains only weak symbols so that
   multiple instances can be merged. it contains __zig_panic
   so that multiple .o files can call the same panic function.
 * remove `@setFnVisible` builtin and add @setGlobalLinkage builtin
   which is more powerful
 * add `@panic` builtin function.
 * fix collision of symbols with extern prototypes and internal
   function names
 * add stack protector safety when linking against libc. To add
   the safety mechanism without libc requires implementing
   Thread Local Storage. See #276
2017-03-26 21:07:07 -04:00

36 lines
876 B
Zig

// These functions are provided when not linking against libc because LLVM
// sometimes generates code that calls them.
// Note that these functions do not return `dest`, like the libc API.
// The semantics of these functions is dictated by the corresponding
// LLVM intrinsics, not by the libc API.
export fn memset(dest: ?&u8, c: u8, n: usize) {
@setDebugSafety(this, false);
if (n == 0)
return;
const d = ??dest;
var index: usize = 0;
while (index != n; index += 1)
d[index] = c;
}
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
@setDebugSafety(this, false);
if (n == 0)
return;
const d = ??dest;
const s = ??src;
var index: usize = 0;
while (index != n; index += 1)
d[index] = s[index];
}
export fn __stack_chk_fail() {
@panic("stack smashing detected");
}