1/* Copyright (C) 1999-2020 Free Software Foundation, Inc. 2 3 NOTE: This source is derived from an old version taken from the GNU C 4 Library (glibc). 5 6This file is part of GCC. 7 8GCC is free software; you can redistribute it and/or modify it under 9the terms of the GNU General Public License as published by the Free 10Software Foundation; either version 3, or (at your option) any later 11version. 12 13GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14WARRANTY; without even the implied warranty of MERCHANTABILITY or 15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16for more details. 17 18Under Section 7 of GPL version 3, you are granted additional 19permissions described in the GCC Runtime Library Exception, version 203.1, as published by the Free Software Foundation. 21 22You should have received a copy of the GNU General Public License and 23a copy of the GCC Runtime Library Exception along with this program; 24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 25<http://www.gnu.org/licenses/>. */ 26 27#include <stdlib.h> 28#include "exit.h" 29 30#define atomic_write_barrier() __asm__ ("eieio" ::: "memory") 31 32/* Register a function to be called by exit. */ 33int 34on_exit (void (*func) (int status, void *arg), void *arg) 35{ 36 struct exit_function *new = __new_exitfn (&__exit_funcs); 37 38 if (new == NULL) 39 return -1; 40 41#ifdef PTR_MANGLE 42 PTR_MANGLE (func); 43#endif 44 new->func.on.fn = func; 45 new->func.on.arg = arg; 46 atomic_write_barrier (); 47 new->flavor = ef_on; 48 return 0; 49} 50