- add sources.
[platform/framework/web/crosswalk.git] / src / sandbox / linux / seccomp-bpf / die.h
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 "sandbox/linux/seccomp-bpf/port.h"
9
10
11 namespace playground2 {
12
13 class Die {
14  public:
15   // This is the main API for using this file. Prints a error message and
16   // exits with a fatal error. This is not async-signal safe.
17   #define SANDBOX_DIE(m) playground2::Die::SandboxDie(m, __FILE__, __LINE__)
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
23   // Adds an informational message to the log file or stderr as appropriate.
24   #define SANDBOX_INFO(m) playground2::Die::SandboxInfo(m, __FILE__, __LINE__)
25
26   // Terminate the program, even if the current sandbox policy prevents some
27   // of the more commonly used functions used for exiting.
28   // Most users would want to call SANDBOX_DIE() instead, as it logs extra
29   // information. But calling ExitGroup() is correct and in some rare cases
30   // preferable. So, we make it part of the public API.
31   static void ExitGroup() __attribute__((noreturn));
32
33   // This method gets called by SANDBOX_DIE(). There is normally no reason
34   // to call it directly unless you are defining your own exiting macro.
35   static void SandboxDie(const char *msg, const char *file, int line)
36     __attribute__((noreturn));
37
38   static void RawSandboxDie(const char *msg) __attribute__((noreturn));
39
40   // This method gets called by SANDBOX_INFO(). There is normally no reason
41   // to call it directly unless you are defining your own logging macro.
42   static void SandboxInfo(const char *msg, const char *file, int line);
43
44   // Writes a message to stderr. Used as a fall-back choice, if we don't have
45   // any other way to report an error.
46   static void LogToStderr(const char *msg, const char *file, int line);
47
48   // We generally want to run all exit handlers. This means, on SANDBOX_DIE()
49   // we should be calling LOG(FATAL). But there are some situations where
50   // we just need to print a message and then terminate. This would typically
51   // happen in cases where we consume the error message internally (e.g. in
52   // unit tests or in the supportsSeccompSandbox() method).
53   static void EnableSimpleExit() { simple_exit_ = true; }
54
55   // Sometimes we need to disable all informational messages (e.g. from within
56   // unittests).
57   static void SuppressInfoMessages(bool flag) { suppress_info_ = flag; }
58
59  private:
60   static bool simple_exit_;
61   static bool suppress_info_;
62
63   DISALLOW_IMPLICIT_CONSTRUCTORS(Die);
64 };
65
66 }  // namespace
67
68 #endif  // SANDBOX_LINUX_SECCOMP_BPF_DIE_H__