1f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel/* 2f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * Copyright (c) 2012 The Android Open Source Project 3f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * All rights reserved. 4f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * 5f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * Redistribution and use in source and binary forms, with or without 6f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * modification, are permitted provided that the following conditions 7f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * are met: 8f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * * Redistributions of source code must retain the above copyright 9f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * notice, this list of conditions and the following disclaimer. 10f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * * Redistributions in binary form must reproduce the above copyright 11f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * notice, this list of conditions and the following disclaimer in 12f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * the documentation and/or other materials provided with the 13f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * distribution. 14f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * 15f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * SUCH DAMAGE. 27f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel */ 28f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel 29f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel#include <sys/types.h> 308f2a5a0b40fc82126c691d5c30131d908772aab7Elliott Hughes#include <private/libc_logging.h> 31144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel#include <stdio.h> 32f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel 33f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel/* 34f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * This source file should only be included by libc.so, its purpose is 35f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * to support legacy ARM binaries by exporting a publicly visible 36f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * implementation of atexit(). 37f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel */ 38f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel 39f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvelextern int __cxa_atexit(void (*func)(void *), void *arg, void *dso); 40f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel 41f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel/* 42f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel * Register a function to be performed at exit. 43f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel */ 44f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvelint 45f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvelatexit(void (*func)(void)) 46f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel{ 47144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel /* 48144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel * Exit functions queued by this version of atexit will not be called 49144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel * on dlclose(), and when they are called (at program exit), the 50144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel * calling library may have been dlclose()'d, causing the program to 51144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel * crash. 52144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel */ 531e980b6bc8315d00a07312b25486531247abd98cElliott Hughes static char const warning[] = "WARNING: generic atexit() called from legacy shared library\n"; 54144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel 558f2a5a0b40fc82126c691d5c30131d908772aab7Elliott Hughes __libc_format_log(ANDROID_LOG_WARN, "libc", warning); 56144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel fprintf(stderr, warning); 57144c2918668ac0d506a86478d5b9966ad816cec4Ard Biesheuvel 58f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel return (__cxa_atexit((void (*)(void *))func, NULL, NULL)); 59f3cfcd869ded41d25c1f4f4e48e7c374a64f9583Ard Biesheuvel} 60