Changeset 73097 in vbox for trunk/include/iprt
- Timestamp:
- Jul 12, 2018 9:06:33 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 123672
- Location:
- trunk/include/iprt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cdefs.h
r72774 r73097 2265 2265 * Our own special offsetof() variant, returns a signed result. 2266 2266 * 2267 * This differs from the usual offsetof() in that it's not relying on builtin2268 * compiler stuff and thus can use variables in arrays the structure may2269 * contain. This is useful to determine the sizes of structures ending2270 * with a variable length field. For gcc >= 4.4 see @bugref{7775}.2271 *2272 2267 * @returns offset into the structure of the specified member. signed. 2273 2268 * @param type Structure type. 2274 2269 * @param member Member. 2275 */ 2276 #if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4) 2277 # define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 ) 2278 #else 2279 # define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) ) 2270 * 2271 * @remarks Only use this for static offset calculations. Please 2272 * use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves 2273 * non-constant array indexing). 2274 * 2275 */ 2276 #if RT_GNUC_PREREQ(4, 0) 2277 # define RT_OFFSETOF(type, member) ( (int)__builtin_offsetof(type, member) ) 2278 #else 2279 # define RT_OFFSETOF(type, member) ( (int)(intptr_t)&( ((type *)(void *)0)->member) ) 2280 2280 #endif 2281 2281 2282 2282 /** @def RT_UOFFSETOF 2283 * Our own special offsetof() variant, returns an unsigned result. 2284 * 2285 * This differs from the usual offsetof() in that it's not relying on builtin 2286 * compiler stuff and thus can use variables in arrays the structure may 2287 * contain. This is useful to determine the sizes of structures ending 2288 * with a variable length field. For gcc >= 4.4 see @bugref{7775}. 2283 * Our own offsetof() variant, returns an unsigned result. 2289 2284 * 2290 2285 * @returns offset into the structure of the specified member. unsigned. 2291 2286 * @param type Structure type. 2292 2287 * @param member Member. 2293 */ 2294 #if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4) 2295 # define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 ) 2288 * 2289 * @remarks Only use this for static offset calculations. Please 2290 * use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves 2291 * non-constant array indexing). 2292 */ 2293 #if RT_GNUC_PREREQ(4, 0) 2294 # define RT_UOFFSETOF(type, member) ( (uintptr_t)__builtin_offsetof(type, member) ) 2296 2295 #else 2297 2296 # define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) ) … … 2305 2304 * @param member Member. 2306 2305 * @param addend The addend to add to the offset. 2306 * 2307 * @remarks Only use this for static offset calculations. 2307 2308 */ 2308 2309 #define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) ) … … 2315 2316 * @param member Member. 2316 2317 * @param addend The addend to add to the offset. 2317 */ 2318 #define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) ) 2318 * 2319 * @remarks Only use this for static offset calculations. 2320 */ 2321 #if RT_GNUC_PREREQ(4, 0) 2322 # define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)(__builtin_offsetof(type, member) + (addend))) 2323 #else 2324 # define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) ) 2325 #endif 2326 2327 /** @def RT_UOFFSETOF_DYN 2328 * Dynamic (runtime) structure offset calculations, involving 2329 * indexing of array members via variable. 2330 * 2331 * @returns offset into the structure of the specified member. signed. 2332 * @param type Structure type. 2333 * @param memberarray Member. 2334 */ 2335 #if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4) 2336 # define RT_UOFFSETOF_DYN(type, memberarray) ( (uintptr_t)&( ((type *)(void *)0x1000)->memberarray) - 0x1000 ) 2337 #else 2338 # define RT_UOFFSETOF_DYN(type, memberarray) ( (uintptr_t)&( ((type *)(void *)0)->memberarray) ) 2339 #endif 2340 2319 2341 2320 2342 /** @def RT_SIZEOFMEMB -
trunk/include/iprt/nt/nt.h
r72639 r73097 1494 1494 #if !defined(NtCurrentTeb) && !defined(IPRT_NT_HAVE_CURRENT_TEB_MACRO) 1495 1495 # ifdef RT_ARCH_X86 1496 DECL_FORCE_INLINE(PTEB) RTNtCurrentTeb(void) { return (PTEB)__readfsdword(RT_ OFFSETOF(TEB_COMMON, NtTib.Self)); }1497 DECL_FORCE_INLINE(PPEB) RTNtCurrentPeb(void) { return (PPEB)__readfsdword(RT_ OFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); }1498 DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readfsdword(RT_ OFFSETOF(TEB_COMMON, ClientId.UniqueThread)); }1499 DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readfsdword(RT_ OFFSETOF(TEB_COMMON, LastStatusValue)); }1500 DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void) { return __readfsdword(RT_ OFFSETOF(TEB_COMMON, LastErrorValue)); }1496 DECL_FORCE_INLINE(PTEB) RTNtCurrentTeb(void) { return (PTEB)__readfsdword(RT_UOFFSETOF(TEB_COMMON, NtTib.Self)); } 1497 DECL_FORCE_INLINE(PPEB) RTNtCurrentPeb(void) { return (PPEB)__readfsdword(RT_UOFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); } 1498 DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readfsdword(RT_UOFFSETOF(TEB_COMMON, ClientId.UniqueThread)); } 1499 DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readfsdword(RT_UOFFSETOF(TEB_COMMON, LastStatusValue)); } 1500 DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void) { return __readfsdword(RT_UOFFSETOF(TEB_COMMON, LastErrorValue)); } 1501 1501 # elif defined(RT_ARCH_AMD64) 1502 DECL_FORCE_INLINE(PTEB) RTNtCurrentTeb(void) { return (PTEB)__readgsqword(RT_ OFFSETOF(TEB_COMMON, NtTib.Self)); }1503 DECL_FORCE_INLINE(PPEB) RTNtCurrentPeb(void) { return (PPEB)__readgsqword(RT_ OFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); }1504 DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readgsdword(RT_ OFFSETOF(TEB_COMMON, ClientId.UniqueThread)); }1505 DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readgsdword(RT_ OFFSETOF(TEB_COMMON, LastStatusValue)); }1506 DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void) { return __readgsdword(RT_ OFFSETOF(TEB_COMMON, LastErrorValue)); }1502 DECL_FORCE_INLINE(PTEB) RTNtCurrentTeb(void) { return (PTEB)__readgsqword(RT_UOFFSETOF(TEB_COMMON, NtTib.Self)); } 1503 DECL_FORCE_INLINE(PPEB) RTNtCurrentPeb(void) { return (PPEB)__readgsqword(RT_UOFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); } 1504 DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readgsdword(RT_UOFFSETOF(TEB_COMMON, ClientId.UniqueThread)); } 1505 DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readgsdword(RT_UOFFSETOF(TEB_COMMON, LastStatusValue)); } 1506 DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void) { return __readgsdword(RT_UOFFSETOF(TEB_COMMON, LastErrorValue)); } 1507 1507 # else 1508 1508 # error "Port me"
Note:
See TracChangeset
for help on using the changeset viewer.