PERFORCE change 86609 for review

Todd Miller millert at FreeBSD.org
Thu Nov 10 18:39:26 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=86609

Change 86609 by millert at millert_ibook on 2005/11/10 18:38:40

	Remove #ifdefs and make this Darwin-specific.  The #ifdefs just
	make things more difficult to read and diffing against the sebsd
	version will give you a better idea of what is different.

Affected files ...

.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/linux-compat.h#9 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/linux-compat.h#9 (text+ko) ====

@@ -39,49 +39,33 @@
 
 /*
  * Try and convert some of the linux kernel routines to something that
- * works in FreeBSD.  Perhaps a bit dangerous, but the hope is that
+ * works in Darwin.  Perhaps a bit dangerous, but the hope is that
  * diffs to the SELinux tree will be quite a bit smaller.
  */
 
 #include <sys/types.h>
 
-#ifdef __APPLE__
-#include <machine/endian.h>
-#include <architecture/byte_order.h>
-#else /* Probably FreeBSD */
-#include <sys/endian.h>
-#endif
-
 typedef u_int64_t u64;
 typedef u_int32_t u32;
 typedef u_int16_t u16;
 typedef u_int8_t  u8;
 
-#if !defined(_KERNEL) && !defined(KERNEL)
+
 #if BYTE_ORDER == LITTLE_ENDIAN
 #define	cpu_to_le32(x)	((__uint32_t)(x))
 #define	cpu_to_le64(x)	((__uint64_t)(x))
 #define	le32_to_cpu(x)	((__uint32_t)(x))
 #define	le64_to_cpu(x)	((__uint64_t)(x))
 #else /* BYTE_ORDER != LITTLE_ENDIAN */
-
-#ifdef __APPLE__
 #define	le32_to_cpu(x)	NXSwapLittleLongToHost(x)
 #define	le64_to_cpu(x)	NXSwapLittleLongLongToHost(x)
 #define	cpu_to_le32(x)	NXSwapHostLongToLittle(x)
 #define	cpu_to_le64(x)	NXSwapHostLongLongToLittle(x)
-#else
-
-#define	cpu_to_le32(x)	bswap32((x))
-#define	cpu_to_le64(x)	bswap64((x))
-#define	le32_to_cpu(x)	bswap32((x))
-#define	le64_to_cpu(x)	bswap64((x))
-
-#endif
 #endif /* BYTE_ORDER */
 
-/* sebsd uses same ss source files for userspace */
+#if !defined(_KERNEL) && !defined(KERNEL)
 
+/* sedarwin uses same ss source files for userspace */
 #define kmalloc(size,flags) malloc(size)
 #define kfree(v) free(v)
 #define __get_free_page(flags) malloc(PAGE_SIZE)
@@ -90,19 +74,6 @@
 
 #else /* _KERNEL */
 
-#ifdef __APPLE__
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define	le32_to_cpu(x)	((__uint32_t)(x))
-#define	le64_to_cpu(x)	((__uint64_t)(x))
-#else /* BYTE_ORDER != LITTLE_ENDIAN */
-#define	le32_to_cpu(x)	NXSwapLittleLongToHost(x)
-#define	le64_to_cpu(x)	NXSwapLittleLongLongToHost(x)
-#endif
-#else
-#define le32_to_cpu(a) le32toh(a) 
-#define le64_to_cpu(a) le64toh(a) 
-#endif
-
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 #define NIPQUAD(addr) \
@@ -113,33 +84,22 @@
 
 #define __init
 
-/* kmalloc */
-
-#include <sys/malloc.h>
-
-#ifdef __APPLE__
-
 extern void *sebsd_malloc(size_t size, int flags);
 extern void sebsd_free(void *);
 
+/* BSD-style malloc/free emulation */
+#include <sys/malloc.h>
 #define malloc(size, type, flags)	sebsd_malloc(size, flags)
 #define free(addr, type)		sebsd_free(addr)
+#define M_SEBSD				M_MACTEMP
 
-#define M_SEBSD M_MACTEMP
-#else 
-#ifndef _M_SEBSD_DEF
-MALLOC_DECLARE(M_SEBSD);
-#define _M_SEBSD_DEF
-#endif
-#endif /* __APPLE__ */
-
+/* Linux-style kmalloc/kfree (note kfree namespace collision) */
 #define kmalloc(size, flags)		sebsd_malloc(size, flags)
-#define kfree(v)			sebsd_free(v)
+#define kfree(addr)			sebsd_free(addr)
 #define __get_free_page(flags)		sebsd_malloc(PAGE_SIZE, flags) 
 #define GFP_ATOMIC  M_NOWAIT
 #define GFP_KERNEL  M_WAITOK
 
-#ifdef __APPLE__
 /* TBD: no boot-time tunable support yet */
 #define TUNABLE_INT_FETCH(str,var)
 
@@ -148,14 +108,6 @@
 #define spin_lock_irqsave(m,flags)	mutex_lock(*(m))
 #define spin_unlock_irqrestore(m,flags)	mutex_unlock(*(m))
 
-#else /* ! __APPLE__ */
-
-/* spinlock */
-#define spinlock_t struct mtx
-#define spin_lock_irqsave(m,flags) mtx_lock(m)
-#define spin_unlock_irqrestore(m,flags) mtx_unlock(m)
-#endif /* !__APPLE__ */
-
 #endif /* _KERNEL */
 
 #define BUG() printf("BUG: %s:%d", __FILE__, __LINE__)
@@ -164,8 +116,11 @@
 #define wmb() 
 
 /* printk */
-
+#ifdef MACH_KDB
+#define printk kprintf
+#else
 #define printk printf
+#endif
 #define KERN_WARNING "warning: "
 #define KERN_INFO
 #define KERN_ERR     "error: "
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list