| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Some headers on Android are missing cdefs: crbug.com/172337. | 5 // Some headers on Android are missing cdefs: crbug.com/172337. |
| 6 // (We can't use OS_ANDROID here since build_config.h is not included). | 6 // (We can't use OS_ANDROID here since build_config.h is not included). |
| 7 #if defined(ANDROID) | 7 #if defined(ANDROID) |
| 8 #include <sys/cdefs.h> | 8 #include <sys/cdefs.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "sandbox/linux/seccomp-bpf/syscall.h" | 31 #include "sandbox/linux/seccomp-bpf/syscall.h" |
| 32 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" | 32 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" |
| 33 #include "sandbox/linux/seccomp-bpf/verifier.h" | 33 #include "sandbox/linux/seccomp-bpf/verifier.h" |
| 34 | 34 |
| 35 namespace playground2 { | 35 namespace playground2 { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const int kExpectedExitCode = 100; | 39 const int kExpectedExitCode = 100; |
| 40 | 40 |
| 41 template <class T> | 41 int popcount(uint32_t x) { |
| 42 int popcount(T x); | |
| 43 template <> | |
| 44 int popcount<unsigned int>(unsigned int x) { | |
| 45 return __builtin_popcount(x); | 42 return __builtin_popcount(x); |
| 46 } | 43 } |
| 47 template <> | |
| 48 int popcount<unsigned long>(unsigned long x) { | |
| 49 return __builtin_popcountl(x); | |
| 50 } | |
| 51 template <> | |
| 52 int popcount<unsigned long long>(unsigned long long x) { | |
| 53 return __builtin_popcountll(x); | |
| 54 } | |
| 55 | 44 |
| 45 #if !defined(NDEBUG) |
| 56 void WriteFailedStderrSetupMessage(int out_fd) { | 46 void WriteFailedStderrSetupMessage(int out_fd) { |
| 57 const char* error_string = strerror(errno); | 47 const char* error_string = strerror(errno); |
| 58 static const char msg[] = | 48 static const char msg[] = |
| 59 "You have reproduced a puzzling issue.\n" | 49 "You have reproduced a puzzling issue.\n" |
| 60 "Please, report to crbug.com/152530!\n" | 50 "Please, report to crbug.com/152530!\n" |
| 61 "Failed to set up stderr: "; | 51 "Failed to set up stderr: "; |
| 62 if (HANDLE_EINTR(write(out_fd, msg, sizeof(msg) - 1)) > 0 && error_string && | 52 if (HANDLE_EINTR(write(out_fd, msg, sizeof(msg) - 1)) > 0 && error_string && |
| 63 HANDLE_EINTR(write(out_fd, error_string, strlen(error_string))) > 0 && | 53 HANDLE_EINTR(write(out_fd, error_string, strlen(error_string))) > 0 && |
| 64 HANDLE_EINTR(write(out_fd, "\n", 1))) { | 54 HANDLE_EINTR(write(out_fd, "\n", 1))) { |
| 65 } | 55 } |
| 66 } | 56 } |
| 57 #endif // !defined(NDEBUG) |
| 67 | 58 |
| 68 // We define a really simple sandbox policy. It is just good enough for us | 59 // We define a really simple sandbox policy. It is just good enough for us |
| 69 // to tell that the sandbox has actually been activated. | 60 // to tell that the sandbox has actually been activated. |
| 70 ErrorCode ProbeEvaluator(Sandbox*, int sysnum, void*) __attribute__((const)); | 61 ErrorCode ProbeEvaluator(Sandbox*, int sysnum, void*) __attribute__((const)); |
| 71 ErrorCode ProbeEvaluator(Sandbox*, int sysnum, void*) { | 62 ErrorCode ProbeEvaluator(Sandbox*, int sysnum, void*) { |
| 72 switch (sysnum) { | 63 switch (sysnum) { |
| 73 case __NR_getpid: | 64 case __NR_getpid: |
| 74 // Return EPERM so that we can check that the filter actually ran. | 65 // Return EPERM so that we can check that the filter actually ran. |
| 75 return ErrorCode(EPERM); | 66 return ErrorCode(EPERM); |
| 76 case __NR_exit_group: | 67 case __NR_exit_group: |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 &*conds_->insert(failed).first); | 1011 &*conds_->insert(failed).first); |
| 1021 } | 1012 } |
| 1022 | 1013 |
| 1023 ErrorCode Sandbox::Kill(const char* msg) { | 1014 ErrorCode Sandbox::Kill(const char* msg) { |
| 1024 return Trap(BpfFailure, const_cast<char*>(msg)); | 1015 return Trap(BpfFailure, const_cast<char*>(msg)); |
| 1025 } | 1016 } |
| 1026 | 1017 |
| 1027 Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN; | 1018 Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN; |
| 1028 | 1019 |
| 1029 } // namespace playground2 | 1020 } // namespace playground2 |
| OLD | NEW |