[M3commit] CVS Update: cm3

Jay K jay.krell at cornell.edu
Wed Aug 15 07:20:19 CEST 2012


diff inline and attached

Index: m3core.h
===================================================================
RCS file: /usr/cvs/cm3/m3-libs/m3core/src/m3core.h,v
retrieving revision 1.75
diff -u -r1.75 m3core.h
--- m3core.h    23 Jun 2012 07:08:25 -0000    1.75
+++ m3core.h    15 Aug 2012 05:17:30 -0000
@@ -461,8 +461,8 @@
 int __cdecl Unix__ftruncate(int fd, m3_off_t length);
 m3_off_t __cdecl Unix__lseek(int fd, m3_off_t offset, int whence);
 m3_off_t __cdecl Unix__tell(int fd);
-int __cdecl Unix__fcntl(int fd, int request, int arg);
-int __cdecl Unix__ioctl(int fd, int request, void* argp);
+int __cdecl Unix__fcntl(int fd, INTEGER request, void* arg);
+int __cdecl Unix__ioctl(int fd, INTEGER request, void* argp);
 int __cdecl Unix__mknod(const char* path, m3_mode_t mode, m3_dev_t dev);
 m3_mode_t __cdecl Unix__umask(m3_mode_t newmask);
 
Index: unix/Common/Uconstants.c
===================================================================
RCS file: /usr/cvs/cm3/m3-libs/m3core/src/unix/Common/Uconstants.c,v
retrieving revision 1.52
diff -u -r1.52 Uconstants.c
--- unix/Common/Uconstants.c    12 Jan 2011 07:00:34 -0000    1.52
+++ unix/Common/Uconstants.c    15 Aug 2012 05:17:31 -0000
@@ -208,6 +208,14 @@
 X(F_SETFD) /* Set close-on-exec flag */
 X(F_GETFL) /* Get fd status flags */
 X(F_SETFL) /* Set fd status flags */
+X(F_DUPFD)  /* Duplicate fd */
+X(F_GETFD)  /* Get close-on-exec flag */
+X(F_GETOWN) /* Set owner */
+X(F_SETOWN) /* Get owner */
+X(F_GETLK)  /* Get file lock */
+X(F_SETLK)  /* Set file lock */
+X(F_SETLKW) /* Set file lock and wait */
+X(FD_CLOEXEC)   /* Close file descriptor on exec() */
 
 Y(MSETUID, S_ISUID) /* set user id on execution */
 Y(MSETGID, S_ISGID) /* set group id on execution */
Index: unix/Common/Unix.i3
===================================================================
RCS file: /usr/cvs/cm3/m3-libs/m3core/src/unix/Common/Unix.i3,v
retrieving revision 1.37
diff -u -r1.37 Unix.i3
--- unix/Common/Unix.i3    23 Apr 2011 10:08:00 -0000    1.37
+++ unix/Common/Unix.i3    15 Aug 2012 05:17:31 -0000
@@ -50,11 +50,29 @@
 <*EXTERNAL "Unix__underscore_exit"*>PROCEDURE underscore_exit (i: int);
 
 (*CONST*)
