(__pipe): Consider MIG_BAD_ID and EOPNOTSUPP as indications that the server port...
[glibc.git] / sysdeps / mach / hurd / jmp-unwind.c
blobf7540f0dde67973bfa79e6be77b5c567f1d711a6
1 /* _longjmp_unwind -- Clean up stack frames unwound by longjmp. Hurd version.
2 Copyright (C) 1995 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 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.
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.
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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <setjmp.h>
21 #include <hurd/signal.h>
22 #include <hurd/userlink.h>
23 #include <assert.h>
25 /* This function is called by `longjmp' (with its arguments) to restore
26 active resources to a sane state before the frames code using them are
27 jumped out of. */
29 void
30 _longjmp_unwind (jmp_buf env, int val)
32 struct hurd_sigstate *ss = _hurd_self_sigstate ();
33 struct hurd_userlink *link;
35 /* All access to SS->active_resources must take place inside a critical
36 section where signal handlers cannot run. */
37 __spin_lock (&ss->lock);
38 assert (! ss->critical_section);
39 ss->critical_section = 1;
40 __spin_unlock (&ss->lock);
42 #ifndef _JMPBUF_UNWINDS
43 #error "sysdeps/MACHINE/jmp_buf.h fails to define _JMPBUF_UNWINDS"
44 #endif
46 /* Iterate over the current thread's list of active resources.
47 Process the head portion of the list whose links reside
48 in stack frames being unwound by this jump. */
50 for (link = ss->active_resources;
51 link && _JMPBUF_UNWINDS (env[0].__jmpbuf, link);
52 link = link->thread.next)
53 /* Remove this link from the resource's users list,
54 since the frame using the resource is being unwound.
55 This call returns nonzero if that was the last user. */
56 if (_hurd_userlink_unlink (link))
57 /* One of the frames being unwound by the longjmp was the last user
58 of its resource. Call the cleanup function to deallocate it. */
59 (*link->cleanup) (link->cleanup_data, env, val);
61 _hurd_critical_section_unlock (ss);