Subject: Re: _get_osfhandle and/or mmap under cygwin.dll on NT?
From: [email-masked] (David Makepeace)

14 Jan 1997 14:56:13 -0800
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="------------651970E7330E"
X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.5 i86pc)
Original-To: Henry Minsky <[email-masked]>
Original-CC: [email-masked]
Original-Sender: [email-masked]

This is a multi-part message in MIME format.

--------------651970E7330E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Henry Minsky wrote:
> 
> Hi,
> 
> Does anyone know if mmap is supposed to work under the current (v B
> 17.1) cygwin.dll?  I get undefined symbol errors when I try to compile
> programs with calls to mmap().
> 
> If mmap() has not yet been implemented, I was given an implementation
> called mman.c written by a fellow in Australia, David Makepeace
> <[email-masked]>, which says it implements mmap using
> the Win32 memory mapping routines.

I plan to do a port of my basic mmap() support to gnu-win32 within the
next
few days and then start on a better implementation which will support
shared
memory IPC and address other limitations.  The new one will probably
live
inside cygwin.dll.

BTW, you probably have an old version of my mman.c which has a handle
leak in
munmap().

> I cannot compile this version of mmap under gcc on Windows NT,
> however, because it references a function called _get_osfhandle. This
> seems to be defined in the Microsoft LIBC, but not in the gnu-win32
> libraries. Can anyone tell me how to link with this function, or more
> generally how to link with a .lib or other object file produced by
> Mirosoft's compiler?
> 
> Thanks,
>         Henry

I have added _get_osfhandle() to my copy of cygwin.dll (patches
attached).

I have put io.h and binaries of cygwin.dll and libcygwin.a - based on
b17, not
b17.1 - (for anyone who wants them) in:

	http://www.uq.oz.au/~zzdmakep/pub/getosfh.zip

The zip file contains three files (io.h, cygwin.dll and libcygwin.a).
These should go in the following locations:

	\cygnus\H-i386-cygwin32\bin\cygwin.dll
	\cygnus\H-i386-cygwin32\i386-cygwin32\lib\libcygwin.a
	\cygnus\H-i386-cygwin32\i386-cygwin32\include\io.h

Back up your original copies of cygwin.dll and libcygwin.a and make sure
you are
not running any programs which use cygwin.dll (such as bash) when it
gets
overwritten.  e.g. Use COPY (not cp) to copy in the new cygwin.dll.

David.

---------------------------------------------------------------------
David Makepeace   Ph:  +61 7 3378 4299
KEAYS Software    Fax: +61 7 3378 7922   [email-masked]
---------------------------------------------------------------------

--------------651970E7330E
Content-Type: text/plain; charset=us-ascii; name="io.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="io.h"

#ifndef _IO_H_
#ifdef __cplusplus
extern "C" {
#endif
#define _IO_H_

long _get_osfhandle(int fd);

#ifdef __cplusplus
}
#endif
#endif /* _IO_H_ */

--------------651970E7330E
Content-Type: text/plain; charset=us-ascii; name="getosfh.pat"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="getosfh.pat"

*** syscalls.cc	Wed Dec 04 13:23:02 1996
--- syscalls.cc	Tue Dec 31 16:53:13 1996
***************
*** 1037,1042 ****
--- 1037,1060 ----
  	}
      }
    syscall_printf ("%d = ftruncate (%d, %d); \n", fd, length);
+ 
+   return res;
+ }
+ 
+ extern "C"
+ long
+ _get_osfhandle (int fd) 
+ {
+   long res = -1;
+ 
+   if (NOT_OPEN_FD(fd))
+     {
+       set_errno ( EBADF);
+     }
+   else
+     {
+       res = (long)u->self->hmap[fd].h->get_handle ();
+     }
  
    return res;
  }

*** cygwin.din	Sat Dec 07 08:38:58 1996
--- cygwin.din	Tue Dec 31 16:55:51 1996
***************
*** 938,940 ****
--- 938,941 ----
  cygwin32_posix_to_win32_path_list = posix_to_win32_path_list
  cygwin32_split_path = split_path
  __small_printf = small_printf__FPCce
+ _get_osfhandle

--------------651970E7330E--

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".