safa_api/syscalls/resources.rs
1use safa_abi::errors::ErrorStatus;
2
3use crate::syscalls::types::{RequiredPtrMut, Ri};
4
5use super::{define_syscall, err_from_u16, SyscallNum};
6define_syscall! {
7 SyscallNum::SysRDestroy => {
8 /// Destroys "closes" a resource with the id `ri`, a resource can be a File, a Directory, a DirIter, etc...
9 ///
10 /// # Returns
11 /// - [`ErrorStatus::InvalidResource`] if the id `ri` is invalid
12 sysr_destroy(ri: Ri)
13 },
14 SyscallNum::SysRDup => {
15 /// Duplicates the resource referred to by the resource id `ri` and puts the new resource id in `dest_ri`
16 sysr_dup(ri: Ri, dest_ri: RequiredPtrMut<Ri>)
17 }
18}
19
20/// Destroys "closes" a resource with the id `ri`, a resource can be a File, Directory, DirIter, etc...
21///
22/// # Returns
23/// - [`ErrorStatus::InvalidResource`] if the id `ri` is invalid
24#[inline]
25pub fn destroy_resource(ri: Ri) -> Result<(), ErrorStatus> {
26 err_from_u16!(sysr_destroy(ri))
27}
28
29#[inline]
30/// Duplicates the resource referred to by the resource id `ri`
31/// and returns the new resource id
32pub fn dup(ri: Ri) -> Result<Ri, ErrorStatus> {
33 let mut dest_ri = 0xAAAAAAAAAAAAAAAAusize;
34 let ptr = unsafe { RequiredPtrMut::new_unchecked(&mut dest_ri) };
35 err_from_u16!(sysr_dup(ri, ptr), dest_ri)
36}