2016-01-06 05:40:25 -08:00
|
|
|
// These functions are provided when not linking against libc because LLVM
|
|
|
|
// sometimes generates code that calls them.
|
|
|
|
|
2017-02-04 20:04:07 -08: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.
|
|
|
|
|
|
|
|
export fn memset(dest: ?&u8, c: u8, n: usize) {
|
2016-09-27 23:33:32 -07:00
|
|
|
@setDebugSafety(this, false);
|
|
|
|
|
2016-11-18 20:52:42 -08:00
|
|
|
if (n == 0)
|
2017-02-04 20:04:07 -08:00
|
|
|
return;
|
2016-11-18 20:52:42 -08:00
|
|
|
|
|
|
|
const d = ??dest;
|
2016-07-26 20:40:11 -07:00
|
|
|
var index: usize = 0;
|
2016-11-18 19:24:41 -08:00
|
|
|
while (index != n; index += 1)
|
2016-11-18 20:52:42 -08:00
|
|
|
d[index] = c;
|
2016-01-06 05:40:25 -08:00
|
|
|
}
|
|
|
|
|
2017-02-04 20:04:07 -08:00
|
|
|
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
|
2016-09-27 23:33:32 -07:00
|
|
|
@setDebugSafety(this, false);
|
|
|
|
|
2016-11-18 20:52:42 -08:00
|
|
|
if (n == 0)
|
2017-02-04 20:04:07 -08:00
|
|
|
return;
|
2016-11-18 20:52:42 -08:00
|
|
|
|
|
|
|
const d = ??dest;
|
|
|
|
const s = ??src;
|
2016-07-26 20:40:11 -07:00
|
|
|
var index: usize = 0;
|
2016-11-18 19:24:41 -08:00
|
|
|
while (index != n; index += 1)
|
2016-11-18 20:52:42 -08:00
|
|
|
d[index] = s[index];
|
2016-01-06 05:40:25 -08:00
|
|
|
}
|
2017-02-08 23:50:03 -08:00
|
|
|
|
2017-03-26 18:07:07 -07:00
|
|
|
export fn __stack_chk_fail() {
|
|
|
|
@panic("stack smashing detected");
|
2017-02-08 23:50:03 -08:00
|
|
|
}
|