Why do these mprotect always fail?
w6b7rk5yu4mt25v3
w6b7rk5yu4mt25v3@protonmail.com
Wed Feb 15 09:43:10 GMT 2023
Almost forgot, PAGE_SIZE is set to 4096. This is a Linux application, when I compile on Cygwin it complained that PAGE_SIZE is redefined but the compilation was success nevertheless. Only when I run the application, I always exited with "Unable to mprotect".
Sent with Proton Mail secure email.
------- Original Message -------
On Wednesday, February 15th, 2023 at 16:38, w6b7rk5yu4mt25v3 <w6b7rk5yu4mt25v3@protonmail.com> wrote:
> mprotect 1:
>
> unsigned char* buffer;
> int32_t available, size;
>
> if(size > PAGE_SIZE) {
>
> factor = size / PAGE_SIZE + 1;
> }
> available = factor * PAGE_SIZE;
>
> if(posix_memalign((void**)&buffer, PAGE_SIZE, available)) {
> std::wcerr << L"Unable to allocate JIT memory!" << std::endl;
> exit(1);
> }
> if(mprotect(buffer, available, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) {
> std::wcerr << L"Unable to mprotect" << std::endl;
> exit(1);
> }
>
> mprotect 2:
>
> if(posix_memalign((void**)& buffer, PAGE_SIZE, PAGE_SIZE)) {
> std::wcerr << L"Unable to allocate JIT memory!" << std::endl;
> exit(1);
> }
>
> if(mprotect(buffer, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) {
> std::wcerr << L"Unable to mprotect" << std::endl;
> exit(1);
> }
>
>
> Sent with Proton Mail secure email.
More information about the Cygwin
mailing list