Skip to content

Commit 8f8e257

Browse files
committed
DNM (needs cleanup): explicitly list functions to be used through c2rust
At this point, the examples build with it.
1 parent 115842b commit 8f8e257

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,15 @@ fn main() {
630630

631631
rustcode = rustcode_functionsreplaced;
632632

633+
// actually we don't even need that function any more, but in particular a) the pub is one too
634+
// many, and b) we don't even want it pub.
635+
rustcode = rustcode.replace(
636+
"pub pub unsafe fn use_everything()",
637+
"unsafe fn use_everything()",
638+
);
639+
// not sure why that pops up everywhere, probably b/c we made them manually pub just before
640+
rustcode = rustcode.replace("pub pub unsafe fn ", "pub unsafe fn ");
641+
633642
let output_replaced = out_path.join("riot_c2rust_replaced.rs");
634643
std::fs::File::create(output_replaced)
635644
.expect("Failed to create riot_c2rust_replaced.rs")

riot-c2rust.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,56 @@ static inline void __masked_builtin_arm_set_fpscr(int fpscr){
148148
#define IS_C2RUST
149149

150150
#include "riot-headers.h"
151+
152+
void use_everything(void) {
153+
/* While most of them are from modules somewhere, we only need to make them
154+
* conditional if their corresponding includes in riot-headers.h are
155+
* conditional. */
156+
157+
ztimer_acquire(NULL);
158+
thread_get(0);
159+
thread_getpid();
160+
pid_is_valid(0);
161+
gpio_is_valid(0);
162+
irq_is_in();
163+
irq_is_enabled();
164+
irq_disable();
165+
irq_restore(0);
166+
mutex_lock(0);
167+
mutex_trylock(0);
168+
ztimer_now(NULL);
169+
ztimer_spin(NULL, 0);
170+
171+
gnrc_netapi_dispatch_send(0, 0, NULL);
172+
gnrc_netif_hdr_sizeof(NULL);
173+
gnrc_pktbuf_release(NULL);
174+
gnrc_pkt_len(NULL);
175+
gnrc_pkt_count(NULL);
176+
177+
thread_measure_stack_free(NULL);
178+
179+
gnrc_ipv6_nib_nc_get_ar_state(NULL);
180+
gnrc_netif_ipv6_addrs_get(NULL, NULL, 0);
181+
ipv6_addr_is_unspecified(NULL);
182+
ipv6_addr_is_loopback(NULL);
183+
ipv6_addr_is_multicast(NULL);
184+
ipv6_addr_is_link_local(NULL);
185+
gnrc_ipv6_nib_nc_get_iface(NULL);
186+
gnrc_netif_ipv6_addrs_get(NULL, NULL, 0);
187+
gnrc_ipv6_nib_nc_get_nud_state(NULL);
188+
gnrc_ipv6_nib_nc_is_router(NULL);
189+
190+
#ifdef MODULE_NANOCOAP
191+
coap_pkt_set_code(NULL, 0);
192+
coap_get_code_raw(NULL);
193+
#endif
194+
195+
#ifdef MODULE_SOCK_UDP
196+
sock_udp_send(NULL, NULL, 0, NULL);
197+
sock_udp_recv(NULL, NULL, 0, 0, NULL);
198+
#endif
199+
200+
#ifdef MODULE_SOCK
201+
gnrc_netreg_entry_init_cb(NULL, 0, NULL);
202+
#endif
203+
}

0 commit comments

Comments
 (0)