From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26757 invoked by alias); 4 Feb 2011 13:06:50 -0000 Received: (qmail 26747 invoked by uid 22791); 4 Feb 2011 13:06:48 -0000 X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL,BAYES_20,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.157) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Feb 2011 13:06:41 +0000 Received: from md1.u-strasbg.fr (md1.u-strasbg.fr [IPv6:2001:660:2402::186]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id p14D6alv003823 for ; Fri, 4 Feb 2011 14:06:36 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms1.u-strasbg.fr [130.79.204.10]) by md1.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p14D6a2T055313 for ; Fri, 4 Feb 2011 14:06:36 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p14D6ZWF008872 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Fri, 4 Feb 2011 14:06:35 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Compte ICS" To: Subject: [RFC] mingw port: Allow use of cvs GDB on Windows 95 Date: Fri, 04 Feb 2011 13:06:00 -0000 Message-ID: <001201cbc46c$5b95b100$12c11300$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00056.txt.bz2 I wanted to test current GDB on windows 95 systems, but CancelIo function is not present in Windows 95 kernel32 DLL which leads to a failure at startup of GDB. According to http://www.codeguru.com/forum/showthread.php?t=80410 CancelIo calls can be emulated on windows 95. My patch simply installs a substitute that calls CloseHandle instead. I don't really care for remote serial connections on windows 95 machines, but the currently compiled GDB cannot be loaded on a windows 95 machine because CancelIo is assumed to be present. I tried to check the existing code to see if I should reopen the handle, but to me it rather seems that a call to CloseHandle is missing for the normal case... Indeed, CancelIo is called from ser_windows_close, and it seems that the handle cannot be used anymore. Does anyone use this serial connection? Is this handle still valid afterwards? Or should it be close inside ser_windows_close in all cases? In any case, the code should function unchanged for all systems that have CancelIo, and allows to use GDB on windows 95 again (even if I am not sure that serial communication will work...). Comments welcome, Pierre Muller 2011-02-04 Pierre Muller * src/gdb/ser-mingw.c (CancelIo): New macro for dynamically loaded DLL entry. (win95_cancelio): New function. (_initialize_ser_windows): Use LoadLirary/GetProcAddress to check for existence of CancelIo function in kernel32 and substitute with win95_cancelio if not found. Index: src/gdb/ser-mingw.c =================================================================== RCS file: /cvs/src/src/gdb/ser-mingw.c,v retrieving revision 1.26 diff -u -p -r1.26 ser-mingw.c --- src/gdb/ser-mingw.c 11 Jan 2011 21:53:23 -0000 1.26 +++ src/gdb/ser-mingw.c 3 Feb 2011 10:28:53 -0000 @@ -45,6 +45,21 @@ struct ser_windows_state HANDLE except_event; }; +/* CancelIo is not available for Windows 95 OS, + so we need to use LoadLibrary/GetProcAddress to avoid + a startup failure. */ +#define CancelIo dyn_CancelIo + +static BOOL WINAPI (*CancelIo) (HANDLE); + +/* Create a subtitute function for Windows 95, that + simply closes the handle. */ +static BOOL WINAPI +win95_cancelio (HANDLE h) +{ + return CloseHandle (h); +} + /* Open up a real live device for serial I/O. */ static int @@ -1208,8 +1223,21 @@ _initialize_ser_windows (void) WSADATA wsa_data; struct serial_ops *ops; - /* First register the serial port driver. */ + HMODULE hm = NULL; + + /* First find out if kernel32 exports CancelIo function. + If it doesn't use win95_cancelio substitute. */ + hm = LoadLibrary ("kernel32.dll"); + if (hm) + { + CancelIo = (void *) GetProcAddress (hm, "CancelIo"); + FreeLibrary (hm); + } + + if (!CancelIo) + CancelIo = (void *) win95_cancelio; + /* Now register the serial port driver. */ ops = XMALLOC (struct serial_ops); memset (ops, 0, sizeof (struct serial_ops)); ops->name = "hardwire";