-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtypes.h
73 lines (62 loc) · 1.9 KB
/
types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef JOS_INC_TYPES_H
#define JOS_INC_TYPES_H
#ifndef NULL
#define NULL ((void*) 0)
#endif
// Represents true-or-false values
typedef _Bool bool;
enum { false, true };
// Explicitly-sized versions of integer types
typedef __signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
// Pointers and addresses are 32 bits long.
// We use pointer types to represent virtual addresses,
// uintptr_t to represent the numerical values of virtual addresses,
// and physaddr_t to represent physical addresses.
typedef int32_t intptr_t;
typedef uint64_t uintptr_t;
typedef uint64_t physaddr_t;
// Page numbers are 32 bits long.
typedef uint64_t ppn_t;
// size_t is used for memory object sizes.
typedef uint64_t size_t;
// ssize_t is a signed version of ssize_t, used in case there might be an
// error return.
typedef int32_t ssize_t;
// off_t is used for file offsets and lengths.
typedef int32_t off_t;
// Efficient min and max operations
#define MIN(_a, _b) \
({ \
typeof(_a) __a = (_a); \
typeof(_b) __b = (_b); \
__a <= __b ? __a : __b; \
})
#define MAX(_a, _b) \
({ \
typeof(_a) __a = (_a); \
typeof(_b) __b = (_b); \
__a >= __b ? __a : __b; \
})
// Rounding operations (efficient when n is a power of 2)
// Round down to the nearest multiple of n
#define ROUNDDOWN(a, n) \
({ \
uint64_t __a = (uint64_t) (a); \
(typeof(a)) (__a - __a % (n)); \
})
// Round up to the nearest multiple of n
#define ROUNDUP(a, n) \
({ \
uint64_t __n = (uint64_t) (n); \
(typeof(a)) (ROUNDDOWN((uint64_t) (a) + __n - 1, __n)); \
})
// Return the offset of 'member' relative to the beginning of a struct type
#define offsetof(type, member) ((size_t) (&((type*)0)->member))
#endif /* !JOS_INC_TYPES_H */