139640842823ba4cd42bd11514c0da39aa939519fBruce Beare/* 29d40326830c2bd407427889c554adeb915ee6b4aNick Kralevich * Copyright (C) 2012 The Android Open Source Project 339640842823ba4cd42bd11514c0da39aa939519fBruce Beare * All rights reserved. 439640842823ba4cd42bd11514c0da39aa939519fBruce Beare * 539640842823ba4cd42bd11514c0da39aa939519fBruce Beare * Redistribution and use in source and binary forms, with or without 639640842823ba4cd42bd11514c0da39aa939519fBruce Beare * modification, are permitted provided that the following conditions 739640842823ba4cd42bd11514c0da39aa939519fBruce Beare * are met: 839640842823ba4cd42bd11514c0da39aa939519fBruce Beare * * Redistributions of source code must retain the above copyright 939640842823ba4cd42bd11514c0da39aa939519fBruce Beare * notice, this list of conditions and the following disclaimer. 1039640842823ba4cd42bd11514c0da39aa939519fBruce Beare * * Redistributions in binary form must reproduce the above copyright 1139640842823ba4cd42bd11514c0da39aa939519fBruce Beare * notice, this list of conditions and the following disclaimer in 1239640842823ba4cd42bd11514c0da39aa939519fBruce Beare * the documentation and/or other materials provided with the 1339640842823ba4cd42bd11514c0da39aa939519fBruce Beare * distribution. 1439640842823ba4cd42bd11514c0da39aa939519fBruce Beare * 1539640842823ba4cd42bd11514c0da39aa939519fBruce Beare * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1639640842823ba4cd42bd11514c0da39aa939519fBruce Beare * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1739640842823ba4cd42bd11514c0da39aa939519fBruce Beare * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1839640842823ba4cd42bd11514c0da39aa939519fBruce Beare * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1939640842823ba4cd42bd11514c0da39aa939519fBruce Beare * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2039640842823ba4cd42bd11514c0da39aa939519fBruce Beare * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2139640842823ba4cd42bd11514c0da39aa939519fBruce Beare * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2239640842823ba4cd42bd11514c0da39aa939519fBruce Beare * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2339640842823ba4cd42bd11514c0da39aa939519fBruce Beare * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2439640842823ba4cd42bd11514c0da39aa939519fBruce Beare * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2539640842823ba4cd42bd11514c0da39aa939519fBruce Beare * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2639640842823ba4cd42bd11514c0da39aa939519fBruce Beare * SUCH DAMAGE. 2739640842823ba4cd42bd11514c0da39aa939519fBruce Beare */ 2839640842823ba4cd42bd11514c0da39aa939519fBruce Beare 299d40326830c2bd407427889c554adeb915ee6b4aNick Kralevichextern void __cxa_finalize(void *); 309d40326830c2bd407427889c554adeb915ee6b4aNick Kralevichextern void *__dso_handle; 319d40326830c2bd407427889c554adeb915ee6b4aNick Kralevich 325ed48a4d7fece002afbbd2bd981563aea6e52e24Ard Biesheuvel__attribute__((visibility("hidden"),destructor)) 339d40326830c2bd407427889c554adeb915ee6b4aNick Kralevichvoid __on_dlclose() { 349d40326830c2bd407427889c554adeb915ee6b4aNick Kralevich __cxa_finalize(&__dso_handle); 359d40326830c2bd407427889c554adeb915ee6b4aNick Kralevich} 369d40326830c2bd407427889c554adeb915ee6b4aNick Kralevich 37f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel/* CRT_LEGACY_WORKAROUND should only be defined when building 38f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * this file as part of the platform's C library. 39f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * 40f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * The C library already defines a function named 'atexit()' 41f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * for backwards compatibility with older NDK-generated binaries. 42f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * 43f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * For newer ones, 'atexit' is actually embedded in the C 44f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * runtime objects that are linked into the final ELF 45f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * binary (shared library or executable), and will call 46f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * __cxa_atexit() in order to un-register any atexit() 47f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * handler when a library is unloaded. 48f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * 49f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * This function must be global *and* hidden. Only the 50f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * code inside the same ELF binary should be able to access it. 51f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel */ 52f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel 539d40326830c2bd407427889c554adeb915ee6b4aNick Kralevich#ifdef CRT_LEGACY_WORKAROUND 54b49c17c2bf1232e29bc390e58d6fa43688929aa5Pavel Chupin# include "__dso_handle.h" 559d40326830c2bd407427889c554adeb915ee6b4aNick Kralevich#else 56b49c17c2bf1232e29bc390e58d6fa43688929aa5Pavel Chupin# include "__dso_handle_so.h" 57b49c17c2bf1232e29bc390e58d6fa43688929aa5Pavel Chupin# include "atexit.h" 58f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel#endif 59b49c17c2bf1232e29bc390e58d6fa43688929aa5Pavel Chupin#ifdef __i386__ 60b49c17c2bf1232e29bc390e58d6fa43688929aa5Pavel Chupin# include "../../arch-x86/bionic/__stack_chk_fail_local.h" 61b49c17c2bf1232e29bc390e58d6fa43688929aa5Pavel Chupin#endif 62