mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
Address Spaces: LLVM F segment address space test
This commit is contained in:
parent
e4ac063297
commit
5a142dfa56
@ -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;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user