Fix off_t args on FreeBSD
diff --git a/ChangeLog b/ChangeLog
index 87ad2d5..1785bd2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2001-03-07  John Hughes <john@Calva.COM>
+
+  * defs.h: add ALIGN64 macro to cope with FreeBSD's strange insistence
+    on alignment for off_t (64 bit) arguments.  Also simplify get64 so
+    we don't need to know endianness of long long.
+  * file.c: FreeBSD now uses 64 bit versions of lseek, truncate,
+    ftruncate, allows reduction in numvber of horrid #if's
+  * io.c: FreeBSD now uses 64 bit versions of pread, pwrite.
+  * mem.c: FreeBSD now uses 64 bit version of mmap.
+  * freebsd/syscalls.print: use 64 bit versions of various syscalls.
+  * freebsd/i386/syscall.h: use 64 bit versions of various syscalls.
+  * freebsd/i386/syscallent.h: use 64 bit versions of various syscalls.
+
 2001-03-06  John Hughes <john@Calva.COM>
 
   * file.c: Implement truncate64 and ftruncate64
diff --git a/defs.h b/defs.h
index ba65f84..1b967cc 100644
--- a/defs.h
+++ b/defs.h
@@ -497,14 +497,38 @@
 extern int nsignals2;
 #endif /* SUPPORTED_PERSONALITIES >= 3 */
 
-#if _LFS64_LARGEFILE
+#if FREEBSD
+/* ARRGH!  off_t args are aligned on 64 bit boundaries! */
+#define ALIGN64(tcp,arg)						\
+do {									\
+	if (arg % 2)							\
+	    memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1],		\
+		     (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]);	\
+} while (0)
+#else
+#define ALIGN64(tcp,arg) do { } while (0)
+#endif
+
+#if _LFS64_LARGEFILE || FREEBSD
+
 /* _l refers to the lower numbered u_arg,
  * _h refers to the higher numbered u_arg
  */
-#if _LITTLE_ENDIAN || I386	/* FIXME! */
+
+#if 1
+/* This should work, assuming we can do non-aligned 64 bit fetches.
+ * if not we'll have to figure out how which of the other versions to use.
+ */
+
+#define get64(_l,_h) (*(long long *) &(_l))
+
+#else
+
+#if _LITTLE_ENDIAN
 #define get64(_l,_h) ((long long)((unsigned long long)(_l) | ((unsigned long long)(_h)<<32)))
 #else
 #define get64(_l,_h) ((long long)((unsigned long long)(_h) | ((unsigned long long)(_l)<<32)))
 #endif
 #endif
+#endif
 
diff --git a/file.c b/file.c
index 090d78d..d2eac9c 100644
--- a/file.c
+++ b/file.c
@@ -350,6 +350,7 @@
 	{ 0,		NULL		},
 };
 
+#ifndef FREEBSD
 int
 sys_lseek(tcp)
 struct tcb *tcp;
@@ -359,30 +360,17 @@
 
 	if (entering(tcp)) {
 		tprintf("%ld, ", tcp->u_arg[0]);
-#ifndef FREEBSD
 		offset = tcp->u_arg[1];
 		_whence = tcp->u_arg[2];
 		if (_whence == SEEK_SET)
 			tprintf("%lu, ", offset);
 		else
 			tprintf("%ld, ", offset);		
-#else /* FREEBSD */
-		offset = ((off_t) tcp->u_arg[1] << 32) +  tcp->u_arg[2];
-		_whence = tcp->u_arg[4];
-		if (_whence == SEEK_SET)
-			tprintf("%llu, ", offset);
-		else
-			tprintf("%lld, ", offset);		
-#endif		
 		printxval(whence, _whence, "SEEK_???");
 	} 
-#ifdef FREEBSD
-	else
-		if (!syserror(tcp))
-			return RVAL_LUDECIMAL;
-#endif /* FREEBSD */
 	return RVAL_UDECIMAL;
 }
+#endif
 
 #ifdef linux
 int
@@ -411,13 +399,15 @@
 }
 #endif
 
