mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix header ordering and format all C++ code.
PiperOrigin-RevId: 291844200
This commit is contained in:
committed by
gVisor bot
parent
db68c85ab7
commit
5776a7b6f6
+2
-1
@@ -36,7 +36,8 @@ directory tree.
|
||||
|
||||
All Go code should conform to the [Go style guidelines][gostyle]. C++ code
|
||||
should conform to the [Google C++ Style Guide][cppstyle] and the guidelines
|
||||
described for [tests][teststyle].
|
||||
described for [tests][teststyle]. Note that code may be automatically formatted
|
||||
per the guidelines when merged.
|
||||
|
||||
As a secure runtime, we need to maintain the safety of all of code included in
|
||||
gVisor. The following rules help mitigate issues.
|
||||
|
||||
@@ -71,7 +71,7 @@ void ExitGroup32(const char instruction[2], int code) {
|
||||
"iretl\n"
|
||||
"int $3\n"
|
||||
:
|
||||
: [code] "m"(code), [ip] "d"(m.ptr())
|
||||
: [ code ] "m"(code), [ ip ] "d"(m.ptr())
|
||||
: "rax", "rbx", "rsp");
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ TEST(FPSigTest, Fork) {
|
||||
"movl %[sig], %%edx;"
|
||||
"syscall;"
|
||||
:
|
||||
: [killnr] "i"(__NR_tgkill), [parent] "rm"(parent),
|
||||
[tid] "rm"(parent_tid), [sig] "i"(SIGUSR1)
|
||||
: [ killnr ] "i"(__NR_tgkill), [ parent ] "rm"(parent),
|
||||
[ tid ] "rm"(parent_tid), [ sig ] "i"(SIGUSR1)
|
||||
: "rax", "rdi", "rsi", "rdx",
|
||||
// Clobbered by syscall.
|
||||
"rcx", "r11");
|
||||
|
||||
@@ -61,8 +61,8 @@ void sigusr1(int s, siginfo_t* siginfo, void* _uc) {
|
||||
"movl %[sig], %%edx;"
|
||||
"syscall;"
|
||||
:
|
||||
: [killnr] "i"(__NR_tgkill), [pid] "rm"(pid), [tid] "rm"(tid),
|
||||
[sig] "i"(SIGUSR2)
|
||||
: [ killnr ] "i"(__NR_tgkill), [ pid ] "rm"(pid), [ tid ] "rm"(tid),
|
||||
[ sig ] "i"(SIGUSR2)
|
||||
: "rax", "rdi", "rsi", "rdx",
|
||||
// Clobbered by syscall.
|
||||
"rcx", "r11");
|
||||
@@ -107,8 +107,8 @@ TEST(FPSigTest, NestedSignals) {
|
||||
"movl %[sig], %%edx;"
|
||||
"syscall;"
|
||||
:
|
||||
: [killnr] "i"(__NR_tgkill), [pid] "rm"(pid), [tid] "rm"(tid),
|
||||
[sig] "i"(SIGUSR1)
|
||||
: [ killnr ] "i"(__NR_tgkill), [ pid ] "rm"(pid), [ tid ] "rm"(tid),
|
||||
[ sig ] "i"(SIGUSR1)
|
||||
: "rax", "rdi", "rsi", "rdx",
|
||||
// Clobbered by syscall.
|
||||
"rcx", "r11");
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace testing {
|
||||
|
||||
namespace {
|
||||
|
||||
void ExpectAllMappingBytes(Mapping const& m, char c) {
|
||||
void ExpectAllMappingBytes(Mapping const &m, char c) {
|
||||
auto const v = m.view();
|
||||
for (size_t i = 0; i < kPageSize; i++) {
|
||||
ASSERT_EQ(v[i], c) << "at offset " << i;
|
||||
@@ -47,7 +47,7 @@ void ExpectAllMappingBytes(Mapping const& m, char c) {
|
||||
|
||||
// Equivalent to ExpectAllMappingBytes but async-signal-safe and with less
|
||||
// helpful failure messages.
|
||||
void CheckAllMappingBytes(Mapping const& m, char c) {
|
||||
void CheckAllMappingBytes(Mapping const &m, char c) {
|
||||
auto const v = m.view();
|
||||
for (size_t i = 0; i < kPageSize; i++) {
|
||||
TEST_CHECK_MSG(v[i] == c, "mapping contains wrong value");
|
||||
|
||||
@@ -213,7 +213,7 @@ TEST(MempolicyTest, GetMempolicyQueryNodeForAddress) {
|
||||
}
|
||||
}
|
||||
|
||||
void* invalid_address = reinterpret_cast<void*>(-1);
|
||||
void *invalid_address = reinterpret_cast<void *>(-1);
|
||||
|
||||
// Invalid address.
|
||||
ASSERT_THAT(get_mempolicy(&mode, nullptr, 0, invalid_address,
|
||||
@@ -221,8 +221,8 @@ TEST(MempolicyTest, GetMempolicyQueryNodeForAddress) {
|
||||
SyscallFailsWithErrno(EFAULT));
|
||||
|
||||
// Invalid mode pointer.
|
||||
ASSERT_THAT(get_mempolicy(reinterpret_cast<int*>(invalid_address), nullptr, 0,
|
||||
&dummy_stack_address, MPOL_F_ADDR | MPOL_F_NODE),
|
||||
ASSERT_THAT(get_mempolicy(reinterpret_cast<int *>(invalid_address), nullptr,
|
||||
0, &dummy_stack_address, MPOL_F_ADDR | MPOL_F_NODE),
|
||||
SyscallFailsWithErrno(EFAULT));
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ bool IsPageMlocked(uintptr_t addr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TEST(MlockTest, Basic) {
|
||||
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(CanMlock()));
|
||||
auto const mapping = ASSERT_NO_ERRNO_AND_VALUE(
|
||||
|
||||
@@ -60,9 +60,7 @@ std::vector<std::function<PosixErrorOr<Mapping>()>> SyncableMappings() {
|
||||
for (int const mflags : {MAP_PRIVATE, MAP_SHARED}) {
|
||||
int const prot = PROT_READ | (writable ? PROT_WRITE : 0);
|
||||
int const oflags = O_CREAT | (writable ? O_RDWR : O_RDONLY);
|
||||
funcs.push_back([=] {
|
||||
return MmapAnon(kPageSize, prot, mflags);
|
||||
});
|
||||
funcs.push_back([=] { return MmapAnon(kPageSize, prot, mflags); });
|
||||
funcs.push_back([=]() -> PosixErrorOr<Mapping> {
|
||||
std::string const path = NewTempAbsPath();
|
||||
ASSIGN_OR_RETURN_ERRNO(auto fd, Open(path, oflags, 0644));
|
||||
|
||||
@@ -178,7 +178,8 @@ TEST(PtraceTest, GetSigMask) {
|
||||
|
||||
// Install a signal handler for kBlockSignal to avoid termination and block
|
||||
// it.
|
||||
TEST_PCHECK(signal(kBlockSignal, +[](int signo) {}) != SIG_ERR);
|
||||
TEST_PCHECK(signal(
|
||||
kBlockSignal, +[](int signo) {}) != SIG_ERR);
|
||||
MaybeSave();
|
||||
TEST_PCHECK(sigprocmask(SIG_SETMASK, &blocked, nullptr) == 0);
|
||||
MaybeSave();
|
||||
|
||||
@@ -113,7 +113,8 @@ TEST(SeccompTest, RetKillCausesDeathBySIGSYS) {
|
||||
pid_t const pid = fork();
|
||||
if (pid == 0) {
|
||||
// Register a signal handler for SIGSYS that we don't expect to be invoked.
|
||||
RegisterSignalHandler(SIGSYS, +[](int, siginfo_t*, void*) { _exit(1); });
|
||||
RegisterSignalHandler(
|
||||
SIGSYS, +[](int, siginfo_t*, void*) { _exit(1); });
|
||||
ApplySeccompFilter(kFilteredSyscall, SECCOMP_RET_KILL);
|
||||
syscall(kFilteredSyscall);
|
||||
TEST_CHECK_MSG(false, "Survived invocation of test syscall");
|
||||
@@ -132,7 +133,8 @@ TEST(SeccompTest, RetKillOnlyKillsOneThread) {
|
||||
pid_t const pid = fork();
|
||||
if (pid == 0) {
|
||||
// Register a signal handler for SIGSYS that we don't expect to be invoked.
|
||||
RegisterSignalHandler(SIGSYS, +[](int, siginfo_t*, void*) { _exit(1); });
|
||||
RegisterSignalHandler(
|
||||
SIGSYS, +[](int, siginfo_t*, void*) { _exit(1); });
|
||||
ApplySeccompFilter(kFilteredSyscall, SECCOMP_RET_KILL);
|
||||
// Pass CLONE_VFORK to block the original thread in the child process until
|
||||
// the clone thread exits with SIGSYS.
|
||||
@@ -346,7 +348,8 @@ TEST(SeccompTest, LeastPermissiveFilterReturnValueApplies) {
|
||||
// one that causes the kill that should be ignored.
|
||||
pid_t const pid = fork();
|
||||
if (pid == 0) {
|
||||
RegisterSignalHandler(SIGSYS, +[](int, siginfo_t*, void*) { _exit(1); });
|
||||
RegisterSignalHandler(
|
||||
SIGSYS, +[](int, siginfo_t*, void*) { _exit(1); });
|
||||
ApplySeccompFilter(kFilteredSyscall, SECCOMP_RET_TRACE);
|
||||
ApplySeccompFilter(kFilteredSyscall, SECCOMP_RET_KILL);
|
||||
ApplySeccompFilter(kFilteredSyscall, SECCOMP_RET_ERRNO | ENOTNAM);
|
||||
|
||||
@@ -168,8 +168,8 @@ TEST(SigaltstackTest, WalksOffBottom) {
|
||||
|
||||
// Trigger a single fault.
|
||||
badhandler_low_water_mark =
|
||||
static_cast<char*>(stack.ss_sp) + SIGSTKSZ; // Expected top.
|
||||
badhandler_recursive_faults = 0; // Disable refault.
|
||||
static_cast<char*>(stack.ss_sp) + SIGSTKSZ; // Expected top.
|
||||
badhandler_recursive_faults = 0; // Disable refault.
|
||||
Fault();
|
||||
EXPECT_TRUE(badhandler_on_sigaltstack);
|
||||
EXPECT_THAT(sigaltstack(nullptr, &stack), SyscallSucceeds());
|
||||
|
||||
@@ -78,8 +78,8 @@ TEST(SigIretTest, CheckRcxR11) {
|
||||
"1: pause; cmpl $0, %[gotvtalrm]; je 1b;" // while (!gotvtalrm);
|
||||
"movq %%rcx, %[rcx];" // rcx = %rcx
|
||||
"movq %%r11, %[r11];" // r11 = %r11
|
||||
: [ready] "=m"(ready), [rcx] "+m"(rcx), [r11] "+m"(r11)
|
||||
: [gotvtalrm] "m"(gotvtalrm)
|
||||
: [ ready ] "=m"(ready), [ rcx ] "+m"(rcx), [ r11 ] "+m"(r11)
|
||||
: [ gotvtalrm ] "m"(gotvtalrm)
|
||||
: "cc", "memory", "rcx", "r11");
|
||||
|
||||
// If sigreturn(2) returns via 'sysret' then %rcx and %r11 will be
|
||||
|
||||
@@ -32,38 +32,38 @@ namespace gvisor {
|
||||
namespace testing {
|
||||
|
||||
TEST_P(BlockingStreamSocketPairTest, BlockPartialWriteClosed) {
|
||||
// FIXME(b/35921550): gVisor doesn't support SO_SNDBUF on UDS, nor does it
|
||||
// enforce any limit; it will write arbitrary amounts of data without
|
||||
// blocking.
|
||||
SKIP_IF(IsRunningOnGvisor());
|
||||
// FIXME(b/35921550): gVisor doesn't support SO_SNDBUF on UDS, nor does it
|
||||
// enforce any limit; it will write arbitrary amounts of data without
|
||||
// blocking.
|
||||
SKIP_IF(IsRunningOnGvisor());
|
||||
|
||||
auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
|
||||
auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
|
||||
|
||||
int buffer_size;
|
||||
socklen_t length = sizeof(buffer_size);
|
||||
ASSERT_THAT(getsockopt(sockets->first_fd(), SOL_SOCKET, SO_SNDBUF,
|
||||
&buffer_size, &length),
|
||||
SyscallSucceeds());
|
||||
int buffer_size;
|
||||
socklen_t length = sizeof(buffer_size);
|
||||
ASSERT_THAT(getsockopt(sockets->first_fd(), SOL_SOCKET, SO_SNDBUF,
|
||||
&buffer_size, &length),
|
||||
SyscallSucceeds());
|
||||
|
||||
int wfd = sockets->first_fd();
|
||||
ScopedThread t([wfd, buffer_size]() {
|
||||
std::vector<char> buf(2 * buffer_size);
|
||||
// Write more than fits in the buffer. Blocks then returns partial write
|
||||
// when the other end is closed. The next call returns EPIPE.
|
||||
//
|
||||
// N.B. writes occur in chunks, so we may see less than buffer_size from
|
||||
// the first call.
|
||||
ASSERT_THAT(write(wfd, buf.data(), buf.size()),
|
||||
SyscallSucceedsWithValue(::testing::Gt(0)));
|
||||
ASSERT_THAT(write(wfd, buf.data(), buf.size()),
|
||||
::testing::AnyOf(SyscallFailsWithErrno(EPIPE),
|
||||
SyscallFailsWithErrno(ECONNRESET)));
|
||||
});
|
||||
int wfd = sockets->first_fd();
|
||||
ScopedThread t([wfd, buffer_size]() {
|
||||
std::vector<char> buf(2 * buffer_size);
|
||||
// Write more than fits in the buffer. Blocks then returns partial write
|
||||
// when the other end is closed. The next call returns EPIPE.
|
||||
//
|
||||
// N.B. writes occur in chunks, so we may see less than buffer_size from
|
||||
// the first call.
|
||||
ASSERT_THAT(write(wfd, buf.data(), buf.size()),
|
||||
SyscallSucceedsWithValue(::testing::Gt(0)));
|
||||
ASSERT_THAT(write(wfd, buf.data(), buf.size()),
|
||||
::testing::AnyOf(SyscallFailsWithErrno(EPIPE),
|
||||
SyscallFailsWithErrno(ECONNRESET)));
|
||||
});
|
||||
|
||||
// Leave time for write to become blocked.
|
||||
absl::SleepFor(absl::Seconds(1));
|
||||
// Leave time for write to become blocked.
|
||||
absl::SleepFor(absl::Seconds(1));
|
||||
|
||||
ASSERT_THAT(close(sockets->release_second_fd()), SyscallSucceeds());
|
||||
ASSERT_THAT(close(sockets->release_second_fd()), SyscallSucceeds());
|
||||
}
|
||||
|
||||
// Random save may interrupt the call to sendmsg() in SendLargeSendMsg(),
|
||||
|
||||
@@ -377,7 +377,7 @@ TEST_F(StatTest, ZeroLinksOpenFdRegularFileChild_NoRandomSave) {
|
||||
//
|
||||
// We need to support this because when a file is unlinked and we forward
|
||||
// the stat to the gofer it would return ENOENT.
|
||||
const char* uncached_gofer = getenv("GVISOR_GOFER_UNCACHED");
|
||||
const char *uncached_gofer = getenv("GVISOR_GOFER_UNCACHED");
|
||||
SKIP_IF(uncached_gofer != nullptr);
|
||||
|
||||
// We don't support saving unlinked files.
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
#ifndef __fuchsia__
|
||||
|
||||
#include "test/syscalls/linux/udp_socket_test_cases.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/errqueue.h>
|
||||
@@ -29,6 +27,7 @@
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "test/syscalls/linux/socket_test_util.h"
|
||||
#include "test/syscalls/linux/udp_socket_test_cases.h"
|
||||
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
|
||||
#include "test/util/test_util.h"
|
||||
#include "test/util/thread_util.h"
|
||||
|
||||
@@ -36,10 +36,10 @@ PosixErrorOr<bool> CanCreateUserNamespace() {
|
||||
ASSIGN_OR_RETURN_ERRNO(
|
||||
auto child_stack,
|
||||
MmapAnon(kPageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE));
|
||||
int const child_pid =
|
||||
clone(+[](void*) { return 0; },
|
||||
reinterpret_cast<void*>(child_stack.addr() + kPageSize),
|
||||
CLONE_NEWUSER | SIGCHLD, /* arg = */ nullptr);
|
||||
int const child_pid = clone(
|
||||
+[](void*) { return 0; },
|
||||
reinterpret_cast<void*>(child_stack.addr() + kPageSize),
|
||||
CLONE_NEWUSER | SIGCHLD, /* arg = */ nullptr);
|
||||
if (child_pid > 0) {
|
||||
int status;
|
||||
int const ret = waitpid(child_pid, &status, /* options = */ 0);
|
||||
|
||||
@@ -452,7 +452,7 @@ PosixErrorOr<std::string> MakeAbsolute(absl::string_view filename,
|
||||
|
||||
std::string CleanPath(const absl::string_view unclean_path) {
|
||||
std::string path = std::string(unclean_path);
|
||||
const char *src = path.c_str();
|
||||
const char* src = path.c_str();
|
||||
std::string::iterator dst = path.begin();
|
||||
|
||||
// Check for absolute path and determine initial backtrack limit.
|
||||
|
||||
@@ -99,7 +99,8 @@ inline PosixErrorOr<Cleanup> ForkAndExec(const std::string& filename,
|
||||
const ExecveArray& argv,
|
||||
const ExecveArray& envv, pid_t* child,
|
||||
int* execve_errno) {
|
||||
return ForkAndExec(filename, argv, envv, [] {}, child, execve_errno);
|
||||
return ForkAndExec(
|
||||
filename, argv, envv, [] {}, child, execve_errno);
|
||||
}
|
||||
|
||||
// Equivalent to ForkAndExec, except using dirfd and flags with execveat.
|
||||
|
||||
Reference in New Issue
Block a user