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 #ifndef SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ | |
6 #define SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ | |
7 | |
8 #include <vector> | |
jln (very slow on Chromium)
2012/08/24 00:49:06
I think this include can go.
| |
9 | |
jln (very slow on Chromium)
2012/08/23 22:53:09
Nit: remove the extra line.
| |
10 | |
11 namespace playground2 { | |
12 | |
13 class Die { | |
14 public: | |
15 // We use macros so that the pre-processor can insert appropriate file names | |
16 // and line numbers, when outputting error messages. | |
17 #if defined(SECCOMP_BPF_STANDALONE) | |
18 #define SECCOMP_BPF_FAIL_MACRO(m) \ | |
19 do { \ | |
20 Die::LogToStderr(m, __FILE__, __LINE__); \ | |
21 } while (false) | |
22 #else | |
23 #define SECCOMP_BPF_FAIL_MACRO(m) LOG(FATAL) << (m) | |
24 #endif | |
25 | |
26 // This is the main API for using this file. Prints a error message and | |
27 // exits with a fatal error. | |
28 #define SANDBOX_DIE(m) \ | |
29 do { \ | |
30 const char *msg = (m); \ | |
31 if (Die::simple_exit()) { \ | |
32 Die::LogToStderr(msg, __FILE__, __LINE__); \ | |
33 } else { \ | |
34 SECCOMP_BPF_FAIL_MACRO(msg); \ | |
35 } \ | |
36 Die::ExitGroup(); \ | |
37 } while (false) | |
jln (very slow on Chromium)
2012/08/23 22:53:09
Could you:
1. Inline the above macros.
2. Make thi
| |
38 | |
39 // Terminate the program, even if the current sandbox policy prevents some | |
40 // of the more commonly used functions used for exiting. | |
41 static void ExitGroup() __attribute__((noreturn)); | |
42 | |
43 // Writes a message to stderr. Used as a fall-back choice, if we don't have | |
44 // any other way to report an error. | |
45 static void LogToStderr(const char *msg, const char *file, int line); | |
46 | |
47 // We generally want to run all exit handler. This means, on SANDBOX_DIE() | |
48 // we should be calling LOG(FATAL). But there are some situations where | |
49 // we just need to print a message and then terminate. This would typically | |
50 // happen in cases where we consume the error message internally (e.g. in | |
51 // unit tests or in the supportsSeccompSandbox() method). | |
52 static void enableSimpleExit() { simple_exit_ = true; } | |
jln (very slow on Chromium)
2012/08/23 22:53:09
Nit: EnableSimpleExit(), capital E.
| |
53 static bool simple_exit() { return simple_exit_; } | |
54 | |
55 private: | |
56 static bool simple_exit_; | |
57 | |
58 DISALLOW_IMPLICIT_CONSTRUCTORS(Die); | |
59 }; | |
60 | |
61 } // namespace | |
62 | |
63 #endif // SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ | |
OLD | NEW |