@@ -377,6 +377,71 @@ struct MappingPPC64_47 {
377377 static const uptr kMidAppMemEnd = 0 ;
378378};
379379
380+ /*
381+ C/C++ on linux/riscv64 (39-bit VMA)
382+ 0000 0010 00 - 0200 0000 00: main binary ( 8 GB)
383+ 0200 0000 00 - 1000 0000 00: -
384+ 1000 0000 00 - 4000 0000 00: shadow memory (64 GB)
385+ 4000 0000 00 - 4800 0000 00: metainfo (16 GB)
386+ 4800 0000 00 - 5500 0000 00: -
387+ 5500 0000 00 - 5a00 0000 00: main binary (PIE) (~8 GB)
388+ 5600 0000 00 - 7c00 0000 00: -
389+ 7d00 0000 00 - 7fff ffff ff: libraries and main thread stack ( 8 GB)
390+
391+ mmap by default allocates from top downwards
392+ VDSO sits below loader and above dynamic libraries, within HiApp region.
393+ Heap starts after program region whose position depends on pie or non-pie.
394+ Disable tracking them since their locations are not fixed.
395+ */
396+ struct MappingRiscv64_39 {
397+ static const uptr kLoAppMemBeg = 0x0000001000ull ;
398+ static const uptr kLoAppMemEnd = 0x0200000000ull ;
399+ static const uptr kShadowBeg = 0x1000000000ull ;
400+ static const uptr kShadowEnd = 0x2000000000ull ;
401+ static const uptr kMetaShadowBeg = 0x2000000000ull ;
402+ static const uptr kMetaShadowEnd = 0x2400000000ull ;
403+ static const uptr kMidAppMemBeg = 0x2aaaaaa000ull ;
404+ static const uptr kMidAppMemEnd = 0x2c00000000ull ;
405+ static const uptr kHeapMemBeg = 0x2c00000000ull ;
406+ static const uptr kHeapMemEnd = 0x2c00000000ull ;
407+ static const uptr kHiAppMemBeg = 0x3c00000000ull ;
408+ static const uptr kHiAppMemEnd = 0x3fffffffffull ;
409+ static const uptr kShadowMsk = 0x3800000000ull ;
410+ static const uptr kShadowXor = 0x0800000000ull ;
411+ static const uptr kShadowAdd = 0x0000000000ull ;
412+ static const uptr kVdsoBeg = 0x4000000000ull ;
413+ };
414+
415+ /*
416+ C/C++ on linux/riscv64 (48-bit VMA)
417+ 0000 0000 1000 - 0500 0000 0000: main binary ( 5 TB)
418+ 0500 0000 0000 - 2000 0000 0000: -
419+ 2000 0000 0000 - 4000 0000 0000: shadow memory (32 TB)
420+ 4000 0000 0000 - 4800 0000 0000: metainfo ( 8 TB)
421+ 4800 0000 0000 - 5555 5555 5000: -
422+ 5555 5555 5000 - 5a00 0000 0000: main binary (PIE) (~5 TB)
423+ 5a00 0000 0000 - 7a00 0000 0000: -
424+ 7a00 0000 0000 - 7fff ffff ffff: libraries and main thread stack ( 5 TB)
425+ */
426+ struct MappingRiscv64_48 {
427+ static const uptr kLoAppMemBeg = 0x000000001000ull ;
428+ static const uptr kLoAppMemEnd = 0x050000000000ull ;
429+ static const uptr kShadowBeg = 0x200000000000ull ;
430+ static const uptr kShadowEnd = 0x400000000000ull ;
431+ static const uptr kMetaShadowBeg = 0x400000000000ull ;
432+ static const uptr kMetaShadowEnd = 0x480000000000ull ;
433+ static const uptr kMidAppMemBeg = 0x555555555000ull ;
434+ static const uptr kMidAppMemEnd = 0x5a0000000000ull ;
435+ static const uptr kHeapMemBeg = 0x5a0000000000ull ;
436+ static const uptr kHeapMemEnd = 0x5a0000000000ull ;
437+ static const uptr kHiAppMemBeg = 0x7a0000000000ull ;
438+ static const uptr kHiAppMemEnd = 0x7fffffffffffull ;
439+ static const uptr kShadowMsk = 0x700000000000ull ;
440+ static const uptr kShadowXor = 0x100000000000ull ;
441+ static const uptr kShadowAdd = 0x000000000000ull ;
442+ static const uptr kVdsoBeg = 0x800000000000ull ;
443+ };
444+
380445/*
381446C/C++ on linux/s390x
382447While the kernel provides a 64-bit address space, we have to restrict ourselves
@@ -665,6 +730,13 @@ ALWAYS_INLINE auto SelectMapping(Arg arg) {
665730 }
666731# elif defined(__mips64)
667732 return Func::template Apply<MappingMips64_40>(arg);
733+ # elif SANITIZER_RISCV64
734+ switch (vmaSize) {
735+ case 39 :
736+ return Func::template Apply<MappingRiscv64_39>(arg);
737+ case 48 :
738+ return Func::template Apply<MappingRiscv64_48>(arg);
739+ }
668740# elif defined(__s390x__)
669741 return Func::template Apply<MappingS390x>(arg);
670742# else
@@ -686,6 +758,8 @@ void ForEachMapping() {
686758 Func::template Apply<MappingPPC64_44>();
687759 Func::template Apply<MappingPPC64_46>();
688760 Func::template Apply<MappingPPC64_47>();
761+ Func::template Apply<MappingRiscv64_39>();
762+ Func::template Apply<MappingRiscv64_48>();
689763 Func::template Apply<MappingS390x>();
690764 Func::template Apply<MappingGo48>();
691765 Func::template Apply<MappingGoWindows>();
@@ -894,7 +968,7 @@ struct RestoreAddrImpl {
894968 Mapping::kMidAppMemEnd , Mapping::kHiAppMemBeg , Mapping::kHiAppMemEnd ,
895969 Mapping::kHeapMemBeg , Mapping::kHeapMemEnd ,
896970 };
897- const uptr indicator = 0x0e0000000000ull ;
971+ const uptr indicator = 0x0f0000000000ull ;
898972 const uptr ind_lsb = 1ull << LeastSignificantSetBitIndex (indicator);
899973 for (uptr i = 0 ; i < ARRAY_SIZE (ranges); i += 2 ) {
900974 uptr beg = ranges[i];
0 commit comments