Open mukeshbharath opened 10 months ago
I'm getting a Segmentation fault that looks the same (same place in the log files). I'm trying to install on Void Linux (musl).
libpthread.a (and presumably librt.a) is supposedly supposed to be empty, as it is built into musl (https://forum.openwrt.org/t/how-to-get-libpthread/116587).
I'm going to try again with the non-musl version of Void...
Edit: I can confirm the issue is resolved when using glibc instead of musl.
My fix for musl was move uint8_t buff_up outside the thread function in global space.
My fix for musl was move uint8_t buff_up outside the thread function in global space.
I got the same segmentation fault issue with musl, and it seems the issue was fixed after moving "uint8_t buff_up" outside the thread function in global space. Could you share more detail about the root cause?
Hi @cb-xiong, the reason is that the thread function's (thread_up()
) stack memory is overflowing when buff_up
is used inside the thread since it consumes more memory. the thread couldn't handle it and led to the segmentation fault, so placing the buff_up
globally (i.e., out of the thread function), helps avoid the seg fault.
Hi @cb-xiong, the reason is that the thread function's (
thread_up()
) stack memory is overflowing whenbuff_up
is used inside the thread since it consumes more memory. the thread couldn't handle it and led to the segmentation fault, so placing thebuff_up
globally (i.e., out of the thread function), helps avoid the seg fault.
Thank you @mukeshbharath for the comment, it helps a lot.
Increase the thread stack size like this (rough code, needs cleanup):
commit 264b355d058f4e66bac53faf570e5c2c04a9e7a8
Author: Catalin Patulea <cronos586@gmail.com>
Date: Sun Oct 6 15:50:38 2024 -0400
Increase stack size for thread_up, otherwise Segfault.
diff --git a/packet_forwarder/src/lora_pkt_fwd.c b/packet_forwarder/src/lora_pkt_fwd.c
index 53661de..48dbe01 100644
--- a/packet_forwarder/src/lora_pkt_fwd.c
+++ b/packet_forwarder/src/lora_pkt_fwd.c
@@ -1670,8 +1670,24 @@ int main(int argc, char ** argv)
printf("INFO: concentrator EUI: 0x%016" PRIx64 "\n", eui);
}
+ pthread_attr_t attr;
+ pthread_t thid;
+
+ i = pthread_attr_init(&attr);
+ if (i == -1) {
+ perror("error in pthread_attr_init");
+ exit(1);
+ }
+
+ int s1 = 409600;
+ i = pthread_attr_setstacksize(&attr, s1);
+ if (i == -1) {
+ perror("error in pthread_attr_setstacksize");
+ exit(2);
+ }
+
/* spawn threads to manage upstream and downstream */
- i = pthread_create(&thrid_up, NULL, (void * (*)(void *))thread_up, NULL);
+ i = pthread_create(&thrid_up, &attr, (void * (*)(void *))thread_up, NULL);
if (i != 0) {
MSG("ERROR: [main] impossible to create upstream thread\n");
exit(EXIT_FAILURE);
I'm using a Raspberry Pi 3B+ board with OpenWRT OS (v23.05.2) and trying to use a Semtech SX1302 LoRa Corecell interface board via USB interface to use them as a LoRa Gateway setup (RPi + Semtech SX1302).
While using the sx1302_hal's Lora packet forwarder, it always ends up in segmentation fault when reaching the uplink thread
thread_up()
My Observations:
buff_up
of thethread_up ()
opkg install
as far as I have noticed. for e.g.,Please share if you have any insights about this. Any help is greatly appreciated!