2 * Copyright 2013 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef FOLLY_PORTABILITY_H_
18 #define FOLLY_PORTABILITY_H_
20 #ifndef FOLLY_NO_CONFIG
21 #include "folly-config.h"
24 #ifdef FOLLY_HAVE_FEATURES_H
29 #ifdef FOLLY_HAVE_SCHED_H
31 #ifndef FOLLY_HAVE_PTHREAD_YIELD
32 #define pthread_yield sched_yield
37 // MaxAlign: max_align_t isn't supported by gcc
39 struct MaxAlign { char c; } __attribute__((aligned));
41 # error Cannot define MaxAlign on this platform
46 #if defined(__clang__) || defined(__GNUC__)
47 # define FOLLY_NORETURN __attribute__((noreturn))
49 # define FOLLY_NORETURN
53 // portable version check
55 # if defined __GNUC__ && defined __GNUC_MINOR__
56 # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= \
57 ((maj) << 16) + (min))
59 # define __GNUC_PREREQ(maj, min) 0
64 /* Define macro wrappers for C++11's "final" and "override" keywords, which
65 * are supported in gcc 4.7 but not gcc 4.6. */
66 #if !defined(FOLLY_FINAL) && !defined(FOLLY_OVERRIDE)
67 # if defined(__clang__) || __GNUC_PREREQ(4, 7)
68 # define FOLLY_FINAL final
69 # define FOLLY_OVERRIDE override
71 # define FOLLY_FINAL /**/
72 # define FOLLY_OVERRIDE /**/
77 // Define to 1 if you have the `preadv' and `pwritev' functions, respectively
78 #if !defined(FOLLY_HAVE_PREADV) && !defined(FOLLY_HAVE_PWRITEV)
79 # if defined(__GLIBC_PREREQ)
80 # if __GLIBC_PREREQ(2, 10)
81 # define FOLLY_HAVE_PREADV 1
82 # define FOLLY_HAVE_PWRITEV 1
87 /* Define attribute wrapper for function attribute used to disable
88 * address sanitizer instrumentation. Unfortunately, this attribute
89 * has issues when inlining is used, so disable that as well. */
90 #if defined(__clang__)
91 # if __has_feature(address_sanitizer)
92 # if __has_attribute(__no_address_safety_analysis__)
93 # define FOLLY_DISABLE_ADDRESS_SANITIZER \
94 __attribute__((__no_address_safety_analysis__, __noinline__))
95 # elif __has_attribute(__no_sanitize_address__)
96 # define FOLLY_DISABLE_ADDRESS_SANITIZER \
97 __attribute__((__no_sanitize_address__, __noinline__))
100 #elif defined (__GNUC__) && \
102 (__GNUC_MINOR__ >= 8) && \
104 # define FOLLY_DISABLE_ADDRESS_SANITIZER \
105 __attribute__((__no_address_safety_analysis__, __noinline__))
107 #ifndef FOLLY_DISABLE_ADDRESS_SANITIZER
108 # define FOLLY_DISABLE_ADDRESS_SANITIZER
111 #endif // FOLLY_PORTABILITY_H_