OLD | NEW |
---|---|
(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); | |
jln (very slow on Chromium)
2012/08/23 22:53:09
I think I would get rid of this complexity: realis
| |
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); | |
jln (very slow on Chromium)
2012/08/23 22:53:09
I'm a bit worried this would really *flood* logs.
| |
36 } | |
37 } | |
38 | |
39 void Die::LogToStderr(const char *msg, const char *file, int line) { | |
40 if (msg) { | |
41 char buf[40]; | |
42 sprintf(buf, "%d", line); | |
jln (very slow on Chromium)
2012/08/23 22:53:09
snprintf, please.
| |
43 std::string s = std::string(file) + ":" + buf + ":" + msg + "\n"; | |
44 if (HANDLE_EINTR(write(2, s.c_str(), s.length()))) { } | |
jln (very slow on Chromium)
2012/08/23 22:53:09
Depending on what stderr actually is, we may need
| |
45 } | |
46 } | |
47 | |
48 bool Die::simple_exit_ = false; | |
49 | |
50 } // namespace | |
OLD | NEW |