forked from OSchip/llvm-project
				
			[sanitizer] Move the errno/ENOMEM allocator checks logic to separate .cc
Summary: The fact that `sanitizer_allocator_checks.h` is including `sanitizer_errno.h` creates complications for future changes, where it would conflict with `errno.h` definitions on Android and Fuchsia (macro redefinition). By moving the portion that sets errno in the checks to a separate compilation unit, we avoid the inclusion of the header there, which solves the issue. Not that it is not vital to have that function in a header as it is called as a result of an unlikely event, and doesn't need to be inlined. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: kubamracek, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D38706 llvm-svn: 315319
This commit is contained in:
		
							parent
							
								
									96d35fe06a
								
							
						
					
					
						commit
						03f9e76790
					
				| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set(SANITIZER_SOURCES_NOTERMINATION
 | 
					set(SANITIZER_SOURCES_NOTERMINATION
 | 
				
			||||||
  sanitizer_allocator.cc
 | 
					  sanitizer_allocator.cc
 | 
				
			||||||
 | 
					  sanitizer_allocator_checks.cc
 | 
				
			||||||
  sanitizer_common.cc
 | 
					  sanitizer_common.cc
 | 
				
			||||||
  sanitizer_deadlock_detector1.cc
 | 
					  sanitizer_deadlock_detector1.cc
 | 
				
			||||||
  sanitizer_deadlock_detector2.cc
 | 
					  sanitizer_deadlock_detector2.cc
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,23 @@
 | 
				
			||||||
 | 
					//===-- sanitizer_allocator_checks.cc ---------------------------*- C++ -*-===//
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//                     The LLVM Compiler Infrastructure
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// This file is distributed under the University of Illinois Open Source
 | 
				
			||||||
 | 
					// License. See LICENSE.TXT for details.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Various checks shared between ThreadSanitizer, MemorySanitizer, etc. memory
 | 
				
			||||||
 | 
					// allocators.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "sanitizer_errno.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace __sanitizer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SetErrnoToENOMEM() {
 | 
				
			||||||
 | 
					  errno = errno_ENOMEM;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace __sanitizer
 | 
				
			||||||
| 
						 | 
					@ -15,17 +15,22 @@
 | 
				
			||||||
#ifndef SANITIZER_ALLOCATOR_CHECKS_H
 | 
					#ifndef SANITIZER_ALLOCATOR_CHECKS_H
 | 
				
			||||||
#define SANITIZER_ALLOCATOR_CHECKS_H
 | 
					#define SANITIZER_ALLOCATOR_CHECKS_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "sanitizer_errno.h"
 | 
					 | 
				
			||||||
#include "sanitizer_internal_defs.h"
 | 
					#include "sanitizer_internal_defs.h"
 | 
				
			||||||
#include "sanitizer_common.h"
 | 
					#include "sanitizer_common.h"
 | 
				
			||||||
#include "sanitizer_platform.h"
 | 
					#include "sanitizer_platform.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace __sanitizer {
 | 
					namespace __sanitizer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The following is defined in a separate compilation unit to avoid pulling in
 | 
				
			||||||
 | 
					// sanitizer_errno.h in this header, which leads to conflicts when other system
 | 
				
			||||||
 | 
					// headers include errno.h. This is usually the result of an unlikely event,
 | 
				
			||||||
 | 
					// and as such we do not care as much about having it inlined.
 | 
				
			||||||
 | 
					void SetErrnoToENOMEM();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// A common errno setting logic shared by almost all sanitizer allocator APIs.
 | 
					// A common errno setting logic shared by almost all sanitizer allocator APIs.
 | 
				
			||||||
INLINE void *SetErrnoOnNull(void *ptr) {
 | 
					INLINE void *SetErrnoOnNull(void *ptr) {
 | 
				
			||||||
  if (UNLIKELY(!ptr))
 | 
					  if (UNLIKELY(!ptr))
 | 
				
			||||||
    errno = errno_ENOMEM;
 | 
					    SetErrnoToENOMEM();
 | 
				
			||||||
  return ptr;
 | 
					  return ptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue