Change current addeess space to be index u64::MAX instead of 0

This commit is contained in:
pjht 2024-11-24 16:29:02 -06:00
parent ea4d9a7784
commit ef81ca1a6c
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -410,7 +410,7 @@ extern "C" fn syscall_handler() {
}
1 => TASKING.exit(regs.rcx.wrapping_cast()),
2 => {
retval = if regs.rcx == 0 {
retval = if regs.rcx == u64::MAX {
ACTIVE_SPACE
.lock()
.map_free(usize(regs.rdx), PageTableFlags::from_bits_truncate(regs.rsi))
@ -418,11 +418,7 @@ extern "C" fn syscall_handler() {
} else {
TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
if let Some(space) = address_spaces.get_mut(usize(regs.rcx - 1)) {
if let Some(space) = address_spaces.get_mut(usize(regs.rcx)) {
space
.map_free(usize(regs.rdx), PageTableFlags::from_bits_truncate(regs.rsi))
.map_or(0, |x| u64(x.expose_provenance()))
@ -438,24 +434,15 @@ extern "C" fn syscall_handler() {
}
4 => {
#[warn(clippy::expect_used, reason = "FIXME")]
#[expect(
clippy::arithmetic_side_effects,
reason = "usize::MAX will never be returned as an index, and so incrementing can never overflow."
)]
let address_space = u64(TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
address_spaces.insert(AddressSpace::new().expect("Failed to create address space"))
+ 1
}));
retval = address_space;
}
5 => {
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
TASKING.current_process(|process| {
process.address_spaces().lock().remove(usize(regs.rcx - 1))
process.address_spaces().lock().remove(usize(regs.rcx))
});
}
6 => 'call6: {
@ -465,16 +452,12 @@ extern "C" fn syscall_handler() {
};
let num_pages = usize(regs.rsi);
let flags = PageTableFlags::from_bits_truncate(regs.rdi);
let failed = if regs.rcx == 0 {
let failed = if regs.rcx == u64::MAX {
ACTIVE_SPACE.lock().map_assert_unused(page, num_pages, flags).is_err()
} else {
TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
if let Some(space) = address_spaces.get_mut(usize(regs.rcx - 1)) {
if let Some(space) = address_spaces.get_mut(usize(regs.rcx)) {
space.map_assert_unused(page, num_pages, flags).is_err()
} else {
true
@ -489,11 +472,7 @@ extern "C" fn syscall_handler() {
assert!(len <= buffer.len());
let err = TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
if let Some(space) = address_spaces.get_mut(usize(regs.rcx - 1)) {
if let Some(space) = address_spaces.get_mut(usize(regs.rcx)) {
let buffer_num_pages = buffer.len() / 4096;
let buffer_raw = Box::into_raw(buffer);
let page = ACTIVE_SPACE
@ -524,12 +503,8 @@ extern "C" fn syscall_handler() {
}
}
8 => {
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
let space = TASKING.current_process(|process| {
process.address_spaces().lock().remove(usize(regs.rdx - 1))
process.address_spaces().lock().remove(usize(regs.rdx))
});
let res = TASKING.new_process(ptr::with_exposed_provenance(usize(regs.rcx)), space);
if let Ok(pid) = res {
@ -605,16 +580,12 @@ extern "C" fn syscall_handler() {
};
let num_pages = usize(regs.rsi);
let flags = PageTableFlags::from_bits_truncate(regs.rdi);
let failed = if regs.rcx == 0 {
let failed = if regs.rcx == u64::MAX {
ACTIVE_SPACE.lock().map_only_unused(page, num_pages, flags).is_err()
} else {
TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
if let Some(space) = address_spaces.get_mut(usize(regs.rcx - 1)) {
if let Some(space) = address_spaces.get_mut(usize(regs.rcx)) {
space.map_only_unused(page, num_pages, flags).is_err()
} else {
true
@ -641,14 +612,10 @@ extern "C" fn syscall_handler() {
}
17 => {
#[warn(clippy::expect_used, reason = "FIXME")]
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
let err = TASKING
.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
let space = address_spaces.get_mut(usize(regs.rcx - 1)).ok_or(())?;
let space = address_spaces.get_mut(usize(regs.rcx)).ok_or(())?;
let slice_start: *mut u8 = ptr::with_exposed_provenance_mut(usize(regs.rdx));
space.run(|| unsafe {
slice::from_raw_parts_mut(slice_start, usize(regs.rsi)).fill(0);
@ -672,7 +639,7 @@ extern "C" fn syscall_handler() {
retval = 0;
break 'call20;
};
retval = if regs.rcx == 0 {
retval = if regs.rcx == u64::MAX {
unsafe {
ACTIVE_SPACE
.lock()
@ -686,11 +653,7 @@ extern "C" fn syscall_handler() {
} else {
TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
if let Some(space) = address_spaces.get_mut(usize(regs.rcx - 1)) {
if let Some(space) = address_spaces.get_mut(usize(regs.rcx)) {
unsafe {
space
.map_free_to(
@ -707,7 +670,7 @@ extern "C" fn syscall_handler() {
}
}
21 => {
retval = if regs.rcx == 0 {
retval = if regs.rcx == u64::MAX {
let (start_virt, start_phys) = ACTIVE_SPACE
.lock()
.map_free_cont_phys(
@ -720,11 +683,7 @@ extern "C" fn syscall_handler() {
} else {
TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
if let Some(space) = address_spaces.get_mut(usize(regs.rcx - 1)) {
if let Some(space) = address_spaces.get_mut(usize(regs.rcx)) {
let (start_virt, start_phys) = space
.map_free_cont_phys(
usize(regs.rdx),
@ -746,16 +705,12 @@ extern "C" fn syscall_handler() {
retval = 1;
break 'call22;
};
retval = if regs.rcx == 0 {
retval = if regs.rcx == u64::MAX {
u64::from(ACTIVE_SPACE.lock().unmap(page, usize(regs.rsi)).is_err())
} else {
TASKING.current_process(|process| {
let mut address_spaces = process.address_spaces().lock();
#[warn(
clippy::arithmetic_side_effects,
reason = "FIXME: The current address space should be usize::MAX as that is an invalid index, instead of 0."
)]
if let Some(space) = address_spaces.get_mut(usize(regs.rcx - 1)) {
if let Some(space) = address_spaces.get_mut(usize(regs.rcx)) {
u64::from(space.unmap(page, usize(regs.rsi)).is_err())
} else {
1