2016-01-06 13:40:25 +00:00
|
|
|
// These functions are provided when not linking against libc because LLVM
|
|
|
|
// sometimes generates code that calls them.
|
|
|
|
|
2017-02-05 04:04:07 +00:00
|
|
|
// 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.
|
2017-05-01 23:16:48 +00:00
|
|
|
const builtin = @import("builtin");
|
2017-02-05 04:04:07 +00:00
|
|
|
|
|
|
|
export fn memset(dest: ?&u8, c: u8, n: usize) {
|
2016-09-28 06:33:32 +00:00
|
|
|
@setDebugSafety(this, false);
|
|
|
|
|
2016-07-27 03:40:11 +00:00
|
|
|
var index: usize = 0;
|
2017-05-03 22:12:07 +00:00
|
|
|
while (index != n) : (index += 1)
|
2017-05-02 23:20:23 +00:00
|
|
|
(??dest)[index] = c;
|
2016-01-06 13:40:25 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 04:04:07 +00:00
|
|
|
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
|
2016-09-28 06:33:32 +00:00
|
|
|
@setDebugSafety(this, false);
|
|
|
|
|
2016-07-27 03:40:11 +00:00
|
|
|
var index: usize = 0;
|
2017-05-03 22:12:07 +00:00
|
|
|
while (index != n) : (index += 1)
|
2017-05-02 23:20:23 +00:00
|
|
|
(??dest)[index] = (??src)[index];
|
2016-01-06 13:40:25 +00:00
|
|
|
}
|
2017-02-09 07:50:03 +00:00
|
|
|
|
2017-03-27 01:07:07 +00:00
|
|
|
export fn __stack_chk_fail() {
|
2017-05-02 21:34:21 +00:00
|
|
|
if (builtin.mode == builtin.Mode.ReleaseFast) {
|
2017-05-01 23:16:48 +00:00
|
|
|
@setGlobalLinkage(__stack_chk_fail, builtin.GlobalLinkage.Internal);
|
|
|
|
unreachable;
|
|
|
|
}
|
2017-03-27 01:07:07 +00:00
|
|
|
@panic("stack smashing detected");
|
2017-02-09 07:50:03 +00:00
|
|
|
}
|