Merge pull request #2060 from xiaobo55x:rseq

PiperOrigin-RevId: 307453436
This commit is contained in:
gVisor bot
2020-04-20 12:31:22 -07:00
7 changed files with 141 additions and 22 deletions
+23 -20
View File
@@ -1,7 +1,7 @@
# This package contains a standalone rseq test binary. This binary must not
# depend on libc, which might use rseq itself.
load("//tools:defs.bzl", "cc_flags_supplier", "cc_library", "cc_toolchain")
load("//tools:defs.bzl", "cc_flags_supplier", "cc_library", "cc_toolchain", "select_arch")
package(licenses = ["notice"])
@@ -9,32 +9,35 @@ genrule(
name = "rseq_binary",
srcs = [
"critical.h",
"critical.S",
"critical_amd64.S",
"critical_arm64.S",
"rseq.cc",
"syscalls.h",
"start.S",
"start_amd64.S",
"start_arm64.S",
"test.h",
"types.h",
"uapi.h",
],
outs = ["rseq"],
cmd = " ".join([
"$(CC)",
"$(CC_FLAGS) ",
"-I.",
"-Wall",
"-Werror",
"-O2",
"-std=c++17",
"-static",
"-nostdlib",
"-ffreestanding",
"-o",
"$(location rseq)",
"$(location critical.S)",
"$(location rseq.cc)",
"$(location start.S)",
]),
cmd = "$(CC) " +
"$(CC_FLAGS) " +
"-I. " +
"-Wall " +
"-Werror " +
"-O2 " +
"-std=c++17 " +
"-static " +
"-nostdlib " +
"-ffreestanding " +
"-o " +
"$(location rseq) " +
select_arch(
amd64 = "$(location critical_amd64.S) $(location start_amd64.S) ",
arm64 = "$(location critical_arm64.S) $(location start_arm64.S) ",
no_match_error = "unsupported architecture",
) +
"$(location rseq.cc)",
toolchains = [
cc_toolchain,
":no_pie_cc_flags",
+66
View File
@@ -0,0 +1,66 @@
// Copyright 2020 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Restartable sequences critical sections.
// Loops continuously until aborted.
//
// void rseq_loop(struct rseq* r, struct rseq_cs* cs)
.text
.globl rseq_loop
.type rseq_loop, @function
rseq_loop:
b begin
// Abort block before the critical section.
// Abort signature.
.byte 0x90, 0x90, 0x90, 0x90
.globl rseq_loop_early_abort
rseq_loop_early_abort:
ret
begin:
// r->rseq_cs = cs
str x1, [x0, #8]
// N.B. rseq_cs will be cleared by any preempt, even outside the critical
// section. Thus it must be set in or immediately before the critical section
// to ensure it is not cleared before the section begins.
.globl rseq_loop_start
rseq_loop_start:
b rseq_loop_start
// "Pre-commit": extra instructions inside the critical section. These are
// used as the abort point in TestAbortPreCommit, which is not valid.
.globl rseq_loop_pre_commit
rseq_loop_pre_commit:
// Extra abort signature + nop for TestAbortPostCommit.
.byte 0x90, 0x90, 0x90, 0x90
nop
// "Post-commit": never reached in this case.
.globl rseq_loop_post_commit
rseq_loop_post_commit:
// Abort signature.
.byte 0x90, 0x90, 0x90, 0x90
.globl rseq_loop_abort
rseq_loop_abort:
ret
.size rseq_loop,.-rseq_loop
.section .note.GNU-stack,"",@progbits
+45
View File
@@ -0,0 +1,45 @@
// Copyright 2020 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
.text
.align 4
.type _start,@function
.globl _start
_start:
mov x29, sp
bl __init
wfi
.size _start,.-_start
.section .note.GNU-stack,"",@progbits
.text
.globl raw_syscall
.type raw_syscall, @function
raw_syscall:
mov x8,x0 // syscall #
mov x0,x1 // arg0
mov x1,x2 // arg1
mov x2,x3 // arg2
mov x3,x4 // arg3
mov x4,x5 // arg4
mov x5,x6 // arg5
svc #0
ret
.size raw_syscall,.-raw_syscall
.section .note.GNU-stack,"",@progbits
+4 -1
View File
@@ -17,10 +17,13 @@
#include "test/syscalls/linux/rseq/types.h"
#ifdef __x86_64__
// Syscall numbers.
#if defined(__x86_64__)
constexpr int kGetpid = 39;
constexpr int kExitGroup = 231;
#elif defined(__aarch64__)
constexpr int kGetpid = 172;
constexpr int kExitGroup = 94;
#else
#error "Unknown architecture"
#endif
+3 -1
View File
@@ -19,9 +19,11 @@
// User-kernel ABI for restartable sequences.
#ifdef __x86_64__
// Syscall numbers.
#if defined(__x86_64__)
constexpr int kRseqSyscall = 334;
#elif defined(__aarch64__)
constexpr int kRseqSyscall = 293;
#else
#error "Unknown architecture"
#endif // __x86_64__