Address Spaces: LLVM F segment address space test

This commit is contained in:
Robin Voetter 2021-09-03 04:37:07 +02:00
parent e4ac063297
commit 5a142dfa56

View File

@ -372,4 +372,54 @@ pub fn addCases(ctx: *TestContext) !void {
\\pub export fn main() void { _ = entry; }
);
}
{
var case = ctx.exeUsingLlvmBackend("f segment address space reading and writing", linux_x64);
case.addCompareOutput(
\\fn assert(ok: bool) void {
\\ if (!ok) unreachable;
\\}
\\
\\fn setFs(value: c_ulong) void {
\\ asm volatile (
\\ \\syscall
\\ :
\\ : [number] "{rax}" (158),
\\ [code] "{rdi}" (0x1002),
\\ [val] "{rsi}" (value),
\\ : "rcx", "r11", "memory"
\\ );
\\}
\\
\\fn getFs() c_ulong {
\\ var result: c_ulong = undefined;
\\ asm volatile (
\\ \\syscall
\\ :
\\ : [number] "{rax}" (158),
\\ [code] "{rdi}" (0x1003),
\\ [ptr] "{rsi}" (@ptrToInt(&result)),
\\ : "rcx", "r11", "memory"
\\ );
\\ return result;
\\}
\\
\\var test_value: u64 = 12345;
\\
\\pub export fn main() c_int {
\\ const orig_fs = getFs();
\\
\\ setFs(@ptrToInt(&test_value));
\\ assert(getFs() == @ptrToInt(&test_value));
\\
\\ var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0);
\\ assert(test_ptr.* == 12345);
\\ test_ptr.* = 98765;
\\ assert(test_value == 98765);
\\
\\ setFs(orig_fs);
\\ return 0;
\\}
, "");
}
}