Separate context and process IDs.
This commit is contained in:
@@ -114,7 +114,7 @@ impl super::Context {
|
||||
pub fn set_userspace_io_allowed(&mut self, allowed: bool) {
|
||||
self.arch.userspace_io_allowed = allowed;
|
||||
|
||||
if self.id == super::context_id() {
|
||||
if self.cid == super::current_cid() {
|
||||
unsafe {
|
||||
crate::gdt::set_userspace_io_allowed(crate::gdt::pcr(), allowed);
|
||||
}
|
||||
|
||||
+10
-7
@@ -131,8 +131,10 @@ impl Eq for WaitpidKey {}
|
||||
/// A context, which identifies either a process or a thread
|
||||
#[derive(Debug)]
|
||||
pub struct Context {
|
||||
/// The ID of this context
|
||||
pub id: ContextId,
|
||||
/// The internal context ID of this context
|
||||
pub cid: ContextId,
|
||||
/// The process ID of this context
|
||||
pub pid: ContextId,
|
||||
/// The group ID of this context
|
||||
pub pgid: ContextId,
|
||||
/// The ID of the parent context
|
||||
@@ -231,10 +233,11 @@ pub struct SignalState {
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new(id: ContextId) -> Result<Context> {
|
||||
pub fn new(cid: ContextId, pid: ContextId) -> Result<Context> {
|
||||
let this = Context {
|
||||
id,
|
||||
pgid: id,
|
||||
cid,
|
||||
pid,
|
||||
pgid: pid,
|
||||
ppid: ContextId::from(0),
|
||||
session_id: ContextId::from(0),
|
||||
ruid: 0,
|
||||
@@ -409,7 +412,7 @@ impl Context {
|
||||
return addr_space;
|
||||
};
|
||||
|
||||
if self.id == super::context_id() {
|
||||
if self.cid == super::current_cid() {
|
||||
// TODO: Share more code with context::arch::switch_to.
|
||||
let this_percpu = PercpuBlock::current();
|
||||
|
||||
@@ -449,7 +452,7 @@ impl Context {
|
||||
}
|
||||
pub fn caller_ctx(&self) -> CallerCtx {
|
||||
CallerCtx {
|
||||
pid: self.id.into(),
|
||||
pid: self.pid.into(),
|
||||
uid: self.euid,
|
||||
gid: self.egid,
|
||||
}
|
||||
|
||||
+3
-2
@@ -50,7 +50,7 @@ impl ContextList {
|
||||
|
||||
/// Get the current context.
|
||||
pub fn current(&self) -> Option<&Arc<RwSpinlock<Context>>> {
|
||||
self.map.get(&super::context_id())
|
||||
self.map.get(&super::current_cid())
|
||||
}
|
||||
|
||||
pub fn iter(
|
||||
@@ -72,7 +72,8 @@ impl ContextList {
|
||||
) -> Result<&Arc<RwSpinlock<Context>>> {
|
||||
assert!(self
|
||||
.map
|
||||
.insert(id, Arc::new(RwSpinlock::new(Context::new(id)?)))
|
||||
// TODO
|
||||
.insert(id, Arc::new(RwSpinlock::new(Context::new(id, id)?)))
|
||||
.is_none());
|
||||
|
||||
Ok(self
|
||||
|
||||
+4
-4
@@ -85,8 +85,8 @@ pub fn init() {
|
||||
|
||||
unsafe {
|
||||
let percpu = PercpuBlock::current();
|
||||
percpu.switch_internals.set_context_id(context.id);
|
||||
percpu.switch_internals.set_idle_id(context.id);
|
||||
percpu.switch_internals.set_current_cid(context.cid);
|
||||
percpu.switch_internals.set_idle_id(context.cid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,8 +100,8 @@ pub fn contexts_mut() -> RwLockWriteGuard<'static, ContextList> {
|
||||
CONTEXTS.write()
|
||||
}
|
||||
|
||||
pub fn context_id() -> ContextId {
|
||||
PercpuBlock::current().switch_internals.context_id()
|
||||
pub fn current_cid() -> ContextId {
|
||||
PercpuBlock::current().switch_internals.current_cid()
|
||||
}
|
||||
|
||||
pub fn current() -> Result<Arc<RwSpinlock<Context>>> {
|
||||
|
||||
+10
-10
@@ -133,11 +133,11 @@ pub fn switch() -> SwitchResult {
|
||||
// Locate next context
|
||||
for (pid, next_context_lock) in contexts
|
||||
// Include all contexts with IDs greater than the current...
|
||||
.range((Bound::Excluded(prev_context_guard.id), Bound::Unbounded))
|
||||
.range((Bound::Excluded(prev_context_guard.cid), Bound::Unbounded))
|
||||
.chain(
|
||||
contexts
|
||||
// ... and all contexts with IDs less than the current...
|
||||
.range((Bound::Unbounded, Bound::Excluded(prev_context_guard.id))),
|
||||
.range((Bound::Unbounded, Bound::Excluded(prev_context_guard.cid))),
|
||||
)
|
||||
.chain(
|
||||
contexts
|
||||
@@ -184,7 +184,7 @@ pub fn switch() -> SwitchResult {
|
||||
next_context.switch_time = switch_time;
|
||||
|
||||
let percpu = PercpuBlock::current();
|
||||
percpu.switch_internals.context_id.set(next_context.id);
|
||||
percpu.switch_internals.current_cid.set(next_context.cid);
|
||||
|
||||
// FIXME set th switch result in arch::switch_to instead
|
||||
let prev_context =
|
||||
@@ -201,7 +201,7 @@ pub fn switch() -> SwitchResult {
|
||||
}));
|
||||
|
||||
let (ptrace_session, ptrace_flags) = if let Some((session, bp)) = ptrace::sessions()
|
||||
.get(&next_context.id)
|
||||
.get(&next_context.pid)
|
||||
.map(|s| (Arc::downgrade(s), s.data.lock().breakpoint))
|
||||
{
|
||||
(Some(session), bp.map_or(PtraceFlags::empty(), |f| f.flags))
|
||||
@@ -251,8 +251,8 @@ pub struct ContextSwitchPercpu {
|
||||
switch_result: Cell<Option<SwitchResultInner>>,
|
||||
pit_ticks: Cell<usize>,
|
||||
|
||||
/// Unique ID of the currently running context.
|
||||
context_id: Cell<ContextId>,
|
||||
/// Unique context ID of the currently running context.
|
||||
current_cid: Cell<ContextId>,
|
||||
|
||||
// The ID of the idle process
|
||||
idle_id: Cell<ContextId>,
|
||||
@@ -260,11 +260,11 @@ pub struct ContextSwitchPercpu {
|
||||
pub(crate) being_sigkilled: Cell<bool>,
|
||||
}
|
||||
impl ContextSwitchPercpu {
|
||||
pub fn context_id(&self) -> ContextId {
|
||||
self.context_id.get()
|
||||
pub fn current_cid(&self) -> ContextId {
|
||||
self.current_cid.get()
|
||||
}
|
||||
pub unsafe fn set_context_id(&self, new: ContextId) {
|
||||
self.context_id.set(new)
|
||||
pub unsafe fn set_current_cid(&self, new: ContextId) {
|
||||
self.current_cid.set(new)
|
||||
}
|
||||
pub fn idle_id(&self) -> ContextId {
|
||||
self.idle_id.get()
|
||||
|
||||
Reference in New Issue
Block a user