* Bug in Win32 version of emacs on x64 machines
@ 2007-07-17 18:29 Eric Youngdale
2007-07-18 22:49 ` Jason Rumney
0 siblings, 1 reply; 3+ messages in thread
From: Eric Youngdale @ 2007-07-17 18:29 UTC (permalink / raw)
To: bug-gnu-emacs
If you are running the 32-bit version of emacs on a 64-bit machine with
a 64-bit version of windows, and the SHELL environment variable points
to a 64-bit executable, then M-x shell will cause emacs to crash.
The reason for this is that in w32proc.c, it starts checking the
executable to be loaded to see if it is a cygwin executable, but it
doesn't bother to check to see if it is a 64-bit executable or a 32-bit
executable and it assumes that the it can dereference structures as if
it were a 32-bit executable. This causes emacs to crash. The
quick-and-dirty fix is enclosed - basically restrict the test and see if
the executable type is x86 before doing the cygwin check.
This fix does work with VC6 - don't know about anything older, nor do I
know if anyone cares in this age.
Anyways, this fix seems to fix the problem I described above. I am also
playing with an x64 port of emacs - I just got it running - need to test
and resolve a few other potential problems before I worry about
submitting diffs....
*** w32proc.c.~1~ Sat Jan 20 23:18:15 2007
--- w32proc.c Tue Jul 17 13:46:42 2007
***************
*** 63,68 ****
--- 63,72 ----
#include "syssignal.h"
#include "w32term.h"
+ #ifndef IMAGE_FILE_MACHINE_AMD64
+ #define IMAGE_FILE_MACHINE_AMD64 0x8664 // AMD64 (K8)
+ #endif
+
#define RVA_TO_PTR(var,section,filedata) \
((void *)((section)->PointerToRawData
\
+ ((DWORD)(var) - (section)->VirtualAddress)
\
***************
*** 630,636 ****
executables use the OS/2 1.x format. */
IMAGE_DOS_HEADER * dos_header;
! IMAGE_NT_HEADERS * nt_header;
dos_header = (PIMAGE_DOS_HEADER) executable.file_base;
if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
--- 634,641 ----
executables use the OS/2 1.x format. */
IMAGE_DOS_HEADER * dos_header;
! IMAGE_NT_HEADERS32 * nt_header;
! IMAGE_NT_HEADERS64 * nt_header64;
dos_header = (PIMAGE_DOS_HEADER) executable.file_base;
if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
***************
*** 637,642 ****
--- 642,648 ----
goto unwind;
nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header +
dos_header->e_lfanew);
+ nt_header64 = (PIMAGE_NT_HEADERS64) ((char *) dos_header +
dos_header->e_lfanew);
if ((char *) nt_header > (char *) dos_header + executable.size)
{
***************
*** 650,678 ****
}
else if (nt_header->Signature == IMAGE_NT_SIGNATURE)
{
! /* Look for cygwin.dll in DLL import list. */
! IMAGE_DATA_DIRECTORY import_dir =
!
nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
! IMAGE_IMPORT_DESCRIPTOR * imports;
! IMAGE_SECTION_HEADER * section;
!
! section = rva_to_section (import_dir.VirtualAddress,
nt_header);
! imports = RVA_TO_PTR (import_dir.VirtualAddress, section,
executable);
!
! for ( ; imports->Name; imports++)
! {
! char * dllname = RVA_TO_PTR (imports->Name, section,
executable);
!
! /* The exact name of the cygwin dll has changed with
! various releases, but hopefully this will be reasonably
! future proof. */
! if (strncmp (dllname, "cygwin", 6) == 0)
{
! *is_cygnus_app = TRUE;
! break;
}
! }
!
/* Check whether app is marked as a console or windowed (aka
GUI) app. Accept Posix and OS2 subsytem apps as console
apps. */
--- 656,694 ----
}
else if (nt_header->Signature == IMAGE_NT_SIGNATURE)
{
! /* cygwin is 32-bit only right now. The code to check a
64-bit binary
! is slightly different. */
! if( nt_header->FileHeader.Machine == IMAGE_FILE_MACHINE_I386 )
! {
! /* Look for cygwin.dll in DLL import list. */
! IMAGE_DATA_DIRECTORY import_dir =
!
nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
! IMAGE_IMPORT_DESCRIPTOR * imports;
! IMAGE_SECTION_HEADER * section;
!
! section = rva_to_section (import_dir.VirtualAddress,
nt_header);
! imports = RVA_TO_PTR (import_dir.VirtualAddress, section,
executable);
!
! for ( ; imports->Name; imports++)
{
! char * dllname = RVA_TO_PTR (imports->Name, section,
executable);
!
! /* The exact name of the cygwin dll has changed with
! various releases, but hopefully this will be
reasonably
! future proof. */
! if (strncmp (dllname, "cygwin", 6) == 0)
! {
! *is_cygnus_app = TRUE;
! break;
! }
}
! }
! else if( nt_header64->FileHeader.Machine ==
IMAGE_FILE_MACHINE_AMD64 )
! {
! /* Ultimately if 64-bit cygwin ever becomes a reality, a
different
! set of checks need to be added here. For now, the stub
is present
! to allow for that possibility. */
! }
/* Check whether app is marked as a console or windowed (aka
GUI) app. Accept Posix and OS2 subsytem apps as console
apps. */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug in Win32 version of emacs on x64 machines
2007-07-17 18:29 Bug in Win32 version of emacs on x64 machines Eric Youngdale
@ 2007-07-18 22:49 ` Jason Rumney
2007-07-19 21:20 ` Bug in Lose32 " Richard Stallman
0 siblings, 1 reply; 3+ messages in thread
From: Jason Rumney @ 2007-07-18 22:49 UTC (permalink / raw)
To: Eric Youngdale
Eric Youngdale wrote:
> If you are running the 32-bit version of emacs on a 64-bit machine with
> a 64-bit version of windows, and the SHELL environment variable points
> to a 64-bit executable, then M-x shell will cause emacs to crash.
>
Thanks for the report and the patch.
I checked in a slightly different patch, as I noticed that the same
structure dereferencing problem exists with the is_gui check, though in
that case it won't cause a crash, just get it wrong.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug in Lose32 version of emacs on x64 machines
2007-07-18 22:49 ` Jason Rumney
@ 2007-07-19 21:20 ` Richard Stallman
0 siblings, 0 replies; 3+ messages in thread
From: Richard Stallman @ 2007-07-19 21:20 UTC (permalink / raw)
To: Jason Rumney, Eric.Youngdale; +Cc: bug-gnu-emacs
Thanks for fixing this problem. Meanwhile, I have fixed a bug in the
message subject. In hacker terminology, calling something a "win" is
a form of praise. We don't want to praise Microsoft Windows here.
Using Microsoft Windows is a problem -- you really need to defenestrate
your computers. Are you working towards that?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-07-19 21:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-17 18:29 Bug in Win32 version of emacs on x64 machines Eric Youngdale
2007-07-18 22:49 ` Jason Rumney
2007-07-19 21:20 ` Bug in Lose32 " Richard Stallman
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.