Stefan Reinauer | 6ceed09 | 2013-04-08 16:55:47 -0700 | [diff] [blame] | 1 | |
| 2 | #include <arch/types.h> |
| 3 | |
| 4 | #ifndef __SIZE_TYPE__ |
| 5 | #define __SIZE_TYPE__ unsigned long |
| 6 | #endif |
| 7 | typedef __SIZE_TYPE__ size_t; |
Stefan Reinauer | f8b3650 | 2013-05-02 14:02:28 -0700 | [diff] [blame] | 8 | /* There is a GCC macro for a size_t type, but not |
| 9 | * for a ssize_t type. Below construct tricks GCC |
| 10 | * into making __SIZE_TYPE__ signed. |
| 11 | */ |
| 12 | #define unsigned signed |
| 13 | typedef __SIZE_TYPE__ ssize_t; |
| 14 | #undef unsigned |
Stefan Reinauer | 6ceed09 | 2013-04-08 16:55:47 -0700 | [diff] [blame] | 15 | |
| 16 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) |
Furquan Shaikh | 63a3e1e | 2015-06-11 05:17:32 -0700 | [diff] [blame] | 17 | #define member_size(TYPE, MEMBER) (sizeof(((TYPE *) 0)->MEMBER)) |
Stefan Reinauer | 6ceed09 | 2013-04-08 16:55:47 -0700 | [diff] [blame] | 18 | |
Daisuke Nojiri | e0a8a88 | 2015-06-29 13:33:34 -0700 | [diff] [blame^] | 19 | #define check_member(structure, member, offset) _Static_assert( \ |
| 20 | offsetof(struct structure, member) == offset, \ |
| 21 | "`struct " #structure "` offset for `" #member "` is not " #offset) |
| 22 | |
Daisuke Nojiri | 0341169 | 2014-03-05 15:46:28 -0800 | [diff] [blame] | 23 | /* Standard units. */ |
| 24 | #define KiB (1<<10) |
| 25 | #define MiB (1<<20) |
| 26 | #define GiB (1<<30) |
Daisuke Nojiri | e0a8a88 | 2015-06-29 13:33:34 -0700 | [diff] [blame^] | 27 | |
| 28 | #define KHz (1000) |
| 29 | #define MHz (1000*KHz) |
| 30 | #define GHz (1000*MHz) |