Changeset 295661 in webkit for trunk/Source/JavaScriptCore/tools


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

Location:
trunk/Source/JavaScriptCore/tools
Files:
2 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}
  • trunk/Source/JavaScriptCore/tools/Integrity.h

    r294287 r295661  
    4949typedef struct OpaqueJSValue* JSObjectRef;
    5050
     51namespace WTF {
     52class PrintStream;
     53}
     54
    5155namespace JSC {
    5256
     
    178182
    179183#define IA_LOG(assertion, format, ...) do { \
    180         WTFLogAlways("Integrity ERROR: %s @ %s:%d\n", #assertion, __FILE__, __LINE__); \
    181         WTFLogAlways("    " format, ##__VA_ARGS__); \
     184        Integrity::logLnF("ERROR: %s @ %s:%d", #assertion, __FILE__, __LINE__); \
    182185    } while (false)
    183186
     
    185188        if (UNLIKELY(!(assertion))) { \
    186189            IA_LOG(assertion, __VA_ARGS__); \
    187             WTFReportBacktraceWithPrefix("    "); \
     190            WTFReportBacktraceWithPrefixAndPrintStream(Integrity::logFile(), "    "); \
    188191            action; \
    189192        } \
     
    192195#define IA_ASSERT(assertion, ...) \
    193196    IA_ASSERT_WITH_ACTION(assertion, { \
    194         RELEASE_ASSERT((assertion), ##__VA_ARGS__); \
    195     }, ## __VA_ARGS__)
     197        RELEASE_ASSERT((assertion)); \
     198    })
    196199
    197200#else // not (COMPILER(MSVC) || !VA_OPT_SUPPORTED)
    198201
    199202#define IA_LOG(assertion, format, ...) do { \
    200         WTFLogAlways("Integrity ERROR: %s @ %s:%d\n", #assertion, __FILE__, __LINE__); \
    201         WTFLogAlways("    " format __VA_OPT__(,) __VA_ARGS__); \
     203        Integrity::logLnF("ERROR: %s @ %s:%d", #assertion, __FILE__, __LINE__); \
     204        Integrity::logLnF("    " format __VA_OPT__(,) __VA_ARGS__); \
    202205    } while (false)
    203206
     
    205208        if (UNLIKELY(!(assertion))) { \
    206209            IA_LOG(assertion, __VA_ARGS__); \
    207             WTFReportBacktraceWithPrefix("    "); \
     210            WTFReportBacktraceWithPrefixAndPrintStream(Integrity::logFile(), "    "); \
    208211            action; \
    209212        } \
     
    217220#endif // COMPILER(MSVC) || !VA_OPT_SUPPORTED
    218221
     222JS_EXPORT_PRIVATE WTF::PrintStream& logFile();
     223JS_EXPORT_PRIVATE void logF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
     224JS_EXPORT_PRIVATE void logLnF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
     225
    219226} // namespace Integrity
    220227
Note: See TracChangeset for help on using the changeset viewer.