Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/arch/arm64/boot/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use libkernel::{
};
use log::info;

const KERNEL_STACK_SZ: usize = 64 * 1024; // 32 KiB
const KERNEL_STACK_SZ: usize = 256 * 1024; // 32 KiB
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Outdated comment

pub const KERNEL_STACK_PG_ORDER: usize = (KERNEL_STACK_SZ / PAGE_SIZE).ilog2() as usize;

const KERNEL_HEAP_SZ: usize = 64 * 1024 * 1024; // 64 MiB
Expand Down
7 changes: 1 addition & 6 deletions src/arch/arm64/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use crate::{
fdt_prober::{probe_for_fdt_devices, set_fdt_va},
init::run_initcalls,
},
interrupts::{
cpu_messenger::{Message, cpu_messenger_init, message_cpu},
get_interrupt_root,
},
interrupts::{cpu_messenger::cpu_messenger_init, get_interrupt_root},
kmain,
memory::{INITAL_ALLOCATOR, PAGE_ALLOC},
sched::{sched_init_secondary, uspc_ret::dispatch_userspace_task},
Expand Down Expand Up @@ -132,8 +129,6 @@ fn arch_init_stage2(frame: *mut ExceptionState) -> *mut ExceptionState {
boot_secondaries();

// Prove that we can send IPIs through the messenger.
let _ = message_cpu(1, Message::Ping(ArchImpl::id() as _));

frame
}

