Commit 37873ae8 authored by Youjie Zheng's avatar Youjie Zheng
Browse files

[style] Fix code style according to the PR content

No related merge requests found
Showing with 37 additions and 67 deletions
+37 -67
# The base address of the user space.
user_space_base = 0x1000
# The size of the user space.
user_space_size = 0x7fff_ffff_f000
# The base address of the user heap.
user_heap_base = 0x3fc0_0000
user-heap-base = 0x3fc0_0000
# The size of the user heap.
user_heap_size = 0x40_0000
# The highest address of the user stack.
user_stack_top = 0x7fff_0000_0000
# The size of the user stack.
user_stack_size = 0x1_0000
user-heap-size = 0x40_0000
# The size of the kernel stack.
kernel_stack_size = 0x40000
\ No newline at end of file
kernel-stack-size = 0x40000
\ No newline at end of file
# The base address of the user space.
user_space_base = 0x1000
# The size of the user space.
user_space_size = 0x3f_ffff_f000
# The base address of the user heap.
user_heap_base = 0x3fc0_0000
# The size of the user heap.
user_heap_size = 0x40_0000
# The highest address of the user stack.
user_stack_top = 0x4_0000_0000
user-stack-top = 0x4_0000_0000
# The size of the user stack.
user_stack_size = 0x1_0000
user-stack-size = 0x1_0000
# The size of the kernel stack.
kernel_stack_size = 0x40000
\ No newline at end of file
kernel-stack-size = 0x40000
\ No newline at end of file
# The base address of the user space.
user_space_base = 0x1000
# The size of the user space.
user_space_size = 0x7fff_ffff_f000
# The base address of the user heap.
user_heap_base = 0x3fc0_0000
# The size of the user heap.
user_heap_size = 0x40_0000
# The highest address of the user stack.
user_stack_top = 0x7fff_0000_0000
user-stack-top = 0x7fff_0000_0000
# The size of the user stack.
user_stack_size = 0x1_0000
user-stack-size = 0x1_0000
# The size of the kernel stack.
kernel_stack_size = 0x40000
\ No newline at end of file
kernel-stack-size = 0x40000
\ No newline at end of file
......@@ -143,7 +143,7 @@ pub(crate) fn load_elf(name: &str, base_addr: VirtAddr) -> ELFInfo {
let elf_offset = kernel_elf_parser::get_elf_base_addr(&elf, base_addr.as_usize()).unwrap();
assert!(
elf_offset & 0xfff == 0,
memory_addr::is_aligned_4k(elf_offset),
"ELF base address must be aligned to 4k"
);
......
......@@ -6,7 +6,7 @@
extern crate log;
extern crate alloc;
extern crate axstd;
#[allow(unused)]
mod config;
mod loader;
mod mm;
......
......@@ -40,33 +40,33 @@ pub fn load_user_app(app_name: &str) -> AxResult<(VirtAddr, VirtAddr, AddrSpace)
}
// The user stack is divided into two parts:
// `ustack_bottom` -> `ustack top`: It is the stack space that users actually read and write.
// `ustack_top` -> `ustack end`: It is the space that contains the arguments, environment variables and auxv passed to the app.
// When the app starts running, the stack pointer points to `ustack_top`.
// `ustack_start` -> `ustack_pointer`: It is the stack space that users actually read and write.
// `ustack_pointer` -> `ustack_end`: It is the space that contains the arguments, environment variables and auxv passed to the app.
// When the app starts running, the stack pointer points to `ustack_pointer`.
let ustack_end = VirtAddr::from_usize(config::USER_STACK_TOP);
let ustack_size = config::USER_STACK_SIZE;
let ustack_bottom = ustack_end - ustack_size;
let ustack_start = ustack_end - ustack_size;
debug!(
"Mapping user stack: {:#x?} -> {:#x?}",
ustack_bottom, ustack_end
ustack_start, ustack_end
);
// FIXME: Add more arguments and environment variables
let (stack_data, ustack_top) = kernel_elf_parser::get_app_stack_region(
let (stack_data, ustack_pointer) = kernel_elf_parser::get_app_stack_region(
&[app_name.to_string()],
&[],
&elf_info.auxv,
ustack_bottom,
ustack_start,
ustack_size,
);
uspace.map_alloc(
ustack_bottom,
ustack_start,
ustack_size,
MappingFlags::READ | MappingFlags::WRITE | MappingFlags::USER,
true,
)?;
uspace.write(VirtAddr::from_usize(ustack_top), stack_data.as_slice())?;
Ok((elf_info.entry, VirtAddr::from(ustack_top), uspace))
uspace.write(VirtAddr::from_usize(ustack_pointer), stack_data.as_slice())?;
Ok((elf_info.entry, VirtAddr::from(ustack_pointer), uspace))
}
#[register_trap_handler(PAGE_FAULT)]
......
......@@ -5,6 +5,7 @@ use arceos_posix_api as api;
pub(crate) fn sys_read(fd: i32, buf: *mut c_void, count: usize) -> isize {
api::sys_read(fd, buf, count)
}
pub(crate) fn sys_write(fd: i32, buf: *const c_void, count: usize) -> isize {
api::sys_write(fd, buf, count)
}
......
mod ctl;
mod io;
pub(crate) use ctl::*;
pub(crate) use io::*;
pub(crate) use self::ctl::*;
pub(crate) use self::io::*;
use axerrno::{AxError, LinuxError};
use axerrno::LinuxError;
use axhal::paging::MappingFlags;
use axtask::{current, TaskExtRef};
use memory_addr::{VirtAddr, VirtAddrRange};
......@@ -91,9 +91,7 @@ pub(crate) fn sys_mmap(
.ok_or(LinuxError::ENOMEM)?
};
aspace
.map_alloc(start_addr, length, permission_flags.into(), false)
.map_err(<AxError as From<_>>::from)?;
aspace.map_alloc(start_addr, length, permission_flags.into(), false)?;
Ok(start_addr.as_usize())
})
......
mod mmap;
pub(crate) use mmap::*;
pub(crate) use self::mmap::*;
......@@ -12,6 +12,7 @@ use mm::*;
use syscalls::Sysno;
use task::*;
use time::*;
/// Macro to generate syscall body
///
/// It will receive a function which return Result<_, LinuxError> and convert it to
......
mod schedule;
mod thread;
pub(crate) use schedule::*;
pub(crate) use thread::*;
pub(crate) use self::schedule::*;
pub(crate) use self::thread::*;
......@@ -5,12 +5,12 @@ use num_enum::TryFromPrimitive;
use crate::syscall_body;
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
#[repr(i32)]
/// ARCH_PRCTL codes
///
/// It is only avaliable on x86_64, and is not convenient
/// to generate automatically via c_to_rust binding.
#[derive(Debug, Eq, PartialEq, TryFromPrimitive)]
#[repr(i32)]
enum ArchPrctlCode {
/// Set the GS segment base
SetGs = 0x1001,
......@@ -61,32 +61,32 @@ pub(crate) fn sys_set_tid_address(tid_ptd: *const i32) -> isize {
}
#[cfg(target_arch = "x86_64")]
pub(crate) fn sys_arch_prctl(code: i32, addr: *mut usize) -> isize {
pub(crate) fn sys_arch_prctl(code: i32, addr: u64) -> isize {
use axerrno::LinuxError;
syscall_body!(sys_arch_prctl, {
match ArchPrctlCode::try_from(code) {
// TODO: check the legality of the address
Ok(ArchPrctlCode::SetFs) => {
unsafe {
axhal::arch::write_thread_pointer(*addr);
axhal::arch::write_thread_pointer(addr as usize);
}
Ok(0)
}
Ok(ArchPrctlCode::GetFs) => {
unsafe {
*addr = axhal::arch::read_thread_pointer();
*(addr as *mut u64) = axhal::arch::read_thread_pointer() as u64;
}
Ok(0)
}
Ok(ArchPrctlCode::SetGs) => {
unsafe {
x86::msr::wrmsr(x86::msr::IA32_KERNEL_GSBASE, *addr as u64);
x86::msr::wrmsr(x86::msr::IA32_KERNEL_GSBASE, addr);
}
Ok(0)
}
Ok(ArchPrctlCode::GetGs) => {
unsafe {
*addr = x86::msr::rdmsr(x86::msr::IA32_KERNEL_GSBASE) as usize;
*(addr as *mut u64) = x86::msr::rdmsr(x86::msr::IA32_KERNEL_GSBASE);
}
Ok(0)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment