-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add stream and file functionality #290
base: develop
Are you sure you want to change the base?
Conversation
0cf9146
to
dec09db
Compare
@@ -60,6 +64,27 @@ pub fn check_cageid(cageid: u64) { | |||
} | |||
} | |||
|
|||
pub fn concat_iovec_to_slice(iovec: *const interface::IovecStruct, iovcnt: i32) -> Vec<u8> { |
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.
Wouldn't it be better if we included some short description for helper functions, especially the new ones? It is hard to jump in and understand everything right away without any comments
@@ -60,6 +64,27 @@ pub fn check_cageid(cageid: u64) { | |||
} | |||
} | |||
|
|||
pub fn concat_iovec_to_slice(iovec: *const interface::IovecStruct, iovcnt: i32) -> Vec<u8> { | |||
// ensure that the iovec pointer is valid and points to a valid iovec array | |||
let iovecs = unsafe { slice::from_raw_parts(iovec, iovcnt as usize) }; |
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 convert the array of segments into a slice? Why can't we just iterate through the array knowing the size of segments?
@@ -60,6 +64,27 @@ pub fn check_cageid(cageid: u64) { | |||
} | |||
} | |||
|
|||
pub fn concat_iovec_to_slice(iovec: *const interface::IovecStruct, iovcnt: i32) -> Vec<u8> { | |||
// ensure that the iovec pointer is valid and points to a valid iovec array |
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.
does this comment mean that the line below it ensures that the iovec pointer is valid or that we have to make sure it is valid before making a syscall?
pub fn log_from_slice(data: &[u8]) -> i32 { | ||
match str::from_utf8(data) { | ||
Ok(s) => { | ||
log_to_stdout(s); |
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.
log_to_stdout writes to the standard out stream regardless of the provided file descriptor, and this helper function is the only function that performs any sort of writing into a stream. what if the provided stream is standard error or any other stream?
@@ -1817,8 +1823,12 @@ impl Cage { | |||
} // Trigger SIGPIPE | |||
retval | |||
} | |||
Stream(_stream_filedesc_obj) => { |
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 believe providing some explanation for what's going on here would be good
let bytes_written = cage.writev_syscall(fd, iovecs.as_ptr(), iovecs.len() as i32); | ||
|
||
// Validate the results | ||
assert_eq!(bytes_written, 13, "Bytes written do not match expected value"); |
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 think it would be good to check that the data from the buffers is written to the specified file and not some other file (instead of just checking the number of bytes written)
Description
Fixes # (issue)
This PR adds stream functionality and still needs to add file functionality to writev_syscall
Type of change
How Has This Been Tested?
lind_project/tests/test_cases/test_a.c
lind_project/tests/test_cases/test_b.c
Checklist: