From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jussi Lahdenniemi Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Override Windows default Win-* key combinations when using Emacs Date: Thu, 14 Jan 2016 14:49:31 +0200 Organization: Aprikoodi Oy Message-ID: <5697995B.5010306@aprikoodi.fi> References: <568BBC58.50702@aprikoodi.fi> <83y4c43qkh.fsf@gnu.org> <5691667C.5000009@aprikoodi.fi> <838u3wkkvb.fsf@gnu.org> <5694E07E.8010005@aprikoodi.fi> <83fuy2kd2w.fsf@gnu.org> <56961607.2090504@aprikoodi.fi> <569634D6.6030404@aprikoodi.fi> <83oacpiial.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090000040506020105000208" X-Trace: ger.gmane.org 1452776074 7005 80.91.229.3 (14 Jan 2016 12:54:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Jan 2016 12:54:34 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 14 13:54:24 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aJhPz-0003Ax-87 for ged-emacs-devel@m.gmane.org; Thu, 14 Jan 2016 13:54:23 +0100 Original-Received: from localhost ([::1]:41799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJhPy-00051L-DJ for ged-emacs-devel@m.gmane.org; Thu, 14 Jan 2016 07:54:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJhPL-0004bG-33 for emacs-devel@gnu.org; Thu, 14 Jan 2016 07:53:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJhPH-00046F-K0 for emacs-devel@gnu.org; Thu, 14 Jan 2016 07:53:42 -0500 Original-Received: from nbjjceehcbh.turbo-smtp.net ([199.244.72.17]:18865) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1aJhPH-00045x-AX for emacs-devel@gnu.org; Thu, 14 Jan 2016 07:53:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aprikoodi.fi; s=turbo-smtp; x=1453380819; h=DomainKey-Signature: Received:Received:Subject:To:References:Cc:From:Organization: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: Content-Type; bh=t/3E/LKzbNYOhXADgVfIxcyni8ArA8hwsFQCXJGycuE=; b=dmeSgrWQr5od28YbLjK0mTJxNBCK6I+3BtgaqSuKPEWju4X39eRgkiybRyZeCL E7leqtpT0s5f/J4Lnv3LB+BouLHFdTzwbkivdkJCO+DSNgoL2Y+lzdLt0U6SFou0 pbzc5w5w9qXAvcWvsOZ7I2l3UHEZNGKQmvsCpn4H1klOA= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=turbo-smtp; d=aprikoodi.fi; h=Received:Received:X-TurboSMTP-Tracking:Subject:To:References:Cc:From:Organization:Message-ID:Date:User-Agent:MIME-Version:In-Reply-To:Content-Type; b=OyIcmM0Sh7luJRD+lsJwWIj84YGvZqoK3qLErkASZA0n/9r8o8akNzbzKgkQ5S kO14CKUfQy49cUh/hDp+QMeji7432aejUsv0pfSBNBbLhm5UooVItHmhMAAXzUSX qT1oLFlOBIeaMA8pJmTiQDCKxJW99zJqSa3L8CEiXdiFM=; Original-Received: (qmail 15622 invoked from network); 14 Jan 2016 12:49:36 -0000 Original-Received: from unknown (HELO ?192.168.100.12?) (authenticated@193.64.142.74) by turbo-smtp.com with SMTP; 14 Jan 2016 12:49:35 -0000 X-TurboSMTP-Tracking: 2734838549 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: <83oacpiial.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 199.244.72.17 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:198128 Archived-At: This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --------------090000040506020105000208 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 13.1.2016 17.57, Eli Zaretskii wrote: > If you can see in GDB where does this come from and show the > backtrace, that would be great. Failing that, let's leave Windows 9X > testing alone for a while (you can always test the fallback code by > forcefully failing one of the run-time tests for the newer versions) > and test only on W2K. We can return to the 9X problem later. I was able to get a GDB dump of this, after installing MinGW from 2009. The backtrace is attached. > I presume you built on a newer version of Windows and only ran on > Windows 9X? I don't think the build procedure supports 9X. Yes, exactly. >> Getting back to the original issue: I verified that my code works on >> Win2000. Unfortunately, I was not able to install NT4 on a VM, so I >> cannot verify the code on that. > > That's OK, W2K is good enough. Thanks. I *was* able to get NT4 installed finally as well, in a VM running inside a Win7 VM. However, even the official Emacs 24.5 release binary fails to work on NT4. It dies right at the start due to being unable to load its initialization files. I investigated the problem and found out that it resulted from NT4's MultiByteToWideChar function not supporting the MB_ERR_INVALID_CHARS flags. I made the flag conditional on the OS version, after which Emacs runs just fine on NT4. I'm attaching a patch that contains this fix, and the conditional use of _resetstkoflw (which is also not supported on NT4) as well. Also, I noticed that addpm.exe fails to load on a out-of-the-box NT4SP6, due to its dependency to a Shell32.dll version that ships with IE4. After installing IE4, addpm works. It's worth noting that directly installing IE6 on NT4 does NOT make addpm functional, as IE6 does not contain the shell update. My keyboard hooking code works on NT4 as well (although not on console mode due to the lack of the GetConsoleWindow function - I'll try to find a workaround for this). -- Jussi Lahdenniemi --------------090000040506020105000208 Content-Type: text/plain; charset=UTF-8; name="emacs-w98-crash.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="emacs-w98-crash.txt" #0 0xbff768a1 in ?? () from C:\WINDOWS\SYSTEM\KERNEL32.DLL #1 0x01232146 in emacs_abort () at ../../emacs/src/w32fns.c:9794 #2 0x01107bd5 in terminate_due_to_signal (sig=22, backtrace_limit=2147483647) at ../../emacs/src/emacs.c:401 #3 0x0118720a in die ( msg=0x14e9974 "XTYPE (a) == type && XUNTAG (a, type) == ptr", file=0x14e987c "../../emacs/src/lisp.h", line=1110) at ../../emacs/src/alloc.c:7063 #4 0x01103082 in make_lisp_ptr (ptr=0x2a3da84, type=Lisp_Vectorlike) at ../../emacs/src/lisp.h:1110 #5 0x01130714 in Fget_buffer_create (buffer_or_name=19694956) at ../../emacs/src/buffer.c:586 #6 0x011a9a9d in Ffuncall (nargs=2, args=0xd2ed64) at ../../emacs/src/eval.c:2693 #7 0x011f0c2b in exec_byte_code (bytestr=19694740, vector=19694757, maxdepth=26, args_template=0, nargs=0, args=0x0) at ../../emacs/src/bytecode.c:880 #8 0x011aa7c1 in funcall_lambda (fun=19694677, nargs=4, arg_vector=0xd2ef94) at ../../emacs/src/eval.c:2921 #9 0x011a9d13 in Ffuncall (nargs=5, args=0xd2ef90) at ../../emacs/src/eval.c:2742 #10 0x011a95b9 in call4 (fn=-11384880, arg1=23769076, arg2=23769076, arg3=23184, arg4=23184) at ../../emacs/src/eval.c:2577 #11 0x011d67ff in Fload (file=23769092, noerror=23184, nomessage=23184, nosuffix=23184, must_suffix=0) at ../../emacs/src/lread.c:1275 #12 0x011a9b9d in Ffuncall (nargs=5, args=0xd2f590) at ../../emacs/src/eval.c:2709 #13 0x011f0c2b in exec_byte_code (bytestr=20205940, vector=20205957, maxdepth=50, args_template=2, nargs=0, args=0xd2f730) at ../../emacs/src/bytecode.c:880 #14 0x011aa3aa in funcall_lambda (fun=20205917, nargs=0, arg_vector=0xd2f730) at ../../emacs/src/eval.c:2855 #15 0x011aa07b in apply_lambda (fun=20205917, args=0, count=3) at ../../emacs/src/eval.c:2794 #16 0x011a85a3 in eval_sub (form=24342443) at ../../emacs/src/eval.c:2211 #17 0x011a7b9b in Feval (form=24342443, lexical=0) at ../../emacs/src/eval.c:1988 #18 0x0110b9ff in top_level_2 () at ../../emacs/src/keyboard.c:1096 #19 0x011a636a in internal_condition_case (bfun=0x110b9dc , handlers=9072, hfun=0x110b424 ) at ../../emacs/src/eval.c:1309 #20 0x0110ba3f in top_level_1 (ignore=0) at ../../emacs/src/keyboard.c:1104 #21 0x011a59fd in internal_catch (tag=24120, func=0x110ba01 , arg=0) at ../../emacs/src/eval.c:1074 #22 0x0110b926 in command_loop () at ../../emacs/src/keyboard.c:1065 #23 0x0110af9f in recursive_edit_1 () at ../../emacs/src/keyboard.c:672 #24 0x0110b187 in Frecursive_edit () at ../../emacs/src/keyboard.c:743 #25 0x011090d9 in main (argc=2, argv=0x2610510) at ../../emacs/src/emacs.c:1667 --------------090000040506020105000208 Content-Type: text/plain; charset=UTF-8; name="0001-Windows-98-and-NT4-compatibility-fixes.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Windows-98-and-NT4-compatibility-fixes.patch" >From adaf947b7d045bbbc6b3fb7febd5e482abf0d28a Mon Sep 17 00:00:00 2001 From: Jussi Lahdenniemi Date: Thu, 14 Jan 2016 14:28:52 +0200 Subject: [PATCH] Windows 98 and NT4 compatibility fixes * w32.h: Add the variable multiByteToWideCharFlags * w32.c: MultiByteToWideChar flags conditional on OS * w32fns.c: Ditto, plus call _resetstkovflw through a function pointer --- src/w32.c | 15 +++++++++++---- src/w32.h | 1 + src/w32fns.c | 39 +++++++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/w32.c b/src/w32.c index 4770718..27a9fea 100644 --- a/src/w32.c +++ b/src/w32.c @@ -484,6 +484,7 @@ typedef DWORD (WINAPI *GetAdaptersInfo_Proc) ( int (WINAPI *pMultiByteToWideChar)(UINT,DWORD,LPCSTR,int,LPWSTR,int); int (WINAPI *pWideCharToMultiByte)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); +DWORD multiByteToWideCharFlags; /* ** A utility function ** */ static BOOL @@ -1550,7 +1551,7 @@ codepage_for_filenames (CPINFO *cp_info) int filename_to_utf16 (const char *fn_in, wchar_t *fn_out) { - int result = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, fn_in, -1, + int result = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, fn_in, -1, fn_out, MAX_PATH); if (!result) @@ -1641,7 +1642,7 @@ filename_from_ansi (const char *fn_in, char *fn_out) { wchar_t fn_utf16[MAX_PATH]; int codepage = codepage_for_filenames (NULL); - int result = pMultiByteToWideChar (codepage, MB_ERR_INVALID_CHARS, fn_in, -1, + int result = pMultiByteToWideChar (codepage, multiByteToWideCharFlags, fn_in, -1, fn_utf16, MAX_PATH); if (!result) @@ -9081,13 +9082,13 @@ check_windows_init_file (void) "not unpacked properly.\nSee the README.W32 file in the " "top-level Emacs directory for more information.", init_file_name, load_path); - needed = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, buffer, + needed = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, buffer, -1, NULL, 0); if (needed > 0) { wchar_t *msg_w = alloca ((needed + 1) * sizeof (wchar_t)); - pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, buffer, -1, + pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, buffer, -1, msg_w, needed); needed = pWideCharToMultiByte (CP_ACP, 0, msg_w, -1, NULL, 0, NULL, NULL); @@ -9275,6 +9276,7 @@ maybe_load_unicows_dll (void) (MultiByteToWideChar_Proc)GetProcAddress (ret, "MultiByteToWideChar"); pWideCharToMultiByte = (WideCharToMultiByte_Proc)GetProcAddress (ret, "WideCharToMultiByte"); + multiByteToWideCharFlags = MB_ERR_INVALID_CHARS; return ret; } else @@ -9304,6 +9306,11 @@ maybe_load_unicows_dll (void) pointers; no need for the LoadLibrary dance. */ pMultiByteToWideChar = MultiByteToWideChar; pWideCharToMultiByte = WideCharToMultiByte; + /* On NT 4.0, though, MB_ERR_INVALID_CHARS is not supported. */ + if (w32_major_version < 5) + multiByteToWideCharFlags = 0; + else + multiByteToWideCharFlags = MB_ERR_INVALID_CHARS; return LoadLibrary ("Gdi32.dll"); } } diff --git a/src/w32.h b/src/w32.h index 501056d..097241b 100644 --- a/src/w32.h +++ b/src/w32.h @@ -183,6 +183,7 @@ typedef int (WINAPI *MultiByteToWideChar_Proc)(UINT,DWORD,LPCSTR,int,LPWSTR,int) typedef int (WINAPI *WideCharToMultiByte_Proc)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); extern MultiByteToWideChar_Proc pMultiByteToWideChar; extern WideCharToMultiByte_Proc pWideCharToMultiByte; +extern DWORD multiByteToWideCharFlags; extern void init_environment (char **); extern void check_windows_init_file (void); diff --git a/src/w32fns.c b/src/w32fns.c index f3806a9..3778557 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -6984,12 +6984,12 @@ value of DIR as in previous invocations; this is standard Windows behavior. */) if (errno == ENOENT && filename_buf_w[MAX_PATH - 1] != 0) report_file_error ("filename too long", default_filename); } - len = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + len = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, SSDATA (prompt), -1, NULL, 0); if (len > 32768) len = 32768; prompt_w = alloca (len * sizeof (wchar_t)); - pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, SSDATA (prompt), -1, prompt_w, len); } else @@ -7002,12 +7002,12 @@ value of DIR as in previous invocations; this is standard Windows behavior. */) if (errno == ENOENT && filename_buf_a[MAX_PATH - 1] != 0) report_file_error ("filename too long", default_filename); } - len = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + len = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, SSDATA (prompt), -1, NULL, 0); if (len > 32768) len = 32768; prompt_w = alloca (len * sizeof (wchar_t)); - pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, SSDATA (prompt), -1, prompt_w, len); len = pWideCharToMultiByte (CP_ACP, 0, prompt_w, -1, NULL, 0, NULL, NULL); if (len > 32768) @@ -7489,10 +7489,10 @@ a ShowWindow flag: current_dir = ENCODE_FILE (current_dir); /* Cannot use filename_to_utf16/ansi with DOCUMENT, since it could be a URL that is not limited to MAX_PATH chararcters. */ - doclen = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + doclen = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, SSDATA (document), -1, NULL, 0); doc_w = xmalloc (doclen * sizeof (wchar_t)); - pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, SSDATA (document), -1, doc_w, doclen); if (use_unicode) { @@ -7507,12 +7507,12 @@ a ShowWindow flag: int len; parameters = ENCODE_SYSTEM (parameters); - len = pMultiByteToWideChar (CP_ACP, MB_ERR_INVALID_CHARS, + len = pMultiByteToWideChar (CP_ACP, multiByteToWideCharFlags, SSDATA (parameters), -1, NULL, 0); if (len > 32768) len = 32768; params_w = alloca (len * sizeof (wchar_t)); - pMultiByteToWideChar (CP_ACP, MB_ERR_INVALID_CHARS, + pMultiByteToWideChar (CP_ACP, multiByteToWideCharFlags, SSDATA (parameters), -1, params_w, len); params_w[len - 1] = 0; } @@ -8959,7 +8959,7 @@ add_tray_notification (struct frame *f, const char *icon, const char *tip, later versions support up to 128. */ if (nidw.cbSize == MYNOTIFYICONDATAW_V1_SIZE) { - tiplen = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + tiplen = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, tip, utf8_mbslen_lim (tip, 63), tipw, 64); if (tiplen >= 63) @@ -8967,7 +8967,7 @@ add_tray_notification (struct frame *f, const char *icon, const char *tip, } else { - tiplen = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + tiplen = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, tip, utf8_mbslen_lim (tip, 127), tipw, 128); if (tiplen >= 127) @@ -8986,7 +8986,7 @@ add_tray_notification (struct frame *f, const char *icon, const char *tip, { int slen; - slen = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + slen = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, msg, utf8_mbslen_lim (msg, 255), msgw, 256); if (slen >= 255) @@ -8999,7 +8999,7 @@ add_tray_notification (struct frame *f, const char *icon, const char *tip, } wcscpy (nidw.szInfo, msgw); nidw.uTimeout = timeout; - slen = pMultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, + slen = pMultiByteToWideChar (CP_UTF8, multiByteToWideCharFlags, title, utf8_mbslen_lim (title, 63), titlew, 64); if (slen >= 63) @@ -9670,6 +9670,11 @@ static PVOID except_addr; /* Stack overflow recovery. */ +/* MinGW headers don't declare this (should be in malloc.h). Also, + the function is not present pre-Win2000, so make the call through + a function pointer. */ +typedef int (__cdecl *_resetstkoflw_proc) (void); + /* Re-establish the guard page at stack limit. This is needed because when a stack overflow is detected, Windows removes the guard bit from the guard page, so if we don't re-establish that protection, @@ -9677,12 +9682,14 @@ static PVOID except_addr; void w32_reset_stack_overflow_guard (void) { - /* MinGW headers don't declare this (should be in malloc.h). */ - _CRTIMP int __cdecl _resetstkoflw (void); - + static _resetstkoflw_proc resetstkoflw; + if (resetstkoflw == NULL) + resetstkoflw = (_resetstkoflw_proc)GetProcAddress (GetModuleHandle ("msvcrt.dll"), + "_resetstkoflw"); /* We ignore the return value. If _resetstkoflw fails, the next stack overflow will crash the program. */ - (void)_resetstkoflw (); + if (resetstkoflw != NULL) + (void)resetstkoflw (); } static void -- 2.6.2 --------------090000040506020105000208--