-#if _LFS64_LARGEFILE
+#if _LFS64_LARGEFILE || FREEBSD
 int
 sys_lseek64 (tcp)
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
-		long long offset = get64(tcp->u_arg [1], tcp->u_arg[2]);
+		long long offset;
+		ALIGN64 (tcp, 1);	/* FreeBSD aligns off_t args */
+		offset = get64(tcp->u_arg [1], tcp->u_arg[2]);
 		if (tcp->u_arg[3] == SEEK_SET)
 			tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
 		else
@@ -428,27 +418,26 @@
 }
 #endif
 
+#ifndef FREEBSD
 int
 sys_truncate(tcp)
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
 		printpath(tcp, tcp->u_arg[0]);
-#ifndef FREEBSD
 		tprintf(", %lu", tcp->u_arg[1]);
-#else
-		tprintf(", %llu", ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
-#endif		
 	}
 	return 0;
 }
+#endif
 
-#if _LFS64_LARGEFILE
+#if _LFS64_LARGEFILE || FREEBSD
 int
 sys_truncate64(tcp)
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
+		ALIGN64 (tcp, 1);
 		printpath(tcp, tcp->u_arg[0]);
 		tprintf(", %llu", get64(tcp->u_arg[1],tcp->u_arg[2]));
 	}
@@ -456,27 +445,25 @@
 }
 #endif
 
+#ifndef FREEBSD
 int
 sys_ftruncate(tcp)
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
-#ifndef FREEBSD
 		tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
-#else
-		tprintf("%ld, %llu", tcp->u_arg[0],
-			((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
-#endif		
 	}
 	return 0;
 }
+#endif
 
-#if _LFS64_LARGEFILE
+#if _LFS64_LARGEFILE || FREEBSD
 int
 sys_ftruncate64(tcp)
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
+		ALIGN64 (tcp, 1);
 		tprintf("%ld, %llu", tcp->u_arg[0],
 			get64(tcp->u_arg[1] ,tcp->u_arg[2]));
 	}
diff --git a/freebsd/i386/syscall.h b/freebsd/i386/syscall.h
index 244d01a..2d7c50d 100644
--- a/freebsd/i386/syscall.h
+++ b/freebsd/i386/syscall.h
@@ -1,5 +1,5 @@
 /*
- * Automatically generated by ./../syscalls.pl on Fri Sep  1 17:43:23 2000
+ * Automatically generated by ./../syscalls.pl on Wed Mar  7 12:22:58 2001
  */
 
 #define sys_syscall printargs
@@ -20,7 +20,7 @@
 int sys_chown();
 #define sys_break printargs
 #define sys_getfsstat printargs
-int sys_lseek();
+int sys_lseek64();
 int sys_getpid();
 #define sys_mount printargs
 #define sys_unmount printargs
@@ -70,7 +70,7 @@
 int sys_vfork();
 int sys_sbrk();
 #define sys_sstk printargs
-int sys_mmap();
+int sys_mmap64();
 #define sys_vadvise printargs
 int sys_munmap();
 int sys_mprotect();
@@ -121,8 +121,8 @@
 int sys_setreuid();
 int sys_setregid();
 int sys_rename();
-int sys_truncate();
-int sys_ftruncate();
+int sys_truncate64();
+int sys_ftruncate64();
 int sys_flock();
 int sys_mkfifo();
 int sys_sendto();
@@ -155,8 +155,8 @@
 #define sys_semsys printargs
 #define sys_msgsys printargs
 #define sys_shmsys printargs
-int sys_pread();
-int sys_pwrite();
+int sys_pread64();
+int sys_pwrite64();
 #define sys_ntp_adjtime printargs
 #define sys_setgid printargs
 #define sys_setegid printargs
@@ -169,11 +169,11 @@
 int sys_getrlimit();
 int sys_setrlimit();
 int sys_getdirentries();
-int sys_mmap();
+int sys_mmap64();
 #define sys___syscall printargs
-int sys_lseek();
-int sys_truncate();
-int sys_ftruncate();
+int sys_lseek64();
+int sys_truncate64();
+int sys_ftruncate64();
 int sys___sysctl();
 #define sys_mlock printargs
 #define sys_munlock printargs