-<*EXTERNAL "Unix__F_SETFD"*> VAR F_SETFD: int; (* Set close-on-exec flag *)
-<*EXTERNAL "Unix__F_GETFL"*> VAR F_GETFL: int; (* Get fd status flags *)
-<*EXTERNAL "Unix__F_SETFL"*> VAR F_SETFL: int; (* Set fd status flags *)
+<*EXTERNAL "Unix__F_DUPFD"*> VAR F_DUPFD: int;      (* Duplicate fd *)
+<*EXTERNAL "Unix__F_GETFD"*> VAR F_GETFD: int;      (* Get close-on-exec flag *)
+<*EXTERNAL "Unix__F_SETFD"*> VAR F_SETFD: int;      (* Set close-on-exec flag *)
+<*EXTERNAL "Unix__F_GETFL"*> VAR F_GETFL: int;      (* Get fd status flags *)
+<*EXTERNAL "Unix__F_SETFL"*> VAR F_SETFL: int;      (* Set fd status flags *)
+<*EXTERNAL "Unix__F_GETOWN"*> VAR F_GETOWN: int;    (* Set owner *)
+<*EXTERNAL "Unix__F_SETOWN"*> VAR F_SETOWN: int;    (* Get owner *)
+<*EXTERNAL "Unix__F_GETLK"*> VAR F_GETLK: int;      (* Get file lock *)
+<*EXTERNAL "Unix__F_SETLK"*> VAR F_SETLK: int;      (* Set file lock *)
+<*EXTERNAL "Unix__F_SETLKW"*> VAR F_SETLKW: int;    (* Set file lock and wait *)
+<*EXTERNAL "Unix__FD_CLOEXEC"*> VAR FD_CLOEXEC: int; (* Close file descriptor on exec() *)
+
+TYPE struct_flock = RECORD
+(* sorted by size and then name
+   This must match between Unix.i3 and UnixC.c. *)
+  l_len:    LONGINT := 0L;
+  l_start:  LONGINT := 0L;
+  l_pid:    INTEGER := 0;
+  l_type:   INTEGER := 0;
+  l_whence: INTEGER := 0;
+END;
 
-<*EXTERNAL "Unix__fcntl"*>PROCEDURE fcntl (fd, request, arg: int): int;
+<*EXTERNAL "Unix__fcntl"*>PROCEDURE fcntl (fd: int; request, arg: INTEGER): int;
 
 <*EXTERNAL "Unix__fsync"*>PROCEDURE fsync (fd: int): int;
 <*EXTERNAL "Unix__getdtablesize"*>PROCEDURE getdtablesize (): int;
@@ -65,7 +83,7 @@
 (*CONST*) <*EXTERNAL "Unix__FIONREAD"*> VAR FIONREAD: int;
 
 <*EXTERNAL "Unix__ioctl"*>
-PROCEDURE ioctl (d, request: int; argp: ADDRESS): int;
+PROCEDURE ioctl (d: int; request: INTEGER; argp: ADDRESS): int;
 
 <*EXTERNAL "Unix__lseek"*>
 PROCEDURE lseek (d: int; offset: off_t; whence: int): off_t;
Index: unix/Common/UnixC.c
===================================================================
RCS file: /usr/cvs/cm3/m3-libs/m3core/src/unix/Common/UnixC.c,v
retrieving revision 1.67
diff -u -r1.67 UnixC.c
--- unix/Common/UnixC.c    23 Apr 2011 10:08:00 -0000    1.67
+++ unix/Common/UnixC.c    15 Aug 2012 05:17:31 -0000
@@ -206,37 +206,71 @@
 
 #else
 
+typedef struct m3_flock_t {
+/* sorted by size and then name
+   This must match between Unix.i3 and UnixC.c. */
+  LONGINT len;
+  LONGINT start;
+  INTEGER pid;
+  INTEGER type;
+  INTEGER whence;
+} m3_flock_t;
+
 M3_DLL_EXPORT int __cdecl
-Unix__fcntl(int fd, int request, int arg)
+Unix__fcntl(int fd, INTEGER request, void* m3_arg)
 /* fcntl is actually fcntl(fd, request, ...).
  * Wrapper is needed on some systems to handle varargs.
  * See http://edoofus.blogspot.com/2008/08/interesting-bug-unbreaking-cvsupamd64.html.
  */
 {
-#ifdef __sun
-/*
- * This is to work around a bug in the Solaris-2 'libsocket' library 
+/* Errno preservation for success:
+ * work around a bug in the Solaris-2 'libsocket' library 
  * which redefines 'fcntl' in such a way as to zero out 'errno' if the
  * call is successful.
  * See m3-libs/m3core/src/unix/solaris-2-x/Unix.m3.
  */
     int e = errno;
-    int r = fcntl(fd, request, arg);
+    struct flock native_lock = { 0 };
+    m3_flock_t* m3_lock = { 0 };
+    void* native_arg = m3_arg;
+    int r = { 0 };
+
+    memset(&native_lock, 0, sizeof(native_lock));
+    if (m3_arg)
+    {
+      switch (request)
+      {
+      case F_GETLK: case F_SETLK: case F_SETLKW:
+        m3_lock = (m3_flock_t*)m3_arg;
+        native_lock.l_len = m3_lock->len;
+        native_lock.l_pid = m3_lock->pid;
+        native_lock.l_start = m3_lock->start;
+        native_lock.l_type = m3_lock->type;
+        native_lock.l_whence = m3_lock->whence;
+        native_arg = &native_lock;
+        break;
+      }
+    }
+    r = fcntl(fd, request, native_arg);
     if (r == 0)
         errno = e;
+   if (m3_lock)
+   {
+      m3_lock->len = native_lock.l_len;
+      m3_lock->pid = native_lock.l_pid;
+      m3_lock->start = native_lock.l_start;
+      m3_lock->type = native_lock.l_type;
+      m3_lock->whence = native_lock.l_whence;
+    }
     return r;
-#else
-    return fcntl(fd, request, arg);
-#endif
 }
 
 M3_DLL_EXPORT int __cdecl
