Replace from/into with get/new when necessary.

This commit is contained in:
4lDO2
2023-09-06 08:31:28 +02:00
parent 9d742387ac
commit f025ece614
13 changed files with 46 additions and 52 deletions
+2 -2
View File
@@ -277,7 +277,7 @@ pub fn fcntl(fd: FileHandle, cmd: usize, arg: usize) -> Result<usize> {
let context = context_lock.read();
let mut files = context.files.write();
match *files.get_mut(fd.into()).ok_or(Error::new(EBADF))? {
match *files.get_mut(fd.get()).ok_or(Error::new(EBADF))? {
Some(ref mut file) => match cmd {
F_GETFD => {
if file.cloexec {
@@ -346,7 +346,7 @@ pub fn fstat(fd: FileHandle, user_buf: UserSliceWo) -> Result<usize> {
// TODO: Ensure only the kernel can access the stat when st_dev is set, or use another API
// for retrieving the scheme ID from a file descriptor.
// TODO: Less hacky method.
let st_dev = scheme_id.into().try_into().map_err(|_| Error::new(EOVERFLOW))?;
let st_dev = scheme_id.get().try_into().map_err(|_| Error::new(EOVERFLOW))?;
user_buf.advance(memoffset::offset_of!(Stat, st_dev)).and_then(|b| b.limit(8)).ok_or(Error::new(EIO))?.copy_from_slice(&u64::to_ne_bytes(st_dev))?;
Ok(0)
+2 -2
View File
@@ -202,7 +202,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, stack
let contexts = crate::context::contexts();
if let Some(context_lock) = contexts.current() {
let context = context_lock.read();
print!("{} ({}): ", context.name, context.id.into());
print!("{} ({}): ", context.name, context.id.get());
}
// Do format_call outside print! so possible exception handlers cannot reentrantly
@@ -244,7 +244,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, stack
let contexts = crate::context::contexts();
if let Some(context_lock) = contexts.current() {
let context = context_lock.read();
print!("{} ({}): ", context.name, context.id.into());
print!("{} ({}): ", context.name, context.id.get());
}
// Do format_call outside print! so possible exception handlers cannot reentrantly
+6 -6
View File
@@ -138,10 +138,10 @@ pub fn setrens(rns: SchemeNamespace, ens: SchemeNamespace) -> Result<usize> {
let mut context = context_lock.write();
let setrns =
if rns.into() == 0 {
if rns.get() == 0 {
// Allow entering capability mode
true
} else if context.rns.into() == 0 {
} else if context.rns.get() == 0 {
// Do not allow leaving capability mode
return Err(Error::new(EPERM));
} else if context.euid == 0 {
@@ -153,7 +153,7 @@ pub fn setrens(rns: SchemeNamespace, ens: SchemeNamespace) -> Result<usize> {
} else if rns == context.rns {
// Allow setting RNS if used for RNS
true
} else if rns.into() as isize == -1 {
} else if rns.get() as isize == -1 {
// Ignore RNS if -1 is passed
false
} else {
@@ -162,10 +162,10 @@ pub fn setrens(rns: SchemeNamespace, ens: SchemeNamespace) -> Result<usize> {
};
let setens =
if ens.into() == 0 {
if ens.get() == 0 {
// Allow entering capability mode
true
} else if context.ens.into() == 0 {
} else if context.ens.get() == 0 {
// Do not allow leaving capability mode
return Err(Error::new(EPERM));
} else if context.euid == 0 {
@@ -177,7 +177,7 @@ pub fn setrens(rns: SchemeNamespace, ens: SchemeNamespace) -> Result<usize> {
} else if ens == context.rns {
// Allow setting ENS if used for RNS
true
} else if ens.into() as isize == -1 {
} else if ens.get() as isize == -1 {
// Ignore ENS if -1 is passed
false
} else {
+12 -12
View File
@@ -120,7 +120,7 @@ pub fn getpid() -> Result<ContextId> {
pub fn getpgid(pid: ContextId) -> Result<ContextId> {
let contexts = context::contexts();
let context_lock = if pid.into() == 0 {
let context_lock = if pid.get() == 0 {
contexts.current().ok_or(Error::new(ESRCH))?
} else {
contexts.get(pid).ok_or(Error::new(ESRCH))?
@@ -174,7 +174,7 @@ pub fn kill(pid: ContextId, sig: usize) -> Result<usize> {
}
};
if pid.into() as isize > 0 {
if pid.get() as isize > 0 {
// Send to a single process
if let Some(context_lock) = contexts.get(pid) {
let mut context = context_lock.write();
@@ -184,12 +184,12 @@ pub fn kill(pid: ContextId, sig: usize) -> Result<usize> {
sent += 1;
}
}
} else if pid.into() as isize == -1 {
} else if pid.get() as isize == -1 {
// Send to every process with permission, except for init
for (_id, context_lock) in contexts.iter() {
let mut context = context_lock.write();
if context.id.into() > 2 {
if context.id.get() > 2 {
found += 1;
if send(&mut context) {
@@ -198,10 +198,10 @@ pub fn kill(pid: ContextId, sig: usize) -> Result<usize> {
}
}
} else {
let pgid = if pid.into() == 0 {
let pgid = if pid.get() == 0 {
current_pgid
} else {
ContextId::from(-(pid.into() as isize) as usize)
ContextId::from(-(pid.get() as isize) as usize)
};
// Send to every process in the process group whose ID
@@ -251,7 +251,7 @@ pub fn setpgid(pid: ContextId, pgid: ContextId) -> Result<usize> {
context.id
};
let context_lock = if pid.into() == 0 {
let context_lock = if pid.get() == 0 {
contexts.current().ok_or(Error::new(ESRCH))?
} else {
contexts.get(pid).ok_or(Error::new(ESRCH))?
@@ -259,7 +259,7 @@ pub fn setpgid(pid: ContextId, pgid: ContextId) -> Result<usize> {
let mut context = context_lock.write();
if context.id == current_pid || context.ppid == current_pid {
if pgid.into() == 0 {
if pgid.get() == 0 {
context.pgid = context.id;
} else {
context.pgid = pgid;
@@ -409,7 +409,7 @@ pub fn waitpid(pid: ContextId, status_ptr: Option<UserSliceWo>, flags: WaitFlags
};
loop {
let res_opt = if pid.into() == 0 {
let res_opt = if pid.get() == 0 {
// Check for existence of child
{
let mut found = false;
@@ -438,8 +438,8 @@ pub fn waitpid(pid: ContextId, status_ptr: Option<UserSliceWo>, flags: WaitFlags
let (_wid, (w_pid, status)) = waitpid.receive_any("waitpid any");
grim_reaper(w_pid, status)
}
} else if (pid.into() as isize) < 0 {
let pgid = ContextId::from(-(pid.into() as isize) as usize);
} else if (pid.get() as isize) < 0 {
let pgid = ContextId::from(-(pid.get() as isize) as usize);
// Check for existence of child in process group PGID
{
@@ -481,7 +481,7 @@ pub fn waitpid(pid: ContextId, status_ptr: Option<UserSliceWo>, flags: WaitFlags
let context_lock = contexts.get(pid).ok_or(Error::new(ECHILD))?;
let mut context = context_lock.write();
if context.ppid != ppid {
println!("TODO: Hack for rustc - changing ppid of {} from {} to {}", context.id.into(), context.ppid.into(), ppid.into());
println!("TODO: Hack for rustc - changing ppid of {} from {} to {}", context.id.get(), context.ppid.get(), ppid.get());
context.ppid = ppid;
//return Err(Error::new(ECHILD));
Some(context.status.clone())