1 //===-- sanitizer_procmaps_solaris.cc -------------------------------------===// 2 // 3 // This file is distributed under the University of Illinois Open Source 4 // License. See LICENSE.TXT for details. 5 // 6 //===----------------------------------------------------------------------===// 7 // 8 // Information about the process mappings (Solaris-specific parts). 9 //===----------------------------------------------------------------------===// 10 11 #include "sanitizer_platform.h" 12 #if SANITIZER_SOLARIS 13 #include "sanitizer_common.h" 14 #include "sanitizer_procmaps.h" 15 16 // Before Solaris 11.4, <procfs.h> doesn't work in a largefile environment. 17 #undef _FILE_OFFSET_BITS 18 #include <procfs.h> 19 #include <limits.h> 20 21 namespace __sanitizer { 22 23 void ReadProcMaps(ProcSelfMapsBuff *proc_maps) { 24 if (!ReadFileToBuffer("/proc/self/xmap", &proc_maps->data, 25 &proc_maps->mmaped_size, &proc_maps->len)) { 26 proc_maps->data = nullptr; 27 proc_maps->mmaped_size = 0; 28 proc_maps->len = 0; 29 } 30 } 31 32 bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) { 33 if (Error()) return false; // simulate empty maps 34 char *last = data_.proc_self_maps.data + data_.proc_self_maps.len; 35 if (data_.current >= last) return false; 36 37 prxmap_t *xmapentry = (prxmap_t*)data_.current; 38 39 segment->start = (uptr)xmapentry->pr_vaddr; 40 segment->end = (uptr)(xmapentry->pr_vaddr + xmapentry->pr_size); 41 segment->offset = (uptr)xmapentry->pr_offset; 42 43 segment->protection = 0; 44 if ((xmapentry->pr_mflags & MA_READ) != 0) 45 segment->protection |= kProtectionRead; 46 if ((xmapentry->pr_mflags & MA_WRITE) != 0) 47 segment->protection |= kProtectionWrite; 48 if ((xmapentry->pr_mflags & MA_EXEC) != 0) 49 segment->protection |= kProtectionExecute; 50 51 if (segment->filename != NULL && segment->filename_size > 0) { 52 internal_snprintf(segment->filename, 53 Min(segment->filename_size, (uptr)PATH_MAX), "%s", 54 xmapentry->pr_mapname); 55 } 56 57 data_.current += sizeof(prxmap_t); 58 59 return true; 60 } 61 62 } // namespace __sanitizer 63 64 #endif // SANITIZER_SOLARIS 65