| 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_ABIFunctions_h |
| 8 |
#define jit_ABIFunctions_h |
| 9 |
|
| 10 |
#include "jstypes.h" // JS_FUNC_TO_DATA_PTR |
| 11 |
|
| 12 |
struct JS_PUBLIC_API JSContext; |
| 13 |
|
| 14 |
namespace JS { |
| 15 |
class JS_PUBLIC_API Value; |
| 16 |
} |
| 17 |
|
| 18 |
namespace js { |
| 19 |
namespace jit { |
| 20 |
|
| 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 |
| 23 |
// time. |
| 24 |
template <typename Sig, Sig fun> |
| 25 |
struct ABIFunctionData { |
| 26 |
static const bool registered = false; |
| 27 |
}; |
| 28 |
|
| 29 |
template <typename Sig, Sig fun> |
| 30 |
struct ABIFunction { |
| 31 |
void* address() const { return JS_FUNC_TO_DATA_PTR(void*, fun); } |
| 32 |
|
| 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. |
| 36 |
// |
| 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."); |
| 43 |
}; |
| 44 |
|
| 45 |
template <typename Sig> |
| 46 |
struct ABIFunctionSignatureData { |
| 47 |
static const bool registered = false; |
| 48 |
}; |
| 49 |
|
| 50 |
template <typename Sig> |
| 51 |
struct ABIFunctionSignature { |
| 52 |
void* address(Sig fun) const { return JS_FUNC_TO_DATA_PTR(void*, fun); } |
| 53 |
|
| 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 |
| 57 |
// call. |
| 58 |
// |
| 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."); |
| 64 |
}; |
| 65 |
|
| 66 |
// This is a structure created to ensure that the dynamically computed |
| 67 |
// function pointer is well typed. |
| 68 |
// |
| 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. |
| 72 |
struct DynFn { |
| 73 |
void* address; |
| 74 |
}; |
| 75 |
|
| 76 |
#ifdef JS_SIMULATOR |
| 77 |
bool CallAnyNative(JSContext* cx, unsigned argc, JS::Value* vp); |
| 78 |
const void* RedirectedCallAnyNative(); |
| 79 |
#endif |
| 80 |
|
| 81 |
} // namespace jit |
| 82 |
} // namespace js |
| 83 |
|
| 84 |
#endif /* jit_VMFunctions_h */ |