003 File Manager
Current Path:
/usr/src/contrib/llvm-project/compiler-rt/lib/builtins
usr
/
src
/
contrib
/
llvm-project
/
compiler-rt
/
lib
/
builtins
/
📁
..
📄
README.txt
(14.85 KB)
📁
aarch64
📄
absvdi2.c
(815 B)
📄
absvsi2.c
(815 B)
📄
absvti2.c
(864 B)
📄
adddf3.c
(859 B)
📄
addsf3.c
(853 B)
📄
addtf3.c
(730 B)
📄
addvdi3.c
(819 B)
📄
addvsi3.c
(819 B)
📄
addvti3.c
(868 B)
📄
apple_versioning.c
(13.1 KB)
📁
arm
📄
ashldi3.c
(1.17 KB)
📄
ashlti3.c
(1.15 KB)
📄
ashrdi3.c
(1.27 KB)
📄
ashrti3.c
(1.25 KB)
📄
assembly.h
(7.11 KB)
📄
atomic.c
(16.86 KB)
📄
atomic_flag_clear.c
(791 B)
📄
atomic_flag_clear_explicit.c
(859 B)
📄
atomic_flag_test_and_set.c
(823 B)
📄
atomic_flag_test_and_set_explicit.c
(898 B)
📄
atomic_signal_fence.c
(761 B)
📄
atomic_thread_fence.c
(761 B)
📄
bswapdi2.c
(958 B)
📄
bswapsi2.c
(743 B)
📄
clear_cache.c
(6.13 KB)
📄
clzdi2.c
(1.27 KB)
📄
clzsi2.c
(1.48 KB)
📄
clzti2.c
(884 B)
📄
cmpdi2.c
(1.12 KB)
📄
cmpti2.c
(974 B)
📄
comparedf2.c
(4.29 KB)
📄
comparesf2.c
(4.28 KB)
📄
comparetf2.c
(3.79 KB)
📄
cpu_model.c
(21.28 KB)
📄
ctzdi2.c
(1.27 KB)
📄
ctzsi2.c
(1.61 KB)
📄
ctzti2.c
(884 B)
📄
divdc3.c
(2.18 KB)
📄
divdf3.c
(7.55 KB)
📄
divdi3.c
(1.13 KB)
📄
divmoddi4.c
(712 B)
📄
divmodsi4.c
(715 B)
📄
divsc3.c
(2.14 KB)
📄
divsf3.c
(6.96 KB)
📄
divsi3.c
(1.32 KB)
📄
divtc3.c
(2.23 KB)
📄
divtf3.c
(8.01 KB)
📄
divti3.c
(1.18 KB)
📄
divxc3.c
(2.17 KB)
📄
emutls.c
(12.39 KB)
📄
enable_execute_stack.c
(2.08 KB)
📄
eprintf.c
(953 B)
📄
extenddftf2.c
(623 B)
📄
extendhfsf2.c
(946 B)
📄
extendsfdf2.c
(716 B)
📄
extendsftf2.c
(622 B)
📄
ffsdi2.c
(900 B)
📄
ffssi2.c
(776 B)
📄
ffsti2.c
(969 B)
📄
fixdfdi.c
(1.22 KB)
📄
fixdfsi.c
(755 B)
📄
fixdfti.c
(633 B)
📄
fixsfdi.c
(1.22 KB)
📄
fixsfsi.c
(755 B)
📄
fixsfti.c
(633 B)
📄
fixtfdi.c
(624 B)
📄
fixtfsi.c
(624 B)
📄
fixtfti.c
(624 B)
📄
fixunsdfdi.c
(1.29 KB)
📄
fixunsdfsi.c
(743 B)
📄
fixunsdfti.c
(611 B)
📄
fixunssfdi.c
(1.3 KB)
📄
fixunssfsi.c
(896 B)
📄
fixunssfti.c
(731 B)
📄
fixunstfdi.c
(604 B)
📄
fixunstfsi.c
(604 B)
📄
fixunstfti.c
(604 B)
📄
fixunsxfdi.c
(1.65 KB)
📄
fixunsxfsi.c
(1.62 KB)
📄
fixunsxfti.c
(1.41 KB)
📄
fixxfdi.c
(1.75 KB)
📄
fixxfti.c
(1.48 KB)
📄
floatdidf.c
(3.37 KB)
📄
floatdisf.c
(2.49 KB)
📄
floatditf.c
(1.5 KB)
📄
floatdixf.c
(1.37 KB)
📄
floatsidf.c
(1.7 KB)
📄
floatsisf.c
(1.89 KB)
📄
floatsitf.c
(1.5 KB)
📄
floattidf.c
(2.49 KB)
📄
floattisf.c
(2.33 KB)
📄
floattitf.c
(2.72 KB)
📄
floattixf.c
(2.53 KB)
📄
floatundidf.c
(3.43 KB)
📄
floatundisf.c
(2.4 KB)
📄
floatunditf.c
(1.27 KB)
📄
floatundixf.c
(1.24 KB)
📄
floatunsidf.c
(1.43 KB)
📄
floatunsisf.c
(1.75 KB)
📄
floatunsitf.c
(1.29 KB)
📄
floatuntidf.c
(2.38 KB)
📄
floatuntisf.c
(2.24 KB)
📄
floatuntitf.c
(2.6 KB)
📄
floatuntixf.c
(2.39 KB)
📄
fp_add_impl.inc
(5.4 KB)
📄
fp_extend.h
(2.36 KB)
📄
fp_extend_impl.inc
(4.53 KB)
📄
fp_fixint_impl.inc
(1.52 KB)
📄
fp_fixuint_impl.inc
(1.42 KB)
📄
fp_lib.h
(10.12 KB)
📄
fp_mode.c
(812 B)
📄
fp_mode.h
(824 B)
📄
fp_mul_impl.inc
(4.37 KB)
📄
fp_trunc.h
(2.01 KB)
📄
fp_trunc_impl.inc
(5.57 KB)
📄
gcc_personality_v0.c
(8.3 KB)
📁
hexagon
📁
i386
📄
int_div_impl.inc
(2.19 KB)
📄
int_endianness.h
(2.75 KB)
📄
int_lib.h
(4.57 KB)
📄
int_math.h
(3.6 KB)
📄
int_types.h
(4.16 KB)
📄
int_util.c
(1.95 KB)
📄
int_util.h
(1.32 KB)
📄
lshrdi3.c
(1.18 KB)
📄
lshrti3.c
(1.17 KB)
📄
mingw_fixfloat.c
(1.29 KB)
📄
moddi3.c
(1004 B)
📄
modsi3.c
(649 B)
📄
modti3.c
(1.03 KB)
📄
muldc3.c
(2.14 KB)
📄
muldf3.c
(918 B)
📄
muldi3.c
(1.55 KB)
📄
mulodi4.c
(1.31 KB)
📄
mulosi4.c
(1.31 KB)
📄
muloti4.c
(1.36 KB)
📄
mulsc3.c
(2.11 KB)
📄
mulsf3.c
(918 B)
📄
multc3.c
(2.02 KB)
📄
multf3.c
(799 B)
📄
multi3.c
(1.53 KB)
📄
mulvdi3.c
(1.26 KB)
📄
mulvsi3.c
(1.26 KB)
📄
mulvti3.c
(1.31 KB)
📄
mulxc3.c
(2.22 KB)
📄
negdf2.c
(832 B)
📄
negdi2.c
(719 B)
📄
negsf2.c
(832 B)
📄
negti2.c
(768 B)
📄
negvdi2.c
(768 B)
📄
negvsi2.c
(768 B)
📄
negvti2.c
(817 B)
📄
os_version_check.c
(8.07 KB)
📄
paritydi2.c
(712 B)
📄
paritysi2.c
(751 B)
📄
parityti2.c
(761 B)
📄
popcountdi2.c
(1.33 KB)
📄
popcountsi2.c
(1.13 KB)
📄
popcountti2.c
(1.69 KB)
📄
powidf2.c
(786 B)
📄
powisf2.c
(783 B)
📄
powitf2.c
(888 B)
📄
powixf2.c
(825 B)
📁
ppc
📁
riscv
📁
sparc64
📄
subdf3.c
(917 B)
📄
subsf3.c
(917 B)
📄
subtf3.c
(825 B)
📄
subvdi3.c
(819 B)
📄
subvsi3.c
(819 B)
📄
subvti3.c
(868 B)
📄
trampoline_setup.c
(1.75 KB)
📄
truncdfhf2.c
(715 B)
📄
truncdfsf2.c
(711 B)
📄
truncsfhf2.c
(940 B)
📄
trunctfdf2.c
(625 B)
📄
trunctfsf2.c
(624 B)
📄
ucmpdi2.c
(1.13 KB)
📄
ucmpti2.c
(978 B)
📄
udivdi3.c
(724 B)
📄
udivmoddi4.c
(5.4 KB)
📄
udivmodsi4.c
(715 B)
📄
udivmodti4.c
(4.87 KB)
📄
udivsi3.c
(802 B)
📄
udivti3.c
(699 B)
📄
umoddi3.c
(724 B)
📄
umodsi3.c
(724 B)
📄
umodti3.c
(717 B)
📄
unwind-ehabi-helpers.h
(1.86 KB)
📁
ve
📁
x86_64
Editing: emutls.c
//===---------- emutls.c - Implements __emutls_get_address ---------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include <stdint.h> #include <stdlib.h> #include <string.h> #include "int_lib.h" #ifdef __BIONIC__ // There are 4 pthread key cleanup rounds on Bionic. Delay emutls deallocation // to round 2. We need to delay deallocation because: // - Android versions older than M lack __cxa_thread_atexit_impl, so apps // use a pthread key destructor to call C++ destructors. // - Apps might use __thread/thread_local variables in pthread destructors. // We can't wait until the final two rounds, because jemalloc needs two rounds // after the final malloc/free call to free its thread-specific data (see // https://reviews.llvm.org/D46978#1107507). #define EMUTLS_SKIP_DESTRUCTOR_ROUNDS 1 #else #define EMUTLS_SKIP_DESTRUCTOR_ROUNDS 0 #endif #if defined(_MSC_VER) && !defined(__clang__) // MSVC raises a warning about a nonstandard extension being used for the 0 // sized element in this array. Disable this for warn-as-error builds. #pragma warning(push) #pragma warning(disable : 4206) #endif typedef struct emutls_address_array { uintptr_t skip_destructor_rounds; uintptr_t size; // number of elements in the 'data' array void *data[]; } emutls_address_array; #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(pop) #endif static void emutls_shutdown(emutls_address_array *array); #ifndef _WIN32 #include <pthread.h> static pthread_mutex_t emutls_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_key_t emutls_pthread_key; static bool emutls_key_created = false; typedef unsigned int gcc_word __attribute__((mode(word))); typedef unsigned int gcc_pointer __attribute__((mode(pointer))); // Default is not to use posix_memalign, so systems like Android // can use thread local data without heavier POSIX memory allocators. #ifndef EMUTLS_USE_POSIX_MEMALIGN #define EMUTLS_USE_POSIX_MEMALIGN 0 #endif static __inline void *emutls_memalign_alloc(size_t align, size_t size) { void *base; #if EMUTLS_USE_POSIX_MEMALIGN if (posix_memalign(&base, align, size) != 0) abort(); #else #define EXTRA_ALIGN_PTR_BYTES (align - 1 + sizeof(void *)) char *object; if ((object = (char *)malloc(EXTRA_ALIGN_PTR_BYTES + size)) == NULL) abort(); base = (void *)(((uintptr_t)(object + EXTRA_ALIGN_PTR_BYTES)) & ~(uintptr_t)(align - 1)); ((void **)base)[-1] = object; #endif return base; } static __inline void emutls_memalign_free(void *base) { #if EMUTLS_USE_POSIX_MEMALIGN free(base); #else // The mallocated address is in ((void**)base)[-1] free(((void **)base)[-1]); #endif } static __inline void emutls_setspecific(emutls_address_array *value) { pthread_setspecific(emutls_pthread_key, (void *)value); } static __inline emutls_address_array *emutls_getspecific() { return (emutls_address_array *)pthread_getspecific(emutls_pthread_key); } static void emutls_key_destructor(void *ptr) { emutls_address_array *array = (emutls_address_array *)ptr; if (array->skip_destructor_rounds > 0) { // emutls is deallocated using a pthread key destructor. These // destructors are called in several rounds to accommodate destructor // functions that (re)initialize key values with pthread_setspecific. // Delay the emutls deallocation to accommodate other end-of-thread // cleanup tasks like calling thread_local destructors (e.g. the // __cxa_thread_atexit fallback in libc++abi). array->skip_destructor_rounds--; emutls_setspecific(array); } else { emutls_shutdown(array); free(ptr); } } static __inline void emutls_init(void) { if (pthread_key_create(&emutls_pthread_key, emutls_key_destructor) != 0) abort(); emutls_key_created = true; } static __inline void emutls_init_once(void) { static pthread_once_t once = PTHREAD_ONCE_INIT; pthread_once(&once, emutls_init); } static __inline void emutls_lock() { pthread_mutex_lock(&emutls_mutex); } static __inline void emutls_unlock() { pthread_mutex_unlock(&emutls_mutex); } #else // _WIN32 #include <assert.h> #include <malloc.h> #include <stdio.h> #include <windows.h> static LPCRITICAL_SECTION emutls_mutex; static DWORD emutls_tls_index = TLS_OUT_OF_INDEXES; typedef uintptr_t gcc_word; typedef void *gcc_pointer; static void win_error(DWORD last_err, const char *hint) { char *buffer = NULL; if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, last_err, 0, (LPSTR)&buffer, 1, NULL)) { fprintf(stderr, "Windows error: %s\n", buffer); } else { fprintf(stderr, "Unkown Windows error: %s\n", hint); } LocalFree(buffer); } static __inline void win_abort(DWORD last_err, const char *hint) { win_error(last_err, hint); abort(); } static __inline void *emutls_memalign_alloc(size_t align, size_t size) { void *base = _aligned_malloc(size, align); if (!base) win_abort(GetLastError(), "_aligned_malloc"); return base; } static __inline void emutls_memalign_free(void *base) { _aligned_free(base); } static void emutls_exit(void) { if (emutls_mutex) { DeleteCriticalSection(emutls_mutex); _aligned_free(emutls_mutex); emutls_mutex = NULL; } if (emutls_tls_index != TLS_OUT_OF_INDEXES) { emutls_shutdown((emutls_address_array *)TlsGetValue(emutls_tls_index)); TlsFree(emutls_tls_index); emutls_tls_index = TLS_OUT_OF_INDEXES; } } #pragma warning(push) #pragma warning(disable : 4100) static BOOL CALLBACK emutls_init(PINIT_ONCE p0, PVOID p1, PVOID *p2) { emutls_mutex = (LPCRITICAL_SECTION)_aligned_malloc(sizeof(CRITICAL_SECTION), 16); if (!emutls_mutex) { win_error(GetLastError(), "_aligned_malloc"); return FALSE; } InitializeCriticalSection(emutls_mutex); emutls_tls_index = TlsAlloc(); if (emutls_tls_index == TLS_OUT_OF_INDEXES) { emutls_exit(); win_error(GetLastError(), "TlsAlloc"); return FALSE; } atexit(&emutls_exit); return TRUE; } static __inline void emutls_init_once(void) { static INIT_ONCE once; InitOnceExecuteOnce(&once, emutls_init, NULL, NULL); } static __inline void emutls_lock() { EnterCriticalSection(emutls_mutex); } static __inline void emutls_unlock() { LeaveCriticalSection(emutls_mutex); } static __inline void emutls_setspecific(emutls_address_array *value) { if (TlsSetValue(emutls_tls_index, (LPVOID)value) == 0) win_abort(GetLastError(), "TlsSetValue"); } static __inline emutls_address_array *emutls_getspecific() { LPVOID value = TlsGetValue(emutls_tls_index); if (value == NULL) { const DWORD err = GetLastError(); if (err != ERROR_SUCCESS) win_abort(err, "TlsGetValue"); } return (emutls_address_array *)value; } // Provide atomic load/store functions for emutls_get_index if built with MSVC. #if !defined(__ATOMIC_RELEASE) #include <intrin.h> enum { __ATOMIC_ACQUIRE = 2, __ATOMIC_RELEASE = 3 }; static __inline uintptr_t __atomic_load_n(void *ptr, unsigned type) { assert(type == __ATOMIC_ACQUIRE); // These return the previous value - but since we do an OR with 0, // it's equivalent to a plain load. #ifdef _WIN64 return InterlockedOr64(ptr, 0); #else return InterlockedOr(ptr, 0); #endif } static __inline void __atomic_store_n(void *ptr, uintptr_t val, unsigned type) { assert(type == __ATOMIC_RELEASE); InterlockedExchangePointer((void *volatile *)ptr, (void *)val); } #endif // __ATOMIC_RELEASE #pragma warning(pop) #endif // _WIN32 static size_t emutls_num_object = 0; // number of allocated TLS objects // Free the allocated TLS data static void emutls_shutdown(emutls_address_array *array) { if (array) { uintptr_t i; for (i = 0; i < array->size; ++i) { if (array->data[i]) emutls_memalign_free(array->data[i]); } } } // For every TLS variable xyz, // there is one __emutls_control variable named __emutls_v.xyz. // If xyz has non-zero initial value, __emutls_v.xyz's "value" // will point to __emutls_t.xyz, which has the initial value. typedef struct __emutls_control { // Must use gcc_word here, instead of size_t, to match GCC. When // gcc_word is larger than size_t, the upper extra bits are all // zeros. We can use variables of size_t to operate on size and // align. gcc_word size; // size of the object in bytes gcc_word align; // alignment of the object in bytes union { uintptr_t index; // data[index-1] is the object address void *address; // object address, when in single thread env } object; void *value; // null or non-zero initial value for the object } __emutls_control; // Emulated TLS objects are always allocated at run-time. static __inline void *emutls_allocate_object(__emutls_control *control) { // Use standard C types, check with gcc's emutls.o. COMPILE_TIME_ASSERT(sizeof(uintptr_t) == sizeof(gcc_pointer)); COMPILE_TIME_ASSERT(sizeof(uintptr_t) == sizeof(void *)); size_t size = control->size; size_t align = control->align; void *base; if (align < sizeof(void *)) align = sizeof(void *); // Make sure that align is power of 2. if ((align & (align - 1)) != 0) abort(); base = emutls_memalign_alloc(align, size); if (control->value) memcpy(base, control->value, size); else memset(base, 0, size); return base; } // Returns control->object.index; set index if not allocated yet. static __inline uintptr_t emutls_get_index(__emutls_control *control) { uintptr_t index = __atomic_load_n(&control->object.index, __ATOMIC_ACQUIRE); if (!index) { emutls_init_once(); emutls_lock(); index = control->object.index; if (!index) { index = ++emutls_num_object; __atomic_store_n(&control->object.index, index, __ATOMIC_RELEASE); } emutls_unlock(); } return index; } // Updates newly allocated thread local emutls_address_array. static __inline void emutls_check_array_set_size(emutls_address_array *array, uintptr_t size) { if (array == NULL) abort(); array->size = size; emutls_setspecific(array); } // Returns the new 'data' array size, number of elements, // which must be no smaller than the given index. static __inline uintptr_t emutls_new_data_array_size(uintptr_t index) { // Need to allocate emutls_address_array with extra slots // to store the header. // Round up the emutls_address_array size to multiple of 16. uintptr_t header_words = sizeof(emutls_address_array) / sizeof(void *); return ((index + header_words + 15) & ~((uintptr_t)15)) - header_words; } // Returns the size in bytes required for an emutls_address_array with // N number of elements for data field. static __inline uintptr_t emutls_asize(uintptr_t N) { return N * sizeof(void *) + sizeof(emutls_address_array); } // Returns the thread local emutls_address_array. // Extends its size if necessary to hold address at index. static __inline emutls_address_array * emutls_get_address_array(uintptr_t index) { emutls_address_array *array = emutls_getspecific(); if (array == NULL) { uintptr_t new_size = emutls_new_data_array_size(index); array = (emutls_address_array *)malloc(emutls_asize(new_size)); if (array) { memset(array->data, 0, new_size * sizeof(void *)); array->skip_destructor_rounds = EMUTLS_SKIP_DESTRUCTOR_ROUNDS; } emutls_check_array_set_size(array, new_size); } else if (index > array->size) { uintptr_t orig_size = array->size; uintptr_t new_size = emutls_new_data_array_size(index); array = (emutls_address_array *)realloc(array, emutls_asize(new_size)); if (array) memset(array->data + orig_size, 0, (new_size - orig_size) * sizeof(void *)); emutls_check_array_set_size(array, new_size); } return array; } void *__emutls_get_address(__emutls_control *control) { uintptr_t index = emutls_get_index(control); emutls_address_array *array = emutls_get_address_array(index--); if (array->data[index] == NULL) array->data[index] = emutls_allocate_object(control); return array->data[index]; } #ifdef __BIONIC__ // Called by Bionic on dlclose to delete the emutls pthread key. __attribute__((visibility("hidden"))) void __emutls_unregister_key(void) { if (emutls_key_created) { pthread_key_delete(emutls_pthread_key); emutls_key_created = false; } } #endif
Upload File
Create Folder