1 #ifndef _HURD_FD_H 2 #include_next <hurd/fd.h> 3 4 #ifndef _ISOMAC 5 #include <libc-lock.h> 6 7 struct _hurd_fd_port_use_data 8 { 9 struct hurd_fd *d; 10 struct hurd_userlink ulink, ctty_ulink; 11 io_t port, ctty; 12 }; 13 14 extern void _hurd_fd_port_use_cleanup (void *arg); 15 16 /* Like HURD_DPORT_USE, but cleans fd on cancel. */ 17 #define HURD_DPORT_USE_CANCEL(fd, expr) \ 18 HURD_FD_USE ((fd), HURD_FD_PORT_USE_CANCEL (descriptor, (expr))) 19 20 /* Like HURD_FD_PORT_USE, but cleans fd on cancel. */ 21 #define HURD_FD_PORT_USE_CANCEL(fd, expr) \ 22 ({ error_t __result; \ 23 struct _hurd_fd_port_use_data __d; \ 24 io_t port, ctty; \ 25 void *__crit; \ 26 __d.d = (fd); \ 27 __crit = _hurd_critical_section_lock (); \ 28 __spin_lock (&__d.d->port.lock); \ 29 if (__d.d->port.port == MACH_PORT_NULL) \ 30 { \ 31 __spin_unlock (&__d.d->port.lock); \ 32 _hurd_critical_section_unlock (__crit); \ 33 __result = EBADF; \ 34 } \ 35 else \ 36 { \ 37 __d.ctty = ctty = _hurd_port_get (&__d.d->ctty, &__d.ctty_ulink); \ 38 __d.port = port = _hurd_port_locked_get (&__d.d->port, &__d.ulink); \ 39 __libc_cleanup_push (_hurd_fd_port_use_cleanup, &__d); \ 40 _hurd_critical_section_unlock (__crit); \ 41 __result = (expr); \ 42 __libc_cleanup_pop (1); \ 43 } \ 44 __result; }) 45 46 libc_hidden_proto (_hurd_intern_fd) 47 libc_hidden_proto (_hurd_fd_error) 48 libc_hidden_proto (_hurd_fd_error_signal) 49 # ifdef _HURD_FD_H_HIDDEN_DEF 50 libc_hidden_def (_hurd_fd_error) 51 libc_hidden_def (_hurd_fd_error_signal) 52 # endif 53 #endif 54 #endif 55