sentry_uapi/
ffi_c.rs

1// SPDX-FileCopyrightText: 2023 Ledger SAS
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::exchange;
5use crate::systypes::*;
6
7/// C interface to [`crate::syscall::get_process_handle`] syscall Rust implementation
8#[no_mangle]
9pub extern "C" fn __sys_get_process_handle(process: TaskLabel) -> Status {
10    crate::syscall::get_process_handle(process)
11}
12
13/// C interface to [`crate::syscall::exit`] syscall Rust implementation
14#[no_mangle]
15pub extern "C" fn __sys_exit(status: i32) -> Status {
16    crate::syscall::exit(status)
17}
18
19/// C interface to [`crate::syscall::get_shm_handle`] syscall Rust implementation
20#[no_mangle]
21pub extern "C" fn __sys_get_shm_handle(shm: ShmLabel) -> Status {
22    crate::syscall::get_shm_handle(shm)
23}
24
25/// C interface to [`crate::syscall::get_dma_stream_handle`] syscall Rust implementation
26#[no_mangle]
27pub extern "C" fn __sys_get_dma_stream_handle(stream: StreamLabel) -> Status {
28    crate::syscall::get_dma_stream_handle(stream)
29}
30
31/// C interface to [`crate::syscall::sched_yield`] syscall Rust implementation
32#[no_mangle]
33pub extern "C" fn __sys_sched_yield() -> Status {
34    crate::syscall::sched_yield()
35}
36
37/// C interface to [`crate::syscall::sleep`] syscall Rust implementation
38#[no_mangle]
39pub extern "C" fn __sys_sleep(duration_ms: SleepDuration, mode: SleepMode) -> Status {
40    crate::syscall::sleep(duration_ms, mode)
41}
42
43/// C interface to [`crate::syscall::start`] syscall Rust implementation
44#[no_mangle]
45pub extern "C" fn __sys_start(process: TaskLabel) -> Status {
46    crate::syscall::start(process)
47}
48
49/// C interface to [`crate::syscall::map_dev`] syscall Rust implementation
50#[no_mangle]
51pub extern "C" fn __sys_map_dev(dev: DeviceHandle) -> Status {
52    crate::syscall::map_dev(dev as DeviceHandle)
53}
54
55/// C interface to [`crate::syscall::map_shm`] syscall Rust implementation
56#[no_mangle]
57pub extern "C" fn __sys_map_shm(shm: ShmHandle) -> Status {
58    crate::syscall::map_shm(shm as ShmHandle)
59}
60
61/// C interface to [`crate::syscall::unmap_dev`] syscall Rust implementation
62#[no_mangle]
63pub extern "C" fn __sys_unmap_dev(dev: DeviceHandle) -> Status {
64    crate::syscall::unmap_dev(dev as DeviceHandle)
65}
66
67/// C interface to [`crate::syscall::unmap_shm`] syscall Rust implementation
68#[no_mangle]
69pub extern "C" fn __sys_unmap_shm(shm: ShmHandle) -> Status {
70    crate::syscall::unmap_shm(shm as ShmHandle)
71}
72
73/// C interface to [`crate::syscall::shm_set_credential`] syscall Rust implementation
74#[no_mangle]
75pub extern "C" fn __sys_shm_set_credential(
76    shm: ShmHandle,
77    id: TaskHandle,
78    shm_perm: u32,
79) -> Status {
80    crate::syscall::shm_set_credential(shm, id, shm_perm)
81}
82
83/// C interface to [`crate::syscall::send_ipc`] syscall Rust implementation
84#[no_mangle]
85pub extern "C" fn __sys_send_ipc(target: TaskHandle, length: u8) -> Status {
86    crate::syscall::send_ipc(target, length)
87}
88
89/// C interface to [`crate::syscall::send_signal`] syscall Rust implementation
90#[no_mangle]
91pub extern "C" fn __sys_send_signal(resource: u32, signal_type: Signal) -> Status {
92    crate::syscall::send_signal(resource, signal_type)
93}
94
95/// C interface to [`crate::syscall::gpio_get`] syscall Rust implementation
96#[no_mangle]
97pub extern "C" fn __sys_gpio_get(resource: u32, io: u8) -> Status {
98    crate::syscall::gpio_get(resource, io)
99}
100
101/// C interface to [`crate::syscall::gpio_set`] syscall Rust implementation
102#[no_mangle]
103pub extern "C" fn __sys_gpio_set(resource: u32, io: u8, val: bool) -> Status {
104    crate::syscall::gpio_set(resource, io, val)
105}
106
107/// C interface to [`crate::syscall::gpio_reset`] syscall Rust implementation
108#[no_mangle]
109pub extern "C" fn __sys_gpio_reset(resource: u32, io: u8) -> Status {
110    crate::syscall::gpio_reset(resource, io)
111}
112
113/// C interface to [`crate::syscall::gpio_toggle`] syscall Rust implementation
114#[no_mangle]
115pub extern "C" fn __sys_gpio_toggle(resource: u32, io: u8) -> Status {
116    crate::syscall::gpio_toggle(resource, io)
117}
118
119/// C interface to [`crate::syscall::gpio_configure`] syscall Rust implementation
120#[no_mangle]
121pub extern "C" fn __sys_gpio_configure(resource: u32, io: u8) -> Status {
122    crate::syscall::gpio_configure(resource, io)
123}
124
125/// C interface to [`crate::syscall::get_device_handle`] syscall Rust implementation
126#[no_mangle]
127pub extern "C" fn __sys_get_device_handle(devlabel: u8) -> Status {
128    crate::syscall::get_device_handle(devlabel)
129}
130
131/// C interface to [`crate::syscall::irq_acknowledge`] syscall Rust implementation
132#[no_mangle]
133pub extern "C" fn __sys_irq_acknowledge(irq: u16) -> Status {
134    crate::syscall::irq_acknowledge(irq)
135}
136
137/// C interface to [`crate::syscall::irq_enable`] syscall Rust implementation
138#[no_mangle]
139pub extern "C" fn __sys_irq_enable(irq: u16) -> Status {
140    crate::syscall::irq_enable(irq)
141}
142
143/// C interface to [`crate::syscall::irq_disable`] syscall Rust implementation
144#[no_mangle]
145pub extern "C" fn __sys_irq_disable(irq: u16) -> Status {
146    crate::syscall::irq_disable(irq)
147}
148
149/// C interface to [`crate::syscall::wait_for_event`] syscall Rust implementation
150#[no_mangle]
151pub extern "C" fn __sys_wait_for_event(mask: u8, timeout: i32) -> Status {
152    crate::syscall::wait_for_event(mask, timeout)
153}
154
155/// C interface to [`crate::syscall::pm_manage`] syscall Rust implementation
156#[no_mangle]
157pub extern "C" fn __sys_pm_manage(mode: CPUSleep) -> Status {
158    crate::syscall::pm_manage(mode)
159}
160
161/// C interface to [`crate::syscall::alarm`] syscall Rust implementation
162#[no_mangle]
163pub extern "C" fn __sys_alarm(timeout_ms: u32, flag: AlarmFlag) -> Status {
164    crate::syscall::alarm(timeout_ms, flag)
165}
166
167/// C interface to [`crate::syscall::log`] syscall Rust implementation
168#[no_mangle]
169pub extern "C" fn __sys_log(length: usize) -> Status {
170    crate::syscall::log(length)
171}
172
173/// C interface to [`crate::syscall::get_random`] syscall Rust implementation
174#[no_mangle]
175pub extern "C" fn __sys_get_random() -> Status {
176    crate::syscall::get_random()
177}
178
179/// C interface to [`crate::syscall::get_cycle`] syscall Rust implementation
180#[no_mangle]
181pub extern "C" fn __sys_get_cycle(precision: Precision) -> Status {
182    crate::syscall::get_cycle(precision)
183}
184
185/// C interface to [`crate::syscall::pm_set_clock`] syscall Rust implementation
186#[no_mangle]
187pub extern "C" fn __sys_pm_set_clock(clk_reg: u32, clkmsk: u32, val: u32) -> Status {
188    crate::syscall::pm_set_clock(clk_reg, clkmsk, val)
189}
190
191/// C interface to [`crate::syscall::dma_start_stream`] syscall Rust implementation
192#[no_mangle]
193pub extern "C" fn __sys_dma_start_stream(dmah: StreamHandle) -> Status {
194    crate::syscall::dma_start_stream(dmah)
195}
196
197/// C interface to [`crate::syscall::dma_suspend_stream`] syscall Rust implementation
198#[no_mangle]
199pub extern "C" fn __sys_dma_suspend_stream(dmah: StreamHandle) -> Status {
200    crate::syscall::dma_suspend_stream(dmah)
201}
202
203/// C interface to [`crate::syscall::dma_get_stream_status`] syscall Rust implementation
204#[no_mangle]
205pub extern "C" fn __sys_dma_get_stream_status(dmah: StreamHandle) -> Status {
206    crate::syscall::dma_get_stream_status(dmah)
207}
208
209/// C interface to [`crate::syscall::shm_get_infos`] syscall Rust implementation
210#[no_mangle]
211pub extern "C" fn __sys_shm_get_infos(shm: ShmHandle) -> Status {
212    crate::syscall::shm_get_infos(shm)
213}
214
215/// C interface to [`crate::syscall::dma_assign_stream`] syscall Rust implementation
216#[no_mangle]
217pub extern "C" fn __sys_dma_assign_stream(dmah: StreamHandle) -> Status {
218    crate::syscall::dma_assign_stream(dmah)
219}
220
221/// C interface to [`crate::syscall::dma_unassign_stream`] syscall Rust implementation
222#[no_mangle]
223pub extern "C" fn __sys_dma_unassign_stream(dmah: StreamHandle) -> Status {
224    crate::syscall::dma_unassign_stream(dmah)
225}
226
227/// C interface to [`crate::syscall::dma_get_stream_info`] syscall Rust implementation
228#[no_mangle]
229pub extern "C" fn __sys_dma_get_stream_info(dmah: StreamHandle) -> Status {
230    crate::syscall::dma_get_stream_info(dmah)
231}
232
233/// C interface to [`crate::syscall::dma_resume_stream`] syscall Rust implementation
234#[no_mangle]
235pub extern "C" fn __sys_dma_resume_stream(dmah: StreamHandle) -> Status {
236    crate::syscall::dma_resume_stream(dmah)
237}
238
239/// C interface to [`crate::copy_to_kernel`] Rust implementation
240#[no_mangle]
241pub extern "C" fn copy_to_kernel(from: *mut u8, length: usize) -> Status {
242    let u8_slice: &[u8] = unsafe { core::slice::from_raw_parts(from, length) };
243    match exchange::copy_to_kernel(&u8_slice) {
244        Ok(_) => Status::Ok,
245        Err(err) => err,
246    }
247}
248
249/// C interface to [`crate::copy_from_kernel`] Rust implementation
250#[no_mangle]
251pub extern "C" fn copy_from_kernel(to: *mut u8, length: usize) -> Status {
252    let mut u8_slice: &mut [u8] =
253        unsafe { core::slice::from_raw_parts_mut(to, length) as &mut [u8] };
254    match exchange::copy_from_kernel(&mut u8_slice) {
255        Ok(_) => Status::Ok,
256        Err(err) => err,
257    }
258}