1*8feb0f0bSmrg /* Copyright (C) 1999-2020 Free Software Foundation, Inc.
236ac495dSmrg
336ac495dSmrg NOTE: This source is derived from an old version taken from the GNU C
436ac495dSmrg Library (glibc).
536ac495dSmrg
636ac495dSmrg This file is part of GCC.
736ac495dSmrg
836ac495dSmrg GCC is free software; you can redistribute it and/or modify it under
936ac495dSmrg the terms of the GNU General Public License as published by the Free
1036ac495dSmrg Software Foundation; either version 3, or (at your option) any later
1136ac495dSmrg version.
1236ac495dSmrg
1336ac495dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1436ac495dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
1536ac495dSmrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1636ac495dSmrg for more details.
1736ac495dSmrg
1836ac495dSmrg Under Section 7 of GPL version 3, you are granted additional
1936ac495dSmrg permissions described in the GCC Runtime Library Exception, version
2036ac495dSmrg 3.1, as published by the Free Software Foundation.
2136ac495dSmrg
2236ac495dSmrg You should have received a copy of the GNU General Public License and
2336ac495dSmrg a copy of the GCC Runtime Library Exception along with this program;
2436ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2536ac495dSmrg <http://www.gnu.org/licenses/>. */
2636ac495dSmrg
2736ac495dSmrg #include <stdlib.h>
2836ac495dSmrg #include "exit.h"
2936ac495dSmrg
3036ac495dSmrg #define atomic_write_barrier() __asm__ ("eieio" ::: "memory")
3136ac495dSmrg
3236ac495dSmrg /* Register a function to be called by exit. */
3336ac495dSmrg int
on_exit(void (* func)(int status,void * arg),void * arg)3436ac495dSmrg on_exit (void (*func) (int status, void *arg), void *arg)
3536ac495dSmrg {
3636ac495dSmrg struct exit_function *new = __new_exitfn (&__exit_funcs);
3736ac495dSmrg
3836ac495dSmrg if (new == NULL)
3936ac495dSmrg return -1;
4036ac495dSmrg
4136ac495dSmrg #ifdef PTR_MANGLE
4236ac495dSmrg PTR_MANGLE (func);
4336ac495dSmrg #endif
4436ac495dSmrg new->func.on.fn = func;
4536ac495dSmrg new->func.on.arg = arg;
4636ac495dSmrg atomic_write_barrier ();
4736ac495dSmrg new->flavor = ef_on;
4836ac495dSmrg return 0;
4936ac495dSmrg }
50