summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-10-31 19:35:54 (GMT)
committerGitHub <noreply@github.com>2022-10-31 19:35:54 (GMT)
commit4702552885811d0af8f0e4545f494336801ad4dd (patch)
treea8d24ed97f3e4561bf79ce6d27bd46cba2ecb303 /Include
parent3b86538661038ee23d0be80bb7593e2e7856f059 (diff)
downloadcpython-4702552885811d0af8f0e4545f494336801ad4dd.zip
cpython-4702552885811d0af8f0e4545f494336801ad4dd.tar.gz
cpython-4702552885811d0af8f0e4545f494336801ad4dd.tar.bz2
gh-98610: Adjust the Optional Restrictions on Subinterpreters (GH-98618)
Previously, the optional restrictions on subinterpreters were: disallow fork, subprocess, and threads. By default, we were disallowing all three for "isolated" interpreters. We always allowed all three for the main interpreter and those created through the legacy `Py_NewInterpreter()` API. Those settings were a bit conservative, so here we've adjusted the optional restrictions to: fork, exec, threads, and daemon threads. The default for "isolated" interpreters disables fork, exec, and daemon threads. Regular threads are allowed by default. We continue always allowing everything For the main interpreter and the legacy API. In the code, we add `_PyInterpreterConfig.allow_exec` and `_PyInterpreterConfig.allow_daemon_threads`. We also add `Py_RTFLAGS_DAEMON_THREADS` and `Py_RTFLAGS_EXEC`.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/initconfig.h14
-rw-r--r--Include/cpython/pystate.h13
2 files changed, 19 insertions, 8 deletions
diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h
index 64748cf..6ce42b4 100644
--- a/Include/cpython/initconfig.h
+++ b/Include/cpython/initconfig.h
@@ -245,15 +245,25 @@ PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
typedef struct {
int allow_fork;
- int allow_subprocess;
+ int allow_exec;
int allow_threads;
+ int allow_daemon_threads;
} _PyInterpreterConfig;
+#define _PyInterpreterConfig_INIT \
+ { \
+ .allow_fork = 0, \
+ .allow_exec = 0, \
+ .allow_threads = 1, \
+ .allow_daemon_threads = 0, \
+ }
+
#define _PyInterpreterConfig_LEGACY_INIT \
{ \
.allow_fork = 1, \
- .allow_subprocess = 1, \
+ .allow_exec = 1, \
.allow_threads = 1, \
+ .allow_daemon_threads = 1, \
}
/* --- Helper functions --------------------------------------- */
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index 7996bd3..70c2342 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -11,16 +11,17 @@ is available in a given context. For example, forking the process
might not be allowed in the current interpreter (i.e. os.fork() would fail).
*/
-// We leave the first 10 for less-specific features.
-
/* Set if threads are allowed. */
-#define Py_RTFLAGS_THREADS (1UL << 10)
+#define Py_RTFLAGS_THREADS (1UL << 10)
+
+/* Set if daemon threads are allowed. */
+#define Py_RTFLAGS_DAEMON_THREADS (1UL << 11)
/* Set if os.fork() is allowed. */
-#define Py_RTFLAGS_FORK (1UL << 15)
+#define Py_RTFLAGS_FORK (1UL << 15)
-/* Set if subprocesses are allowed. */
-#define Py_RTFLAGS_SUBPROCESS (1UL << 16)
+/* Set if os.exec*() is allowed. */
+#define Py_RTFLAGS_EXEC (1UL << 16)
PyAPI_FUNC(int) _PyInterpreterState_HasFeature(PyInterpreterState *interp,