public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
From: w6b7rk5yu4mt25v3 <w6b7rk5yu4mt25v3@protonmail.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>,
	"cygwin-developers@cygwin.com" <cygwin-developers@cygwin.com>
Subject: Re: Why do these mprotect always fail?
Date: Wed, 15 Feb 2023 09:43:10 +0000	[thread overview]
Message-ID: <ruVqVpKyYTyh3m-4mzaAg2pyhJAqlamcbUYKB8ghh_LwAKIqpabv0LNqlt8_Owfzx0Hc6c1C6nJE4Czf4hod2ukAWe3b6p_WAaaGLPk7CI8=@protonmail.com> (raw)
In-Reply-To: <yxifinJpR7DQ4XDFwpYMrUknNpsg8wu5T1KYPeNIwjf3FL_lYou0whmzg-XCoFgYlcz96k0yEjkrxCOQOOTztnk_tvW7ZNi8_riHbsOn-ZU=@protonmail.com>

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.

      reply	other threads:[~2023-02-15  9:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15  9:38 w6b7rk5yu4mt25v3
2023-02-15  9:43 ` w6b7rk5yu4mt25v3 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ruVqVpKyYTyh3m-4mzaAg2pyhJAqlamcbUYKB8ghh_LwAKIqpabv0LNqlt8_Owfzx0Hc6c1C6nJE4Czf4hod2ukAWe3b6p_WAaaGLPk7CI8=@protonmail.com' \
    --to=w6b7rk5yu4mt25v3@protonmail.com \
    --cc=cygwin-developers@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).