mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-47162: Add call trampoline to mitigate bad fpcasts on Emscripten (GH-32189)
This commit is contained in:
parent
795c00b91c
commit
581c4434de
8 changed files with 99 additions and 18 deletions
|
@ -242,6 +242,33 @@ extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
|
|||
|
||||
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *);
|
||||
|
||||
/* C function call trampolines to mitigate bad function pointer casts.
|
||||
*
|
||||
* Typical native ABIs ignore additional arguments or fill in missing
|
||||
* values with 0/NULL in function pointer cast. Compilers do not show
|
||||
* warnings when a function pointer is explicitly casted to an
|
||||
* incompatible type.
|
||||
*
|
||||
* Bad fpcasts are an issue in WebAssembly. WASM's indirect_call has strict
|
||||
* function signature checks. Argument count, types, and return type must
|
||||
* match.
|
||||
*
|
||||
* Third party code unintentionally rely on problematic fpcasts. The call
|
||||
* trampoline mitigates common occurences of bad fpcasts on Emscripten.
|
||||
*/
|
||||
#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)
|
||||
#define _PyCFunction_TrampolineCall(meth, self, args) \
|
||||
_PyCFunctionWithKeywords_TrampolineCall( \
|
||||
(*(PyCFunctionWithKeywords)(void(*)(void))meth), self, args, NULL)
|
||||
extern PyObject* _PyCFunctionWithKeywords_TrampolineCall(
|
||||
PyCFunctionWithKeywords meth, PyObject *, PyObject *, PyObject *);
|
||||
#else
|
||||
#define _PyCFunction_TrampolineCall(meth, self, args) \
|
||||
(meth)((self), (args))
|
||||
#define _PyCFunctionWithKeywords_TrampolineCall(meth, self, args, kw) \
|
||||
(meth)((self), (args), (kw))
|
||||
#endif // __EMSCRIPTEN__ && PY_CALL_TRAMPOLINE
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue