chromium/base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/log_message.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "partition_alloc/partition_alloc_base/log_message.h"

// TODO(crbug.com/40158212): After finishing copying //base files to PA library,
// remove defined(BASE_CHECK_H_) from here.
#if defined(                                                                                 \
    BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_ALLOC_BASE_CHECK_H_) || \
    defined(BASE_CHECK_H_) ||                                                                \
    defined(                                                                                 \
        BASE_ALLOCATOR_PARTITION_ALLOCATOR_SRC_PARTITION_ALLOC_PARTITION_ALLOC_CHECK_H_)
#error "log_message.h should not include check.h"
#endif

#include "partition_alloc/build_config.h"
#include "partition_alloc/partition_alloc_base/component_export.h"
#include "partition_alloc/partition_alloc_base/debug/alias.h"
#include "partition_alloc/partition_alloc_base/debug/stack_trace.h"
#include "partition_alloc/partition_alloc_base/immediate_crash.h"
#include "partition_alloc/partition_alloc_base/logging.h"
#include "partition_alloc/partition_alloc_base/strings/safe_sprintf.h"
#include "partition_alloc/partition_alloc_base/strings/string_util.h"
#include "partition_alloc/partition_alloc_base/strings/stringprintf.h"

#if PA_BUILDFLAG(IS_WIN)
#include <windows.h>

#include <io.h>
#endif

#if PA_BUILDFLAG(IS_POSIX) || PA_BUILDFLAG(IS_FUCHSIA)
#include <unistd.h>

#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#endif

#if PA_BUILDFLAG(IS_POSIX) || PA_BUILDFLAG(IS_FUCHSIA)
#include "partition_alloc/partition_alloc_base/posix/safe_strerror.h"
#endif

namespace partition_alloc::internal::logging {

namespace {

const char* const log_severity_names[] =;
static_assert;

const char* log_severity_name(int severity) {}

// A log message handler that gets notified of every log message we process.
LogMessageHandlerFunction g_log_message_handler =;

}  // namespace

#if PA_BUILDFLAG(DCHECK_IS_CONFIGURABLE)
// In DCHECK-enabled Chrome builds, allow the meaning of LOGGING_DCHECK to be
// determined at run-time. We default it to ERROR, to avoid it triggering
// crashes before the run-time has explicitly chosen the behaviour.
PA_COMPONENT_EXPORT(PARTITION_ALLOC_BASE)
logging::LogSeverity LOGGING_DCHECK = LOGGING_ERROR;
#endif  // PA_BUILDFLAG(DCHECK_IS_CONFIGURABLE)

// This is never instantiated, it's just used for EAT_STREAM_PARAMETERS to have
// an object of the correct type on the LHS of the unused part of the ternary
// operator.
base::strings::CStringBuilder* g_swallow_stream;

void SetLogMessageHandler(LogMessageHandlerFunction handler) {}

LogMessageHandlerFunction GetLogMessageHandler() {}

LogMessage::LogMessage(const char* file, int line, LogSeverity severity)
    :{}

LogMessage::LogMessage(const char* file, int line, const char* condition)
    :{}

LogMessage::~LogMessage() {}

// writes the common header info to the stream
void LogMessage::Init(const char* file, int line) {}

#if PA_BUILDFLAG(IS_WIN)
// This has already been defined in the header, but defining it again as DWORD
// ensures that the type used in the header is equivalent to DWORD. If not,
// the redefinition is a compile error.
typedef DWORD SystemErrorCode;
#endif

SystemErrorCode GetLastSystemErrorCode() {}

void SystemErrorCodeToStream(base::strings::CStringBuilder& os,
                             SystemErrorCode error_code) {}

#if PA_BUILDFLAG(IS_WIN)
Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file,
                                           int line,
                                           LogSeverity severity,
                                           SystemErrorCode err)
    : LogMessage(file, line, severity), err_(err) {}

Win32ErrorLogMessage::~Win32ErrorLogMessage() {
  stream() << ": ";
  SystemErrorCodeToStream(stream(), err_);
  // We're about to crash (CHECK). Put |err_| on the stack (by placing it in a
  // field) and use Alias in hopes that it makes it into crash dumps.
  DWORD last_error = err_;
  base::debug::Alias(&last_error);
}
#elif PA_BUILDFLAG(IS_POSIX) || PA_BUILDFLAG(IS_FUCHSIA)
ErrnoLogMessage::ErrnoLogMessage(const char* file,
                                 int line,
                                 LogSeverity severity,
                                 SystemErrorCode err)
    :{}

ErrnoLogMessage::~ErrnoLogMessage() {}
#endif  // PA_BUILDFLAG(IS_WIN)

}  // namespace partition_alloc::internal::logging