@@ -184,7 +184,6 @@
 #define sys___semctl printargs
 int sys_semget();
 int sys_semop();
-#define sys_semconfig printargs
 int sys_msgctl();
 int sys_msgget();
 int sys_msgsnd();
@@ -271,3 +270,5 @@
 #define sys_aio_waitcomplete printargs
 #define sys_getresuid printargs
 #define sys_getresgid printargs
+#define sys_kqueue printargs
+#define sys_kevent printargs
diff --git a/freebsd/i386/syscallent.h b/freebsd/i386/syscallent.h
index 17f67bc..f8b1e4e 100644
--- a/freebsd/i386/syscallent.h
+++ b/freebsd/i386/syscallent.h
@@ -1,5 +1,5 @@
 /*
- * Automatically generated by ./../syscalls.pl on Fri Sep  1 17:43:23 2000
+ * Automatically generated by ./../syscalls.pl on Wed Mar  7 12:22:58 2001
  */
 
   { 1,	0,	sys_syscall,	"syscall"	}, /* 0 */
@@ -21,7 +21,7 @@
   { 3,	TF,	sys_chown,	"chown"	}, /* 16 */
   { 1,	0,	sys_break,	"break"	}, /* 17 */
   { 3,	0,	sys_getfsstat,	"getfsstat"	}, /* 18 */
-  { 3,	0,	sys_lseek,	"lseek"	}, /* 19 */
+  { 3,	0,	sys_lseek64,	"lseek"	}, /* 19 */
   { 1,	0,	sys_getpid,	"getpid"	}, /* 20 */
   { 4,	TF,	sys_mount,	"mount"	}, /* 21 */
   { 2,	TF,	sys_unmount,	"unmount"	}, /* 22 */
@@ -73,7 +73,7 @@
   { -1,	0,	printargs,	"SYS_68"	}, /* 68 */
   { 1,	0,	sys_sbrk,	"sbrk"	}, /* 69 */
   { 1,	0,	sys_sstk,	"sstk"	}, /* 70 */
-  { 6,	0,	sys_mmap,	"mmap"	}, /* 71 */
+  { 6,	0,	sys_mmap64,	"mmap"	}, /* 71 */
   { 1,	0,	sys_vadvise,	"vadvise"	}, /* 72 */
   { 2,	0,	sys_munmap,	"munmap"	}, /* 73 */
   { 3,	0,	sys_mprotect,	"mprotect"	}, /* 74 */
@@ -131,8 +131,8 @@
   { 2,	0,	sys_setreuid,	"setreuid"	}, /* 126 */
   { 2,	0,	sys_setregid,	"setregid"	}, /* 127 */
   { 2,	TF,	sys_rename,	"rename"	}, /* 128 */
-  { 2,	TF,	sys_truncate,	"truncate"	}, /* 129 */
-  { 2,	0,	sys_ftruncate,	"ftruncate"	}, /* 130 */
+  { 2,	TF,	sys_truncate64,	"truncate"	}, /* 129 */
+  { 2,	0,	sys_ftruncate64,	"ftruncate"	}, /* 130 */
   { 2,	0,	sys_flock,	"flock"	}, /* 131 */
   { 2,	0,	sys_mkfifo,	"mkfifo"	}, /* 132 */
   { 6,	TN,	sys_sendto,	"sendto"	}, /* 133 */
@@ -175,8 +175,8 @@
   { 6,	TI,	sys_msgsys,	"msgsys"	}, /* 170 */
   { 4,	TI,	sys_shmsys,	"shmsys"	}, /* 171 */
   { -1,	0,	printargs,	"SYS_172"	}, /* 172 */
-  { 5,	TF,	sys_pread,	"pread"	}, /* 173 */
-  { 5,	TF,	sys_pwrite,	"pwrite"	}, /* 174 */
+  { 5,	TF,	sys_pread64,	"pread"	}, /* 173 */
+  { 5,	TF,	sys_pwrite64,	"pwrite"	}, /* 174 */
   { -1,	0,	printargs,	"SYS_175"	}, /* 175 */
   { 1,	0,	sys_ntp_adjtime,	"ntp_adjtime"	}, /* 176 */
   { -1,	0,	printargs,	"SYS_177"	}, /* 177 */
@@ -199,11 +199,11 @@
   { 2,	0,	sys_getrlimit,	"getrlimit"	}, /* 194 */
   { 2,	0,	sys_setrlimit,	"setrlimit"	}, /* 195 */
   { 4,	0,	sys_getdirentries,	"getdirentries"	}, /* 196 */
-  { 7,	0,	sys_mmap,	"mmap"	}, /* 197 */
+  { 7,	0,	sys_mmap64,	"mmap"	}, /* 197 */
   { 1,	0,	sys___syscall,	"__syscall"	}, /* 198 */
-  { 4,	0,	sys_lseek,	"lseek"	}, /* 199 */
-  { 3,	TF,	sys_truncate,	"truncate"	}, /* 200 */
-  { 3,	0,	sys_ftruncate,	"ftruncate"	}, /* 201 */
+  { 4,	0,	sys_lseek64,	"lseek"	}, /* 199 */
+  { 3,	TF,	sys_truncate64,	"truncate"	}, /* 200 */
+  { 3,	0,	sys_ftruncate64,	"ftruncate"	}, /* 201 */
   { 6,	0,	sys___sysctl,	"__sysctl"	}, /* 202 */
   { 2,	0,	sys_mlock,	"mlock"	}, /* 203 */
   { 2,	0,	sys_munlock,	"munlock"	}, /* 204 */
@@ -225,7 +225,7 @@
   { 4,	0,	sys___semctl,	"__semctl"	}, /* 220 */
   { 3,	TI,	sys_semget,	"semget"	}, /* 221 */
   { 3,	TI,	sys_semop,	"semop"	}, /* 222 */
-  { 1,	0,	sys_semconfig,	"semconfig"	}, /* 223 */
+  { -1,	0,	printargs,	"SYS_223"	}, /* 223 */
   { 3,	TI,	sys_msgctl,	"msgctl"	}, /* 224 */
   { 2,	TI,	sys_msgget,	"msgget"	}, /* 225 */
   { 4,	TI,	sys_msgsnd,	"msgsnd"	}, /* 226 */
@@ -364,3 +364,5 @@
   { 2,	0,	sys_aio_waitcomplete,	"aio_waitcomplete"	}, /* 359 */
   { 3,	0,	sys_getresuid,	"getresuid"	}, /* 360 */
   { 3,	0,	sys_getresgid,	"getresgid"	}, /* 361 */
+  { 1,	0,	sys_kqueue,	"kqueue"	}, /* 362 */
+  { 6,	0,	sys_kevent,	"kevent"	}, /* 363 */
diff --git a/freebsd/syscalls.print b/freebsd/syscalls.print
index bc59a6f..3461f43 100644
--- a/freebsd/syscalls.print
+++ b/freebsd/syscalls.print
@@ -67,7 +67,7 @@
 fstat
 fstatfs
 fsync
-ftruncate
+ftruncate	sys_ftruncate64
 getdents
 getdirentries
 getdomainname
@@ -96,13 +96,13 @@
 killpg
 link
 listen
-lseek
+lseek		sys_lseek64
 lstat
 mincore
 mkdir
 mkfifo
 mknod
-mmap
+mmap		sys_mmap64
 mprotect
 msgctl
 msgget
@@ -116,9 +116,9 @@
 pathconf
 pipe
 poll
-pread
+pread		sys_pread64
 ptrace
-pwrite
+pwrite		sys_pwrite64
 quotactl
 read
 readlink
@@ -178,7 +178,7 @@
 sysctl
 time
 times
-truncate
+truncate	sys_truncate64
 umask
 uname
 unlink
diff --git a/io.c b/io.c
index 0fe8c3d..6bb986c 100644
--- a/io.c
+++ b/io.c
@@ -130,7 +130,7 @@
 	return 0;
 }
 
