1 /* _longjmp_unwind -- Clean up stack frames unwound by longjmp. Hurd version.
2 Copyright (C) 1995, 1996, 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <hurd/userlink.h>
22 #include <hurd/signal.h>
23 #include <hurd/sigpreempt.h>
27 #ifndef _JMPBUF_UNWINDS
28 #error "<bits/setjmp.h> fails to define _JMPBUF_UNWINDS"
31 static inline uintptr_t
32 demangle_ptr (uintptr_t x
)
40 /* This function is called by `longjmp' (with its arguments) to restore
41 active resources to a sane state before the frames code using them are
45 _longjmp_unwind (jmp_buf env
, int val
)
47 struct hurd_sigstate
*ss
= _hurd_self_sigstate ();
48 struct hurd_userlink
*link
;
50 /* All access to SS->active_resources must take place inside a critical
51 section where signal handlers cannot run. */
52 __spin_lock (&ss
->lock
);
53 assert (! __spin_lock_locked (&ss
->critical_section_lock
));
54 __spin_lock (&ss
->critical_section_lock
);
56 /* Remove local signal preemptors being unwound past. */
57 while (ss
->preemptors
&&
58 _JMPBUF_UNWINDS (env
[0].__jmpbuf
, ss
->preemptors
, demangle_ptr
))
59 ss
->preemptors
= ss
->preemptors
->next
;
61 __spin_unlock (&ss
->lock
);
63 /* Iterate over the current thread's list of active resources.
64 Process the head portion of the list whose links reside
65 in stack frames being unwound by this jump. */
67 for (link
= ss
->active_resources
;
68 link
&& _JMPBUF_UNWINDS (env
[0].__jmpbuf
, link
, demangle_ptr
);
69 link
= link
->thread
.next
)
70 /* Remove this link from the resource's users list,
71 since the frame using the resource is being unwound.
72 This call returns nonzero if that was the last user. */
73 if (_hurd_userlink_unlink (link
))
74 /* One of the frames being unwound by the longjmp was the last user
75 of its resource. Call the cleanup function to deallocate it. */
76 (*link
->cleanup
) (link
->cleanup_data
, env
, val
);
78 _hurd_critical_section_unlock (ss
);