On Feb 15 12:40, w6b7rk5yu4mt25v3 via Cygwin wrote:
> On Wednesday, February 15th, 2023 at 19:13, Corinna Vinschen wrote:
> > On Feb 15 11:14, w6b7rk5yu4mt25v3 via Cygwin wrote:
> > > Corinna Vinschen wrote:
> > > 
> > > > cygwin-developers is for developers woking on Cygwin itself, not for
> > > > developers using Cygwin to develop something else. I dropped the ML
> > > > from the recipient list.
> > > > 
> > > > And please don't top-post. Thanks.
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> > [...]
> > You're misunderstanding what PAGESIZE or PAGE_SIZE means. It's the
> > system page size used for mappings, and it's a fixed value defined by
> > the system and provided to you by the system headers and, especially,
> > sysconf(_SC_PAGE_SIZE).
> > 
> > It's NOT something you can just change and think the result will still
> > work. Especially given that mmap doesn't know that you changed a macro
> > in your application code...
> > 
> > > The problem is Cygwin
> > > is not fine with the particular value 4096 but the program needs the
> > > value to be exactly 4096.
> > 
> > 
> > Sorry, but that can't work. If the program actually demands it, it's
> > non-portable.
> 
> You misunderstood what I said.
> 
> It's really just a naming conflict and a coincident. On the context of
> the source code (it's an interpreter), PAGE_SIZE is indeed
> JIT_PAGE_SIZE (not the system page size, but the page size defined
> internally by the interpreter). On Linux, the name doesn't conflict.
> On Cygwin, I found on limits.h and cygwin/limits.h already defined
> PAGE_SIZE so it caused a naming conflict:
> 
> #define __PAGESIZE 65536
> #define PAGESIZE __PAGESIZE
> #define PAGE_SIZE PAGESIZE
> 
> But the problem not related to the naming conflict. If I renamed
> PAGE_SIZE to JIT_PAGE_SIZE, the problem is still there. The problem is
> Cygwin will not work with JIT_PAGE_SIZE = 4096. Please have a look at
> the code I posted. It will always error with "Unable to mprotect".

Again, it doesn't matter what your application is doing with PAGE_SIZE.
PAGE_SIZE in limits.h is a read-only value to inform your application
about the system page size.  Just because your application overwrites
PAGE_SIZE doesn't change the fact that the system's mmap uses the real
page size, i. e., 64K.

Look, let's make a Windows example:

Somewhere in the headers there's a definition

  # define MAX_PATH 260

This defines the maximum path length when using the Windows ANSI File
API, for instance, CreateFileA().

Now you go ahead and overwrite this value in your application:

  #undef MAX_PATH
  #define MAX_PATH 1024

Do you really think that the Windows functions will even notice that
you changed MAX_PATH in your application and they will suddenly happily
work with 1K paths?  No, they won't.

And it's, hopefully obviously, the same with mmap and mprotect.  Just
because you define your own PAGE_SIZE value doesn't mean the system will
even see this.  It will continue to use the real page size value, as
returned by sysconf(_SC_PAGE_SIZE), and mprotect will fail if the
address isn't given in multiples of sysconf(_SC_PAGE_SIZE).


Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to