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

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

Issue 23461032: Linux Sandbox: add RawSandboxDie() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: __attribute__ ((noinline)) for SigSys Created 7 years, 3 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 | « no previous file | sandbox/linux/seccomp-bpf/die.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_DIE_H__
6 #define SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ 6 #define SANDBOX_LINUX_SECCOMP_BPF_DIE_H__
7 7
8 #include "sandbox/linux/seccomp-bpf/port.h" 8 #include "sandbox/linux/seccomp-bpf/port.h"
9 9
10 10
11 namespace playground2 { 11 namespace playground2 {
12 12
13 class Die { 13 class Die {
14 public: 14 public:
15 // This is the main API for using this file. Prints a error message and 15 // This is the main API for using this file. Prints a error message and
16 // exits with a fatal error. 16 // exits with a fatal error. This is not async-signal safe.
17 #define SANDBOX_DIE(m) playground2::Die::SandboxDie(m, __FILE__, __LINE__) 17 #define SANDBOX_DIE(m) playground2::Die::SandboxDie(m, __FILE__, __LINE__)
18 18
19 // An async signal safe version of the same API. Won't print the filename
20 // and line numbers.
21 #define RAW_SANDBOX_DIE(m) playground2::Die::RawSandboxDie(m)
22
19 // Adds an informational message to the log file or stderr as appropriate. 23 // Adds an informational message to the log file or stderr as appropriate.
20 #define SANDBOX_INFO(m) playground2::Die::SandboxInfo(m, __FILE__, __LINE__) 24 #define SANDBOX_INFO(m) playground2::Die::SandboxInfo(m, __FILE__, __LINE__)
21 25
22 // Terminate the program, even if the current sandbox policy prevents some 26 // Terminate the program, even if the current sandbox policy prevents some
23 // of the more commonly used functions used for exiting. 27 // of the more commonly used functions used for exiting.
24 // Most users would want to call SANDBOX_DIE() instead, as it logs extra 28 // Most users would want to call SANDBOX_DIE() instead, as it logs extra
25 // information. But calling ExitGroup() is correct and in some rare cases 29 // information. But calling ExitGroup() is correct and in some rare cases
26 // preferable. So, we make it part of the public API. 30 // preferable. So, we make it part of the public API.
27 static void ExitGroup() __attribute__((noreturn)); 31 static void ExitGroup() __attribute__((noreturn));
28 32
29 // This method gets called by SANDBOX_DIE(). There is normally no reason 33 // This method gets called by SANDBOX_DIE(). There is normally no reason
30 // to call it directly unless you are defining your own exiting macro. 34 // to call it directly unless you are defining your own exiting macro.
31 static void SandboxDie(const char *msg, const char *file, int line) 35 static void SandboxDie(const char *msg, const char *file, int line)
32 __attribute__((noreturn)); 36 __attribute__((noreturn));
33 37
38 static void RawSandboxDie(const char *msg) __attribute__((noreturn));
39
34 // This method gets called by SANDBOX_INFO(). There is normally no reason 40 // This method gets called by SANDBOX_INFO(). There is normally no reason
35 // to call it directly unless you are defining your own logging macro. 41 // to call it directly unless you are defining your own logging macro.
36 static void SandboxInfo(const char *msg, const char *file, int line); 42 static void SandboxInfo(const char *msg, const char *file, int line);
37 43
38 // Writes a message to stderr. Used as a fall-back choice, if we don't have 44 // Writes a message to stderr. Used as a fall-back choice, if we don't have
39 // any other way to report an error. 45 // any other way to report an error.
40 static void LogToStderr(const char *msg, const char *file, int line); 46 static void LogToStderr(const char *msg, const char *file, int line);
41 47
42 // We generally want to run all exit handlers. This means, on SANDBOX_DIE() 48 // We generally want to run all exit handlers. This means, on SANDBOX_DIE()
43 // we should be calling LOG(FATAL). But there are some situations where 49 // we should be calling LOG(FATAL). But there are some situations where
44 // we just need to print a message and then terminate. This would typically 50 // we just need to print a message and then terminate. This would typically
45 // happen in cases where we consume the error message internally (e.g. in 51 // happen in cases where we consume the error message internally (e.g. in
46 // unit tests or in the supportsSeccompSandbox() method). 52 // unit tests or in the supportsSeccompSandbox() method).
47 static void EnableSimpleExit() { simple_exit_ = true; } 53 static void EnableSimpleExit() { simple_exit_ = true; }
48 54
49 // Sometimes we need to disable all informational messages (e.g. from within 55 // Sometimes we need to disable all informational messages (e.g. from within
50 // unittests). 56 // unittests).
51 static void SuppressInfoMessages(bool flag) { suppress_info_ = flag; } 57 static void SuppressInfoMessages(bool flag) { suppress_info_ = flag; }
52 58
53 private: 59 private:
54 static bool simple_exit_; 60 static bool simple_exit_;
55 static bool suppress_info_; 61 static bool suppress_info_;
56 62
57 DISALLOW_IMPLICIT_CONSTRUCTORS(Die); 63 DISALLOW_IMPLICIT_CONSTRUCTORS(Die);
58 }; 64 };
59 65
60 } // namespace 66 } // namespace
61 67
62 #endif // SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ 68 #endif // SANDBOX_LINUX_SECCOMP_BPF_DIE_H__
OLDNEW
« no previous file with comments | « no previous file | sandbox/linux/seccomp-bpf/die.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698