Open TysonAndre opened 2 years ago
The SHM_RDONLY flag is a no-op in TSRM/tsrm_win32.c, so it might also make sense to error and fail with a message saying it does nothing on windows
The SHM_RDONLY flag is a no-op in TSRM/tsrm_win32.c, so it might also make sense to error and fail with a message saying it does nothing on windows
Replacing it with VirtualProtect and mprotect similar to what opcache.protect_memory=1 does seems like a good alternative, which would work on both mmap and shmat with anonymous shared mappings (default, /dev/zero) where APC_MEMPROTECT only worked with named files
Refer to https://github.com/TysonAndre/immutable_cache-pecl/pull/11/files for how this might be implemented (though I expect APCu would be more complicated, e.g. have edge cases for cache clears) - this would be done by moving locks/mutexes into a separate shared memory region (go from n -> n+1 regions) (because acquiring mutexes requires the ability to write to shared memory)
Currently, I assume it'd be manually set with
-DAPC_MEMPROTECT=1
, but I wouldn't recommend that since I assume nobody has used this in years?It may be of use to have a way to mark the returned pointers as read-only (to crash as early as possible instead of having applications misbehave when memory is being used in a way it shouldn't, e.g. due to bugs in pecls or unserializers)