This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


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

Re: strchr bug?



Sorry for my obtrusiveness. I've posted this two times but the message
got trashed somewhere on the way - may be due to mime-attachment.
I make one more try - this time as plain text.

Tor Lillqvist <tml@iki.fi> writes:

> Vadim Egorov writes:
>  > While porting ElectricFence to cygwin I encountered a problem
> 
> Great! Would it be possible to have a copy? (Luckily I got your
> message, as I earlier today was thinking of porting it to Win32
> myself...) (I assume your port doesn't rely on cygwin features, but
> would work as well on "mingw32".)
> 
> --tml
> 
Chris Faylor <cgf@cygnus.com> writes:

> Thanks for the bug report and especially for the test case.  I've
> forwarded this to our newlib development team and they've come up
> with a fix.  It is below.
> 
> 

Thanks, Chris. Now it works. 
For those who is interested I apply a patch for ElectricFence-2.1 
(from ftp://ftp.perens.com/pub/ElectricFence/)
The main idea was to replace mmap/mprotect calls with native
VirtualAlloc/VirualProtect because cygwin mmap calls 
malloc internally. 
By now it builds and seems to work for cygwin target -- don't
know about mingw32 (but for consistency sake it should also provide
strdup and company) -- with two limitations.
There is long lasting problem with win32 SEH and signals 
which causes eftest to hang - it's okay.
Next, without strchr patch posted by Chris Faylor to this thread
it quite useless - apps linked against it tend to crash at startup.

Any comments will be appreciated.
-- 
Regards,
Vadim Egorov 

===File ~/src/electric-fence-2.1.cygwin.diff================
diff -u3 -p ../electric-fence-2.1/Makefile ./Makefile
--- ../electric-fence-2.1/Makefile	Thu Mar 12 22:52:19 1998
+++ ./Makefile	Wed Nov 10 08:43:29 1999
@@ -11,6 +11,11 @@ MAN_INSTALL_DIR= /usr/man/man3
 PACKAGE_SOURCE= README libefence.3 Makefile efence.h \
 	efence.c page.c print.c eftest.c tstheap.c CHANGES COPYING
 
+IS_CYGWIN=$(findstring CYGWIN, $(shell uname -s))
+ifeq ($(IS_CYGWIN),CYGWIN)
+EXEEXT= .exe
+endif
+
 # Un-comment the following if you are running HP/UX.
 # CFLAGS= -Aa -g -D_HPUX_SOURCE -DPAGE_PROTECTION_VIOLATED_SIGNAL=SIGBUS
 
@@ -28,7 +33,7 @@ PACKAGE_SOURCE= README libefence.3 Makef
 
 OBJECTS= efence.o page.o print.o
 
-all:	libefence.a tstheap eftest
+all:	libefence.a tstheap$(EXEEXT) eftest$(EXEEXT)
 	@ echo
 	@ echo "Testing Electric Fence."
 	@ echo "After the last test, it should print that the test has PASSED."
@@ -45,7 +50,7 @@ install: libefence.a libefence.3
 	$(CHMOD) 644 $(MAN_INSTALL_DIR)/libefence.3
 
 clean:
-	- rm -f $(OBJECTS) tstheap.o eftest.o tstheap eftest libefence.a \
+	- rm -f $(OBJECTS) tstheap.o eftest.o tstheap$(EXEEXT) eftest$(EXEEXT) libefence.a \
 	 libefence.cat ElectricFence.shar
 
 roff:
@@ -61,12 +66,12 @@ libefence.a: $(OBJECTS)
 	- rm -f libefence.a
 	$(AR) crv libefence.a $(OBJECTS)
 
-tstheap: libefence.a tstheap.o
-	- rm -f tstheap
+tstheap$(EXEEXT): libefence.a tstheap.o
+	- rm -f tstheap$(EXEEXT)
 	$(CC) $(CFLAGS) tstheap.o libefence.a -o tstheap
 
-eftest: libefence.a eftest.o
-	- rm -f eftest
+eftest$(EXEEXT): libefence.a eftest.o
+	- rm -f eftest$(EXEEXT)
 	$(CC) $(CFLAGS) eftest.o libefence.a -o eftest
 
 $(OBJECTS) tstheap.o eftest.o: efence.h
Only in ./: cygwin
Common subdirectories: ../electric-fence-2.1/debian and ./debian
diff -u3 -p ../electric-fence-2.1/efence.c ./efence.c
--- ../electric-fence-2.1/efence.c	Mon Aug 16 20:36:48 1999
+++ ./efence.c	Thu Nov 04 08:41:36 1999
@@ -35,6 +35,14 @@
 #include <memory.h>
 #include <string.h>
 
+#ifdef __CYGWIN__
+#include <windows.h>
+static char cygwin_getenv_buffer[32];
+#define getenv(var) GetEnvironmentVariable((var), \
+                        cygwin_getenv_buffer, sizeof(cygwin_getenv_buffer))\
+                    ? cygwin_getenv_buffer : 0
+#endif /*__CYGWIN__*/
+
 #ifdef	malloc
 #undef	malloc
 #endif
