Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Mar 2013 13:49:42 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 222968 for review
Message-ID:  <201303171349.r2HDngA0056801@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@222968?ac=10

Change 222968 by rwatson@rwatson_cinnamon on 2013/03/17 13:48:44

	Various header and definition fixes to allow increasing amounts
	of libtesla to compile in the FreeBSD kernel.  Primarily, this
	consited of adding missing includes, and preventing inclusion of
	specific headers (e.g., stdio) when _KERNEL.  There was also a
	syntax issue with assertions, which is not tested with the
	userspace version of libtesla and may require further refinement.
	Now comes the harder bit.

Affected files ...

.. //depot/projects/ctsrd/tesla/src/sys/libtesla/debug.c#2 edit
.. //depot/projects/ctsrd/tesla/src/sys/libtesla/key.c#2 edit
.. //depot/projects/ctsrd/tesla/src/sys/libtesla/libtesla.h#2 edit
.. //depot/projects/ctsrd/tesla/src/sys/libtesla/state.c#2 edit
.. //depot/projects/ctsrd/tesla/src/sys/libtesla/tesla_internal.h#2 edit
.. //depot/projects/ctsrd/tesla/src/sys/libtesla/update.c#2 edit

Differences ...

==== //depot/projects/ctsrd/tesla/src/sys/libtesla/debug.c#2 (text+ko) ====

@@ -32,7 +32,10 @@
  */
 
 #include "tesla_internal.h"
+
+#ifndef _KERNEL
 #include <stdlib.h>
+#endif
 
 char*
 transition_matrix(const struct tesla_transitions *trans)

==== //depot/projects/ctsrd/tesla/src/sys/libtesla/key.c#2 (text+ko) ====

@@ -32,8 +32,10 @@
 
 #include "tesla_internal.h"
 
+#ifndef _KERNEL
 #include <inttypes.h>
 #include <stdio.h>
+#endif
 
 
 #define	IS_SET(mask, index) (mask & (1 << index))

==== //depot/projects/ctsrd/tesla/src/sys/libtesla/libtesla.h#2 (text+ko) ====

@@ -34,7 +34,11 @@
 #ifndef _TESLA_STATE
 #define	_TESLA_STATE
 
+#ifdef _KERNEL
+#include <sys/types.h>
+#else
 #include <stdint.h>		/* int32_t, uint32_t */
+#endif
 
 /*
  * libtesla functions mostly return error values, and therefore return

==== //depot/projects/ctsrd/tesla/src/sys/libtesla/state.c#2 (text+ko) ====

@@ -33,11 +33,11 @@
 
 #include "tesla_internal.h"
 
+#ifdef _KERNEL
+MALLOC_DEFINE(M_TESLA, "tesla", "TESLA internal state");
+#else
 #include <inttypes.h>
 #include <stdio.h>
-
-#ifdef _KERNEL
-MALLOC_DEFINE(M_TESLA, "tesla", "TESLA internal state");
 #endif
 
 
@@ -135,7 +135,7 @@
 
 	struct tesla_table *ttp = tclass->ts_table;
 	assert(ttp != NULL);
-	tesla_assert(ttp->tt_length != 0, "Uninitialized tesla_table");
+	tesla_assert(ttp->tt_length != 0, ("Uninitialized tesla_table"));
 
 	if (ttp->tt_free == 0)
 		return (TESLA_ERROR_ENOMEM);
@@ -154,7 +154,7 @@
 		break;
 	}
 
-	tesla_assert(*out != NULL, "no free instances but tt_free was > 0");
+	tesla_assert(*out != NULL, ("no free instances but tt_free was > 0"));
 
 	return (TESLA_SUCCESS);
 }

==== //depot/projects/ctsrd/tesla/src/sys/libtesla/tesla_internal.h#2 (text+ko) ====

@@ -36,21 +36,26 @@
 #ifdef _KERNEL
 #include "opt_kdb.h"
 #include <sys/param.h>
+#include <sys/eventhandler.h>
 #include <sys/kdb.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/sx.h>
 #include <sys/systm.h>
+
+#include <libtesla/libtesla.h>
 #else
 #include <assert.h>
 #include <err.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
-#endif
 
 #include <libtesla.h>
+#endif
 
 //! Is @ref x a subset of @ref y?
 #define	SUBSET(x,y) ((x & y) == x)
@@ -98,8 +103,13 @@
 
 #define __debug
 
+#ifdef _KERNEL
+#include <sys/systm.h>
+#define DEBUG_PRINT(...) printf(__VA_ARGS__)
+#else
 #include <stdio.h>
 #define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
+#endif
 #define VERBOSE_PRINT(...) if (verbose_debug()) DEBUG_PRINT(__VA_ARGS__)
 
 /** Are we in (verbose) debug mode? */
@@ -127,7 +137,7 @@
 #define tesla_assert(...) KASSERT(__VA_ARGS__)
 
 /** Emulate simple POSIX assertions. */
-#define assert(cond) KASSERT(cond, "Assertion failed: '" # cond "'")
+#define assert(cond) KASSERT((cond), ("Assertion failed: '%s'", #cond))
 
 #define tesla_malloc(len) malloc(len, M_TESLA, M_WAITOK | M_ZERO)
 #define tesla_free(x) free(x, M_TESLA)

==== //depot/projects/ctsrd/tesla/src/sys/libtesla/update.c#2 (text+ko) ====

@@ -32,8 +32,10 @@
 
 #include "tesla_internal.h"
 
+#ifndef _KERNEL
 #include <stdbool.h>
 #include <inttypes.h>
+#endif
 
 #define	CHECK(fn, ...) do { \
 	int err = fn(__VA_ARGS__); \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303171349.r2HDngA0056801>