delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/07/15/12:20:17

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <1089908398.40f6aeaed7044@imp1-q.free.fr>
Date: Thu, 15 Jul 2004 18:19:58 +0200
From: Xavier Joubert <xavier DOT joubert AT free DOT fr>
To: cygwin AT cygwin DOT com
Subject: [BUG] mprotect() on Windows NT 5+
MIME-Version: 1.0
User-Agent: Internet Messaging Program (IMP) 3.2.1

---MOQ1089908398b552623037b9a2e42426cb7ade7d6e79
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Hello dear Cygwin developpers !


This is my first post here, so I would like to begin by sending you a big thank 
for Cygwin ! This is a great tool to port programs to Windows.


I think I found a bug in mprotect() implementation. This call is unable to set 
some protections (PROT_READ|PROT_WRITE for example) on a given memory area, 
while it can set some others (PROT_NONE or PROT_READ for example) on the same 
memory area. From my tests, it seems to happen only on WNT5+ (ie. Windows 2000 
and Windows XP - detailed results below).

I upgraded my whole Cygwin setup to confirm the problem is still alive. I also 
searched the web, FAQ, and ML archive without success before posting here.

I wrote a simple testcase to allow you to reproduce the bug. You'll find the 
source code as an attachement to this mail (to compile with "gcc -o 
testcase.exe testcase.c" and to run with "./testcase.exe"). This testcase 
allocate a block of memory with mmap(), fill it with memset(), plays with its 
protection with mprotect() and fill it again with memset().

I ran this test on various Windows flavour available around. Here are the 
results :

Windows OS                Lang   Result
------------------------- ------ ----------------------------------------
W98                       French OK
WNT4 SP6 (Workstation)    French OK
WNT4 SP6 (Server)         French OK
W2K SP4 (Professional)    French mprotect() (3) failed : Invalid argument
W2K SP4 (Advanced server) French mprotect() (3) failed : Invalid argument
WXP SP1 (Professional)    French mprotect() (3) failed : Invalid argument

Of course I'm ready to dig more if needed. But I really need some help since 
I'm not familiar with Cygwin source code, nor with Windows developpement.


For the curious, I discovered this bug while trying to support ARAnyM's m68k 
JIT compiler on Cygwin. ARAnyM (http://aranym.atari.org) is a free (GPLed) 
virtual Atari-compatible system.


Best Regards, and thanks in advance for any help,


Xavier
---MOQ1089908398b552623037b9a2e42426cb7ade7d6e79
Content-Type: text/plain; name="testcase.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="testcase.c"

I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1
ZGUgPHN5cy9tbWFuLmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUg
PGVycm5vLmg+CgppbnQgbWFpbih2b2lkKQp7Cgl2b2lkICphZGRyOwoJc2l6
ZV90IHNpemUsIHBhZ2Vfc2l6ZTsKCiAgICAgICAgcGFnZV9zaXplID0gZ2V0
cGFnZXNpemUoKTsKCXByaW50ZigiUGFnZSBzaXplIDogJWlcbiIsIChpbnQp
cGFnZV9zaXplKTsKICAgICAgICBzaXplID0gNiAqIChpbnQpcGFnZV9zaXpl
OwoKICAgICAgICBhZGRyID0gbW1hcCgoY2FkZHJfdCkwLAoJICAgICAgICAg
ICAgc2l6ZSwKCSAgICAgICAgICAgIChQUk9UX1JFQUQgfCBQUk9UX1dSSVRF
KSwKCSAgICAgICAgICAgIChNQVBfUFJJVkFURSB8IE1BUF9BTk9OWU1PVVMp
LAoJICAgICAgICAgICAgMCwKCSAgICAgICAgICAgIDApOwoJaWYgKGFkZHIg
PT0gTUFQX0ZBSUxFRCkKCXsKCQlwcmludGYoIm1tYXAoKSBmYWlsZWQgIVxu
Iik7CiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCX0KCXByaW50ZigiQWRk
cmVzcyAgIDogJVhcbiIsIChpbnQpYWRkcik7CgoJaWYgKG1lbXNldChhZGRy
LCAwLCBzaXplKSAhPSBhZGRyKQoJewoJCXByaW50ZigibWVtc2V0KCkgZmFp
bGVkICFcbiIpOwogICAgICAgICAgICAgICAgcmV0dXJuIDI7Cgl9CgoJaWYg
KG1wcm90ZWN0KChjYWRkcl90KWFkZHIsIHNpemUsIChQUk9UX05PTkUpKSAh
PSAwKQoJewoJCXByaW50ZigibXByb3RlY3QoKSAoMSkgZmFpbGVkIDogJXNc
biIsIHN0cmVycm9yKGVycm5vKSk7CiAgICAgICAgICAgICAgICByZXR1cm4g
MzsKCX0KCglpZiAobXByb3RlY3QoKGNhZGRyX3QpYWRkciwgc2l6ZSwgKFBS
T1RfUkVBRCkpICE9IDApCgl7CgkJcHJpbnRmKCJtcHJvdGVjdCgpICgyKSBm
YWlsZWQgOiAlc1xuIiwgc3RyZXJyb3IoZXJybm8pKTsKICAgICAgICAgICAg
ICAgIHJldHVybiAzOwoJfQoKCWlmIChtcHJvdGVjdCgoY2FkZHJfdClhZGRy
LCBzaXplLCAoUFJPVF9SRUFEIHwgUFJPVF9XUklURSkpICE9IDApCgl7CgkJ
cHJpbnRmKCJtcHJvdGVjdCgpICgzKSBmYWlsZWQgOiAlc1xuIiwgc3RyZXJy
b3IoZXJybm8pKTsKICAgICAgICAgICAgICAgIHJldHVybiAzOwoJfQoKCWlm
IChtZW1zZXQoYWRkciwgMSwgc2l6ZSkgIT0gYWRkcikKCXsKCQlwcmludGYo
Im1lbXNldCgpIGZhaWxlZCAhXG4iKTsKICAgICAgICAgICAgICAgIHJldHVy
biA0OwoJfQoKCXJldHVybiAwOwp9Cg==


---MOQ1089908398b552623037b9a2e42426cb7ade7d6e79
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019