Only in ./: electric-fence-2.1.cygwin.diff
diff -u3 -p ../electric-fence-2.1/page.c ./page.c
--- ../electric-fence-2.1/page.c	Wed Jun 16 16:50:35 1999
+++ ./page.c	Fri Nov 05 08:55:25 1999
@@ -6,6 +6,9 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
+#ifdef __CYGWIN__
+#include <windows.h>
+#endif
 
 /*
  * Lots of systems are missing the definition of PROT_NONE.
@@ -41,6 +44,18 @@ stringErrorReport(void)
 	return strerror(oserror());
 #elif ( defined(_AIX) )
 	return strerror(errno);
+#elif ( defined(__CYGWIN__) )
+        static char message_buffer[1024];
+        FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | 
+                       FORMAT_MESSAGE_IGNORE_INSERTS,
+                       NULL,
+                       GetLastError(),
+                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+                       message_buffer,
+                       sizeof(message_buffer)/sizeof(message_buffer[0]),
+                       NULL 
+            );
+        return message_buffer;
 #else
 	if ( errno > 0 && errno < sys_nerr )
 		return sys_errlist[errno];
@@ -52,6 +67,7 @@ stringErrorReport(void)
 /*
  * Create memory.
  */
+#ifndef __CYGWIN__
 #if defined(MAP_ANONYMOUS)
 void *
 Page_Create(size_t size)
@@ -136,6 +152,22 @@ Page_Create(size_t size)
 	return (void *)allocation;
 }
 #endif
+#else /* __CYGWIN__*/
+void *
+Page_Create(size_t size)
+{
+	caddr_t		allocation = startAddr;
+	allocation = (caddr_t) VirtualAlloc(0, (int)size + Page_Size(), 
+                                            MEM_RESERVE, PAGE_READWRITE);
+	allocation = (caddr_t) VirtualAlloc(allocation, (int)size, 
+                                            MEM_COMMIT, PAGE_READWRITE);
+	if ( allocation == 0 )
+                EF_Exit("VirtualAlloc failed: %s", stringErrorReport());
+
+        return (void *)allocation;
+}
+
+#endif /* __CYGWIN__*/
 
 static void
 mprotectFailed(void)
@@ -143,6 +175,7 @@ mprotectFailed(void)
 	EF_Exit("mprotect() failed: %s", stringErrorReport());
 }
 
+#ifndef __CYGWIN__
 void
 Page_AllowAccess(void * address, size_t size)
 {
@@ -162,6 +195,30 @@ Page_Delete(void * address, size_t size)
 {
 	Page_DenyAccess(address, size);
 }
+#else /*__CYGWIN__*/
+void
+Page_AllowAccess(void * address, size_t size)
+{
+        DWORD dw;
+        if ( !VirtualProtect(address, size, PAGE_READWRITE, &dw) )
+                mprotectFailed();
+}
+
+void
+Page_DenyAccess(void * address, size_t size)
+{
+        DWORD dw;
+        if ( !VirtualProtect(address, size, PAGE_NOACCESS, &dw) )
+                mprotectFailed();
+}
+
+void
+Page_Delete(void * address, size_t size)
+{
+        if ( !VirtualFree(address, size, MEM_DECOMMIT))
+		Page_DenyAccess(address, size);
+}
+#endif /*__CYGWIN__*/
 
 #if defined(_SC_PAGESIZE)
 size_t
diff -u3 -p ../electric-fence-2.1/tstheap.c ./tstheap.c
--- ../electric-fence-2.1/tstheap.c	Fri Jan 20 07:54:32 1995
+++ ./tstheap.c	Wed Nov 10 08:41:03 1999
@@ -3,6 +3,9 @@
 #include <math.h>
 #include <limits.h>
 #include "efence.h"
+#ifdef __CYGWIN__
+#define FAKE_DRAND48
+#endif
 
 /*
  * This is a simple program to exercise the allocator. It allocates and frees
============================================================



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


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