Skip to content

Commit

Permalink
* stdlib/Makefile (routines): Add quick_exit, at_quick_exit, and
Browse files Browse the repository at this point in the history
	cxa_at_quick_exit.
	(static-only-routines): Add at_quick_exit.
	* stdlib/Versions: Export quick_exit and __cxa_at_quick_exit for
	GLIBC_2.10.
	* stdlib/quick_exit.c: New file.
	* stdlib/at_quick_exit.c: New file.
	* stdlib/cxa_at_quick_exit.c: New file.
	* stdlib/cxa_atexit.c (__cxa_atexit): Move body to new function.  Call
	it appropriately.
	(__internal_atexit): New function.
	(__new_exitfn): Now takes parameter to point to the list to use.
	* stdlib/cxa_finalize.c: Remove quick_exit handlers, don't call them.
	* stdlib/exit.c (__run_exit_handlers): New function.  Split from...
	(exit): ...here.  Just call __run_exit_handlers appropriately.
	* stdlib/exit.h: Declare __quick_exit_funcs, __run_exit_handlers,
	__internal_atexit, __cxa_at_quick_exit.  Adjust __new_exitfn.
	* stdlib/on_exit.c: Adjust call to __new_exitfn.
	* stdlib/stdlib.h: Declare at_quick_exit and quick_exit.
  • Loading branch information
Ulrich Drepper committed Mar 8, 2009
1 parent 130ca12 commit 610e67e
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 30 deletions.
20 changes: 20 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
2009-03-08 Ulrich Drepper <drepper@redhat.com>

* stdlib/Makefile (routines): Add quick_exit, at_quick_exit, and
cxa_at_quick_exit.
(static-only-routines): Add at_quick_exit.
* stdlib/Versions: Export quick_exit and __cxa_at_quick_exit for
GLIBC_2.10.
* stdlib/quick_exit.c: New file.
* stdlib/at_quick_exit.c: New file.
* stdlib/cxa_at_quick_exit.c: New file.
* stdlib/cxa_atexit.c (__cxa_atexit): Move body to new function. Call
it appropriately.
(__internal_atexit): New function.
(__new_exitfn): Now takes parameter to point to the list to use.
* stdlib/cxa_finalize.c: Remove quick_exit handlers, don't call them.
* stdlib/exit.c (__run_exit_handlers): New function. Split from...
(exit): ...here. Just call __run_exit_handlers appropriately.
* stdlib/exit.h: Declare __quick_exit_funcs, __run_exit_handlers,
__internal_atexit, __cxa_at_quick_exit. Adjust __new_exitfn.
* stdlib/on_exit.c: Adjust call to __new_exitfn.
* stdlib/stdlib.h: Declare at_quick_exit and quick_exit.

* po/id.po: Update from translation team.

2009-03-07 Ulrich Drepper <drepper@redhat.com>
Expand Down
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GNU C Library NEWS -- history of user-visible changes. 2009-2-26
GNU C Library NEWS -- history of user-visible changes. 2009-3-8
Copyright (C) 1992-2008, 2009 Free Software Foundation, Inc.
See the end for copying conditions.

Expand All @@ -18,6 +18,9 @@ Version 2.10
* New POSIX 2008 interface: psiginfo
Implemented by Ulrich Drepper.

* New ISO C++1x interfaces: quick_exit, at_quick_exit
Implemented by Ulrich Drepper.


Version 2.9

Expand Down
5 changes: 3 additions & 2 deletions stdlib/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 1991-2006, 2007, 2008 Free Software Foundation, Inc.
# Copyright (C) 1991-2006, 2007, 2008, 2009 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

# The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -34,6 +34,7 @@ routines := \
bsearch qsort msort \
getenv putenv setenv secure-getenv \
exit on_exit atexit cxa_atexit cxa_finalize old_atexit \
quick_exit at_quick_exit cxa_at_quick_exit \
abs labs llabs \
div ldiv lldiv \
mblen mbstowcs mbtowc wcstombs wctomb \
Expand All @@ -57,7 +58,7 @@ aux = grouping groupingwc tens_in_limb
# These routines will be omitted from the libc shared object.
# Instead the static object files will be included in a special archive
# linked against when the shared library will be used.
static-only-routines = atexit
static-only-routines = atexit at_quick_exit

