1 /*
2 * Copyright (c) 2008-2012 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #pragma once
24
25 #include <inttypes.h>
26 #include <limits.h>
27 #include <stdint.h>
28 #include <stddef.h>
29 #include <stdbool.h>
30
31 typedef unsigned char uchar;
32 typedef unsigned short ushort;
33 typedef unsigned int uint;
34 typedef unsigned long ulong;
35 typedef unsigned char u_char;
36 typedef unsigned short u_short;
37 typedef unsigned int u_int;
38 typedef unsigned long u_long;
39
40 typedef int status_t;
41
42 typedef uintptr_t addr_t;
43 #define ADDR_MAX UINTPTR_MAX
44 #define PRIxADDR PRIxPTR
45 #define PRIdADDR PRIdPTR
46 typedef uintptr_t vaddr_t;
47 #define VADDR_MAX UINTPTR_MAX
48 #define PRIxVADDR PRIxPTR
49 #define PRIdVADDR PRIdPTR
50 typedef uintptr_t paddr_t;
51 #define PADDR_MAX UINTPTR_MAX
52 #define PRIxPADDR PRIxPTR
53 #define PRIdPADDR PRIdPTR
54
55 typedef int kobj_id;
56
57 typedef uint32_t lk_time_t;
58 typedef unsigned long long lk_time_ns_t;
59 #define INFINITE_TIME UINT32_MAX
60
61 /* The overflow here is intended to deal with timestamps near wrapping */
62 __attribute__((no_sanitize("unsigned-integer-overflow")))
time_delta(lk_time_ns_t a,lk_time_ns_t b)63 static inline int64_t time_delta(lk_time_ns_t a, lk_time_ns_t b) {
64 return (int64_t)(a - b);
65 }
66
time_gte(lk_time_ns_t a,lk_time_ns_t b)67 static inline bool time_gte(lk_time_ns_t a, lk_time_ns_t b) {
68 return time_delta(a, b) >= 0;
69 }
70
time_lte(lk_time_ns_t a,lk_time_ns_t b)71 static inline bool time_lte(lk_time_ns_t a, lk_time_ns_t b) {
72 return time_delta(a, b) <= 0;
73 }
74
time_gt(lk_time_ns_t a,lk_time_ns_t b)75 static inline bool time_gt(lk_time_ns_t a, lk_time_ns_t b) {
76 return time_delta(a, b) > 0;
77 }
78
time_lt(lk_time_ns_t a,lk_time_ns_t b)79 static inline bool time_lt(lk_time_ns_t a, lk_time_ns_t b) {
80 return time_delta(a, b) < 0;
81 }
82
83 enum handler_return {
84 INT_NO_RESCHEDULE = 0,
85 INT_RESCHEDULE,
86 };
87
88 typedef uint8_t u8;
89 typedef uint16_t u16;
90 typedef uint32_t u32;
91 typedef uint64_t u64;
92
93 typedef int8_t s8;
94 typedef int16_t s16;
95 typedef int32_t s32;
96 typedef int64_t s64;
97
98 typedef uint8_t u_int8_t;
99 typedef uint16_t u_int16_t;
100 typedef uint32_t u_int32_t;
101 typedef uint64_t u_int64_t;
102