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/. */
7 #ifndef jit_ABIFunctions_h
8 #define jit_ABIFunctions_h
10 #include "jstypes.h" // JS_FUNC_TO_DATA_PTR
12 struct JS_PUBLIC_API JSContext
;
15 class JS_PUBLIC_API Value
;
21 // This class is used to ensure that all known targets of callWithABI are
22 // registered here. Otherwise, this would raise a static assertion at compile
24 template <typename Sig
, Sig fun
>
25 struct ABIFunctionData
{
26 static const bool registered
= false;
29 template <typename Sig
, Sig fun
>
31 void* address() const { return JS_FUNC_TO_DATA_PTR(void*, fun
); }
33 // If this assertion fails, you are likely in the context of a
34 // `callWithABI<Sig, fn>()` call. This error indicates that ABIFunction has
35 // not been specialized for `<Sig, fn>` by the time of this call.
37 // This can be fixed by adding the function signature to either
38 // ABIFUNCTION_LIST or ABIFUNCTION_AND_TYPE_LIST (if overloaded) within
39 // `ABIFunctionList-inl.h` and to add an `#include` statement of this header
40 // in the file which is making the call to `callWithABI<Sig, fn>()`.
41 static_assert(ABIFunctionData
<Sig
, fun
>::registered
,
42 "ABI function is not registered.");
45 template <typename Sig
>
46 struct ABIFunctionSignatureData
{
47 static const bool registered
= false;
50 template <typename Sig
>
51 struct ABIFunctionSignature
{
52 void* address(Sig fun
) const { return JS_FUNC_TO_DATA_PTR(void*, fun
); }
54 // If this assertion fails, you are likely in the context of a
55 // `DynamicFunction<Sig>(fn)` call. This error indicates that
56 // ABIFunctionSignature has not been specialized for `Sig` by the time of this
59 // This can be fixed by adding the function signature to ABIFUNCTIONSIG_LIST
60 // within `ABIFunctionList-inl.h` and to add an `#include` statement of this
61 // header in the file which is making the call to `DynamicFunction<Sig>(fn)`.
62 static_assert(ABIFunctionSignatureData
<Sig
>::registered
,
63 "ABI function signature is not registered.");
66 // This is a structure created to ensure that the dynamically computed
67 // function pointer is well typed.
69 // It is meant to be created only through DynamicFunction function calls. In
70 // extremelly rare cases, such as VMFunctions, it might be produced as a result
71 // of GetVMFunctionTarget.
77 bool CallAnyNative(JSContext
* cx
, unsigned argc
, JS::Value
* vp
);
78 const void* RedirectedCallAnyNative();
84 #endif /* jit_VMFunctions_h */