]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/jmp-unwind.c
update from main archive 961217
[thirdparty/glibc.git] / sysdeps / mach / hurd / jmp-unwind.c
1 /* _longjmp_unwind -- Clean up stack frames unwound by longjmp. Hurd version.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <setjmp.h>
21 #include <hurd/userlink.h>
22 #include <hurd/signal.h>
23 #include <hurd/sigpreempt.h>
24 #include <assert.h>
25
26
27 #ifndef _JMPBUF_UNWINDS
28 #error "sysdeps/MACHINE/jmp_buf.h fails to define _JMPBUF_UNWINDS"
29 #endif
30
31 /* This function is called by `longjmp' (with its arguments) to restore
32 active resources to a sane state before the frames code using them are
33 jumped out of. */
34
35 void
36 _longjmp_unwind (jmp_buf env, int val)
37 {
38 struct hurd_sigstate *ss = _hurd_self_sigstate ();
39 struct hurd_userlink *link;
40
41 /* All access to SS->active_resources must take place inside a critical
42 section where signal handlers cannot run. */
43 __spin_lock (&ss->lock);
44 assert (! __spin_lock_locked (&ss->critical_section_lock));
45 __spin_lock (&ss->critical_section_lock);
46
47 /* Remove local signal preemptors being unwound past. */
48 while (ss->preemptors &&
49 _JMPBUF_UNWINDS (env[0].__jmpbuf, ss->preemptors))
50 ss->preemptors = ss->preemptors->next;
51
52 __spin_unlock (&ss->lock);
53
54 /* Iterate over the current thread's list of active resources.
55 Process the head portion of the list whose links reside
56 in stack frames being unwound by this jump. */
57
58 for (link = ss->active_resources;
59 link && _JMPBUF_UNWINDS (env[0].__jmpbuf, link);
60 link = link->thread.next)
61 /* Remove this link from the resource's users list,
62 since the frame using the resource is being unwound.
63 This call returns nonzero if that was the last user. */
64 if (_hurd_userlink_unlink (link))
65 /* One of the frames being unwound by the longjmp was the last user
66 of its resource. Call the cleanup function to deallocate it. */
67 (*link->cleanup) (link->cleanup_data, env, val);
68
69 _hurd_critical_section_unlock (ss);
70 }