Ignore:
Timestamp:
Jun 18, 2022, 9:13:05 PM (3 years ago)
Author:
[email protected]
Message:

Change Integrity audit logging to use OS_LOG_TYPE_ERROR.
https://bugs.webkit.org/show_bug.cgi?id=241742

Reviewed by Yusuke Suzuki.

On OS(DARWIN), Integrity audit code now uses an OSLogPrintStream to achieve this
logging with type OS_LOG_TYPE_ERROR. On other ports, we just route the logging
to WTF::dataFile() instead.

Also removed VA_ARGS support when !VA_OPT_SUPPORTED. This never worked in the first
place. Ports without VA_OPT_SUPPORTED will have to live with degraded logging.

Added WTFReportBacktraceWithPrefixAndPrintStream and WTFPrintBacktraceWithPrefixAndPrintStream
to support this new Integrity audit logging. Removed the old WTFPrintBacktraceWithPrefix
because it was never used by external clients. It was only used by as an internal support
function by other stack dumper functions.

  • Source/JavaScriptCore/tools/Integrity.cpp:

(JSC::Integrity::logFile):
(JSC::Integrity::logF):
(JSC::Integrity::logLnF):
(JSC::Integrity::verifyCell):

  • Source/JavaScriptCore/tools/Integrity.h:
  • Source/WTF/wtf/Assertions.cpp:
  • Source/WTF/wtf/Assertions.h:

Canonical link: https://commits.webkit.org/251666@main

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/tools/Integrity.cpp

    r295660 r295661  
    3535#include "Options.h"
    3636#include "VMInspectorInlines.h"
     37#include <wtf/DataLog.h>
     38#include <wtf/OSLogPrintStream.h>
    3739
    3840namespace JSC {
     
    4143namespace IntegrityInternal {
    4244static constexpr bool verbose = false;
     45}
     46
     47PrintStream& logFile()
     48{
     49#if OS(DARWIN)
     50    static PrintStream* s_file;
     51    static std::once_flag once;
     52    std::call_once(once, [] {
     53        // We want to use OS_LOG_TYPE_ERROR because we want to guarantee that the log makes it into
     54        // the file system, and is not potentially stuck in some memory buffer. Integrity audit logs
     55        // are used for debugging error states. So, this is an appropriate use of OS_LOG_TYPE_ERROR.
     56        s_file = OSLogPrintStream::open("com.apple.JavaScriptCore", "Integrity", OS_LOG_TYPE_ERROR).release();
     57    });
     58    return *s_file;
     59#else
     60    return WTF::dataFile();
     61#endif
     62}
     63
     64void logF(const char* format, ...)
     65{
     66    va_list argList;
     67    va_start(argList, format);
     68    logFile().vprintf(format, argList);
     69    va_end(argList);
     70}
     71
     72void logLnF(const char* format, ...)
     73{
     74    va_list argList;
     75    va_start(argList, format);
     76    logFile().vprintf(format, argList);
     77    va_end(argList);
     78    logFile().println();
    4379}
    4480
     
    141177#define AUDIT_VERIFY(cond, format, ...) do { \
    142178        IA_ASSERT_WITH_ACTION(cond, { \
    143             WTFLogAlways("    cell %p", cell); \
     179            Integrity::logLnF("    cell %p", cell); \
    144180            if (action == Action::LogAndCrash) \
    145                 RELEASE_ASSERT((cond), ##__VA_ARGS__); \
     181                RELEASE_ASSERT((cond)); \
    146182            else \
    147183                return false; \
    148         }, format, ##__VA_ARGS__); \
     184        }); \
    149185    } while (false)
    150186
     
    153189#define AUDIT_VERIFY(cond, format, ...) do { \
    154190        IA_ASSERT_WITH_ACTION(cond, { \
    155             WTFLogAlways("    cell %p", cell); \
     191            Integrity::logLnF("    cell %p", cell); \
    156192            if (action == Action::LogAndCrash) \
    157193                RELEASE_ASSERT((cond) __VA_OPT__(,) __VA_ARGS__); \
     
    291327{
    292328    bool valid = Analyzer::analyzeCell(cell, Analyzer::Action::LogOnly);
    293     WTFLogAlways("Cell %p is %s", cell, valid ? "VALID" : "INVALID");
     329    Integrity::logLnF("Cell %p is %s", cell, valid ? "VALID" : "INVALID");
    294330    return valid;
    295331}
     
    298334{
    299335    bool valid = Analyzer::analyzeCell(vm, cell, Analyzer::Action::LogOnly);
    300     WTFLogAlways("Cell %p is %s", cell, valid ? "VALID" : "INVALID");
     336    Integrity::logLnF("Cell %p is %s", cell, valid ? "VALID" : "INVALID");
    301337    return valid;
    302338}
Note: See TracChangeset for help on using the changeset viewer.