]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOReporterDefs.h
xnu-3789.70.16.tar.gz
[apple/xnu.git] / iokit / Kernel / IOReporterDefs.h
CommitLineData
fe8ab488
A
1/*
2 * Copyright (c) 2012-2013 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _IOEPORTERDEFS_H
30#define _IOEPORTERDEFS_H
31
32//#include "IOReportHubCommon.h"
33
34//#define IORDEBUG_IOLOG
35
36#if defined(IORDEBUG_IOLOG)
37#define IORLOG(fmt, args...) \
38do { \
39 IOLog((fmt), ##args); \
40 IOLog("\n"); \
41} while(0)
42
43#else
44#define IORLOG(fmt, args...)
45#endif
46
47#define IORERROR_LOG
48
49#ifdef IORERROR_LOG
50#define IORERROR(fmt, args...) IOLog(fmt, ##args);
51#else
52#define IORERROR(fmt, args...)
53#endif
54
55// overflow detection routines
56#if (SIZE_T_MAX < INT_MAX)
57#error "(SIZE_T_MAX < INT_MAX) -> PREFL_MEMOP_*()) unsafe for size_t"
58#endif
59
60#define PREFL_MEMOP_FAIL(__val, __type) do { \
61 if (__val <= 0) { \
3e170ce0 62 IORERROR("%s - %s <= 0!\n", __func__, #__val); \
fe8ab488
A
63 res = kIOReturnUnderrun; \
64 goto finish; \
65 } else if (__val > INT_MAX / (int)sizeof(__type)) { \
3e170ce0 66 IORERROR("%s - %s > INT_MAX / sizeof(%s)!\n",__func__,#__val,#__type);\
fe8ab488
A
67 res = kIOReturnOverrun; \
68 goto finish; \
69 } \
70} while(0)
71
72#define PREFL_MEMOP_PANIC(__val, __type) do { \
73 if (__val <= 0) { \
74 panic("%s - %s <= 0!", __func__, #__val); \
75 } else if (__val > INT_MAX / (int)sizeof(__type)) { \
76 panic("%s - %s > INT_MAX / sizeof(%s)!", __func__, #__val, #__type); \
77 } \
78} while(0)
79
80//#include "IOReportHubCommon.h"//
81
82
83
84#define IOREPORTER_DEBUG_ELEMENT(idx) \
85do { \
86IOLog("IOReporter::DrvID: %llx | Elt:[%3d] |ID: %llx |Ticks: %llu |", \
87_elements[idx].provider_id, \
88idx, \
89_elements[idx].channel_id, \
90_elements[idx].timestamp); \
91IOLog("0: %llu | 1: %llu | 2: %llu | 3: %llu\n", \
92_elements[idx].values.v[0], \
93_elements[idx].values.v[1], \
94_elements[idx].values.v[2], \
95_elements[idx].values.v[3]); \
96} while(0)
97
98
99#define IOREPORTER_CHECK_LOCK() \
100do { \
101 if (!_reporterIsLocked) { \
102 panic("%s was called out of locked context!", __PRETTY_FUNCTION__); \
103 } \
104} while(0) \
105
106#define IOREPORTER_CHECK_CONFIG_LOCK() \
107do { \
108 if (!_reporterConfigIsLocked) { \
109 panic("%s was called out of config locked context!", __PRETTY_FUNCTION__); \
110 } \
111} while(0) \
112
113#endif /* ! _IOEPORTERDEFS_H */
114