* Why do these mprotect always fail?
@ 2023-02-15 9:38 w6b7rk5yu4mt25v3
2023-02-15 9:43 ` w6b7rk5yu4mt25v3
0 siblings, 1 reply; 2+ messages in thread
From: w6b7rk5yu4mt25v3 @ 2023-02-15 9:38 UTC (permalink / raw)
To: cygwin, cygwin-developers
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Why do these mprotect always fail?
2023-02-15 9:38 Why do these mprotect always fail? w6b7rk5yu4mt25v3
@ 2023-02-15 9:43 ` w6b7rk5yu4mt25v3
0 siblings, 0 replies; 2+ messages in thread
From: w6b7rk5yu4mt25v3 @ 2023-02-15 9:43 UTC (permalink / raw)
To: cygwin, cygwin-developers
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-15 9:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15 9:38 Why do these mprotect always fail? w6b7rk5yu4mt25v3
2023-02-15 9:43 ` w6b7rk5yu4mt25v3
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).