diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-11-10 11:01:39 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-11-10 11:01:54 +0100 |
commit | 72d5fa11a8e3a0e4640da289d76ae672eb070565 (patch) | |
tree | d0a8362fffca074cb753e8a4d4c4aabc7ce5cbeb /freebsd/sys/sys | |
parent | Change RTEMS version to 5 (diff) | |
download | rtems-libbsd-72d5fa11a8e3a0e4640da289d76ae672eb070565.tar.bz2 |
Fix reference counting for file descriptors
Update #3132.
Diffstat (limited to 'freebsd/sys/sys')
-rw-r--r-- | freebsd/sys/sys/file.h | 7 | ||||
-rw-r--r-- | freebsd/sys/sys/filedesc.h | 5 |
2 files changed, 11 insertions, 1 deletions
diff --git a/freebsd/sys/sys/file.h b/freebsd/sys/sys/file.h index 18274d67..2adbd0af 100644 --- a/freebsd/sys/sys/file.h +++ b/freebsd/sys/sys/file.h @@ -413,6 +413,13 @@ rtems_bsd_fdrop(struct file *fp) rtems_libio_iop_drop(&fp->f_io); } +/* + * WARNING: fdalloc() and falloc_caps() do not increment the reference count of + * the file descriptor in contrast to FreeBSD. We must not call the fdrop() + * corresponding to a fdalloc() or falloc_caps(). The reason for this is that + * FreeBSD performs a lazy cleanup once the reference count reaches zero. + * RTEMS uses the reference count to determine if a cleanup is allowed. + */ #define fdrop(fp, td) rtems_bsd_fdrop(fp) #endif /* __rtems__ */ diff --git a/freebsd/sys/sys/filedesc.h b/freebsd/sys/sys/filedesc.h index b1c3e24b..457898ef 100644 --- a/freebsd/sys/sys/filedesc.h +++ b/freebsd/sys/sys/filedesc.h @@ -202,7 +202,6 @@ falloc_caps(struct thread *td, struct file **resultfp, int *resultfd, *resultfp = rtems_bsd_iop_to_fp(iop); if (iop != NULL) { - rtems_libio_iop_hold(iop); iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry; rtems_filesystem_location_add_to_mt_entry(&iop->pathinfo); *resultfd = rtems_libio_iop_to_descriptor(iop); @@ -223,6 +222,10 @@ int fdcheckstd(struct thread *td); #ifndef __rtems__ void fdclose(struct thread *td, struct file *fp, int idx); #else /* __rtems__ */ +/* + * WARNING: Use of fdrop() after fclose() corrupts the file descriptor. See + * fdrop() comment. + */ static inline void fdclose(struct thread *td, struct file *fp, int idx) { |