Skip to content

Commit deb03e7

Browse files
authored
ESP: lwIP fixes (#908)
Before this PR, lwIP caused null pointer dereferences in my setup (see https://savannah.nongnu.org/bugs/?59831). It was also possible to use APIs that expected the core mutex to be locked without locking it. Now it will instead panic, letting you know. My project is now much more stable, and I haven't encountered any crashes.
1 parent 6349674 commit deb03e7

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

examples/espressif/esp/src/lwip/exports.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export fn lwip_unlock_core_mutex() void {
2424
core_mutex.unlock();
2525
}
2626

27+
export fn lwip_assert_core_locked() void {
28+
if (c.lock_tcpip_core == null) return;
29+
30+
const mutex: *rtos.Mutex = @ptrCast(@alignCast(c.lock_tcpip_core));
31+
std.debug.assert(mutex.locked != null);
32+
}
33+
2734
export fn lwip_rand() u32 {
2835
return esp.rng.random_u32();
2936
}

examples/espressif/esp/src/lwip/include/arch/cc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ typedef unsigned int sys_prot_t;
99
extern uint32_t lwip_rand(void);
1010
extern void lwip_lock_core_mutex();
1111
extern void lwip_unlock_core_mutex();
12+
extern void lwip_assert_core_locked();
1213
extern void lwip_assert(const char *msg, const char *file, int line);
1314
extern void lwip_diag(const char *msg, const char *file, int line);
1415

16+
#define LWIP_ASSERT_CORE_LOCKED() do { lwip_assert_core_locked(); } while (0)
17+
1518
#define LWIP_PLATFORM_DIAG(x) \
1619
do { \
1720
lwip_diag((msg), __FILE__, __LINE__); \

modules/lwip/build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const files = [_][]const u8{
7272
"core/ipv4/ip4_addr.c",
7373
"core/ipv4/igmp.c",
7474
"core/ipv4/icmp.c",
75+
"core/ipv4/acd.c",
7576

7677
// IPv6 implementation:
7778
"core/ipv6/icmp6.c",

modules/lwip/build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
},
88
.dependencies = .{
99
.lwip = .{
10-
//.url = "https://download.savannah.nongnu.org/releases/lwip/lwip-2.1.3.zip",
11-
.url = "https://github.com/Ashet-Technologies/deps/raw/refs/heads/main/lwip-2.1.3.zip",
12-
.hash = "N-V-__8AAKCP6ADEah-rtpC4uEsB_-GFFCqsNInUAJY7bH3S",
10+
// .url = "https://download.savannah.nongnu.org/releases/lwip/lwip-2.2.1.zip",
11+
.url = "https://github.com/lwip-tcpip/lwip/archive/refs/tags/STABLE-2_2_1_RELEASE.zip",
12+
.hash = "N-V-__8AAGSTdQCcOKeNITCRoYez502saFXZqz4ucBJ4xTa9",
1313
},
1414
},
1515
}

0 commit comments

Comments
 (0)