You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am porting a gdbserver application from Linux to Zephyr. An issue is that the user/GDB sometimes sends memory access requests to invalid memory areas and when gdbserver attempts an access there, it will fail and cause a processor exception. On Linux, this ultimately results in a SIGBUS error which I can recover from by catching the signal and using sigsetjmp and siglongjmp to resume operation and just returning a failed memory access.
I am looking for ideas on how to approach that on Zephyr. I know when I expect these errors to happen (generally during read/write-memory requests from the host) so I can run code before and afterwards to prepare/cleanup. I've been reading into k_sys_fatal_error_handler which seems to be called in these cases. Since it always seem to terminate the thread where the error was caused, I was thinking along the lines:
Create an extra thread for memory accesses that waits on some synchronization primitive (possibly a semaphore / mutex)
When a memory access request arrives, server thread fills a shared data structure with the details and triggers the memory access thread through the sync primitive, memory access thread then performs the memory operation and the server thread waits on a sync primitive
If the access succeeds, the memory thread returns a successful result through the shared data and uses a sync primitive to signal this back to the server
If the access fails, k_sys_fatal_error_handler uses the same shared data structure and sync primitive to signal failure, per documentation of k_sys_fatal_error_handler, the memory access thread is terminated
On failure, the server thread restarts the memory access thread
From experience, these errors can happen quite frequently, so restarting the memory access thread should not leak any memory. Could something like this work, or am I totally on the wrong track here?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am porting a gdbserver application from Linux to Zephyr. An issue is that the user/GDB sometimes sends memory access requests to invalid memory areas and when gdbserver attempts an access there, it will fail and cause a processor exception. On Linux, this ultimately results in a SIGBUS error which I can recover from by catching the signal and using
sigsetjmp
andsiglongjmp
to resume operation and just returning a failed memory access.I am looking for ideas on how to approach that on Zephyr. I know when I expect these errors to happen (generally during read/write-memory requests from the host) so I can run code before and afterwards to prepare/cleanup. I've been reading into
k_sys_fatal_error_handler
which seems to be called in these cases. Since it always seem to terminate the thread where the error was caused, I was thinking along the lines:k_sys_fatal_error_handler
uses the same shared data structure and sync primitive to signal failure, per documentation ofk_sys_fatal_error_handler
, the memory access thread is terminatedFrom experience, these errors can happen quite frequently, so restarting the memory access thread should not leak any memory. Could something like this work, or am I totally on the wrong track here?
Beta Was this translation helpful? Give feedback.
All reactions