summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
Diffstat (limited to 'kern')
-rw-r--r--kern/assert.h2
-rw-r--r--kern/ast.h2
-rw-r--r--kern/list.h4
-rw-r--r--kern/macro_help.h50
-rw-r--r--kern/macros.h72
-rw-r--r--kern/pc_sample.h2
-rw-r--r--kern/rbtree.h5
-rw-r--r--kern/refcount.h2
-rw-r--r--kern/sched.h2
-rw-r--r--kern/sched_prim.c2
-rw-r--r--kern/slab.c2
-rw-r--r--kern/timer.c2
-rw-r--r--kern/timer.h2
13 files changed, 83 insertions, 66 deletions
diff --git a/kern/assert.h b/kern/assert.h
index bd2a8be..7b66d1b 100644
--- a/kern/assert.h
+++ b/kern/assert.h
@@ -29,7 +29,7 @@
/* assert.h 4.2 85/01/21 */
-#include <kern/macro_help.h>
+#include <kern/macros.h>
#ifndef NDEBUG
#define MACH_ASSERT 1
diff --git a/kern/ast.h b/kern/ast.h
index 4c28b1e..7d472be 100644
--- a/kern/ast.h
+++ b/kern/ast.h
@@ -41,7 +41,7 @@
*/
#include "cpu_number.h"
-#include <kern/macro_help.h>
+#include <kern/macros.h>
#include <machine/ast.h>
/*
diff --git a/kern/list.h b/kern/list.h
index ad782a8..be92762 100644
--- a/kern/list.h
+++ b/kern/list.h
@@ -31,9 +31,7 @@
#include <stddef.h>
#include <sys/types.h>
-
-#define structof(ptr, type, member) \
- ((type *)((char *)ptr - offsetof(type, member)))
+#include <kern/macros.h>
/*
* Structure used as both head and node.
diff --git a/kern/macro_help.h b/kern/macro_help.h
deleted file mode 100644
index 7ce171f..0000000
--- a/kern/macro_help.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Mach Operating System
- * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- */
-/*
- * File: kern/macro_help.h
- *
- * Provide help in making lint-free macro routines
- *
- */
-
-#ifndef _KERN_MACRO_HELP_H_
-#define _KERN_MACRO_HELP_H_
-
-#if !defined(MACRO_BEGIN)
-
-#include <mach/boolean.h>
-
-#define NEVER FALSE
-#define ALWAYS TRUE
-
-#define MACRO_BEGIN ({
-#define MACRO_END })
-
-#define MACRO_RETURN if (ALWAYS) return
-
-#endif /* !MACRO_BEGIN */
-
-#endif /* _KERN_MACRO_HELP_H_ */
diff --git a/kern/macros.h b/kern/macros.h
new file mode 100644
index 0000000..fb8dc5e
--- /dev/null
+++ b/kern/macros.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2009, 2010, 2013 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * Helper macros.
+ */
+
+#ifndef _KERN_MACROS_H
+#define _KERN_MACROS_H
+
+#define MACRO_BEGIN ({
+#define MACRO_END })
+#define MACRO_RETURN if (1) return
+
+#define __QUOTE(x) #x
+#define QUOTE(x) __QUOTE(x)
+
+#ifdef __ASSEMBLER__
+#define DECL_CONST(x, s) x
+#else /* __ASSEMBLER__ */
+#define __DECL_CONST(x, s) x##s
+#define DECL_CONST(x, s) __DECL_CONST(x, s)
+#endif /* __ASSEMBLER__ */
+
+#define STRLEN(x) (sizeof(x) - 1)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+#define DIV_CEIL(n, d) (((n) + (d) - 1) / (d))
+
+#define P2ALIGNED(x, a) (((x) & ((a) - 1)) == 0)
+#define ISP2(x) P2ALIGNED(x, x)
+#define P2ALIGN(x, a) ((x) & -(a))
+#define P2ROUND(x, a) (-(-(x) & -(a)))
+#define P2END(x, a) (-(~(x) & -(a)))
+
+#define structof(ptr, type, member) \
+ ((type *)((char *)(ptr) - offsetof(type, member)))
+
+#define alignof(x) __alignof__(x)
+
+#define likely(expr) __builtin_expect(!!(expr), 1)
+#define unlikely(expr) __builtin_expect(!!(expr), 0)
+
+#define barrier() asm volatile("" : : : "memory")
+
+#define __noreturn __attribute__((noreturn))
+#define __aligned(x) __attribute__((aligned(x)))
+#define __always_inline inline __attribute__((always_inline))
+#define __section(x) __attribute__((section(x)))
+#define __packed __attribute__((packed))
+#define __alias(x) __attribute__((alias(x)))
+
+#define __format_printf(fmt, args) \
+ __attribute__((format(printf, fmt, args)))
+
+#endif /* _KERN_MACROS_H */
diff --git a/kern/pc_sample.h b/kern/pc_sample.h
index 3c64068..4832cb9 100644
--- a/kern/pc_sample.h
+++ b/kern/pc_sample.h
@@ -49,7 +49,7 @@
#include <mach/pc_sample.h>
#include <mach/machine/vm_types.h>
#include <kern/kern_types.h>
-#include <kern/macro_help.h>
+#include <kern/macros.h>
/*
* Control structure for sampling, included in
diff --git a/kern/rbtree.h b/kern/rbtree.h
index 189a7fd..16ef273 100644
--- a/kern/rbtree.h
+++ b/kern/rbtree.h
@@ -31,12 +31,9 @@
#include <stddef.h>
#include <kern/assert.h>
-#include <kern/macro_help.h>
+#include <kern/macros.h>
#include <sys/types.h>
-#define structof(ptr, type, member) \
- ((type *)((char *)ptr - offsetof(type, member)))
-
/*
* Indexes of the left and right nodes in the children array of a node.
*/
diff --git a/kern/refcount.h b/kern/refcount.h
index 74204d6..f32feb8 100644
--- a/kern/refcount.h
+++ b/kern/refcount.h
@@ -27,7 +27,7 @@
#ifndef _KERN_REFCOUNT_H_
#define _KERN_REFCOUNT_H_
-#include <kern/macro_help.h>
+#include <kern/macros.h>
/* Unless the above include file specified otherwise,
use the system-independent (unoptimized) atomic reference counter. */
diff --git a/kern/sched.h b/kern/sched.h
index ea601c5..f82f9f5 100644
--- a/kern/sched.h
+++ b/kern/sched.h
@@ -38,7 +38,7 @@
#include <kern/queue.h>
#include <kern/lock.h>
#include <kern/kern_types.h>
-#include <kern/macro_help.h>
+#include <kern/macros.h>
#if MACH_FIXPRI
#include <mach/policy.h>
diff --git a/kern/sched_prim.c b/kern/sched_prim.c
index d7792ae..e8f260e 100644
--- a/kern/sched_prim.c
+++ b/kern/sched_prim.c
@@ -44,7 +44,7 @@
#include <kern/lock.h>
#include <kern/mach_clock.h>
#include <kern/mach_factor.h>
-#include <kern/macro_help.h>
+#include <kern/macros.h>
#include <kern/processor.h>
#include <kern/queue.h>
#include <kern/sched.h>
diff --git a/kern/slab.c b/kern/slab.c
index 19ebfed..60378b5 100644
--- a/kern/slab.c
+++ b/kern/slab.c
@@ -79,6 +79,7 @@
#include <string.h>
#include <kern/assert.h>
#include <kern/mach_clock.h>
+#include <kern/macros.h>
#include <kern/printf.h>
#include <kern/slab.h>
#include <kern/kalloc.h>
@@ -96,7 +97,6 @@
/*
* Utility macros.
*/
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define P2ALIGNED(x, a) (((x) & ((a) - 1)) == 0)
#define ISP2(x) P2ALIGNED(x, x)
#define P2ALIGN(x, a) ((x) & -(a))
diff --git a/kern/timer.c b/kern/timer.c
index 6d6517e..79ada27 100644
--- a/kern/timer.c
+++ b/kern/timer.c
@@ -33,7 +33,7 @@
#include <kern/cpu_number.h>
#include <kern/assert.h>
-#include <kern/macro_help.h>
+#include <kern/macros.h>
diff --git a/kern/timer.h b/kern/timer.h
index 57f017a..2f473cf 100644
--- a/kern/timer.h
+++ b/kern/timer.h
@@ -27,7 +27,7 @@
#ifndef _KERN_TIMER_H_
#define _KERN_TIMER_H_
-#include <kern/macro_help.h>
+#include <kern/macros.h>
#if STAT_TIME
/*