tor-browser

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

ABIFunctionList-inl.h (16800B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef jit_ABIFunctionList_inl_h
      8 #define jit_ABIFunctionList_inl_h
      9 
     10 #include "mozilla/MacroArgs.h"  // MOZ_CONCAT
     11 #include "mozilla/SIMD.h"       // mozilla::SIMD::memchr{,2x}{8,16}
     12 
     13 #include "jslibmath.h"  // js::NumberMod
     14 #include "jsmath.h"     // js::ecmaPow, js::ecmaHypot, js::hypot3, js::hypot4,
     15                        // js::ecmaAtan2, js::UnaryMathFunctionType, js::powi
     16 #include "jsnum.h"      // js::StringToNumberPure, js::Int32ToStringPure,
     17                        // js::NumberToStringPure
     18 
     19 #include "builtin/Array.h"             // js::ArrayShiftMoveElements
     20 #include "builtin/MapObject.h"         // js::MapIteratorObject::next,
     21                                       // js::SetIteratorObject::next
     22 #include "builtin/Object.h"            // js::ObjectClassToString
     23 #include "builtin/RegExp.h"            // js::RegExpPrototypeOptimizableRaw,
     24                                       // js::RegExpInstanceOptimizableRaw
     25 #include "builtin/Sorting.h"           // js::ArraySortData
     26 #include "builtin/TestingFunctions.h"  // js::FuzzilliHash*
     27 #include "builtin/WeakMapObject.h"     // js::WeakMapObject::{get,has}Object
     28 #include "builtin/WeakSetObject.h"     // js::WeakSetObject::hasObject
     29 #include "irregexp/RegExpAPI.h"
     30 // js::irregexp::CaseInsensitiveCompareNonUnicode,
     31 // js::irregexp::CaseInsensitiveCompareUnicode,
     32 // js::irregexp::GrowBacktrackStack,
     33 // js::irregexp::IsCharacterInRangeArray
     34 
     35 #include "jit/ABIFunctions.h"
     36 #include "jit/Bailouts.h"  // js::jit::FinishBailoutToBaseline, js::jit::Bailout,
     37                           // js::jit::InvalidationBailout
     38 
     39 #include "jit/Ion.h"          // js::jit::LazyLinkTopActivation
     40 #include "jit/JitFrames.h"    // HandleException
     41 #include "jit/VMFunctions.h"  // Rest of js::jit::* functions.
     42 
     43 #include "js/CallArgs.h"     // JSNative
     44 #include "js/Conversions.h"  // JS::ToInt32
     45 // JSJitGetterOp, JSJitSetterOp, JSJitMethodOp
     46 #include "js/experimental/JitInfo.h"
     47 
     48 #include "proxy/Proxy.h"  // js::ProxyGetProperty
     49 
     50 #include "vm/ArgumentsObject.h"   // js::ArgumentsObject::finishForIonPure
     51 #include "vm/Interpreter.h"       // js::TypeOfObject
     52 #include "vm/NativeObject.h"      // js::NativeObject
     53 #include "vm/RegExpShared.h"      // js::ExecuteRegExpAtomRaw
     54 #include "vm/TypedArrayObject.h"  // js::TypedArraySortFromJit
     55 #include "wasm/WasmBuiltins.h"    // js::wasm::*
     56 
     57 #include "builtin/Boolean-inl.h"  // js::EmulatesUndefined
     58 
     59 namespace js {
     60 
     61 namespace wasm {
     62 
     63 class AnyRef;
     64 
     65 }  // namespace wasm
     66 
     67 namespace jit {
     68 
     69 // List of all ABI functions to be used with callWithABI. Each entry stores
     70 // the fully qualified name of the C++ function. This list must be sorted.
     71 #if JS_GC_PROBES
     72 #  define ABIFUNCTION_JS_GC_PROBES_LIST(_) _(js::jit::TraceCreateObject)
     73 #else
     74 #  define ABIFUNCTION_JS_GC_PROBES_LIST(_)
     75 #endif
     76 
     77 #if defined(JS_CODEGEN_ARM)
     78 #  define ABIFUNCTION_JS_CODEGEN_ARM_LIST(_) \
     79    _(__aeabi_idivmod)                       \
     80    _(__aeabi_uidivmod)
     81 #else
     82 #  define ABIFUNCTION_JS_CODEGEN_ARM_LIST(_)
     83 #endif
     84 
     85 #ifdef WASM_CODEGEN_DEBUG
     86 #  define ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_) \
     87    _(js::wasm::PrintF32)                        \
     88    _(js::wasm::PrintF64)                        \
     89    _(js::wasm::PrintI32)                        \
     90    _(js::wasm::PrintPtr)                        \
     91    _(js::wasm::PrintText)
     92 #else
     93 #  define ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_)
     94 #endif
     95 
     96 #ifdef FUZZING_JS_FUZZILLI
     97 #  define ABIFUNCTION_FUZZILLI_LIST(_) _(js::FuzzilliHashBigInt)
     98 #else
     99 #  define ABIFUNCTION_FUZZILLI_LIST(_)
    100 #endif
    101 
    102 #define ABIFUNCTION_LIST(_)                                                    \
    103  ABIFUNCTION_JS_GC_PROBES_LIST(_)                                             \
    104  ABIFUNCTION_JS_CODEGEN_ARM_LIST(_)                                           \
    105  ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_)                                       \
    106  _(js::ArgumentsObject::finishForIonPure)                                     \
    107  _(js::ArgumentsObject::finishInlineForIonPure)                               \
    108  _(js::ArrayShiftMoveElements)                                                \
    109  _(js::ArraySortData::sortArrayWithComparator)                                \
    110  _(js::ArraySortData::sortTypedArrayWithComparator)                           \
    111  _(js::ArraySortFromJit)                                                      \
    112  _(js::ecmaAtan2)                                                             \
    113  _(js::ecmaHypot)                                                             \
    114  _(js::ecmaPow)                                                               \
    115  _(js::EmulatesUndefined)                                                     \
    116  _(js::EmulatesUndefinedCheckFuse)                                            \
    117  _(js::ExecuteRegExpAtomRaw)                                                  \
    118  _(js::hypot3)                                                                \
    119  _(js::hypot4)                                                                \
    120  _(js::Interpret)                                                             \
    121  _(js::Int32ToStringPure)                                                     \
    122  _(js::irregexp::CaseInsensitiveCompareNonUnicode)                            \
    123  _(js::irregexp::CaseInsensitiveCompareUnicode)                               \
    124  _(js::irregexp::GrowBacktrackStack)                                          \
    125  _(js::irregexp::IsCharacterInRangeArray)                                     \
    126  _(js::jit::AllocateAndInitTypedArrayBuffer)                                  \
    127  _(js::jit::AllocateBigIntNoGC)                                               \
    128  _(js::jit::AllocateFatInlineString)                                          \
    129  _(js::jit::AllocateDependentString)                                          \
    130  _(js::jit::AssertMapObjectHash)                                              \
    131  _(js::jit::AssertPropertyLookup)                                             \
    132  _(js::jit::AssertSetObjectHash)                                              \
    133  _(js::jit::AssertValidBigIntPtr)                                             \
    134  _(js::jit::AssertValidObjectPtr)                                             \
    135  _(js::jit::AssertValidStringPtr)                                             \
    136  _(js::jit::AssertValidSymbolPtr)                                             \
    137  _(js::jit::AssertValidValue)                                                 \
    138  _(js::jit::AssumeUnreachable)                                                \
    139  _(js::jit::AtomicsStore64)                                                   \
    140  _(js::jit::AtomizeStringNoGC)                                                \
    141  _(js::jit::Bailout)                                                          \
    142  _(js::jit::BigIntNumberEqual<js::jit::EqualityKind::Equal>)                  \
    143  _(js::jit::BigIntNumberEqual<js::jit::EqualityKind::NotEqual>)               \
    144  _(js::jit::BigIntNumberCompare<js::jit::ComparisonKind::LessThan>)           \
    145  _(js::jit::NumberBigIntCompare<js::jit::ComparisonKind::LessThan>)           \
    146  _(js::jit::NumberBigIntCompare<js::jit::ComparisonKind::GreaterThanOrEqual>) \
    147  _(js::jit::BigIntNumberCompare<js::jit::ComparisonKind::GreaterThanOrEqual>) \
    148  _(js::jit::DateFillLocalTimeSlots)                                           \
    149  _(js::jit::EqualStringsHelperPure)                                           \
    150  _(js::jit::FinishBailoutToBaseline)                                          \
    151  _(js::jit::Float16ToFloat32)                                                 \
    152  _(js::jit::Float32ToFloat16)                                                 \
    153  _(js::jit::FrameIsDebuggeeCheck)                                             \
    154  _(js::jit::GetContextSensitiveInterpreterStub)                               \
    155  _(js::jit::GetIndexFromString)                                               \
    156  _(js::jit::GetInt32FromStringPure)                                           \
    157  _(js::jit::GetNativeDataPropertyPure)                                        \
    158  _(js::jit::GetNativeDataPropertyPureWithCacheLookup)                         \
    159  _(js::jit::GetNativeDataPropertyByValuePure)                                 \
    160  _(js::jit::GlobalHasLiveOnDebuggerStatement)                                 \
    161  _(js::jit::HandleCodeCoverageAtPC)                                           \
    162  _(js::jit::HandleCodeCoverageAtPrologue)                                     \
    163  _(js::jit::HandleException)                                                  \
    164  _(js::jit::HasNativeDataPropertyPure<false>)                                 \
    165  _(js::jit::HasNativeDataPropertyPure<true>)                                  \
    166  _(js::jit::HasNativeElementPure)                                             \
    167  _(js::jit::InitBaselineFrameForOsr)                                          \
    168  _(js::jit::InvalidationBailout)                                              \
    169  _(js::jit::InvokeFromInterpreterStub)                                        \
    170  _(js::jit::LazyLinkTopActivation)                                            \
    171  _(js::jit::LinearizeForCharAccessPure)                                       \
    172  _(js::jit::ObjectHasGetterSetterPure)                                        \
    173  _(js::jit::ObjectIsCallable)                                                 \
    174  _(js::jit::ObjectIsConstructor)                                              \
    175  _(js::jit::PostGlobalWriteBarrier)                                           \
    176  _(js::jit::PostWriteBarrier)                                                 \
    177  _(js::jit::PostWriteElementBarrier)                                          \
    178  _(js::jit::PreserveWrapper)                                                  \
    179  _(js::jit::Printf0)                                                          \
    180  _(js::jit::Printf1)                                                          \
    181  _(js::jit::ReadBarrier)                                                      \
    182  _(js::jit::StringFromCharCodeNoGC)                                           \
    183  _(js::jit::StringTrimEndIndex)                                               \
    184  _(js::jit::StringTrimStartIndex)                                             \
    185  _(js::jit::TypeOfNameObject)                                                 \
    186  _(js::jit::TypeOfEqObject)                                                   \
    187  _(js::jit::WrapObjectPure)                                                   \
    188  ABIFUNCTION_FUZZILLI_LIST(_)                                                 \
    189  _(js::MapIteratorObject::next)                                               \
    190  _(js::NativeObject::addDenseElementPure)                                     \
    191  _(js::NativeObject::growSlotsPure)                                           \
    192  _(js::NumberMod)                                                             \
    193  _(js::NumberToStringPure)                                                    \
    194  _(js::ObjectClassToString)                                                   \
    195  _(js::powi)                                                                  \
    196  _(js::ProxyGetProperty)                                                      \
    197  _(js::RoundFloat16)                                                          \
    198  _(js::SetIteratorObject::next)                                               \
    199  _(js::StringToNumberPure)                                                    \
    200  _(js::TypedArrayFillBigInt)                                                  \
    201  _(js::TypedArrayFillDouble)                                                  \
    202  _(js::TypedArrayFillFloat32)                                                 \
    203  _(js::TypedArrayFillInt32)                                                   \
    204  _(js::TypedArrayFillInt64)                                                   \
    205  _(js::TypedArraySetFromSubarrayInfallible)                                   \
    206  _(js::TypedArraySetInfallible)                                               \
    207  _(js::TypedArraySortFromJit)                                                 \
    208  _(js::TypeOfObject)                                                          \
    209  _(js::WeakMapObject::getObject)                                              \
    210  _(js::WeakMapObject::hasObject)                                              \
    211  _(js::WeakSetObject::hasObject)                                              \
    212  _(mozilla::SIMD::memchr16)                                                   \
    213  _(mozilla::SIMD::memchr2x16)                                                 \
    214  _(mozilla::SIMD::memchr2x8)                                                  \
    215  _(mozilla::SIMD::memchr8)
    216 
    217 // List of all ABI functions to be used with callWithABI, which are
    218 // overloaded. Each entry stores the fully qualified name of the C++ function,
    219 // followed by the signature of the function to be called. When the function
    220 // is not overloaded, you should prefer adding the function to
    221 // ABIFUNCTION_LIST instead. This list must be sorted with the name of the C++
    222 // function.
    223 #define ABIFUNCTION_AND_TYPE_LIST(_)                    \
    224  _(JS::ToInt32, int32_t (*)(double))                   \
    225  _(js::jit::RoundFloat16ToFloat32, float (*)(int32_t)) \
    226  _(js::jit::RoundFloat16ToFloat32, float (*)(float))   \
    227  _(js::jit::RoundFloat16ToFloat32, float (*)(double))
    228 
    229 // List of all ABI function signature which are using a computed function
    230 // pointer instead of a statically known function pointer.
    231 #define ABIFUNCTIONSIG_LIST(_)                      \
    232  _(AtomicsCompareExchangeFn)                       \
    233  _(AtomicsReadWriteModifyFn)                       \
    234  _(bool (*)(BigInt*, BigInt*))                     \
    235  _(bool (*)(BigInt*, double))                      \
    236  _(bool (*)(double, BigInt*))                      \
    237  _(float (*)(float))                               \
    238  _(JSJitGetterOp)                                  \
    239  _(JSJitMethodOp)                                  \
    240  _(JSJitSetterOp)                                  \
    241  _(JSNative)                                       \
    242  _(js::UnaryMathFunctionType)                      \
    243  _(void (*)(js::gc::StoreBuffer*, js::gc::Cell**)) \
    244  _(void (*)(JSRuntime * rt, JSObject * *objp))     \
    245  _(void (*)(JSRuntime * rt, JSString * *stringp))  \
    246  _(void (*)(JSRuntime * rt, Shape * *shapep))      \
    247  _(void (*)(JSRuntime * rt, wasm::AnyRef * refp))  \
    248  _(void (*)(JSRuntime * rt, Value * vp))
    249 
    250 // GCC warns when the signature does not have matching attributes (for example
    251 // [[nodiscard]]). Squelch this warning to avoid a GCC-only footgun.
    252 #if MOZ_IS_GCC
    253 #  pragma GCC diagnostic push
    254 #  pragma GCC diagnostic ignored "-Wignored-attributes"
    255 #endif
    256 
    257 #define DEF_TEMPLATE(fp)                      \
    258  template <>                                 \
    259  struct ABIFunctionData<decltype(&fp), fp> { \
    260    static constexpr bool registered = true;  \
    261  };
    262 ABIFUNCTION_LIST(DEF_TEMPLATE)
    263 #undef DEF_TEMPLATE
    264 
    265 #define DEF_TEMPLATE(fp, ...)                \
    266  template <>                                \
    267  struct ABIFunctionData<__VA_ARGS__, fp> {  \
    268    static constexpr bool registered = true; \
    269  };
    270 ABIFUNCTION_AND_TYPE_LIST(DEF_TEMPLATE)
    271 #undef DEF_TEMPLATE
    272 
    273 // Define a known list of function signatures.
    274 #define DEF_TEMPLATE(...)                        \
    275  template <>                                    \
    276  struct ABIFunctionSignatureData<__VA_ARGS__> { \
    277    static constexpr bool registered = true;     \
    278  };
    279 ABIFUNCTIONSIG_LIST(DEF_TEMPLATE)
    280 #undef DEF_TEMPLATE
    281 
    282 #if MOZ_IS_GCC
    283 #  pragma GCC diagnostic pop
    284 #endif
    285 
    286 }  // namespace jit
    287 }  // namespace js
    288 
    289 // Make sure that all names are fully qualified (or at least, are resolvable
    290 // within the toplevel namespace).
    291 //
    292 // Previously this was accomplished just by using `::fp` to force resolution
    293 // within the toplevel namespace, but (1) that prevented using templated
    294 // functions with more than one parameter (eg `void foo<T, U>`) because the
    295 // macro split on the comma and wrapping it in parens doesn't work because
    296 // `::(foo)` is invalid; and (2) that would only check the function name itself,
    297 // not eg template parameters.
    298 namespace check_fully_qualified {
    299 #define CHECK_NS_VISIBILITY(fp)                               \
    300  [[maybe_unused]] static constexpr decltype(&fp) MOZ_CONCAT( \
    301      fp_, __COUNTER__) = nullptr;
    302 ABIFUNCTION_LIST(CHECK_NS_VISIBILITY)
    303 #undef CHECK_NS_VISIBILITY
    304 }  // namespace check_fully_qualified
    305 
    306 #endif  // jit_VMFunctionList_inl_h