Prevent swap RAM for the swap area (mlock)

Is there a way to call a POSIX functionmlock from Python? The effect mlockis to disable the replacement of some objects.

I know that there are still problems associated with the protection of cryptographic keys, I just want to know how to keep them in RAM.

+3
source share
1 answer

For CPython, there is no good answer for this, which does not involve writing a Python C extension, since it mlockworks on pages, not objects. Even if you used ctypesto extract the necessary addresses and mlockused them through calls ctypes mlock, you will have some time determining when mlockand when munlock, you need to know the address and memory sizes of all protected data types; since it mlockworks on pages, you will need to carefully monitor how many objects are currently on any given page (because if you are simple mlockand munlockblind, and there are several things that need to be blocked on the page, the first munlockwill unlock all of them:mlock/munlock - a logical flag, it does not take into account the number of locks and unlocks).

, mlock, .

mmap memoryview (mmap , memoryview , ctypes mlock ), .

, Python , ; , (, ), , .

+3

Source: https://habr.com/ru/post/1609277/


All Articles