distribute := exit.h grouping.h abort-instr.h isomac.c tst-fmtmsg.sh \
allocalim.h
Expand Down
3 changes: 3 additions & 0 deletions stdlib/Versions
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ libc {
GLIBC_2.8 {
qsort_r;
}
GLIBC_2.10 {
quick_exit; __cxa_at_quick_exit;
}
GLIBC_PRIVATE {
# functions which have an additional interface since they are
# are cancelable.
Expand Down
50 changes: 50 additions & 0 deletions stdlib/at_quick_exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright (C) 1991,1996,1999,2001,2006,2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
In addition to the permissions in the GNU Lesser General Public
License, the Free Software Foundation gives you unlimited
permission to link the compiled version of this file with other
programs, and to distribute those programs without any restriction
coming from the use of this file. (The GNU Lesser General Public
License restrictions do apply in other respects; for example, they
cover modification of the file, and distribution when not linked
into another program.)
Note that people who make modified versions of this file are not
obligated to grant this special exception for their modified
versions; it is their choice whether to do so. The GNU Lesser
General Public License gives permission to release a modified
version without this exception; this exception also makes it
possible to release a modified version which carries forward this
exception.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#include <stdlib.h>
#include "exit.h"


/* This is defined by newer gcc version unique for each module. */
extern void *__dso_handle __attribute__ ((__weak__));


/* Register FUNC to be executed by `quick_exit'. */
int
at_quick_exit (void (*func) (void))
{
return __cxa_at_quick_exit ((void (*) (void *)) func,
&__dso_handle == NULL ? NULL : __dso_handle);
}
32 changes: 32 additions & 0 deletions stdlib/cxa_at_quick_exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (C) 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#include <stdlib.h>
#include "exit.h"


static struct exit_function_list initial_quick;
struct exit_function_list *__quick_exit_funcs = &initial_quick;

/* Register a function to be called by quick_exit. */
int
attribute_hidden
__cxa_at_quick_exit (void (*func) (void *), void *d)
{
return __internal_atexit (func, NULL, d, &__quick_exit_funcs);
}
30 changes: 20 additions & 10 deletions stdlib/cxa_atexit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1999, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
/* Copyright (C) 1999,2001,2002,2005,2006,2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -26,13 +26,13 @@

#undef __cxa_atexit

/* Register a function to be called by exit or when a shared library
is unloaded. This function is only called from code generated by
the C++ compiler. */

int
__cxa_atexit (void (*func) (void *), void *arg, void *d)
attribute_hidden
__internal_atexit (void (*func) (void *), void *arg, void *d,
struct exit_function_list **listp)
{
struct exit_function *new = __new_exitfn ();
struct exit_function *new = __new_exitfn (listp);

if (new == NULL)
return -1;
Expand All @@ -47,6 +47,16 @@ __cxa_atexit (void (*func) (void *), void *arg, void *d)
new->flavor = ef_cxa;
return 0;
}


/* Register a function to be called by exit or when a shared library
is unloaded. This function is only called from code generated by
the C++ compiler. */
int
__cxa_atexit (void (*func) (void *), void *arg, void *d)
{
return __internal_atexit (func, arg, d, &__exit_funcs);
}
INTDEF(__cxa_atexit)


Expand All @@ -59,7 +69,7 @@ struct exit_function_list *__exit_funcs = &initial;
uint64_t __new_exitfn_called;

struct exit_function *
__new_exitfn (void)
__new_exitfn (struct exit_function_list **listp)
{
struct exit_function_list *p = NULL;
struct exit_function_list *l;
Expand All @@ -68,7 +78,7 @@ __new_exitfn (void)

__libc_lock_lock (lock);

for (l = __exit_funcs; l != NULL; p = l, l = l->next)
for (l = *listp; l != NULL; p = l, l = l->next)
{
for (i = l->idx; i > 0; --i)
if (l->fns[i - 1].flavor != ef_free)
Expand All @@ -92,8 +102,8 @@ __new_exitfn (void)
calloc (1, sizeof (struct exit_function_list));
if (p != NULL)
{
p->next = __exit_funcs;
__exit_funcs = p;
p->next = *listp;
*listp = p;
}
}

Expand Down
12 changes: 11 additions & 1 deletion stdlib/cxa_finalize.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1999,2001,2002,2003,2005,2006 Free Software Foundation, Inc.
/* Copyright (C) 1999,2001-2003,2005,2006,2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -63,6 +63,16 @@ __cxa_finalize (void *d)
}
}

/* Also remove the quick_exit handlers, but do not call them. */
for (funcs = __quick_exit_funcs; funcs; funcs = funcs->next)
{
struct exit_function *f;

for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f)
if (d == NULL || d == f->func.cxa.dso_handle)
f->flavor = ef_free;
}

/* Remove the registered fork handlers. We do not have to
unregister anything if the program is going to terminate anyway. */
#ifdef UNREGISTER_ATFORK
Expand Down
32 changes: 21 additions & 11 deletions stdlib/exit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (C) 1991,95,96,97,99,2001,2002,2005 Free Software Foundation, Inc.
/* Copyright (C) 1991,95,96,97,99,2001,2002,2005,2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -30,20 +31,22 @@ DEFINE_HOOK (__libc_atexit, (void))
in the reverse of the order in which they were registered
perform stdio cleanup, and terminate program execution with STATUS. */
void
exit (int status)
attribute_hidden
__run_exit_handlers (int status, struct exit_function_list **listp,
bool run_list_atexit)
{
/* We do it this way to handle recursive calls to exit () made by
the functions registered with `atexit' and `on_exit'. We call
everyone on the list and use the status value in the last
exit (). */
while (__exit_funcs != NULL)
while (*listp != NULL)
{
struct exit_function_list *old;
struct exit_function_list *cur = *listp;

while (__exit_funcs->idx > 0)
while (cur->idx > 0)
{
const struct exit_function *const f =
&__exit_funcs->fns[--__exit_funcs->idx];
&cur->fns[--cur->idx];
switch (f->flavor)
{
void (*atfct) (void);
Expand Down Expand Up @@ -77,16 +80,23 @@ exit (int status)
}
}

old = __exit_funcs;
__exit_funcs = __exit_funcs->next;
if (__exit_funcs != NULL)
*listp = cur->next;
if (*listp != NULL)
/* Don't free the last element in the chain, this is the statically
allocate element. */
free (old);
free (cur);
}

RUN_HOOK (__libc_atexit, ());
if (run_list_atexit)
RUN_HOOK (__libc_atexit, ());

_exit (status);
}


void
exit (int status)
{
__run_exit_handlers (status, __exit_funcs, true);
}
libc_hidden_def (exit)
16 changes: 14 additions & 2 deletions stdlib/exit.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1991,1996,1997,1999,2001,2002,2006
/* Copyright (C) 1991,1996,1997,1999,2001,2002,2006,2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Expand All @@ -20,6 +20,7 @@
#ifndef _EXIT_H
#define _EXIT_H 1

#include <stdbool.h>
#include <stdint.h>

enum
Expand Down Expand Up @@ -59,8 +60,19 @@ struct exit_function_list
struct exit_function fns[32];
};
extern struct exit_function_list *__exit_funcs attribute_hidden;
extern struct exit_function_list *__quick_exit_funcs attribute_hidden;

extern struct exit_function *__new_exitfn (void);
extern struct exit_function *__new_exitfn (struct exit_function_list **listp);
extern uint64_t __new_exitfn_called attribute_hidden;

extern void __run_exit_handlers (int status, struct exit_function_list **listp,
bool run_list_atexit) attribute_hidden;

extern int __internal_atexit (void (*func) (void *), void *arg, void *d,
struct exit_function_list **listp)
attribute_hidden;
extern int __cxa_at_quick_exit (void (*func) (void *), void *d)
attribute_hidden;


#endif /* exit.h */
4 changes: 2 additions & 2 deletions stdlib/on_exit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1996, 2005 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1996, 2005, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand All @@ -25,7 +25,7 @@
int
__on_exit (void (*func) (int status, void *arg), void *arg)
{
struct exit_function *new = __new_exitfn ();
struct exit_function *new = __new_exitfn (&__exit_funcs);

if (new == NULL)
return -1;
Expand Down
30 changes: 30 additions & 0 deletions stdlib/quick_exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (C) 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sysdep.h>
#include "exit.h"


void
quick_exit (int status)
{
__run_exit_handlers (status, __quick_exit_funcs, false);
}
Loading

0 comments on commit 610e67e

Please sign in to comment.