Stefan Reinauer | da1ef02 | 2012-12-07 17:24:06 -0800 | [diff] [blame] | 1 | #ifndef STDDEF_H |
| 2 | #define STDDEF_H |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 3 | |
| 4 | typedef long ptrdiff_t; |
Stefan Reinauer | 0e740d3 | 2012-05-14 13:21:08 -0700 | [diff] [blame] | 5 | #ifndef __SIZE_TYPE__ |
| 6 | #define __SIZE_TYPE__ unsigned long |
| 7 | #endif |
| 8 | typedef __SIZE_TYPE__ size_t; |
Stefan Reinauer | f8b3650 | 2013-05-02 14:02:28 -0700 | [diff] [blame] | 9 | /* There is a GCC macro for a size_t type, but not |
| 10 | * for a ssize_t type. Below construct tricks GCC |
| 11 | * into making __SIZE_TYPE__ signed. |
| 12 | */ |
| 13 | #define unsigned signed |
| 14 | typedef __SIZE_TYPE__ ssize_t; |
| 15 | #undef unsigned |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 16 | |
| 17 | typedef int wchar_t; |
| 18 | typedef unsigned int wint_t; |
| 19 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 20 | #define NULL ((void *)0) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 21 | |
Ronald G. Minnich | aa3f428 | 2013-03-15 20:17:26 -0700 | [diff] [blame] | 22 | /* Standard units. */ |
| 23 | #define KiB (1<<10) |
| 24 | #define MiB (1<<20) |
| 25 | #define GiB (1<<30) |
| 26 | /* Could we ever run into this one? I hope we get this much memory! */ |
| 27 | #define TiB (1<<40) |
| 28 | |
Aaron Durbin | 46826c3 | 2015-04-02 15:43:12 -0500 | [diff] [blame] | 29 | #define KHz (1000) |
| 30 | #define MHz (1000 * KHz) |
| 31 | #define GHz (1000 * MHz) |
| 32 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 33 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
| 34 | |
Julius Werner | 03784fa | 2013-12-09 17:46:22 -0800 | [diff] [blame] | 35 | #define check_member(structure, member, offset) _Static_assert( \ |
| 36 | offsetof(struct structure, member) == offset, \ |
| 37 | "`struct " #structure "` offset for `" #member "` is not " #offset ) |
| 38 | |
Stefan Reinauer | 4417deb | 2015-01-05 11:09:11 -0800 | [diff] [blame] | 39 | /** |
| 40 | * container_of - cast a member of a structure out to the containing structure |
| 41 | * @param ptr: the pointer to the member. |
| 42 | * @param type: the type of the container struct this is embedded in. |
| 43 | * @param member: the name of the member within the struct. |
| 44 | * |
| 45 | */ |
| 46 | #define container_of(ptr, type, member) ({ \ |
| 47 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
| 48 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
| 49 | |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 50 | #ifdef __PRE_RAM__ |
| 51 | #define ROMSTAGE_CONST const |
| 52 | #else |
| 53 | #define ROMSTAGE_CONST |
| 54 | #endif |
| 55 | |
Julius Werner | dbe0df1 | 2014-06-06 16:10:56 -0700 | [diff] [blame] | 56 | /* Work around non-writable data segment in execute-in-place romstage on x86. */ |
| 57 | #if defined(__PRE_RAM__) && CONFIG_ARCH_X86 |
| 58 | #define MAYBE_STATIC |
| 59 | #else |
| 60 | #define MAYBE_STATIC static |
| 61 | #endif |
| 62 | |
Stefan Reinauer | da1ef02 | 2012-12-07 17:24:06 -0800 | [diff] [blame] | 63 | #endif /* STDDEF_H */ |