From f2e10eb84ea608a534f47de7339839ecac021806 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 19 Apr 2024 18:45:13 -0700 Subject: [PATCH 1/4] Executors in the COLD_EXITS array are not GC'able Implement a `tp_is_gc` slot that tests for this. --- Python/optimizer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Python/optimizer.c b/Python/optimizer.c index bb537c9111a51f..ab343ff126a2c6 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -394,6 +394,15 @@ executor_traverse(PyObject *o, visitproc visit, void *arg) return 0; } +static int +executor_is_gc(PyObject *o) +{ + if ((void*)COLD_EXITS <= (void*)o && (void*)o < (void*)COLD_EXITS + UOP_MAX_TRACE_LENGTH) { + return 0; + } + return 1; +} + PyTypeObject _PyUOpExecutor_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) .tp_name = "uop_executor", @@ -405,6 +414,7 @@ PyTypeObject _PyUOpExecutor_Type = { .tp_methods = executor_methods, .tp_traverse = executor_traverse, .tp_clear = executor_clear, + .tp_is_gc = executor_is_gc, }; /* TO DO -- Generate these tables */ From e748e8a182d88cae65437bbb6a30df12e1910ad7 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 19 Apr 2024 21:39:12 -0700 Subject: [PATCH 2/4] Fix address arithmetic bug --- Python/optimizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/optimizer.c b/Python/optimizer.c index ab343ff126a2c6..9546bdf10cfb32 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -397,7 +397,7 @@ executor_traverse(PyObject *o, visitproc visit, void *arg) static int executor_is_gc(PyObject *o) { - if ((void*)COLD_EXITS <= (void*)o && (void*)o < (void*)COLD_EXITS + UOP_MAX_TRACE_LENGTH) { + if ((PyObject *)&COLD_EXITS[0] <= o && o < (PyObject *)&COLD_EXITS[UOP_MAX_TRACE_LENGTH]) { return 0; } return 1; From bb71ae9fdf698a4d51cb7c483f5b64c3b0d6fdf9 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 22 Apr 2024 08:32:01 -0700 Subject: [PATCH 3/4] Use correct COLD_EXITS upper bound --- Python/optimizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/optimizer.c b/Python/optimizer.c index 9546bdf10cfb32..5863336c0d9ecf 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -397,7 +397,7 @@ executor_traverse(PyObject *o, visitproc visit, void *arg) static int executor_is_gc(PyObject *o) { - if ((PyObject *)&COLD_EXITS[0] <= o && o < (PyObject *)&COLD_EXITS[UOP_MAX_TRACE_LENGTH]) { + if ((PyObject *)&COLD_EXITS[0] <= o && o < (PyObject *)&COLD_EXITS[COLD_EXIT_COUNT]) { return 0; } return 1; From 1653fe53c2addd6d7f9991d6ca11f2b1aac4f866 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 22 Apr 2024 08:34:37 -0700 Subject: [PATCH 4/4] Add blurb --- .../2024-04-22-08-34-28.gh-issue-118074.5_JnIa.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-22-08-34-28.gh-issue-118074.5_JnIa.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-22-08-34-28.gh-issue-118074.5_JnIa.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-22-08-34-28.gh-issue-118074.5_JnIa.rst new file mode 100644 index 00000000000000..69d29bce12ee57 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-22-08-34-28.gh-issue-118074.5_JnIa.rst @@ -0,0 +1,2 @@ +Make sure that the Executor objects in the COLD_EXITS array aren't assumed +to be GC-able (which would access bytes outside the object).