Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: sandbox/linux/seccomp-bpf/die.cc

Issue 10878033: Simplified unit testing of sandboxing code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing parameter that suppresses benign error messages Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/seccomp-bpf/die.h ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
8
9
10 namespace playground2 {
11
12 void Die::ExitGroup() {
13 // exit_group() should exit our program. After all, it is defined as a
14 // function that doesn't return. But things can theoretically go wrong.
15 // Especially, since we are dealing with system call filters. Continuing
16 // execution would be very bad in most cases where ExitGroup() gets called.
17 // So, we'll try a few other strategies too.
18 syscall(__NR_exit_group, 1);
19
20 // We have no idea what our run-time environment looks like. So, signal
21 // handlers might or might not do the right thing. Try to reset settings
22 // to a defined state; but we have not way to verify whether we actually
23 // succeeded in doing so. Nonetheless, triggering a fatal signal could help
24 // us terminate.
25 signal(SIGSEGV, SIG_DFL);
26 syscall(__NR_prctl, PR_SET_DUMPABLE, (void *)0, (void *)0, (void *)0);
27 if (*(volatile char *)0) { }
28
29 // If there is no way for us to ask for the program to exit, the next
30 // best thing we can do is to loop indefinitely. Maybe, somebody will notice
31 // and file a bug...
32 // We in fact retry the system call inside of our loop so that it will
33 // stand out when somebody tries to diagnose the problem by using "strace".
34 for (;;) {
35 syscall(__NR_exit_group, 1);
36 }
37 }
38
39 void Die::SandboxDie(const char *msg, const char *file, int line) {
40 if (simple_exit_) {
41 LogToStderr(msg, file, line);
42 } else {
43 #if defined(SECCOMP_BPF_STANDALONE)
44 Die::LogToStderr(msg, file, line);
45 #else
46 logging::LogMessage(file, line, logging::LOG_FATAL).stream() << msg;
47 #endif
48 }
49 ExitGroup();
50 }
51
52 void Die::LogToStderr(const char *msg, const char *file, int line) {
53 if (msg) {
54 char buf[40];
55 snprintf(buf, sizeof(buf), "%d", line);
56 std::string s = std::string(file) + ":" + buf + ":" + msg + "\n";
57
58 // No need to loop. Short write()s are unlikely and if they happen we
59 // probably prefer them over a loop that blocks.
60 if (HANDLE_EINTR(write(2, s.c_str(), s.length()))) { }
61 }
62 }
63
64 bool Die::simple_exit_ = false;
65
66 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/die.h ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698