Replace from/into with get/new when necessary.
This commit is contained in:
@@ -72,10 +72,11 @@ macro_rules! int_like {
|
||||
container: $backing_atomic_type::new(x.get())
|
||||
}
|
||||
}
|
||||
// TODO: Rename/replace with Default trait?
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub const fn default() -> Self {
|
||||
Self::new($new_type_name::from(0))
|
||||
Self::new($new_type_name::new(0))
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
|
||||
@@ -415,8 +415,8 @@ impl Context {
|
||||
/// Get a file
|
||||
pub fn get_file(&self, i: FileHandle) -> Option<FileDescriptor> {
|
||||
let files = self.files.read();
|
||||
if i.into() < files.len() {
|
||||
files[i.into()].clone()
|
||||
if i.get() < files.len() {
|
||||
files[i.get()].clone()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -426,12 +426,12 @@ impl Context {
|
||||
/// Return the file descriptor number or None if the slot was not empty, or i was invalid
|
||||
pub fn insert_file(&self, i: FileHandle, file: FileDescriptor) -> Option<FileHandle> {
|
||||
let mut files = self.files.write();
|
||||
if i.into() < super::CONTEXT_MAX_FILES {
|
||||
while i.into() >= files.len() {
|
||||
if i.get() < super::CONTEXT_MAX_FILES {
|
||||
while i.get() >= files.len() {
|
||||
files.push(None);
|
||||
}
|
||||
if files[i.into()].is_none() {
|
||||
files[i.into()] = Some(file);
|
||||
if files[i.get()].is_none() {
|
||||
files[i.get()] = Some(file);
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
@@ -445,8 +445,8 @@ impl Context {
|
||||
// TODO: adjust files vector to smaller size if possible
|
||||
pub fn remove_file(&self, i: FileHandle) -> Option<FileDescriptor> {
|
||||
let mut files = self.files.write();
|
||||
if i.into() < files.len() {
|
||||
files[i.into()].take()
|
||||
if i.get() < files.len() {
|
||||
files[i.get()].take()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1631,8 +1631,6 @@ fn correct_inner<'l>(addr_space_lock: &'l Arc<RwLock<AddrSpace>>, mut addr_space
|
||||
|
||||
let mut allow_writable = true;
|
||||
|
||||
let mut debug = false;
|
||||
|
||||
let frame = match grant_info.provider {
|
||||
Provider::Allocated { .. } | Provider::AllocatedShared { .. } if access == AccessMode::Write => {
|
||||
match faulting_pageinfo_opt {
|
||||
@@ -1673,8 +1671,6 @@ fn correct_inner<'l>(addr_space_lock: &'l Arc<RwLock<AddrSpace>>, mut addr_space
|
||||
base.next_by(pages_from_grant_start)
|
||||
}
|
||||
Provider::External { address_space: ref foreign_address_space, src_base, .. } => {
|
||||
debug = true;
|
||||
|
||||
let foreign_address_space = Arc::clone(foreign_address_space);
|
||||
|
||||
if Arc::ptr_eq(addr_space_lock, &foreign_address_space) {
|
||||
@@ -1773,9 +1769,6 @@ fn correct_inner<'l>(addr_space_lock: &'l Arc<RwLock<AddrSpace>>, mut addr_space
|
||||
}
|
||||
};
|
||||
|
||||
if super::context_id().into() == 3 && debug {
|
||||
//log::info!("Correcting {:?} => {:?} (base {:?} info {:?})", faulting_page, frame, grant_base, grant_info);
|
||||
}
|
||||
let new_flags = grant_flags.write(grant_flags.has_write() && allow_writable);
|
||||
let Some(flush) = (unsafe { addr_space.table.utable.map_phys(faulting_page.start_address(), frame.start_address(), new_flags) }) else {
|
||||
// TODO
|
||||
|
||||
@@ -62,7 +62,7 @@ pub extern "C" fn signal_handler(sig: usize) {
|
||||
pgid: Some(pgid)
|
||||
}, (pid, 0xFFFF));
|
||||
} else {
|
||||
println!("{}: {} not found for continue", pid.into(), ppid.into());
|
||||
println!("{}: {} not found for continue", pid.get(), ppid.get());
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -90,7 +90,7 @@ pub extern "C" fn signal_handler(sig: usize) {
|
||||
pgid: Some(pgid)
|
||||
}, (pid, (sig << 8) | 0x7F));
|
||||
} else {
|
||||
println!("{}: {} not found for stop", pid.into(), ppid.into());
|
||||
println!("{}: {} not found for stop", pid.get(), ppid.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -191,7 +191,7 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
|
||||
for (id, context_lock) in crate::context::contexts().iter() {
|
||||
if target_id.map_or(false, |target_id| *id != target_id) { continue; }
|
||||
let context = context_lock.read();
|
||||
println!("{}: {}", (*id).into(), context.name);
|
||||
println!("{}: {}", (*id).get(), context.name);
|
||||
|
||||
// Switch to context page table to ensure syscall debug and stack dump will work
|
||||
if let Some(ref space) = context.addr_space {
|
||||
|
||||
+2
-2
@@ -554,7 +554,7 @@ impl Scheme for ProcScheme {
|
||||
} else if self.access == Access::Restricted {
|
||||
return Err(Error::new(EACCES));
|
||||
} else {
|
||||
ContextId::from(pid_str.parse().map_err(|_| Error::new(ENOENT))?)
|
||||
ContextId::new(pid_str.parse().map_err(|_| Error::new(ENOENT))?)
|
||||
};
|
||||
|
||||
self.open_inner(pid, parts.next(), flags, uid, gid)
|
||||
@@ -1096,7 +1096,7 @@ impl KernelScheme for ProcScheme {
|
||||
let handles = self.handles.read();
|
||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
let path = format!("proc:{}/{}", handle.info.pid.into(), match handle.info.operation {
|
||||
let path = format!("proc:{}/{}", handle.info.pid.get(), match handle.info.operation {
|
||||
Operation::Regs(RegsKind::Float) => "regs/float",
|
||||
Operation::Regs(RegsKind::Int) => "regs/int",
|
||||
Operation::Regs(RegsKind::Env) => "regs/env",
|
||||
|
||||
@@ -100,15 +100,15 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
};
|
||||
|
||||
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<12}{:<8}{}\n",
|
||||
context.id.into(),
|
||||
context.pgid.into(),
|
||||
context.ppid.into(),
|
||||
context.id.get(),
|
||||
context.pgid.get(),
|
||||
context.ppid.get(),
|
||||
context.ruid,
|
||||
context.rgid,
|
||||
context.rns.into(),
|
||||
context.rns.get(),
|
||||
context.euid,
|
||||
context.egid,
|
||||
context.ens.into(),
|
||||
context.ens.get(),
|
||||
stat_string,
|
||||
cpu_string,
|
||||
affinity,
|
||||
|
||||
@@ -38,7 +38,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
match schemes.get(description.scheme) {
|
||||
Some(scheme) => scheme.clone(),
|
||||
None => {
|
||||
let _ = writeln!(string, " {:>4}: {:>8} {:>8} {:>08X}: no scheme", fd, description.scheme.into(), description.number, description.flags);
|
||||
let _ = writeln!(string, " {:>4}: {:>8} {:>8} {:>08X}: no scheme", fd, description.scheme.get(), description.number, description.flags);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -48,10 +48,10 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
match scheme.fpath(description.number, &mut fpath) {
|
||||
Ok(path_len) => {
|
||||
let fname = str::from_utf8(&fpath[..path_len]).unwrap_or("?");
|
||||
let _ = writeln!(string, "{:>6}: {:>8} {:>8} {:>08X}: {}", fd, description.scheme.into(), description.number, description.flags, fname);
|
||||
let _ = writeln!(string, "{:>6}: {:>8} {:>8} {:>08X}: {}", fd, description.scheme.get(), description.number, description.flags, fname);
|
||||
},
|
||||
Err(err) => {
|
||||
let _ = writeln!(string, "{:>6}: {:>8} {:>8} {:>08X}: {}", fd, description.scheme.into(), description.number, description.flags, err);
|
||||
let _ = writeln!(string, "{:>6}: {:>8} {:>8} {:>08X}: {}", fd, description.scheme.get(), description.number, description.flags, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
|
||||
let schemes = scheme::schemes();
|
||||
for (name, &scheme_id) in schemes.iter_name(scheme_ns) {
|
||||
data.extend_from_slice(format!("{:>4}: ", scheme_id.into()).as_bytes());
|
||||
data.extend_from_slice(format!("{:>4}: ", scheme_id.get()).as_bytes());
|
||||
data.extend_from_slice(name.as_bytes());
|
||||
data.push(b'\n');
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
@@ -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
|
||||
|
||||
@@ -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
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user