-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do Not Allow Static Objects to be Deallocated #101265
Comments
Possible solutions:
(We'd probably hide the check behind one or more internal/static helper functions.)int _Py_IsStaticObject(PyObject *obj);
// or, in the respective Objects/*.c files:
int is_static_bytes(PyObject *obj);
int is_static_int(PyObject *obj);
int is_static_tuple(PyObject *obj);
... (For efficiency those could also be Check Address RangeAn "obvious" solution is to check if the pointer is in the address range of known static objects (e.g. Per Raymond Chen, for architectures with "flat" addressing and where the compiler's pointer-to-integer conversion produces the numeric value of the linear address, we can convert-then-compare for address ranges. So we'd add something to For architectures/compilers that don't support that, we'd have to do a linear search for the address. Check a Per-Object FlagFor every static object we would set a bit somewhere on the object indicating that it is static. Then we could check that. |
How is it done for Also I've lost track of the draft PR where Eddie's work is happening. Can someone link to it? |
|
Unless I missed something, deepfreeze does not generates static slice objects. |
Correct, there's no slice object in deepfreeze, it's these types:
Upstream we have In the Immortal PR, I added extra signaling by extending This gives us two options for strings, either guaranteeing a call to intern all static strings (through the interpreter initialization), or just adding an extra bit in the unicode state, say: |
The runtime currently has many objects that are statically defined. See Include/internal/pycore_global_objects.h. For the singletons, all instances of the type are statically defined. Otherwise only some instances are.
(affected types)
The following types are those that have only some statically defined instances (not counting deep-frozen objects):
int
bytes
str
tuple
Deepfreeze adds the following:
float
complex
[actually not added]slice
code
bytes
,int
,tuple
, &str
objects)The problem is that if
tp_dealloc()
for one of the affected types tries to free a static object then it will crash. We've set the refcount for such objects to a really high number to avoid this, but it is still possible. The risk rises a bit for immortal objects (see PEP 683).For all types with static objects, we need to add a check in
tp_dealloc()
to either fail or reset the refcount to the really high number. We already have a check like this for the singletons and forstr
. For the other types we need to identify if the object is static and respond accordingly. The catch is that identifying that can be expensive, which is problematic for types that are deallocated frequently.The text was updated successfully, but these errors were encountered: