obsd44-pass1-20090123
[openafs.git] / src / afs / OBSD / osi_machdep.h
index a449b6c..933f03c 100644 (file)
 #define AFS_UIOUSER    UIO_USERSPACE
 
 /* malloc */
-#define AFS_KALLOC(s)  afs_nbsd_Alloc(s)
-#define AFS_KFREE(p, s)        afs_nbsd_Free((p), (s))
+inline void afs_osi_Free(void *buf, size_t asize);
+inline void afs_osi_FreeStr(char *x);
+extern void *osi_obsd_Alloc(size_t asize, int cansleep);
+extern void osi_obsd_Free(void *p, size_t asize);
+
+#define afs_osi_Alloc_NoSleep(asize) osi_obsd_Alloc((asize), 0)
+#define afs_osi_Alloc(asize) osi_obsd_Alloc((asize), 1)
+#define afs_osi_FreeStr(s) afs_osi_Free((s), strlen((s)) + 1)
+#define afs_osi_Free(buf, asize) osi_obsd_Free((buf), (asize))
+
+#ifdef AFS_KALLOC
+#undef AFS_KALLOC
+#define AFS_KALLOC(s) osi_obsd_Alloc((s), 1 /* cansleep */)
+#endif
+
+#ifdef AFS_KFREE
+#undef AFS_KFREE
+#define AFS_KFREE(p, s) (osi_obsd_Free((p), (s)))
+#endif
+
+#ifdef AFS_OBSD42_ENV
+/* removed, live with it */
+#define BSD_KMALLOC(p, ptype, msize, mtype, mflags)     \
+  (p) = malloc((msize), (mtype), (mflags))
+
+#define BSD_KFREE(p, mflags) \
+  free((p), (mflags))
+#else
+#define BSD_KMALLOC MALLOC
+#define BSD_KFREE KFREE
+#endif /* AFS_OBSD42_ENV */
 
 /* proc, cred */
 #define        AFS_PROC        struct proc
@@ -69,7 +98,7 @@
 /* time */
 #define        afs_hz          hz
 #define osi_GetTime(x) microtime(x)
-#define osi_Time()     (time.tv_sec)
+extern time_t osi_Time();
 
 /* str */
 #define afs_strcasecmp(s1, s2) strncasecmp((s1), (s2), 65535)
 #ifndef iodone
 #define iodone biodone
 #endif
-#define PAGESIZE       8192
 #define printk         printf  /* for RX version of xdr_* */
 #define setgroups      sys_setgroups
 #define UVM
 /* This is not always in scope yet */
 struct vcache;
 
-extern int afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg,
+extern int afs_obsd_lookupname(char *fnamep, enum uio_seg segflg,
                               int followlink, struct vnode **compvpp);
-extern void afs_nbsd_getnewvnode(struct vcache *tvc);
-extern void *afs_nbsd_Alloc(size_t asize);
-extern void afs_nbsd_Free(void *p, size_t asize);
+extern void afs_obsd_getnewvnode(struct vcache *tvc);
+extern void *afs_obsd_Alloc(size_t asize);
+extern void afs_obsd_Free(void *p, size_t asize);
 extern int afs_vget();
 
 #undef gop_lookupname
 #define        gop_lookupname(fnamep, segflg, followlink, compvpp) \
        afs_nbsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
 
+#ifdef AFS_OBSD39_ENV
+#define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i))
+#else
+#define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i), (p))
+#endif
+
 #ifdef KERNEL
 
+#ifdef AFS_OBSD44_ENV
+/* Revert to classical, BSD locks */
+
+extern struct lock afs_global_lock;
+extern struct proc *afs_global_owner;
+
+#ifdef AFS_GLOBAL_SUNLOCK
+
+#if defined(LOCKDEBUG)
+
+#define AFS_GLOCK() \
+  do { \
+  _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
+  } while(0);
+#define AFS_GUNLOCK() \
+  do { \
+  _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
+  } while(0);
+
+#else
+
+#define AFS_GLOCK() \
+  do { \
+  lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
+  } while(0);
+#define AFS_GUNLOCK() \
+  do { \
+  lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
+  } while(0);
+#endif /* LOCKDEBUG */
+#define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE)
+#else
+extern struct lock afs_global_lock;
+#define AFS_GLOCKP(p)
+#define AFS_GUNLOCKP(p)
+#define AFS_ASSERT_GLOCK()
+#define ISAFS_GLOCK() 1
+#endif
+
+#else
+/* I don't see doing locks this way for older kernels, either,
+ * but, smart folks wrote this
+ */
+#define AFS_GLOCK() AFS_GLOCKP(curproc)
+#define AFS_GUNLOCK() AFS_GUNLOCKP(curproc)
 #ifdef AFS_GLOBAL_SUNLOCK
 extern struct proc *afs_global_owner;
 extern struct lock afs_global_lock;
-#define AFS_GLOCK() \
+#define AFS_GLOCKP(p) \
     do { \
-        osi_Assert(curproc); \
-       lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
+        osi_Assert(p); \
+       afs_osi_lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, (p)); \
         osi_Assert(afs_global_owner == NULL); \
-       afs_global_owner = curproc; \
+       afs_global_owner = (p); \
     } while (0)
-#define AFS_GUNLOCK() \
+#define AFS_GUNLOCKP(p) \
     do { \
-        osi_Assert(curproc); \
-       osi_Assert(afs_global_owner == curproc); \
+        osi_Assert(p); \
+       osi_Assert(afs_global_owner == (p)); \
         afs_global_owner = NULL; \
-        lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
+        afs_osi_lockmgr(&afs_global_lock, LK_RELEASE, 0, (p)); \
     } while(0)
 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
 #else
 extern struct lock afs_global_lock;
-#define AFS_GLOCK()
-#define AFS_GUNLOCK()
+#define AFS_GLOCKP(p)
+#define AFS_GUNLOCKP(p)
 #define AFS_ASSERT_GLOCK()
 #define ISAFS_GLOCK() 1
 #endif
 
+#endif /* AFS_OBSD44_ENV */
+
 #undef SPLVAR
 #define SPLVAR int splvar
 #undef NETPRI