sanitizer_common: make parsing of smaps testable (NFC)
Move parsing of /proc/self/smaps into a separate function so that it can be tested. Depends on D112788. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D112789
This commit is contained in:
		
							parent
							
								
									a871c34e8d
								
							
						
					
					
						commit
						d4602f759a
					
				| 
						 | 
				
			
			@ -198,6 +198,8 @@ typedef void (*fill_profile_f)(uptr start, uptr rss, bool file,
 | 
			
		|||
// |cb| is a tool-specific callback that fills the |stats| array containing
 | 
			
		||||
// |stats_size| elements.
 | 
			
		||||
void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size);
 | 
			
		||||
void ParseUnixMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size,
 | 
			
		||||
                            const char *smaps, uptr smaps_len);
 | 
			
		||||
 | 
			
		||||
// Simple low-level (mmap-based) allocator for internal use. Doesn't have
 | 
			
		||||
// constructor, so all instances of LowLevelAllocator should be
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -151,6 +151,12 @@ void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) {
 | 
			
		|||
  uptr smaps_len = 0;
 | 
			
		||||
  if (!ReadFileToBuffer("/proc/self/smaps", &smaps, &smaps_cap, &smaps_len))
 | 
			
		||||
    return;
 | 
			
		||||
  ParseUnixMemoryProfile(cb, stats, stats_size, smaps, smaps_len);
 | 
			
		||||
  UnmapOrDie(smaps, smaps_cap);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ParseUnixMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size,
 | 
			
		||||
                            const char *smaps, uptr smaps_len) {
 | 
			
		||||
  uptr start = 0;
 | 
			
		||||
  bool file = false;
 | 
			
		||||
  const char *pos = smaps;
 | 
			
		||||
| 
						 | 
				
			
			@ -166,7 +172,6 @@ void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) {
 | 
			
		|||
    }
 | 
			
		||||
    while (*pos++ != '\n') {}
 | 
			
		||||
  }
 | 
			
		||||
  UnmapOrDie(smaps, smaps_cap);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace __sanitizer
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue