This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] mingw port: Allow use of cvs GDB on Windows 95


  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  <muller@ics.u-strasbg.fr>

	* 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";




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]