tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SandboxProfilerParent.h (2838B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef SANDBOX_PROFILER_PARENT_H
      6 #define SANDBOX_PROFILER_PARENT_H
      7 
      8 #include "SandboxProfiler.h"
      9 #include "SandboxInfo.h"
     10 
     11 #if defined(HAVE_REPORT_UPROFILER_CHILD)
     12 #error Cannot include SandboxProfilerParent.h when already included SandboxProfilerChild.h
     13 #endif
     14 
     15 #define HAVE_REPORT_UPROFILER_PARENT
     16 
     17 namespace mozilla {
     18 
     19 struct UprofilerFuncPtrs uprofiler = {
     20    .register_thread = uprofiler_register_thread,
     21    .unregister_thread = uprofiler_unregister_thread,
     22    .simple_event_marker = uprofiler_simple_event_marker,
     23    .simple_event_marker_capture_stack =
     24        uprofiler_simple_event_marker_capture_stack,
     25    .simple_event_marker_with_stack = uprofiler_simple_event_marker_with_stack,
     26    .backtrace_into_buffer = uprofiler_backtrace_into_buffer,
     27    .native_backtrace = uprofiler_native_backtrace,
     28    .is_active = uprofiler_is_active,
     29    .feature_active = uprofiler_feature_active,
     30 };
     31 
     32 bool uprofiler_initted = true;
     33 
     34 #if defined(DEBUG)
     35 // On the parent side there is no sandbox so calls don't have to care about that
     36 thread_local Atomic<bool> sInSignalContext = Atomic<bool>(false);
     37 #endif  // defined(DEBUG)
     38 
     39 /* static */
     40 void SandboxProfiler::ReportAudit(const char* aKind, const char* aOp,
     41                                  int aFlags, uint64_t aId, int aPerms,
     42                                  const char* aPath, pid_t aPid) {
     43  if (!Active()) {
     44    return;
     45  }
     46 
     47  std::array arg_names = {"id", "op", "rflags", "path", "pid"};
     48  std::array arg_types = {
     49      TRACE_VALUE_TYPE_UINT,    // id
     50      TRACE_VALUE_TYPE_STRING,  // op
     51      TRACE_VALUE_TYPE_UINT,    // rflags
     52      TRACE_VALUE_TYPE_STRING,  // path
     53      TRACE_VALUE_TYPE_UINT     // pid
     54  };
     55 
     56  std::array arg_values = {static_cast<unsigned long long>(aId),
     57                           reinterpret_cast<unsigned long long>(aOp),
     58                           static_cast<unsigned long long>(aFlags),
     59                           reinterpret_cast<unsigned long long>(aPath),
     60                           static_cast<unsigned long long>(aPid)};
     61 
     62  Report(aKind, arg_names, arg_types, arg_values, nullptr);
     63 }
     64 
     65 /*  static */
     66 void SandboxProfiler::ReportLog(const char* buf) {
     67  if (!Active()) {
     68    return;
     69  }
     70 
     71  if (!SandboxInfo::Get().Test(SandboxInfo::kVerbose) &&
     72      !SandboxInfo::Get().Test(SandboxInfo::kVerboseTests)) {
     73    return;
     74  }
     75 
     76  std::array arg_names = {"log"};
     77  std::array arg_types = {
     78      TRACE_VALUE_TYPE_STRING,
     79  };
     80  std::array arg_values = {reinterpret_cast<unsigned long long>(buf)};
     81 
     82  Report("SandboxBroker::Log", arg_names, arg_types, arg_values, nullptr);
     83 }
     84 
     85 }  // namespace mozilla
     86 
     87 #endif  // SANDBOX_PROFILER_PARENT_H