-Unix__ioctl(int fd, int request, void* argp)
+Unix__ioctl(int fd, INTEGER request, void* argp)
 /* ioctl is varargs. See fcntl. */
 {
-#ifdef __sun
-/*
- * This is to work around a bug in the Solaris-2 'libsocket' library 
+/* Errno preservation for success:
+ * Work around a bug in the Solaris-2 'libsocket' library 
  * which redefines 'ioctl' in such a way as to zero out 'errno' if the
  * call is successful.
  * See m3-libs/m3core/src/unix/solaris-2-x/Unix.m3.
@@ -246,9 +280,6 @@
     if (r == 0)
         errno = e;
     return r;
-#else
-    return ioctl(fd, request, argp);
-#endif
 }
 
 #endif





> Date: Wed, 15 Aug 2012 07:18:56 +0000
> To: m3commit at elegosoft.com
> From: jkrell at elego.de
> Subject: [M3commit] CVS Update: cm3
> 
> CVSROOT:	/usr/cvs
> Changes by:	jkrell at birch.	12/08/15 07:18:56
> 
> Modified files:
> 	cm3/m3-libs/m3core/src/: m3core.h 
> 	./: m3core.h 
> 	cm3/m3-libs/m3core/src/unix/Common/: Uconstants.c Unix.i3 
> 	                                     UnixC.c 
> 
> Log message:
> 	add back:
> 	Unix.F_DUPFD
> 	Unix.F_GETFD
> 	Unix.F_GETOWN
> 	Unix.F_SETOWN
> 	Unix.F_GETLK
> 	Unix.F_SETLK
> 	Unix.F_SETLKW
> 	Unix.FD_CLOEXEC
> 	Unix.struct_flock idealized/portable sorted by size and then name,
> 	making len/start LONGINT
> 	
> 	change ioctl int request to INTEGER -- Darwin uses unsigned long
> 	change fnctl int request and arg from int to INTEGER
> 	no clear rationale to change request, but it is reasonable
> 	arg changed to accommodate GETLK/SETLK/SETKLW struct_flock
> 	expectation is a pointer will be passed via LOOPHOLE,
> 	and passing it as an int instead of INTEGER is wrong for 64bit systems
> 	
> 	In the C code, change fnctl and ioctl last parameter to void*
> 	void* vs. INTEGER, eh, if just passing it on, same thing really
> 	
> 	In Unix__fcntl:
> 	handle F_GETLK, F_SETLK, F_SETLKW in fnctl, via copy to/from portable struct
> 	not actually tested
> 	This was because someone complained about the loss
> 	of compatibility in m3core/src/unix.
> 	It probably works now.
> 	
> 	In Unix__fcntl, Unix__ioctl:
> 	make the #ifdef __sun errno preservation workaround not #ifdef'ed,
> 	on the principle that more #ifdef is worse; the workaround is present
> 	for all platforms now, it should be harmless where not needed
> 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3commit/attachments/20120815/bb580c16/attachment-0002.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 1.txt
URL: <http://m3lists.elegosoft.com/pipermail/m3commit/attachments/20120815/bb580c16/attachment-0002.txt>


More information about the M3commit mailing list