Skip to content

Commit c8150e3

Browse files
committed
fixed formatting
1 parent 5711bca commit c8150e3

File tree

2 files changed

+32
-78
lines changed

2 files changed

+32
-78
lines changed

src/safeposix/syscalls/fs_calls.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,9 @@ impl Cage {
14811481
/// refer to the statfs man page [here](https://man7.org/linux/man-pages/man2/statfs.2.html).
14821482
14831483
pub fn fstatfs_syscall(&self, fd: i32, databuf: &mut FSData) -> i32 {
1484+
// BUG: If the provided file descriptor is out of bounds, get_filedescriptor
1485+
// returns Err(), unwrapping on which produces a 'panic!'
1486+
// otherwise, file descriptor table entry is stored in 'checkedfd'
14841487
let checkedfd = self.get_filedescriptor(fd).unwrap();
14851488
let unlocked_fd = checkedfd.read();
14861489
if let Some(filedesc_enum) = &*unlocked_fd {
@@ -5371,16 +5374,19 @@ impl Cage {
53715374

53725375
/// ### Description
53735376
///
5374-
/// `shmget_syscall` returns the shared memory segment identifier associated with a particular `key`
5375-
/// If a key doesn't exist, shmget creates a new memory segment and attaches it to the key.
5376-
/// Traditionally if the value of the key equals `IPC_PRIVATE`, we also create a new memory segment which
5377-
/// is not associated with a key during this syscall,
5378-
/// but for our implementaion, we return an error and only create a new memory
5379-
/// segment when the IPC_CREAT flag is specified in the`shmflag` argument.
5377+
/// `shmget_syscall` returns the shared memory segment identifier associated
5378+
/// with a particular `key` If a key doesn't exist, shmget creates a new
5379+
/// memory segment and attaches it to the key. Traditionally if the
5380+
/// value of the key equals `IPC_PRIVATE`, we also create a new memory
5381+
/// segment which is not associated with a key during this syscall,
5382+
/// but for our implementaion, we return an error and only create a new
5383+
/// memory segment when the IPC_CREAT flag is specified in the`shmflag`
5384+
/// argument.
53805385
///
53815386
/// ### Returns
53825387
///
5383-
/// An 32 bit integer which represens the identifier of the memory segment associated with the key
5388+
/// An 32 bit integer which represens the identifier of the memory segment
5389+
/// associated with the key
53845390
///
53855391
/// ### Arguments
53865392
///
@@ -5389,20 +5395,22 @@ impl Cage {
53895395
/// `shmflag` : mode flags which indicate whether to create a new key or not
53905396
/// The `shmflag` is composed of the following
53915397
/// * IPC_CREAT - specify that the system call creates a new segment
5392-
/// * IPC_EXCL - this flag is used with IPC_CREAT to cause this function to fail when IPC_CREAT is also used
5393-
/// and the key passed has a memory segment associated with it.
5398+
/// * IPC_EXCL - this flag is used with IPC_CREAT to cause this function to
5399+
/// fail when IPC_CREAT is also used and the key passed has a memory
5400+
/// segment associated with it.
53945401
///
53955402
/// ### Errors
53965403
///
53975404
/// * ENOENT : the key equals the `IPC_PRIVATE` constant
5398-
/// * EEXIST : key exists and yet either `IPC_CREAT` or `IPC_EXCL` are passed as flags
5405+
/// * EEXIST : key exists and yet either `IPC_CREAT` or `IPC_EXCL` are
5406+
/// passed as flags
53995407
/// * ENOENT : key did not exist and the `IPC_CREAT` flag was not passed
5400-
/// * EINVAL : the size passed was less than the minimum size of segment or greater than the maximum possible size
5408+
/// * EINVAL : the size passed was less than the minimum size of segment or
5409+
/// greater than the maximum possible size
54015410
///
54025411
/// ### Panics
54035412
///
54045413
/// There are no cases where the function directly panics
5405-
///
54065414
pub fn shmget_syscall(&self, key: i32, size: usize, shmflg: i32) -> i32 {
54075415
//Check if the key passed equals the IPC_PRIVATE flag
54085416
if key == IPC_PRIVATE {
@@ -5414,7 +5422,8 @@ impl Cage {
54145422
// data of the shm table
54155423
let metadata = &SHM_METADATA;
54165424

5417-
// Check if there exists a memory segment associated with the key passed as argument
5425+
// Check if there exists a memory segment associated with the key passed as
5426+
// argument
54185427
match metadata.shmkeyidtable.entry(key) {
54195428
// If there exists a memory segment at that key
54205429
interface::RustHashEntry::Occupied(occupied) => {
@@ -5440,8 +5449,8 @@ impl Cage {
54405449
);
54415450
}
54425451

5443-
// If memory segment doesn't exist and IPC_CREAT was specified - we create a new memory segment
5444-
// Check if the size passed is a valid value
5452+
// If memory segment doesn't exist and IPC_CREAT was specified - we create a new
5453+
// memory segment Check if the size passed is a valid value
54455454
if (size as u32) < SHMMIN || (size as u32) > SHMMAX {
54465455
return syscall_error(
54475456
Errno::EINVAL,

src/tests/fs_tests.rs

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4038,64 +4038,6 @@ pub mod fs_tests {
40384038
lindrustfinalize();
40394039
}
40404040

4041-
pub fn ut_lind_fs_stat_syscall_tests() {
4042-
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently,
4043-
// and also performs clean env setup
4044-
let _thelock = setup::lock_and_init();
4045-
4046-
let cage = interface::cagetable_getref(1);
4047-
4048-
let mut statdata = StatData::default();
4049-
4050-
// test out whether an error is output for a non existent file path
4051-
// (ENOENT[-2])
4052-
assert_eq!(
4053-
cage.stat_syscall("non_existent_file_path", &mut statdata),
4054-
syscall_error(Errno::ENOENT, "stat", "test_failure")
4055-
);
4056-
4057-
// setting up directory inode object '/tmp' for testing stat_syscall with a
4058-
// directory
4059-
let dir_path = "/tmp"; // since setup already initializes tmp, assuming it is there
4060-
assert_eq!(cage.stat_syscall(dir_path, &mut statdata), 0);
4061-
4062-
// setting up generic inode object "/tmp/generic" for testing stat_syscall with
4063-
// a generic file
4064-
let generic_path = "/tmp/generic";
4065-
let creat_fd = cage.creat_syscall(generic_path, S_IRWXA);
4066-
assert!(creat_fd > 0);
4067-
assert_eq!(cage.stat_syscall(generic_path, &mut statdata), 0);
4068-
4069-
// setting up character device inode object "/chardev" for testing stat_syscall
4070-
// with a character device
4071-
let dev = makedev(&DevNo { major: 1, minor: 3 });
4072-
let chardev_path = "/chardev";
4073-
assert_eq!(
4074-
cage.mknod_syscall(chardev_path, S_IRWXA | S_IFCHR as u32, dev),
4075-
0
4076-
);
4077-
assert_eq!(cage.stat_syscall(chardev_path, &mut statdata), 0);
4078-
4079-
// setting up socket inode object with path "/socket.sock" for testing
4080-
// stat_syscall with a socket
4081-
let socketfile_path = "/socket.sock";
4082-
let socketfd = cage.socket_syscall(AF_UNIX, SOCK_STREAM, 0);
4083-
assert!(socketfd > 0);
4084-
let sockaddr = interface::new_sockaddr_unix(AF_UNIX as u16, socketfile_path.as_bytes());
4085-
let socket = interface::GenSockaddr::Unix(sockaddr);
4086-
assert_eq!(cage.bind_syscall(socketfd, &socket), 0);
4087-
4088-
// stat_syscall test here
4089-
assert_eq!(cage.stat_syscall(socketfile_path, &mut statdata), 0);
4090-
4091-
// socket teardown
4092-
assert_eq!(cage.close_syscall(socketfd), 0);
4093-
cage.unlink_syscall(socketfile_path);
4094-
4095-
lindrustfinalize();
4096-
return;
4097-
}
4098-
40994041
pub fn ut_lind_fs_shmget_syscall() {
41004042
// acquire locks and start env cleanup
41014043
let _thelock = setup::lock_and_init();
@@ -4106,7 +4048,8 @@ pub mod fs_tests {
41064048
let shmid = cage.shmget_syscall(33123, 1024, IPC_CREAT);
41074049
assert_eq!(shmid, 4);
41084050

4109-
// Check error upon asking for a valid key and passing the IPC_CREAT and IPC_EXCL flag
4051+
// Check error upon asking for a valid key and passing the IPC_CREAT and
4052+
// IPC_EXCL flag
41104053
assert_eq!(
41114054
cage.shmget_syscall(key, 1024, IPC_CREAT | IPC_EXCL),
41124055
-(Errno::EEXIST as i32)
@@ -4118,10 +4061,12 @@ pub mod fs_tests {
41184061
-(Errno::ENOENT as i32)
41194062
);
41204063

4121-
// Check if the function returns a correct shmid upon asking with a key that we know exists
4064+
// Check if the function returns a correct shmid upon asking with a key that we
4065+
// know exists
41224066
assert_eq!(cage.shmget_syscall(key, 1024, 0666), shmid);
41234067

4124-
// Check if the function returns the correct error when we don't pass IPC_CREAT for a key that doesn't exist
4068+
// Check if the function returns the correct error when we don't pass IPC_CREAT
4069+
// for a key that doesn't exist
41254070
assert_eq!(
41264071
cage.shmget_syscall(123456, 1024, 0),
41274072
-(Errno::ENOENT as i32)
@@ -4466,7 +4411,7 @@ pub mod fs_tests {
44664411
assert_eq!(cage.exit_syscall(EXIT_SUCCESS), EXIT_SUCCESS);
44674412
lindrustfinalize();
44684413
}
4469-
4414+
44704415
#[test]
44714416
pub fn ut_lind_fs_stat_syscall_tests() {
44724417
// acquiring a lock on TESTMUTEX prevents other tests from running concurrently,
@@ -4588,7 +4533,7 @@ pub mod fs_tests {
45884533
let socket = interface::GenSockaddr::Unix(sockaddr);
45894534
assert_eq!(cage.bind_syscall(socketfd, &socket), 0);
45904535

4591-
// Errno::EOPNOTSUPP : -95
4536+
// Errno::EOPNOTSUPP : -95
45924537
assert_eq!(cage.fstat_syscall(socketfd, &mut statdata), -95);
45934538

45944539
// Clean up

0 commit comments

Comments
 (0)