Skip to content

Commit 460f257

Browse files
committed
build: explicitly list functions to be used through c2rust
1 parent 115842b commit 460f257

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

build.rs

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

631631
rustcode = rustcode_functionsreplaced;
632632

633+
// We don't even need that function any more, we just have that in there so that c2rust gives
634+
// us its callees as functions. (In bindgen, we'd just list the functions we'd like to have).
635+
rustcode = rustcode.replace(
636+
"pub pub unsafe fn use_everything()",
637+
"#[cfg(false)] unsafe fn use_everything()",
638+
);
639+
// The macro_ wrappers are already `pub` because they are regular functions we create here that
640+
// just go around the macro code; removing the double pub.
641+
rustcode = rustcode.replace("pub pub unsafe fn ", "pub unsafe fn ");
642+
633643
let output_replaced = out_path.join("riot_c2rust_replaced.rs");
634644
std::fs::File::create(output_replaced)
635645
.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(0);
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(0);
169+
ztimer_spin(0, 0);
170+
171+
gnrc_netapi_dispatch_send(0, 0, 0);
172+
gnrc_netif_hdr_sizeof(0);
173+
gnrc_pktbuf_release(0);
174+
gnrc_pkt_len(0);
175+
gnrc_pkt_count(0);
176+
177+
thread_measure_stack_free(0);
178+
179+
gnrc_ipv6_nib_nc_get_ar_state(0);
180+
gnrc_netif_ipv6_addrs_get(0, 0, 0);
181+
ipv6_addr_is_unspecified(0);
182+
ipv6_addr_is_loopback(0);
183+
ipv6_addr_is_multicast(0);
184+
ipv6_addr_is_link_local(0);
185+
gnrc_ipv6_nib_nc_get_iface(0);
186+
gnrc_netif_ipv6_addrs_get(0, 0, 0);
187+
gnrc_ipv6_nib_nc_get_nud_state(0);
188+
gnrc_ipv6_nib_nc_is_router(0);
189+
190+
#ifdef MODULE_NANOCOAP
191+
coap_pkt_set_code(0, 0);
192+
coap_get_code_raw(0);
193+
#endif
194+
195+
#ifdef MODULE_SOCK_UDP
196+
sock_udp_send(0, 0, 0, 0);
197+
sock_udp_recv(0, 0, 0, 0, 0);
198+
#endif
199+
200+
#ifdef MODULE_SOCK
201+
gnrc_netreg_entry_init_cb(0, 0, 0);
202+
#endif
203+
}

0 commit comments

Comments
 (0)