Expand Down
6 changes: 3 additions & 3 deletions src/arch/arm64/exceptions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
arch::ArchImpl,
interrupts::get_interrupt_root,
ksym_pa,
sched::{current_task, uspc_ret::dispatch_userspace_task},
sched::{current::current_task, uspc_ret::dispatch_userspace_task},
spawn_kernel_work,
};
use aarch64_cpu::registers::{CPACR_EL1, ReadWriteable, VBAR_EL1};
Expand Down Expand Up @@ -144,7 +144,7 @@ extern "C" fn el1_serror_spx(state: &mut ExceptionState) {

#[unsafe(no_mangle)]
extern "C" fn el0_sync(state_ptr: *mut ExceptionState) -> *const ExceptionState {
current_task().ctx.lock_save_irq().save_user_ctx(state_ptr);
current_task().ctx.save_user_ctx(state_ptr);

let state = unsafe { state_ptr.as_ref().unwrap() };

Expand Down Expand Up @@ -174,7 +174,7 @@ extern "C" fn el0_sync(state_ptr: *mut ExceptionState) -> *const ExceptionState

#[unsafe(no_mangle)]
extern "C" fn el0_irq(state: *mut ExceptionState) -> *mut ExceptionState {
current_task().ctx.lock_save_irq().save_user_ctx(state);
current_task().ctx.save_user_ctx(state);

match get_interrupt_root() {
Some(ref im) => im.handle_interrupt(),
Expand Down
16 changes: 8 additions & 8 deletions src/arch/arm64/exceptions/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use crate::{
},
threading::{futex::sys_futex, sys_set_robust_list, sys_set_tid_address},
},
sched::{current_task, sys_sched_yield},
sched::{current::current_task, sys_sched_yield},
};
use alloc::boxed::Box;
use libkernel::{
Expand All @@ -78,10 +78,10 @@ use libkernel::{
};

pub async fn handle_syscall() {
let task = current_task();

let (nr, arg1, arg2, arg3, arg4, arg5, arg6) = {
let ctx = task.ctx.lock_save_irq();
let mut task = current_task();

let ctx = &mut task.ctx;
let state = ctx.user();

(
Expand Down Expand Up @@ -314,8 +314,8 @@ pub async fn handle_syscall() {
}
0x8b => {
// Special case for sys_rt_sigreturn
task.ctx
.lock_save_irq()
current_task()
.ctx
.put_signal_work(Box::pin(ArchImpl::do_signal_return()));

return;
Expand Down Expand Up @@ -449,7 +449,7 @@ pub async fn handle_syscall() {
}
_ => panic!(
"Unhandled syscall 0x{nr:x}, PC: 0x{:x}",
current_task().ctx.lock_save_irq().user().elr_el1
current_task().ctx.user().elr_el1
),
};

Expand All @@ -458,5 +458,5 @@ pub async fn handle_syscall() {
Err(e) => kern_err_to_syscall(e),
};

task.ctx.lock_save_irq().user_mut().x[0] = ret_val.cast_unsigned() as u64;
current_task().ctx.user_mut().x[0] = ret_val.cast_unsigned() as u64;
}
4 changes: 2 additions & 2 deletions src/arch/arm64/memory/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
memory::uaccess::UAccessResult,
},
memory::fault::{FaultResolution, handle_demand_fault, handle_protection_fault},
sched::{current_task, spawn_kernel_work},
sched::{current::current_task, spawn_kernel_work},
};
use alloc::boxed::Box;
use libkernel::{
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn handle_mem_fault(exception: Exception, info: AbortIss) {
"SIGSEGV on process {} {:?} PC: {:x}",
current_task().process.tgid,
exception,
current_task().ctx.lock_save_irq().user().elr_el1
current_task().ctx.user().elr_el1
),
// If the page fault involves sleepy kernel work, we can
// spawn that work on the process, since there is no other
Expand Down
4 changes: 3 additions & 1 deletion src/arch/arm64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use memory::{
use crate::{
process::{
Task,
owned::OwnedTask,
thread_group::signal::{SigId, ksigaction::UserspaceSigAction},
},
sync::SpinLock,
Expand All @@ -37,6 +38,7 @@ mod proc;
pub mod psci;

pub struct Aarch64 {}

impl CpuOps for Aarch64 {
fn id() -> usize {
MPIDR_EL1.read(MPIDR_EL1::Aff0) as _
Expand Down Expand Up @@ -109,7 +111,7 @@ impl Arch for Aarch64 {
proc::context_switch(new);
}

fn create_idle_task() -> Task {
fn create_idle_task() -> OwnedTask {
proc::idle::create_idle_task()
}

Expand Down
6 changes: 3 additions & 3 deletions src/arch/arm64/proc/idle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
arch::{ArchImpl, arm64::exceptions::ExceptionState},
memory::{PageOffsetTranslator, page::ClaimedPage},
process::Task,
process::owned::OwnedTask,
};
use core::arch::global_asm;
use libkernel::{
Expand All @@ -16,7 +16,7 @@ use libkernel::{

global_asm!(include_str!("idle.s"));

pub fn create_idle_task() -> Task {
pub fn create_idle_task() -> OwnedTask {
let code_page = ClaimedPage::alloc_zeroed().unwrap().leak();
let code_addr = VA::from_value(0xd00d0000);

Expand Down Expand Up @@ -60,5 +60,5 @@ pub fn create_idle_task() -> Task {
VMAPermissions::rx(),
);

Task::create_idle_task(addr_space, ctx, code_map)
OwnedTask::create_idle_task(addr_space, ctx, code_map)
}
7 changes: 3 additions & 4 deletions src/arch/arm64/proc/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
process::thread_group::signal::{
SigId, ksigaction::UserspaceSigAction, sigaction::SigActionFlags,
},
sched::current_task,
sched::current::current_task,
};
use libkernel::{
error::Result,
Expand All @@ -29,7 +29,7 @@ pub async fn do_signal(id: SigId, sa: UserspaceSigAction) -> Result<ExceptionSta
let task = current_task();
let mut signal = task.process.signals.lock_save_irq();

let saved_state = *task.ctx.lock_save_irq().user();
let saved_state = *task.ctx.user();
let mut new_state = saved_state;
let mut frame = RtSigFrame {
uctx: saved_state,
Expand Down Expand Up @@ -65,8 +65,7 @@ pub async fn do_signal(id: SigId, sa: UserspaceSigAction) -> Result<ExceptionSta
pub async fn do_signal_return() -> Result<ExceptionState> {
let task = current_task();

let sig_frame_addr: TUA<RtSigFrame> =
TUA::from_value(task.ctx.lock_save_irq().user().sp_el0 as _);
let sig_frame_addr: TUA<RtSigFrame> = TUA::from_value(task.ctx.user().sp_el0 as _);

let sig_frame = copy_from_user(sig_frame_addr).await?;

Expand Down
3 changes: 2 additions & 1 deletion src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use crate::process::{
Task,
owned::OwnedTask,
thread_group::signal::{SigId, ksigaction::UserspaceSigAction},
};
use alloc::sync::Arc;
Expand Down Expand Up @@ -39,7 +40,7 @@ pub trait Arch: CpuOps + VirtualMemory {
fn context_switch(new: Arc<Task>);

/// Construct a new idle task.
fn create_idle_task() -> Task;
fn create_idle_task() -> OwnedTask;

/// Powers off the machine. Implementations must never return.
fn power_off() -> !;
Expand Down
2 changes: 1 addition & 1 deletion src/console/chardev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
fs::open_file::OpenFile,
kernel_driver,
process::fd_table::Fd,
sched::current_task,
sched::current::current_task,
};
use alloc::{string::ToString, sync::Arc};
use libkernel::{
Expand Down
2 changes: 1 addition & 1 deletion src/console/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
kernel::kpipe::KPipe,
memory::uaccess::{copy_from_user, copy_from_user_slice, copy_to_user},
process::thread_group::Pgid,
sched::current_task,
sched::current::current_task,
sync::SpinLock,
};
use alloc::{boxed::Box, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion src/console/tty/cooker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::kernel::kpipe::KPipe;
use crate::process::thread_group::Pgid;
use crate::process::thread_group::signal::SigId;
use crate::process::thread_group::signal::kill::send_signal_to_pg;
use crate::sched::current_task;
use crate::sched::current::current_task;
use crate::sync::{CondVar, SpinLock};
use alloc::{sync::Arc, vec::Vec};
use libkernel::error::Result;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/fs/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::process::find_task_by_descriptor;
use crate::process::thread_group::Tgid;
use crate::sched::current_task;
use crate::sched::current::current_task;
use crate::sync::OnceLock;
use crate::{
drivers::{Driver, FilesystemDriver},
Expand Down
14 changes: 0 additions & 14 deletions src/drivers/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,6 @@ pub fn schedule_preempt(when: Instant) {
}
}

pub fn schedule_force_preempt() {
// Schedule a preemption event if none are scheduled
let when = now().unwrap() + Duration::from_millis(5);

if let Some(next_event) = WAKEUP_Q.borrow().peek()
&& next_event.when <= when
{
// An event is already scheduled before our forced preemption
return;
}

schedule_preempt(when);
}

static SYS_TIMER: OnceLock<Arc<SysTimer>> = OnceLock::new();

per_cpu! {
Expand Down
6 changes: 4 additions & 2 deletions src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use libkernel::{
};
use ringbuf::Arc;

use crate::{memory::uaccess::copy_to_user_slice, process::fd_table::Fd, sched::current_task};
use crate::{
memory::uaccess::copy_to_user_slice, process::fd_table::Fd, sched::current::current_task_shared,
};

use super::{fops::FileOps, open_file::FileCtx};

Expand Down Expand Up @@ -132,7 +134,7 @@ struct Dirent64Hdr {
}

pub async fn sys_getdents64(fd: Fd, mut ubuf: UA, size: u32) -> Result<usize> {
let task = current_task();
let task = current_task_shared();
let file = task
.fd_table
.lock_save_irq()
Expand Down
Loading