-#if defined(SVR4) || defined(FREEBSD)
+#if defined(SVR4)
 
 int
 sys_pread(tcp)
@@ -147,14 +147,9 @@
 		/* off_t is signed int */
 		tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
 #else
-#ifndef FREEBSD
 		tprintf(", %lu, %llu", tcp->u_arg[2],
 				(((unsigned long long) tcp->u_arg[4]) << 32
 				 | tcp->u_arg[3]));
-#else
-		tprintf(", %lu, %llu", tcp->u_arg[2], 
-				(((off_t) tcp->u_arg[3]) << 32) +  tcp->u_arg[4]);
-#endif
 #endif
 	}
 	return 0;
@@ -171,19 +166,14 @@
 		/* off_t is signed int */
 		tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
 #else
-#ifndef FREEBSD
 		tprintf(", %lu, %llu", tcp->u_arg[2],
 				(((unsigned long long) tcp->u_arg[4]) << 32
 				 | tcp->u_arg[3]));
-#else
-		tprintf(", %lu, %llu", tcp->u_arg[2],
-				(((off_t) tcp->u_arg[3]) << 32) + tcp->u_arg[4]);
-#endif
 #endif
 	}
 	return 0;
 }
-#endif /* SVR4 || FREEBSD */
+#endif /* SVR4 */
 
 #ifdef FREEBSD
 #include <sys/types.h>
@@ -279,7 +269,7 @@
 
 #endif /* LINUX */
 
-#if _LFS64_LARGEFILE
+#if _LFS64_LARGEFILE || FREEBSD
 int
 sys_pread64(tcp)
 struct tcb *tcp;
@@ -287,11 +277,13 @@
 	if (entering(tcp)) {
 		tprintf("%ld, ", tcp->u_arg[0]);
 	} else {
+		ALIGN64 (tcp, 3);
 		if (syserror(tcp))
 			tprintf("%#lx", tcp->u_arg[1]);
 		else
 			printstr(tcp, tcp->u_arg[1], tcp->u_rval);
-		tprintf(", %lu, %#llx", tcp->u_arg[2], get64(tcp->u_arg[3], tcp->u_arg[4]));
+		tprintf(", %lu, %#llx", tcp->u_arg[2],
+			get64(tcp->u_arg[3], tcp->u_arg[4]));
 	}
 	return 0;
 }
@@ -301,9 +293,11 @@
 struct tcb *tcp;
 {
 	if (entering(tcp)) {
+		ALIGN64 (tcp, 3);
 		tprintf("%ld, ", tcp->u_arg[0]);
 		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
-		tprintf(", %lu, %#llx", tcp->u_arg[2], get64(tcp->u_arg[3], tcp->u_arg[4]));
+		tprintf(", %lu, %#llx", tcp->u_arg[2],
+			get64(tcp->u_arg[3], tcp->u_arg[4]));
 	}
 	return 0;
 }
diff --git a/mem.c b/mem.c
index ec9b441..7278c53 100644
--- a/mem.c
+++ b/mem.c
@@ -224,7 +224,7 @@
     return print_mmap(tcp, tcp->u_arg);
 }
 
-#if _LFS64_LARGEFILE
+#if _LFS64_LARGEFILE || FREEBSD
 int
 sys_mmap64(tcp)
 struct tcb *tcp;
@@ -247,6 +247,7 @@
 			return 0;
 #endif /* ALPHA */
 #endif /* linux */
+		ALIGN64 (tcp, 5);	/* FreeBSD wierdies */
 
 		/* addr */
 		tprintf("%#lx, ", u_arg[0]);
@@ -256,8 +257,12 @@
 		printflags(mmap_prot, u_arg[2]);
 		tprintf(", ");
 		/* flags */
+#ifdef MAP_TYPE
 		printxval(mmap_flags, u_arg[3] & MAP_TYPE, "MAP_???");
 		addflags(mmap_flags, u_arg[3] & ~MAP_TYPE);
+#else
+		printflags(mmap_flags, u_arg[3]);
+#endif
 		/* fd */
 		tprintf(", %ld, ", u_arg[4]);
 		/* offset */