From: SourceForge.net <no...@so...> - 2007-05-28 11:56:28
|
Bugs item #1674783, was opened at 2007-03-06 14:01 Message generated for change (Comment added) made by madwizard You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1674783&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: msys Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: jdrasch (jdrasch) Assigned to: Nobody/Anonymous (nobody) Summary: Problem with Vista 64 bit ( Initial Comment: Hi, Msys didn't work on Vista 64 bit in the 32 bit emulation environment (<windir>/syswow64/cmd.exe) After a research I found the following in the nabble forums. http://www.nabble.com/MSYS-and-Vista-64-tf3292881.html#a9183478 The cygwin folks have figured out that Vista's WOW64 works differently than XP's WOW64. This patch should fix it. #### ChangeSet #### 2007-01-22 22:12:41-08:00, ob@... Work around what appears to be a bug in Vista 64-bits. The problem is related to how fork passes information to the child. Basically the child_info struct * is put in the lpReserved2 field of the STARTUPINFO struct that gets passed to CreateProcess(). In all versions of Windows, the size of the data to be passed is in the cbReserved2 field of the same structure, excep on Vista 64-bits. It seems that WOW64 (the 32-bit emmulation layer of 64-bit Vista) expects the size of the data passed in lpReserved2 to be the first word in that same pointer, only it expects the size in "elements" of a BYTE[] and HANDLE[] arrays (the MS C runtime has this convention). We work around it by filling in the size as (sizeof struct)/5 and zero padding the end of the child_info_* structs. ==== rt/src/winsup/cygwin/child_info.h ==== 2007-01-22 22:12:39-08:00, ob@... +4 -1 pad the end of the child_info_* structs and change the zero at the beginning for a placeholder for the size. --- 1.3/rt/src/winsup/cygwin/child_info.h 2001-10-15 15:22:32 -07:00 +++ 1.4/rt/src/winsup/cygwin/child_info.h 2007-01-22 22:12:39 -08:00 @@ -29,7 +29,7 @@ enum class child_info { public: - DWORD zero[1]; // must be zeroed + DWORD msv_cnt; // size of struct on vista64, zero on others DWORD cb; // size of this record DWORD type; // type of record int cygpid; // cygwin pid of child process @@ -53,6 +53,7 @@ public: jmp_buf jmp; // where child will jump to void *stacktop; // location of top of parent stack void *stackbottom; // location of bottom of parent stack + char filler[4]; }; class fhandler_base; @@ -67,6 +68,7 @@ public: int envc; char **envp; HANDLE myself_pinfo; + char filler[4]; }; class child_info_spawn: public child_info @@ -74,6 +76,7 @@ class child_info_spawn: public child_inf public: cygheap_exec_info *moreinfo; HANDLE hexec_proc; + char filler[4]; child_info_spawn (): moreinfo (NULL) {} ~child_info_spawn () ==== rt/src/winsup/cygwin/dcrt0.cc ==== 2007-01-22 22:12:40-08:00, ob@... +1 -3 the child_info_* structs no longer have a zero at the beginning. --- 1.10/rt/src/winsup/cygwin/dcrt0.cc 2004-03-15 03:51:36 -08:00 +++ 1.11/rt/src/winsup/cygwin/dcrt0.cc 2007-01-22 22:12:40 -08:00 @@ -903,7 +903,6 @@ _dll_crt0 () if (GetEnvironmentVariable ("CYGWIN_TESTING", envbuf, sizeof (envbuf) - 1)) _cygwin_testing = 1; - char zeros[sizeof (fork_info->zero)] = {0}; #ifdef DEBUGGING strace.microseconds (); #endif @@ -924,8 +923,7 @@ _dll_crt0 () &hMainThread, 0, FALSE, DUPLICATE_SAME_ACCESS); GetStartupInfo (&si); - if (si.cbReserved2 >= EXEC_MAGIC_SIZE && - memcmp (fork_info->zero, zeros, sizeof (zeros)) == 0) + if (si.cbReserved2 >= EXEC_MAGIC_SIZE) { switch (fork_info->type) { ==== rt/src/winsup/cygwin/fork.cc ==== 2007-01-22 22:12:40-08:00, ob@... +2 -0 fill in the size of child_info_fork --- 1.4/rt/src/winsup/cygwin/fork.cc 2002-10-31 06:32:21 -08:00 +++ 1.5/rt/src/winsup/cygwin/fork.cc 2007-01-22 22:12:40 -08:00 @@ -430,6 +430,8 @@ fork_parent (HANDLE& hParent, dll *&firs init_child_info (PROC_FORK1, &ch, 1, subproc_ready); + ch.msv_cnt = (sizeof ch)/5; + ch.forker_finished = forker_finished; stack_base (ch); ==== rt/src/winsup/cygwin/sigproc.cc ==== 2007-01-22 22:12:40-08:00, ob@... +1 -0 fill in the size of child_info --- 1.5/rt/src/winsup/cygwin/sigproc.cc 2003-02-12 07:50:27 -08:00 +++ 1.6/rt/src/winsup/cygwin/sigproc.cc 2007-01-22 22:12:40 -08:00 @@ -849,6 +849,7 @@ init_child_info (DWORD chtype, child_inf { TRACE_IN; memset (ch, 0, sizeof *ch); + ch->msv_cnt = (sizeof *ch)/5; ch->cb = sizeof *ch; ch->type = chtype; ch->cygpid = pid; ==== rt/src/winsup/cygwin/spawn.cc ==== 2007-01-22 22:12:40-08:00, ob@... +1 -0 fill in the size of child_info_spawn --- 1.22/rt/src/winsup/cygwin/spawn.cc 2003-10-11 07:35:26 -07:00 +++ 1.23/rt/src/winsup/cygwin/spawn.cc 2007-01-22 22:12:40 -08:00 @@ -346,6 +346,7 @@ spawn_guts (HANDLE hToken, const char * STARTUPINFO si = {0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL}; child_info_spawn ciresrv; + ciresrv.msv_cnt = (sizeof ciresrv)/5; si.lpReserved2 = (LPBYTE) &ciresrv; si.cbReserved2 = sizeof (ciresrv); ---------------------------------------------------------------------- Comment By: madwizard (madwizard) Date: 2007-05-28 13:56 Message: Logged In: YES user_id=1729144 Originator: NO Because the WinAVR package uses some tools (make, sh, rm, mkdir etc.) built with MSYS I ran into the same bug on Vista 64. Because WinAVR uses MSYS 1.0.8 I modified the patch slightly but the code is largely the same in those files. However, this patch did not fix the problem and I found out the formula used for the msv_cnt field is wrong. See this topic on the MSDN forums: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=998172&SiteID=1 A quote: "A workaround (just as you have said) is writing (((sizeof_the_buffer - 4) / 5) + 2) as a DWORD value to the first 4 bytes of the buffer. Then the buffer will be copied without any alterations." I modified the patch to use (size - 4) / 5 + 2 and the problem was solved. Also, I do not see the point of those 4 byte 'filler' members in the different structures. Why are they included? I removed those as well as they did not seem to cause or solve any problems. Seeing as size / 5 produces a number less than (size - 4) / 5 + 2 I wonder if anyone has had success with this patch. In any case I think it should be corrected to the right formula. ---------------------------------------------------------------------- Comment By: jdrasch (jdrasch) Date: 2007-03-09 12:27 Message: Logged In: YES user_id=1723996 Originator: YES Hi, I finally set up an environment to build MSYS, so I did the patch myself. The originally described patch is not simply possible, as it is based on the actual cygwin code, therefore I did some research and changed the according sourcecode. I also fixed this so that only for Vista the needed changes in the child-info are applied. Tested on Win XP SP2, Vista 32bit and Vista 64bit. Patch is attached for Files: Index: src/winsup/cygwin/spawn.cc Index: src/winsup/cygwin/fork.cc Index: src/winsup/cygwin/winsup.h Index: src/winsup/cygwin/dcrt0.cc Index: src/winsup/cygwin/sigproc.cc Index: src/winsup/cygwin/child_info.h File Added: patch.txt ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1674783&group_id=2435 |