delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/10/01/13:49:38

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
From: "David J. Fiddes" <D DOT J AT fiddes DOT surfaid DOT org>
To: "Cygwin" <cygwin AT sourceware DOT cygnus DOT com>
Subject: Fix to allow attempted run of non-Win32 EXEs
Date: Fri, 1 Oct 1999 18:46:31 +0100
Message-ID: <000101bf0c34$e59c6d50$2a84c389@fiddesenterprises.com>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Importance: Normal

------=_NextPart_000_0002_01BF0C3D.47625BF0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hi,

I have been trying to get RTEMS an embedded RTOS to build cleanly with
Cygwin. I ran into a nasty problem. When RTEMS is configuring itself for the
target processor it uses the standard autoconf process to test to see if the
compiler it has been asked to use works and is a cross compiler.

This test involves building a small EXE with the compiler and, if that
succeeds, attempting to run it. If the program runs then the compiler is
native(the normal route for most programs) if it fails to run then it is a
cross-compiler. Unfortunately due to the "flexibility" of NT's process
loader this causes interesting results when you try to load say a m68k
program... What happens is that NT figures out that it is not a PE, NE or
standard DOS EXE and concludes that it is a .COM and just loads the first
64K into memory and runs it. If you are lucky you get the "This program has
executed and invalid instruction" dialog...if you are unlucky it just hangs
in an infinte loop.

Of course on a unix/Linux box the OS is smart enough to reject the EXE.

Having tried the latest snapshot to see if that fixed it I have ended up
hacking the 20.1 source for cygwin so that it checks for the magic 'MZ' at
the start of each program passed to CreateProcess(). This assumes that each
EXE has a DOS stub. It is bound to slow down cygwin but it does allow RTEMS
to build properly.

I don't suppose that this(or a variant) could make it into the official
version... Even if the behaviour had to be turned on with CYGWIN= flag it
would be really useful.

thanks,
Dave

------=_NextPart_000_0002_01BF0C3D.47625BF0
Content-Type: application/octet-stream;
	name="cygwin-hack-19990902.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="cygwin-hack-19990902.diff"

*** spawn.cc.orig	Tue Dec 01 21:24:52 1998=0A=
--- spawn.cc	Thu Sep 02 22:09:47 1999=0A=
***************=0A=
*** 490,496 ****=0A=
        si.lpDesktop =3D wstname;=0A=
        /* force the new process to reread /etc/passwd and /etc/group */=0A=
        myself->uid =3D USHRT_MAX;=0A=
!       rc =3D CreateProcessAsUser (hToken,=0A=
  		       real_path,	/* image name - with full path */=0A=
  		       copy,	/* what was passed to exec */=0A=
  		       &sec_all_nih,	/* process security attrs */=0A=
--- 490,526 ----=0A=
        si.lpDesktop =3D wstname;=0A=
        /* force the new process to reread /etc/passwd and /etc/group */=0A=
        myself->uid =3D USHRT_MAX;=0A=
!       =0A=
!       /* carry out a quick and dirty hack to check that what we exec =
is an EXE */=0A=
!       HANDLE hnd =3D CreateFileA (real_path, =0A=
! 				GENERIC_READ,=0A=
! 				FILE_SHARE_READ | FILE_SHARE_WRITE,=0A=
! 				&sec_none_nih,=0A=
! 				OPEN_EXISTING,=0A=
! 				FILE_ATTRIBUTE_NORMAL,=0A=
! 				0);=0A=
!       if (hnd =3D=3D INVALID_HANDLE_VALUE)=0A=
! 	{=0A=
! 	  __seterrno ();=0A=
! 	  return -1;=0A=
! 	}=0A=
! =0A=
!       DWORD done;=0A=
! =0A=
!       char buf[3];=0A=
!       buf[0] =3D buf[1] =3D buf[2] =3D '\0';=0A=
!       if (! ReadFile (hnd, buf, sizeof (buf) - 1, &done, 0))=0A=
! 	{=0A=
! 	  CloseHandle (hnd);=0A=
! 	  __seterrno ();=0A=
! 	  return -1;=0A=
! 	}=0A=
! =0A=
!       CloseHandle (hnd);=0A=
! =0A=
!       if (buf[0] =3D=3D 'M' && buf[1] =3D=3D 'Z')=0A=
!         {=0A=
!           rc =3D CreateProcessAsUser (hToken,=0A=
  		       real_path,	/* image name - with full path */=0A=
  		       copy,	/* what was passed to exec */=0A=
  		       &sec_all_nih,	/* process security attrs */=0A=
***************=0A=
*** 501,509 ****=0A=
  		       0,	/* use current drive/directory */=0A=
  		       &si,=0A=
  		       &pi);=0A=
      }=0A=
    else=0A=
!     rc =3D CreateProcessA (real_path,	/* image name - with full path */=0A=
  		       copy,	/* what was passed to exec */=0A=
  		       &sec_all_nih,	/* process security attrs */=0A=
  		       &sec_all_nih,	/* thread security attrs */=0A=
--- 531,574 ----=0A=
  		       0,	/* use current drive/directory */=0A=
  		       &si,=0A=
  		       &pi);=0A=
+         }	       =0A=
+       else=0A=
+         {=0A=
+ 	  rc =3D 0; /* report an error */=0A=
+ 	}=0A=
      }=0A=
    else=0A=
!     {=0A=
!       /* carry out a quick and dirty hack to check that what we exec =
is an EXE */=0A=
!       HANDLE hnd =3D CreateFileA (real_path, =0A=
! 				GENERIC_READ,=0A=
! 				FILE_SHARE_READ | FILE_SHARE_WRITE,=0A=
! 				&sec_none_nih,=0A=
! 				OPEN_EXISTING,=0A=
! 				FILE_ATTRIBUTE_NORMAL,=0A=
! 				0);=0A=
!       if (hnd =3D=3D INVALID_HANDLE_VALUE)=0A=
! 	{=0A=
! 	  __seterrno ();=0A=
! 	  return -1;=0A=
! 	}=0A=
! =0A=
!       DWORD done;=0A=
! =0A=
!       char buf[3];=0A=
!       buf[0] =3D buf[1] =3D buf[2] =3D '\0';=0A=
!       if (! ReadFile (hnd, buf, sizeof (buf) - 1, &done, 0))=0A=
! 	{=0A=
! 	  CloseHandle (hnd);=0A=
! 	  __seterrno ();=0A=
! 	  return -1;=0A=
! 	}=0A=
! =0A=
!       CloseHandle (hnd);=0A=
! =0A=
!       if (buf[0] =3D=3D 'M' && buf[1] =3D=3D 'Z')=0A=
!         {=0A=
!           rc =3D CreateProcessA (real_path,	/* image name - with full =
path */=0A=
  		       copy,	/* what was passed to exec */=0A=
  		       &sec_all_nih,	/* process security attrs */=0A=
  		       &sec_all_nih,	/* thread security attrs */=0A=
***************=0A=
*** 513,519 ****=0A=
--- 578,591 ----=0A=
  		       0,	/* use current drive/directory */=0A=
  		       &si,=0A=
  		       &pi);=0A=
+         }	       =0A=
+       else=0A=
+         {=0A=
+ 	  rc =3D 0; /* report an error */=0A=
+ 	}=0A=
  =0A=
+     }=0A=
+     =0A=
    free (envblock);=0A=
  =0A=
    /* Set errno now so that debugging messages from it appear before our=0A=


------=_NextPart_000_0002_01BF0C3D.47625BF0
Content-Type: text/plain; charset=us-ascii

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
------=_NextPart_000_0002_01BF0C3D.47625BF0--

- Raw text -


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