1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 #ifndef __LIBCFS_DARWIN_LIBCFS_H__
5 #define __LIBCFS_DARWIN_LIBCFS_H__
7 #ifndef __LIBCFS_LIBCFS_H__
8 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
11 #include <mach/mach_types.h>
12 #include <sys/errno.h>
14 #include <libcfs/darwin/darwin-types.h>
15 #include <libcfs/darwin/darwin-time.h>
16 #include <libcfs/darwin/darwin-prim.h>
17 #include <libcfs/darwin/darwin-mem.h>
18 #include <libcfs/darwin/darwin-lock.h>
19 #include <libcfs/darwin/darwin-fs.h>
20 #include <libcfs/darwin/darwin-tcpip.h>
23 # include <sys/types.h>
24 # include <sys/time.h>
25 # define do_gettimeofday(tv) microuptime(tv)
27 # include <sys/time.h>
28 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
29 typedef unsigned long long cycles_t;
32 #define __cpu_to_le64(x) OSSwapHostToLittleInt64(x)
33 #define __cpu_to_le32(x) OSSwapHostToLittleInt32(x)
34 #define __cpu_to_le16(x) OSSwapHostToLittleInt16(x)
36 #define __le16_to_cpu(x) OSSwapLittleToHostInt16(x)
37 #define __le32_to_cpu(x) OSSwapLittleToHostInt32(x)
38 #define __le64_to_cpu(x) OSSwapLittleToHostInt64(x)
40 #define cpu_to_le64(x) __cpu_to_le64(x)
41 #define cpu_to_le32(x) __cpu_to_le32(x)
42 #define cpu_to_le16(x) __cpu_to_le16(x)
44 #define le64_to_cpu(x) __le64_to_cpu(x)
45 #define le32_to_cpu(x) __le32_to_cpu(x)
46 #define le16_to_cpu(x) __le16_to_cpu(x)
48 #define __swab16(x) OSSwapInt16(x)
49 #define __swab32(x) OSSwapInt32(x)
50 #define __swab64(x) OSSwapInt64(x)
51 #define __swab16s(x) do { *(x) = __swab16(*(x)); } while (0)
52 #define __swab32s(x) do { *(x) = __swab32(*(x)); } while (0)
53 #define __swab64s(x) do { *(x) = __swab64(*(x)); } while (0)
55 struct ptldebug_header {
67 } __attribute__((packed));
71 # include <sys/systm.h>
72 # include <pexpert/pexpert.h>
74 # define THREAD_SIZE 8192
76 # define THREAD_SIZE 8192
78 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
80 #define CHECK_STACK() do { } while(0)
81 #define CDEBUG_STACK() (0L)
83 /* Darwin has defined RETURN, so we have to undef it in lustre */
89 * When this is enabled debugging messages are indented according to the
90 * current "nesting level". Nesting level in increased when ENTRY macro
91 * is executed, and decreased on EXIT and RETURN.
94 #define ENTRY_NESTING_SUPPORT (0)
97 #if ENTRY_NESTING_SUPPORT
100 * Currently ENTRY_NESTING_SUPPORT is only supported for XNU port. Basic
101 * idea is to keep per-thread pointer to small data structure (struct
102 * cfs_debug_data) describing current nesting level. In XNU unused
103 * proc->p_wmegs field in hijacked for this. On Linux
104 * current->journal_info can be used. In user space
105 * pthread_{g,s}etspecific().
107 * ENTRY macro allocates new cfs_debug_data on stack, and installs it as
108 * a current nesting level, storing old data in cfs_debug_data it just
111 * EXIT pops old value back.
116 * One problem with this approach is that there is a lot of code that
117 * does ENTRY and then escapes scope without doing EXIT/RETURN. In this
118 * case per-thread current nesting level pointer is dangling (it points
119 * to the stack area that is possible already overridden). To detect
120 * such cases, we add two magic fields to the cfs_debug_data and check
121 * them whenever current nesting level pointer is dereferenced. While
122 * looking flaky this works because stack is always consumed
126 CDD_MAGIC1 = 0x02128506,
127 CDD_MAGIC2 = 0x42424242
130 struct cfs_debug_data {
132 struct cfs_debug_data *parent;
137 void __entry_nesting(struct cfs_debug_data *child);
138 void __exit_nesting(struct cfs_debug_data *child);
139 unsigned int __current_nesting_level(void);
141 #define ENTRY_NESTING \
142 struct cfs_debug_data __cdd = { .magic1 = CDD_MAGIC1, \
144 .nesting_level = 0, \
145 .magic2 = CDD_MAGIC2 }; \
146 __entry_nesting(&__cdd);
148 #define EXIT_NESTING __exit_nesting(&__cdd)
150 /* ENTRY_NESTING_SUPPORT */
153 #define ENTRY_NESTING do {;} while (0)
154 #define EXIT_NESTING do {;} while (0)
155 #define __current_nesting_level() (0)
157 /* ENTRY_NESTING_SUPPORT */
160 #define LUSTRE_LNET_PID 12345
162 #define _XNU_LIBCFS_H
165 * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
167 * Implementation is in darwin-curproc.c
169 #define CFS_CURPROC_COMM_MAX MAXCOMLEN
171 * XNU has no capabilities
173 typedef int cfs_kernel_cap_t;
177 /* if you change this, update darwin-util.c:cfs_stack_trace_fill() */
178 CFS_STACK_TRACE_DEPTH = 16
181 struct cfs_stack_trace {
182 void *frame[CFS_STACK_TRACE_DEPTH];
185 #define printk(format, args...) printf(format, ## args)
191 #endif /* __KERNEL__ */
193 #endif /* _XNU_LIBCFS_H */