136
136
#define __has_c_attribute (attr ) 0
137
137
#endif
138
138
139
+ // C attributes support namespaces according to the C2X
140
+ // standard, but MSVC toolsets fail to parse namespaces
141
+ // in that location anyway when not parsing as C++.
142
+ #if !defined(__cplusplus) && (MSVC_COMPAT && !GCC_COMPAT && !CLANG_COMPAT && !MINGW_COMPAT && !ICC_COMPAT)
143
+ #define __has_c_attribute_with_namespace (attr ) 0
144
+ #else
145
+ #define __has_c_attribute_with_namespace (attr ) __has_c_attribute(attr)
146
+ #endif
147
+
139
148
// - GNU Attributes
140
149
#ifndef __has_attribute
141
150
#define __has_attribute (attr ) 0
283
292
// - [[likely]] Equivalent Attributes
284
293
#if __has_cpp_attribute(likely) >= 201803L
285
294
#define TH_LIKELY [[likely]]
286
- #elif __has_c_attribute (clang::likely)
295
+ #elif __has_c_attribute_with_namespace (clang::likely)
287
296
#define TH_LIKELY [[clang::likely]]
288
297
#else
289
298
#define TH_LIKELY
292
301
// - [[unlikely]] Equivalent Attributes
293
302
#if __has_cpp_attribute(unlikely) >= 201803L
294
303
#define TH_UNLIKELY [[unlikely]]
295
- #elif __has_c_attribute (clang::unlikely)
304
+ #elif __has_c_attribute_with_namespace (clang::unlikely)
296
305
#define TH_UNLIKELY [[clang::unlikely]]
297
306
#else
298
307
#define TH_UNLIKELY
@@ -542,49 +551,59 @@ extern "C++" {
542
551
#define read_fs_byte (offset ) (*(uint8_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset))
543
552
#define read_fs_word (offset ) (*(uint16_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset))
544
553
#define read_fs_dword (offset ) (*(uint32_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset))
554
+ #define read_fs_qword (offset ) (*(uint64_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset))
545
555
#define write_fs_byte (offset, data ) ((void )(*(uint8_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset) = (uint8_t )(data)))
546
556
#define write_fs_word (offset, data ) ((void )(*(uint16_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset) = (uint16_t )(data)))
547
557
#define write_fs_dword (offset, data ) ((void )(*(uint32_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset) = (uint32_t )(data)))
548
- #elif defined(__SEG_FS) && (CLANG_COMPAT || !defined(__cplusplus)) // __seg_fs isn't recognized by GCC when compiling C++
558
+ #define write_fs_qword (offset, data ) ((void )(*(uint64_t __attribute__ ((address_space(257 )))*)((uintptr_t )offset) = (uint64_t )(data)))
559
+ #elif defined(__SEG_FS)
560
+ #if CLANG_COMPAT || !defined(__cplusplus) // __seg_fs isn't recognized by GCC when compiling C++
549
561
#define read_fs_byte (offset ) (*(__seg_fs uint8_t *)((uintptr_t )offset))
550
562
#define read_fs_word (offset ) (*(__seg_fs uint16_t *)((uintptr_t )offset))
551
563
#define read_fs_dword (offset ) (*(__seg_fs uint32_t *)((uintptr_t )offset))
564
+ #define read_fs_qword (offset ) (*(__seg_fs uint64_t *)((uintptr_t )offset))
552
565
#define write_fs_byte (offset, data ) ((void )(*(__seg_fs uint8_t *)((uintptr_t )offset) = (uint8_t )(data)))
553
566
#define write_fs_word (offset, data ) ((void )(*(__seg_fs uint16_t *)((uintptr_t )offset) = (uint16_t )(data)))
554
567
#define write_fs_dword (offset, data ) ((void )(*(__seg_fs uint32_t *)((uintptr_t )offset) = (uint32_t )(data)))
555
- #elif GCC_COMPAT
556
- #ifdef __cplusplus
568
+ #define write_fs_qword ( offset, data ) (( void )(*(__seg_fs uint64_t *)(( uintptr_t )offset) = ( uint64_t )(data)))
569
+ #else
557
570
extern " C" {
558
- #endif
559
- #define read_fs_byte (offset ) read_fs_byte_gcc(offset)
560
- #define read_fs_word (offset ) read_fs_word_gcc(offset)
561
- #define read_fs_dword (offset ) read_fs_dword_gcc(offset)
562
- #define write_fs_byte (offset, data ) write_fs_byte_gcc(offset, data)
563
- #define write_fs_word (offset, data ) write_fs_word_gcc(offset, data)
564
- #define write_fs_dword (offset, data ) write_fs_dword_gcc(offset, data)
565
571
uint8_t read_fs_byte_gcc (size_t offset);
566
572
uint16_t read_fs_word_gcc (size_t offset);
567
573
uint32_t read_fs_dword_gcc (size_t offset);
574
+ uint32_t read_fs_qword_gcc (size_t offset);
568
575
void write_fs_byte_gcc (size_t offset, uint8_t data);
569
576
void write_fs_word_gcc (size_t offset, uint16_t data);
570
577
void write_fs_dword_gcc (size_t offset, uint32_t data);
571
- # ifdef __cplusplus
578
+ void write_fs_qword_gcc ( size_t offset, uint32_t data);
572
579
};
580
+ #define read_fs_byte (offset ) read_fs_byte_gcc(offset)
581
+ #define read_fs_word (offset ) read_fs_word_gcc(offset)
582
+ #define read_fs_dword (offset ) read_fs_dword_gcc(offset)
583
+ #define read_fs_qword (offset ) read_fs_qword_gcc(offset)
584
+ #define write_fs_byte (offset, data ) write_fs_byte_gcc(offset, data)
585
+ #define write_fs_word (offset, data ) write_fs_word_gcc(offset, data)
586
+ #define write_fs_dword (offset, data ) write_fs_dword_gcc(offset, data)
587
+ #define write_fs_qword (offset, data ) write_fs_qword_gcc(offset, data)
573
588
#endif
574
589
#elif MSVC_COMPAT
575
590
#define read_fs_byte (offset ) __readfsbyte(offset)
576
591
#define read_fs_word (offset ) __readfsword(offset)
577
592
#define read_fs_dword (offset ) __readfsdword(offset)
593
+ #define read_fs_qword (offset ) __readfsqword(offset)
578
594
#define write_fs_byte (offset, data ) __writefsbyte(offset, data)
579
595
#define write_fs_word (offset, data ) __writefsword(offset, data)
580
596
#define write_fs_dword (offset, data ) __writefsdword(offset, data)
597
+ #define write_fs_qword (offset, data ) __writefsqword(offset, data)
581
598
#else
582
599
#define read_fs_byte (offset ) (*(uint8_t *)((uintptr_t )offset))
583
600
#define read_fs_word (offset ) (*(uint16_t *)((uintptr_t )offset))
584
601
#define read_fs_dword (offset ) (*(uint32_t *)((uintptr_t )offset))
602
+ #define read_fs_qword (offset ) (*(uint64_t *)((uintptr_t )offset))
585
603
#define write_fs_byte (offset, data ) ((void )(*(uint8_t *)((uintptr_t )offset) = (uint8_t )(data)))
586
604
#define write_fs_word (offset, data ) ((void )(*(uint16_t *)((uintptr_t )offset) = (uint16_t )(data)))
587
605
#define write_fs_dword (offset, data ) ((void )(*(uint32_t *)((uintptr_t )offset) = (uint32_t )(data)))
606
+ #define write_fs_qword (offset, data ) ((void )(*(uint64_t *)((uintptr_t )offset) = (uint64_t )(data)))
588
607
#endif
589
608
#if __has_attribute(address_space)
590
609
#define read_gs_byte (offset ) (*(uint8_t __attribute__ ((address_space(256 )))*)((uintptr_t )offset))
@@ -595,7 +614,8 @@ void write_fs_dword_gcc(size_t offset, uint32_t data);
595
614
#define write_gs_word (offset, data ) ((void )(*(uint16_t __attribute__ ((address_space(256 )))*)((uintptr_t )offset) = (uint16_t )(data)))
596
615
#define write_gs_dword (offset, data ) ((void )(*(uint32_t __attribute__ ((address_space(256 )))*)((uintptr_t )offset) = (uint32_t )(data)))
597
616
#define write_gs_qword (offset, data ) ((void )(*(uint64_t __attribute__ ((address_space(256 )))*)((uintptr_t )offset) = (uint64_t )(data)))
598
- #elif defined(__SEG_GS) && (CLANG_COMPAT || !defined(__cplusplus)) // __seg_gs isn't recognized by GCC when compiling C++
617
+ #elif defined(__SEG_GS)
618
+ #if CLANG_COMPAT || !defined(__cplusplus) // __seg_gs isn't recognized by GCC when compiling C++
599
619
#define read_gs_byte (offset ) (*(__seg_gs uint8_t *)((uintptr_t )offset))
600
620
#define read_gs_word (offset ) (*(__seg_gs uint16_t *)((uintptr_t )offset))
601
621
#define read_gs_dword (offset ) (*(__seg_gs uint32_t *)((uintptr_t )offset))
@@ -604,18 +624,8 @@ void write_fs_dword_gcc(size_t offset, uint32_t data);
604
624
#define write_gs_word (offset, data ) ((void )(*(__seg_gs uint16_t *)((uintptr_t )offset) = (uint16_t )(data)))
605
625
#define write_gs_dword (offset, data ) ((void )(*(__seg_gs uint32_t *)((uintptr_t )offset) = (uint32_t )(data)))
606
626
#define write_gs_qword (offset, data ) ((void )(*(__seg_gs uint64_t *)((uintptr_t )offset) = (uint64_t )(data)))
607
- #elif GCC_COMPAT
608
- #ifdef __cplusplus
627
+ #else
609
628
extern " C" {
610
- #endif
611
- #define read_gs_byte (offset ) read_gs_byte_gcc(offset)
612
- #define read_gs_word (offset ) read_gs_word_gcc(offset)
613
- #define read_gs_dword (offset ) read_gs_dword_gcc(offset)
614
- #define read_gs_qword (offset ) read_gs_qword_gcc(offset)
615
- #define write_gs_byte (offset, data ) write_gs_byte_gcc(offset, data)
616
- #define write_gs_word (offset, data ) write_gs_word_gcc(offset, data)
617
- #define write_gs_dword (offset, data ) write_gs_dword_gcc(offset, data)
618
- #define write_gs_qword (offset, data ) write_gs_qword_gcc(offset, data)
619
629
uint8_t read_gs_byte_gcc (size_t offset);
620
630
uint16_t read_gs_word_gcc (size_t offset);
621
631
uint32_t read_gs_dword_gcc (size_t offset);
@@ -624,8 +634,15 @@ void write_gs_byte_gcc(size_t offset, uint8_t data);
624
634
void write_gs_word_gcc (size_t offset, uint16_t data);
625
635
void write_gs_dword_gcc (size_t offset, uint32_t data);
626
636
void write_gs_qword_gcc (size_t offset, uint64_t data);
627
- #ifdef __cplusplus
628
637
};
638
+ #define read_gs_byte (offset ) read_gs_byte_gcc(offset)
639
+ #define read_gs_word (offset ) read_gs_word_gcc(offset)
640
+ #define read_gs_dword (offset ) read_gs_dword_gcc(offset)
641
+ #define read_gs_qword (offset ) read_gs_qword_gcc(offset)
642
+ #define write_gs_byte (offset, data ) write_gs_byte_gcc(offset, data)
643
+ #define write_gs_word (offset, data ) write_gs_word_gcc(offset, data)
644
+ #define write_gs_dword (offset, data ) write_gs_dword_gcc(offset, data)
645
+ #define write_gs_qword (offset, data ) write_gs_qword_gcc(offset, data)
629
646
#endif
630
647
#elif MSVC_COMPAT
631
648
#define read_gs_byte (offset ) __readgsbyte(offset)
@@ -647,7 +664,7 @@ void write_gs_qword_gcc(size_t offset, uint64_t data);
647
664
#define write_gs_qword (offset, data ) ((void )(*(uint64_t *)((uintptr_t )offset) = (uint64_t )(data)))
648
665
#endif
649
666
650
- #ifdef GCC_COMPAT
667
+ #if GCC_COMPAT
651
668
#ifndef __sptr
652
669
#define __sptr
653
670
#endif
0 commit comments