* execve() fails in a thread under 98/ME
@ 2001-07-14 12:16 Greg Smith
2001-07-14 12:42 ` Christopher Faylor
0 siblings, 1 reply; 5+ messages in thread
From: Greg Smith @ 2001-07-14 12:16 UTC (permalink / raw)
To: cygwin; +Cc: Fish
One of our developers has found a subtle bug due to the fact
that PAGE_GUARD is not valid for VirtualAlloc() under
Windows 98/ME. A testcase is provided below. I don't
have access to 98/ME so I haven't created the failure myself,
but I am assured it happens. I do know the testcase doesn't
fail under w2k.
Below are the developers comments.
Thanks, Greg
It's in Cygwin's code, but in all fairness it's probably not their fault. I
suspect this particular part of Cygwin was more than likely coded before
Microsoft corrected their documentation oversight.
You see, if you look at cygwin's "alloc_stack_hard_way" function (in source
module "dcrt0.cc"), you'll notice them doing:
if (!VirtualAlloc ((LPVOID) m.BaseAddress, 1, MEM_COMMIT,
PAGE_EXECUTE_READWRITE|PAGE_GUARD))
api_fatal ("fork: couldn't allocate new stack guard page %p, %E",
m.BaseAddress);
The only problem is, the "PAGE_GUARD" flag is not supported on Win9x/ME
platforms!
This is NOT mentioned anywhere in the *original* SDK documentation, but
apparently they've finally gotten around to correcting this oversight in their
latest version of the docs, because it now mentions it quite plainly in the
description of the VirtualAlloc function:
-------------------------------
[...]
PAGE_GUARD
Windows NT/2000 or later: Pages in the region become guard pages. Any attempt to
read from or write to a guard page causes the system to raise a
STATUS_GUARD_PAGE exception and turn off the guard page status. Guard pages thus
act as a one-shot access alarm.
PAGE_GUARD is a page protection modifier. An application uses it with one of the
other page protection modifiers, with one exception: it cannot be used with
PAGE_NOACCESS. When an access attempt leads the system to turn off guard page
status, the underlying page protection takes over.
If a guard page exception occurs during a system service, the service typically
returns a failure status indicator.
Windows 95/98/Me: To simulate this behavior, use PAGE_NOACCESS.
PAGE_NOACCESS
Disables all access to the committed region of pages. An attempt to read from,
write to, or execute in the committed region results in an access violation
exception, called a general protection (GP) fault.
[...]
-------------------------------
So Greg, could you mention this to them please? They need to either add some
Win9x specific code to dcrt0.cc or else change it to use PAGE_NOACCESS for
*all* platforms (in which case they'll have to catch the access violation
exception rather than the STATUS_GUARD_PAGE exception).
Test case:
$ cat shtest.c
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <setjmp.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <fcntl.h>
#include <termios.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>
#include <sys/utsname.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
typedef u_int8_t BYTE;
typedef pthread_attr_t ATTR;
typedef pthread_t TID;
ATTR detattr;
FILE* msgpiper;
FILE* msgpipew;
int herc_system (char *command)
{
extern char **environ;
int pid, status;
if (command == 0)
return 1;
pid = fork();
if (pid == -1)
return -1;
if (pid == 0) {
char *argv[4];
dup2(msgpiper, STDIN_FILENO);
dup2(fileno(msgpipew), STDOUT_FILENO);
dup2(fileno(msgpipew), STDERR_FILENO);
argv[0] = "sh";
argv[1] = "-c";
argv[2] = command;
argv[3] = 0;
execve("/bin/sh", argv, environ);
exit(127);
}
do {
if (waitpid(pid, &status, 0) == -1) {
if (errno != EINTR)
return -1;
} else
return status;
} while(1);
}
static void *panel_command (void *cmdline)
{
herc_system("ls -al");
return NULL;
}
#define CMD_SIZE 32767
#define initialize_detach_attr(pat) \
pthread_attr_init((pat)); \
pthread_attr_setdetachstate((pat),PTHREAD_CREATE_DETACHED)
typedef void*THREAD_FUNC(void*);
#define create_thread(ptid,pat,fn,arg) \
pthread_create(ptid,pat,(THREAD_FUNC*)&(fn),arg)
int main (int argc, char *argv[])
{
TID cmdtid;
BYTE cmdline[CMD_SIZE+1];
msgpiper = stdin;
msgpipew = stdout;
initialize_detach_attr (&detattr);
// panel_command("xxx");
create_thread (&cmdtid, &detattr, panel_command, cmdline);
sleep(3);
return 0;
}
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execve() fails in a thread under 98/ME
2001-07-14 12:16 execve() fails in a thread under 98/ME Greg Smith
@ 2001-07-14 12:42 ` Christopher Faylor
2001-07-15 19:39 ` Greg Smith
0 siblings, 1 reply; 5+ messages in thread
From: Christopher Faylor @ 2001-07-14 12:42 UTC (permalink / raw)
To: cygwin
On Sat, Jul 14, 2001 at 03:16:51PM -0400, Greg Smith wrote:
>One of our developers has found a subtle bug due to the fact
>that PAGE_GUARD is not valid for VirtualAlloc() under
>Windows 98/ME. A testcase is provided below. I don't
>have access to 98/ME so I haven't created the failure myself,
>but I am assured it happens. I do know the testcase doesn't
>fail under w2k.
>
>Below are the developers comments.
>
>Thanks, Greg
>
>
>It's in Cygwin's code, but in all fairness it's probably not their
>fault. I suspect this particular part of Cygwin was more than likely
>coded before Microsoft corrected their documentation oversight.
>
>You see, if you look at cygwin's "alloc_stack_hard_way" function (in
>source module "dcrt0.cc"), you'll notice them doing:
>
>
> if (!VirtualAlloc ((LPVOID) m.BaseAddress, 1, MEM_COMMIT,
> PAGE_EXECUTE_READWRITE|PAGE_GUARD))
> api_fatal ("fork: couldn't allocate new stack guard page %p, %E",
> m.BaseAddress);
>
>
>The only problem is, the "PAGE_GUARD" flag is not supported on Win9x/ME
>platforms!
alloc_stack_hard_way is executed when a fork is performed from something
other than the non-main thread. I doubt that this problem has anything
specifically to do with execve.
If PAGE_GUARD is not implemented for Windows 9x, then the "solution"
will be "don't do that on Windows 9x". I'll add a guard against this in
fork when I return from vacation. I'll have the fork fail with a ENOSYS
or something.
As the author of the original code, I'm not interested in trying to
kludge around this for Windows 9x. It was hard enough to get right in
its current form. However, I'll certainly, as always, accept patches.
cgf
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execve() fails in a thread under 98/ME
2001-07-14 12:42 ` Christopher Faylor
@ 2001-07-15 19:39 ` Greg Smith
2001-07-15 20:08 ` Christopher Faylor
0 siblings, 1 reply; 5+ messages in thread
From: Greg Smith @ 2001-07-15 19:39 UTC (permalink / raw)
To: cygwin
Yes, I understand. I can't help but contribute our developer's
analysis of your analysis :-)
(Patient): "Doctor! It hurts when I do this!"
(Doctor): "Well then don't do that!"
Someday maybe 9x will disappear; I shudder, though, when I think
what it might be replaced by.
We have decided, btw, that it is far easier to kludge our own code
rather than yours.
Greg
Christopher Faylor wrote:
> If PAGE_GUARD is not implemented for Windows 9x, then the "solution"
> will be "don't do that on Windows 9x". I'll add a guard against this in
> fork when I return from vacation. I'll have the fork fail with a ENOSYS
> or something.
>
> As the author of the original code, I'm not interested in trying to
> kludge around this for Windows 9x. It was hard enough to get right in
> its current form. However, I'll certainly, as always, accept patches.
>
> cgf
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execve() fails in a thread under 98/ME
2001-07-15 19:39 ` Greg Smith
@ 2001-07-15 20:08 ` Christopher Faylor
2001-07-15 20:43 ` Greg Smith
0 siblings, 1 reply; 5+ messages in thread
From: Christopher Faylor @ 2001-07-15 20:08 UTC (permalink / raw)
To: cygwin
On Sun, Jul 15, 2001 at 10:40:31PM -0400, Greg Smith wrote:
>Yes, I understand. I can't help but contribute our developer's
>analysis of your analysis :-)
>
> (Patient): "Doctor! It hurts when I do this!"
> (Doctor): "Well then don't do that!"
>[snip]
>We have decided, btw, that it is far easier to kludge our own code
>rather than yours.
(Patient): "Doctor! I don't have any money. I've been hanging around
your office, using your stethoscope and your blood pressure
monitor, leafing through your medical journals (taking some of
them home for my own library), asking your nurses for free
samples and bugging you for free medical advice. It hurts
when I do this!"
(Doctor): "I have limited time and a number of patients with more
serious illnesses and as your condition is not life threatening
in any way, I advise you not to do that. However, if you want
to research your condition in one of those medical journals and
suggest a course of treatment, I'll try to set aside some time to
analyze your findings and possibly write a prescription. Then
I'll also be able to easily treat the next gratis patient who
manifests the same symptom."
(Patient): "What unmitigated gall! Why should I help *you*? It's not
my job to be a doctor. Nurse! Gimme one of those tylenol
samples. The doctor gave me a headache."
cgf
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: execve() fails in a thread under 98/ME
2001-07-15 20:08 ` Christopher Faylor
@ 2001-07-15 20:43 ` Greg Smith
0 siblings, 0 replies; 5+ messages in thread
From: Greg Smith @ 2001-07-15 20:43 UTC (permalink / raw)
To: cygwin
Yes, touche` [ouch!!]. `Point' is well taken !!
Perhaps other developers can heed this problem and avoid it like
we did. Meanwhile, I do try to contribute what I can to make up
for the gall.
We *do*, actually, appreciate and sympathize with your efforts.
Now go and enjoy the rest of your vacation !!
Greg
Christopher Faylor wrote:
> (Patient): "What unmitigated gall! Why should I help *you*? It's not
> my job to be a doctor. Nurse! Gimme one of those tylenol
> samples. The doctor gave me a headache."
>
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-07-15 20:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-14 12:16 execve() fails in a thread under 98/ME Greg Smith
2001-07-14 12:42 ` Christopher Faylor
2001-07-15 19:39 ` Greg Smith
2001-07-15 20:08 ` Christopher Faylor
2001-07-15 20:43 ` Greg Smith
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).