This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Possible bug with mmap on XP?

Hash: SHA1

According to Dave Bodenstab on 2/2/2006 5:16 PM:
>   mmap(0,1500,PROT_EXEC|PROT_READ|PROT_WRITE,MAP_PRIVATE,<the fd>,0)
> I've found that changing the permissions (chmod +x) on the file being
> mmap'ed makes the problem go away.
> Is this the way things are supposed to work on XP?

Cygwin's behavior sounds reasonable to me - POSIX permits an
implementation to fail with EACCESS if the prot parameter requests writes
but filedes was not opened for writing, and permits failure with ENOTSUP
if a combination of prot flags is not supported.  But I see nothing in
POSIX that requires PROT_EXEC to either fail or succeed based on whether
filedes is tied to a file that has execute privileges, so you are treading
in unspecified waters.

> PS.  I have a test program that demonstrates this problem, but I wanted
> to ask if this is a known problem before I start posting test programs.

A test program would be very helpful.

> PPS.  If this is a limitation for XP, is there a way for a Cygwin program
> to tell if it's running on XP?

Yes, uname(2) can be used to give you an idea of what version of Windows
you are running on.

>   My program generates x86 machine code and writes it to a file.
>   The program then mmap's the file and executes the code.
>   The problem is that I want the file prepended with '#!/bin/myprog\n"
>   to be "executable", but I don't want a file with just the raw
>   x86 code to be "executable" -- because it isn't without being
>   run under control of my program that generated it.  This works
>   entirely correctly on Linux, FreeBSD and Solaris.

"works entirely correctly" is subjective, since there is no standards
document that requires it to either succeed or to fail.  However, since
cygwin strives to emulate Linux, I imagine Corinna will probably
investigate this further to see if it really is an inherent limitation of
XP.  And in the meantime, you have a workaround of marking files
executable that have executable bytes, even if they are not executable in

- --
Life is short - so eat dessert first!

Eric Blake   
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Thunderbird -


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]