Allan Hessenflow commented: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5411#note_138880


I'm testing in main, not a 6.x branch, but newlib01 is also broken for the 
efm32gg11 bsp and it runs okay if I revert the referenced IOP changes. It seems 
likely to be the same issue seen with the zynqmp_qemu. Here's what I've found 
and a possible fix:

This call chain occurs (omitting some irrelevant stuff) exit() -\> 
fatal_extension() -\> fstat() -\> rtems_libio_get_iop().

That calls rtems_libio_iop_hold() followed by rtems_libio_iop_drop() because 
the descriptor is closed.

Then rtems_libio_iop_drop() -\> rtems_libio_free() -\> rtems_libio_free_iop(). 
However the referenced iop is already on the free list. So I added an 
additional check below before calling rtems_libio_free_iop(), which appears to 
fix the problem. However I don't feel I have a good understanding of how all 
this IOP stuff is intended to work so hopefully someone who does will evaluate 
and comment.

I'll also note that spintrcritical24 was failing as well on the efm32gg11 and 
it appears to be fixed with this change as well. It had been ending up in an 
infinite loop trying to count free iops because 
rtems_libio_iop_free_head-\>data1 == rtems_libio_iop_free_head. That state is 
consistent with an iop being appended to the free list twice.

```
diff --git a/cpukit/include/rtems/libio_.h b/cpukit/include/rtems/libio_.h
index 21a57cdc4f..0bd088d498 100644
--- a/cpukit/include/rtems/libio_.h
+++ b/cpukit/include/rtems/libio_.h
@@ -150,12 +150,13 @@ static inline void rtems_libio_free(
    * the iop so consider it an indirect reference. We cannot return
    * the iop to the free list while the user owns the fd.
    *
-   * Read the flags once as it is an atomic and we need to test 2
+   * Read the flags once as it is an atomic and we need to test 3
    * flags. No convenience call as this is the only case we have.
    */
   const unsigned int flags = rtems_libio_iop_flags( iop );
   if ( ( ( flags & LIBIO_FLAGS_OPEN ) == 0 )
-       && ( ( flags & LIBIO_FLAGS_REFERENCE_MASK ) == 0 ) ) {
+       && ( ( flags & LIBIO_FLAGS_REFERENCE_MASK ) == 0 )
+       && ( ( flags & LIBIO_FLAGS_FREE ) == 0 ) ) {
     rtems_libio_free_iop( iop );
   }
 }
```

-- 
View it on GitLab: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5411#note_138880
You're receiving this email because of your account on gitlab.rtems.org.


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to