-
Notifications
You must be signed in to change notification settings - Fork 12
rawposix - misc fixes #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1022,7 +1022,8 @@ pub fn lind_syscall_api( | |
// Convert user space buffer address to physical address | ||
let optval_ptr = translate_vmmap_addr(&cage, arg4).unwrap() as *mut i32; | ||
let optval = unsafe { &mut *optval_ptr }; | ||
cage.getsockopt_syscall(virtual_fd, level, optname, optval) | ||
let optlen = arg5 as u32; | ||
cage.getsockopt_syscall(virtual_fd, level, optname, optval, optlen) | ||
} | ||
|
||
SOCKETPAIR_SYSCALL => { | ||
|
@@ -1089,18 +1090,30 @@ pub fn lind_syscall_api( | |
|
||
WAIT_SYSCALL => { | ||
let cage = interface::cagetable_getref(cageid); | ||
// Convert user space buffer address to physical address | ||
let status_addr = translate_vmmap_addr(&cage, arg1).unwrap() as u64; | ||
let status = interface::get_i32_ref(status_addr).unwrap(); | ||
// status could possibly be NULL | ||
let status = { | ||
if arg1 == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does dennis's pr affect this? |
||
None | ||
} else { | ||
let status_addr = translate_vmmap_addr(&cage, arg1).unwrap() as u64; | ||
Some(interface::get_i32_ref(status_addr).unwrap()) | ||
} | ||
}; | ||
cage.wait_syscall(status) | ||
} | ||
|
||
WAITPID_SYSCALL => { | ||
let pid = arg1 as i32; | ||
let cage = interface::cagetable_getref(cageid); | ||
// Convert user space buffer address to physical address | ||
let status_addr = translate_vmmap_addr(&cage, arg2).unwrap(); | ||
let status = interface::get_i32_ref(status_addr).unwrap(); | ||
// status could possibly be NULL | ||
let status = { | ||
if arg2 == 0 { | ||
None | ||
} else { | ||
let status_addr = translate_vmmap_addr(&cage, arg2).unwrap() as u64; | ||
Some(interface::get_i32_ref(status_addr).unwrap()) | ||
} | ||
}; | ||
let options = arg3 as i32; | ||
|
||
cage.waitpid_syscall(pid, status, options) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1435,9 +1435,10 @@ impl Cage { | |
return syscall_error(Errno::EBADF, "getdents", "Bad File Descriptor"); | ||
} | ||
let vfd = wrappedvfd.unwrap(); | ||
// calling getdents64 instead of getdents since glibc expects result from getdents64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this? |
||
let ret = unsafe { | ||
libc::syscall( | ||
libc::SYS_getdents as c_long, | ||
libc::SYS_getdents64 as c_long, | ||
vfd.underfd as i32, | ||
buf as *mut c_void, | ||
nbytes, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,7 @@ impl Cage { | |
* into the end of its parent's zombie list. Then when parent wants to wait for any of child, it could just check its | ||
* zombie list and retrieve the first entry from it (first in, first out). | ||
*/ | ||
pub fn waitpid_syscall(&self, cageid: i32, status: &mut i32, options: i32) -> i32 { | ||
pub fn waitpid_syscall(&self, cageid: i32, status: Option<&mut i32>, options: i32) -> i32 { | ||
let mut zombies = self.zombies.write(); | ||
let child_num = self.child_num.load(interface::RustAtomicOrdering::Relaxed); | ||
|
||
|
@@ -311,13 +311,13 @@ impl Cage { | |
// reach here means we already found the desired exited child | ||
let zombie = zombie_opt.unwrap(); | ||
// update the status | ||
*status = zombie.exit_code; | ||
let _ = status.map(|st| *st = zombie.exit_code); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im probably just too much of a newbie at rust, but why do we use map here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is equivalent to
It has no meaningful difference in terms of performance. Though this approach (map method) is indeed more difficult for new people to understand. Do we have a perference to write rust code with simple form for new people to understand? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a rule of thumb writing code that's simpler to follow is the best option, though adding a comment here also achieves the same results. I just wasn't sure if using map like this would be clear to anyone with basic understanding of rust. I'd either change it or add a comment. |
||
|
||
// return child's cageid | ||
zombie.cageid as i32 | ||
} | ||
|
||
pub fn wait_syscall(&self, status: &mut i32) -> i32 { | ||
pub fn wait_syscall(&self, status: Option<&mut i32>) -> i32 { | ||
self.waitpid_syscall(0, status, 0) | ||
} | ||
|
||
|
@@ -336,15 +336,15 @@ impl Cage { | |
if self.getgid.load(interface::RustAtomicOrdering::Relaxed) == -1 { | ||
self.getgid | ||
.store(DEFAULT_GID as i32, interface::RustAtomicOrdering::Relaxed); | ||
return -1; | ||
return DEFAULT_GID as i32; | ||
} | ||
DEFAULT_GID as i32 //Lind is only run in one group so a default value is returned | ||
} | ||
pub fn getegid_syscall(&self) -> i32 { | ||
if self.getegid.load(interface::RustAtomicOrdering::Relaxed) == -1 { | ||
self.getegid | ||
.store(DEFAULT_GID as i32, interface::RustAtomicOrdering::Relaxed); | ||
return -1; | ||
return DEFAULT_GID as i32; | ||
} | ||
DEFAULT_GID as i32 //Lind is only run in one group so a default value is returned | ||
} | ||
|
@@ -353,15 +353,15 @@ impl Cage { | |
if self.getuid.load(interface::RustAtomicOrdering::Relaxed) == -1 { | ||
self.getuid | ||
.store(DEFAULT_UID as i32, interface::RustAtomicOrdering::Relaxed); | ||
return -1; | ||
return DEFAULT_UID as i32; | ||
} | ||
DEFAULT_UID as i32 //Lind is only run as one user so a default value is returned | ||
} | ||
pub fn geteuid_syscall(&self) -> i32 { | ||
if self.geteuid.load(interface::RustAtomicOrdering::Relaxed) == -1 { | ||
self.geteuid | ||
.store(DEFAULT_UID as i32, interface::RustAtomicOrdering::Relaxed); | ||
return -1; | ||
return DEFAULT_UID as i32; | ||
} | ||
DEFAULT_UID as i32 //Lind is only run as one user so a default value is returned | ||
} | ||
|
@@ -407,6 +407,15 @@ impl Cage { | |
return syscall_error(Errno::EINVAL, "sigkill", "Invalid signal number"); | ||
} | ||
|
||
// if cage id is 0, send signal to itself | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we expand this comment a bit? I think from the manpage: If pid equals 0, then sig is sent to every process in the process we should just explain that we dont have process groups so it just sends to itself if thats correct? |
||
let cage_id = { | ||
if cage_id == 0 { | ||
self.cageid | ||
} else { | ||
cage_id as u64 | ||
} | ||
}; | ||
|
||
if !lind_send_signal(cage_id as u64, sig) { | ||
return syscall_error(Errno::ESRCH, "kill", "Target cage does not exist"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have to call remove here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I still remember correctly,
add_entry_with_overwrite
from vmmap does not automatically remove the old entries when the inserted new entries is overlapping with it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd comment that here then. Also worth checking that the comment for the function is clear about that wherever add_entry_with_overwrite lives