|
30 | 30 | #include "pycore_instruction_sequence.h" // _PyInstructionSequence_New() |
31 | 31 | #include "pycore_interpframe.h" // _PyFrame_GetFunction() |
32 | 32 | #include "pycore_jit.h" // _PyJIT_AddressInJitCode() |
33 | | -#include "pycore_jit_unwind.h" // DWRF_EH_PE_* constants |
34 | 33 | #include "pycore_object.h" // _PyObject_IsFreed() |
35 | 34 | #include "pycore_optimizer.h" // _Py_Executor_DependsOn |
36 | 35 | #include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal() |
@@ -2719,121 +2718,6 @@ _testinternalcapi_test_long_numbits_impl(PyObject *module) |
2719 | 2718 | Py_RETURN_NONE; |
2720 | 2719 | } |
2721 | 2720 |
|
2722 | | -#if defined(PY_HAVE_PERF_TRAMPOLINE) |
2723 | | -#include "trampoline_ehframe.h" |
2724 | | - |
2725 | | -/* Structural checks on the generated perf trampoline .eh_frame and the |
2726 | | - * field offsets Python/jit_unwind.c patches. Raises instead of assert() |
2727 | | - * so the checks also run in release builds. */ |
2728 | | -static PyObject * |
2729 | | -test_trampoline_ehframe(PyObject *self, PyObject *Py_UNUSED(args)) |
2730 | | -{ |
2731 | | -#define CHECK(cond, msg) \ |
2732 | | - do { \ |
2733 | | - if (!(cond)) { \ |
2734 | | - PyErr_SetString(PyExc_AssertionError, \ |
2735 | | - "trampoline_ehframe: " msg); \ |
2736 | | - return NULL; \ |
2737 | | - } \ |
2738 | | - } while (0) |
2739 | | - |
2740 | | - const uint8_t *data = _trampoline_ehframe; |
2741 | | - size_t size = TRAMPOLINE_EHFRAME_SIZE; |
2742 | | - size_t field_size = TRAMPOLINE_EHFRAME_FDE_FIELD_SIZE; |
2743 | | - |
2744 | | - CHECK(field_size == 4 || field_size == 8, "unsupported FDE field size"); |
2745 | | - CHECK(size >= 8 + 8 + 2 * field_size + 1, "data too small for a CIE and an FDE"); |
2746 | | - |
2747 | | - /* CIE: length, CIE_id == 0, version 1, augmentation "zR". */ |
2748 | | - uint32_t cie_length; |
2749 | | - memcpy(&cie_length, data, sizeof(cie_length)); |
2750 | | - CHECK(cie_length > 0 && cie_length < size, "bad CIE length"); |
2751 | | - |
2752 | | - uint32_t cie_id; |
2753 | | - memcpy(&cie_id, data + 4, sizeof(cie_id)); |
2754 | | - CHECK(cie_id == 0, "first entry is not a CIE"); |
2755 | | - |
2756 | | - CHECK(data[8] == 1, "CIE version is not 1"); |
2757 | | - CHECK(data[9] == 'z' && data[10] == 'R' && data[11] == '\0', |
2758 | | - "CIE augmentation is not \"zR\""); |
2759 | | - |
2760 | | - /* Exactly one FDE must follow the CIE, and the walk below must stay |
2761 | | - * inside the data. */ |
2762 | | - size_t cie_total = 4 + cie_length; |
2763 | | - CHECK(cie_total + 8 + 2 * field_size <= size, |
2764 | | - "no room for an FDE after the CIE"); |
2765 | | - |
2766 | | - /* FDE pointer encoding byte: skip version(1), "zR\0"(3), code_align |
2767 | | - * (ULEB128), data_align (SLEB128), RA column (1 byte in version 1), |
2768 | | - * augmentation data length (ULEB128). */ |
2769 | | - size_t pos = 12; |
2770 | | - while (pos < cie_total && (data[pos] & 0x80)) { /* code alignment */ |
2771 | | - pos++; |
2772 | | - } |
2773 | | - pos++; |
2774 | | - while (pos < cie_total && (data[pos] & 0x80)) { /* data alignment */ |
2775 | | - pos++; |
2776 | | - } |
2777 | | - pos++; |
2778 | | - pos++; /* RA column */ |
2779 | | - /* Augmentation data length (ULEB128) must be 1: the encoding byte. */ |
2780 | | - uint32_t aug_length = 0; |
2781 | | - int shift = 0; |
2782 | | - while (pos < cie_total && (data[pos] & 0x80)) { |
2783 | | - CHECK(shift < 28, "CIE augmentation data length is too long"); |
2784 | | - aug_length |= (uint32_t)(data[pos] & 0x7f) << shift; |
2785 | | - shift += 7; |
2786 | | - pos++; |
2787 | | - } |
2788 | | - CHECK(pos < cie_total, "CIE augmentation data length is truncated"); |
2789 | | - CHECK((uint32_t)(data[pos] & 0x7f) <= (UINT32_MAX >> shift), |
2790 | | - "CIE augmentation data length overflows"); |
2791 | | - aug_length |= (uint32_t)(data[pos] & 0x7f) << shift; |
2792 | | - pos++; |
2793 | | - CHECK(aug_length == 1 && pos < cie_total, |
2794 | | - "CIE augmentation data length is not 1"); |
2795 | | - uint8_t fde_enc = data[pos]; |
2796 | | - CHECK(fde_enc == (DWRF_EH_PE_pcrel | DWRF_EH_PE_sdata4) |
2797 | | - || fde_enc == (DWRF_EH_PE_pcrel | DWRF_EH_PE_absptr), |
2798 | | - "unsupported FDE pointer encoding"); |
2799 | | - size_t enc_field_size = (fde_enc & 0x0f) == DWRF_EH_PE_sdata4 ? 4 : 8; |
2800 | | - CHECK(enc_field_size == field_size, |
2801 | | - "FDE field size does not match the CIE pointer encoding"); |
2802 | | - |
2803 | | - /* The FDE ends exactly at the end of the data. */ |
2804 | | - uint32_t fde_length; |
2805 | | - memcpy(&fde_length, data + cie_total, sizeof(fde_length)); |
2806 | | - CHECK(fde_length > 0, "FDE length is zero"); |
2807 | | - CHECK(cie_total + 4 + fde_length == size, |
2808 | | - "FDE does not end at the end of the data"); |
2809 | | - |
2810 | | - /* The CIE pointer is the distance from its own field back to the CIE. */ |
2811 | | - uint32_t fde_cie_ptr; |
2812 | | - memcpy(&fde_cie_ptr, data + cie_total + 4, sizeof(fde_cie_ptr)); |
2813 | | - CHECK(fde_cie_ptr == cie_total + 4, "FDE CIE pointer does not point at the CIE"); |
2814 | | - |
2815 | | - /* The runtime patches initial_location and address_range at the |
2816 | | - * recorded offsets. They must be the two fields after the CIE pointer |
2817 | | - * and must be zeroed placeholders in the header. */ |
2818 | | - CHECK(TRAMPOLINE_EHFRAME_FDE_PC_OFFSET == cie_total + 8, |
2819 | | - "FDE initial_location offset is wrong"); |
2820 | | - CHECK(TRAMPOLINE_EHFRAME_FDE_RANGE_OFFSET |
2821 | | - == TRAMPOLINE_EHFRAME_FDE_PC_OFFSET + field_size, |
2822 | | - "FDE address_range offset is wrong"); |
2823 | | - for (size_t i = 0; i < 2 * field_size; i++) { |
2824 | | - CHECK(data[TRAMPOLINE_EHFRAME_FDE_PC_OFFSET + i] == 0, |
2825 | | - "FDE placeholder fields are not zero"); |
2826 | | - } |
2827 | | - /* The FDE's own augmentation data length must follow and be 0. */ |
2828 | | - size_t fde_aug_offset = TRAMPOLINE_EHFRAME_FDE_RANGE_OFFSET + field_size; |
2829 | | - CHECK(fde_aug_offset < size, "FDE augmentation data length byte is missing"); |
2830 | | - CHECK(data[fde_aug_offset] == 0, "FDE augmentation data length is not 0"); |
2831 | | - |
2832 | | -#undef CHECK |
2833 | | - Py_RETURN_NONE; |
2834 | | -} |
2835 | | -#endif /* PY_HAVE_PERF_TRAMPOLINE */ |
2836 | | - |
2837 | 2721 | static PyObject * |
2838 | 2722 | compile_perf_trampoline_entry(PyObject *self, PyObject *args) |
2839 | 2723 | { |
@@ -3469,9 +3353,6 @@ static PyMethodDef module_functions[] = { |
3469 | 3353 | {"interpreter_refcount_linked", interpreter_refcount_linked, METH_O}, |
3470 | 3354 | {"compile_perf_trampoline_entry", compile_perf_trampoline_entry, METH_VARARGS}, |
3471 | 3355 | {"perf_trampoline_set_persist_after_fork", perf_trampoline_set_persist_after_fork, METH_VARARGS}, |
3472 | | -#if defined(PY_HAVE_PERF_TRAMPOLINE) |
3473 | | - {"test_trampoline_ehframe", test_trampoline_ehframe, METH_NOARGS}, |
3474 | | -#endif |
3475 | 3356 | {"get_crossinterp_data", _PyCFunction_CAST(get_crossinterp_data), |
3476 | 3357 | METH_VARARGS | METH_KEYWORDS}, |
3477 | 3358 | {"restore_crossinterp_data", restore_crossinterp_data, METH_VARARGS}, |
|
0 commit comments