Skip to content
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

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft

Conversation

rupeshkoushik07
Copy link
Member

@rupeshkoushik07 rupeshkoushik07 commented Jul 6, 2024

Description

Fixes # (issue)
This PR adds stream functionality and still needs to add file functionality to writev_syscall

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Test A - lind_project/tests/test_cases/test_a.c
  • Test B - lind_project/tests/test_cases/test_b.c

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been added to a pull request and/or merged in other modules (native-client, lind-glibc, lind-project)

@@ -60,6 +64,27 @@ pub fn check_cageid(cageid: u64) {
}
}

pub fn concat_iovec_to_slice(iovec: *const interface::IovecStruct, iovcnt: i32) -> Vec<u8> {
Copy link
Contributor

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) };
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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) => {
Copy link
Contributor

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");
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants