From 97099400e07abe17a5476fd3ecd5252436bde62c Mon Sep 17 00:00:00 2001 From: Dennis Kaarsemaker Date: Mon, 2 Nov 2020 20:10:25 +0100 Subject: [PATCH] Backwards compatibility fixes - Older pythons don't know EXT_SUFFIX - Linux 4.17-4.19 know PR_GET_SPECULATION_CTRL but not PR_SPEC_INDIRECT_BRANCH --- _prctlmodule.c | 10 ++++++++++ test_prctl.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/_prctlmodule.c b/_prctlmodule.c index 37c385b..f930953 100644 --- a/_prctlmodule.c +++ b/_prctlmodule.c @@ -177,7 +177,11 @@ prctl_prctl(PyObject *self, PyObject *args) #endif #ifdef PR_GET_SPECULATION_CTRL case(PR_SET_SPECULATION_CTRL): +#ifdef PR_SPEC_INDIRECT_BRANCH if(arg != PR_SPEC_STORE_BYPASS && arg != PR_SPEC_INDIRECT_BRANCH) { +#else + if(arg != PR_SPEC_STORE_BYPASS) { +#endif PyErr_SetString(PyExc_ValueError, "Invalid speculation control setting"); return NULL; } @@ -193,7 +197,11 @@ prctl_prctl(PyObject *self, PyObject *args) } /* Intentionally not breaking */ case(PR_GET_SPECULATION_CTRL): +#ifdef PR_SPEC_INDIRECT_BRANCH if(arg != PR_SPEC_STORE_BYPASS && arg != PR_SPEC_INDIRECT_BRANCH) { +#else + if(arg != PR_SPEC_STORE_BYPASS) { +#endif PyErr_SetString(PyExc_ValueError, "Invalid speculation control setting"); return NULL; } @@ -793,7 +801,9 @@ PyInit__prctl(void) #ifdef PR_SET_SPECULATION_CTRL namedattribute(SPECULATION_CTRL); namedconstant(PR_SPEC_STORE_BYPASS); +#ifdef PR_SPEC_INDIRECT_BRANCH namedconstant(PR_SPEC_INDIRECT_BRANCH); +#endif namedconstant(PR_SPEC_PRCTL); namedconstant(PR_SPEC_ENABLE); namedconstant(PR_SPEC_DISABLE); diff --git a/test_prctl.py b/test_prctl.py index 3084276..df84986 100644 --- a/test_prctl.py +++ b/test_prctl.py @@ -15,7 +15,7 @@ so = '.so' try: import sysconfig - so = sysconfig.get_config_var('EXT_SUFFIX') + so = sysconfig.get_config_var('EXT_SUFFIX') or sysconfig.get_config_var('SO') except ImportError: pass