Many minor fixes to allow gcc to run inside rCore. Add some syscalls, fix SEEK_* and enlarge the heap

master
Jiajie Chen 6 years ago
parent 524865ebd8
commit 311cf104f9

4
kernel/Cargo.lock generated

@ -328,12 +328,12 @@ dependencies = [
[[package]] [[package]]
name = "rcore-fs" name = "rcore-fs"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs#ff3dd7d157bfdfaa05f8228ebb80456799fe6b4d" source = "git+https://github.com/rcore-os/rcore-fs#f8d7b06727b0a66091419b2dd6a15f620a7152af"
[[package]] [[package]]
name = "rcore-fs-sfs" name = "rcore-fs-sfs"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs#ff3dd7d157bfdfaa05f8228ebb80456799fe6b4d" source = "git+https://github.com/rcore-os/rcore-fs#f8d7b06727b0a66091419b2dd6a15f620a7152af"
dependencies = [ dependencies = [
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

@ -30,8 +30,8 @@ link_user = []
run_cmdline = [] run_cmdline = []
[profile.dev] [profile.dev]
# MUST >= 1 : Enable RVO to avoid stack overflow # MUST >= 2 : Enable RVO to avoid stack overflow
opt-level = 1 opt-level = 2
[dependencies] [dependencies]
log = "0.4" log = "0.4"

@ -68,6 +68,7 @@ qemu_opts += \
-drive format=raw,file=$(bootimage) \ -drive format=raw,file=$(bootimage) \
-drive format=qcow2,file=$(SFSIMG),media=disk,cache=writeback \ -drive format=qcow2,file=$(SFSIMG),media=disk,cache=writeback \
-serial mon:stdio \ -serial mon:stdio \
-m 4G \
-device isa-debug-exit -device isa-debug-exit
ifeq ($(pci_passthru), ) ifeq ($(pci_passthru), )
qemu_net_opts += \ qemu_net_opts += \
@ -307,4 +308,4 @@ endif
.PHONY: .PHONY:
addr2line: addr2line:
@python3 ../tools/addr2line.py $(prefix)addr2line $(arch) @python3 ../tools/addr2line.py $(prefix)addr2line $(arch) $(mode)

@ -2,7 +2,10 @@ use crate::consts::KERNEL_OFFSET;
use bit_allocator::BitAlloc; use bit_allocator::BitAlloc;
// Depends on kernel // Depends on kernel
use super::{BootInfo, MemoryRegionType}; use super::{BootInfo, MemoryRegionType};
use crate::memory::{active_table, init_heap, FRAME_ALLOCATOR}; use crate::memory::{active_table, init_heap, FRAME_ALLOCATOR, alloc_frame};
use crate::HEAP_ALLOCATOR;
use rcore_memory::PAGE_SIZE;
use alloc::vec::Vec;
use log::*; use log::*;
use once::*; use once::*;
use rcore_memory::paging::*; use rcore_memory::paging::*;
@ -12,6 +15,7 @@ pub fn init(boot_info: &BootInfo) {
init_frame_allocator(boot_info); init_frame_allocator(boot_info);
init_device_vm_map(); init_device_vm_map();
init_heap(); init_heap();
enlarge_heap();
info!("memory: init end"); info!("memory: init end");
} }
@ -38,3 +42,32 @@ fn init_device_vm_map() {
.map(KERNEL_OFFSET + 0xfee00000, 0xfee00000) .map(KERNEL_OFFSET + 0xfee00000, 0xfee00000)
.update(); .update();
} }
fn enlarge_heap() {
let mut page_table = active_table();
let mut addrs = Vec::new();
let va_offset = KERNEL_OFFSET + 0xe0000000;
for i in 0..16384 {
let page = alloc_frame().unwrap();
let va = KERNEL_OFFSET + 0xe0000000 + page;
if let Some((ref mut addr, ref mut len)) = addrs.last_mut() {
if *addr - PAGE_SIZE == va {
*len += PAGE_SIZE;
*addr -= PAGE_SIZE;
continue;
}
}
addrs.push((va, PAGE_SIZE));
}
for (addr, len) in addrs.into_iter() {
for va in (addr..(addr+len)).step_by(PAGE_SIZE) {
page_table.map(va, va - va_offset).update();
}
info!("Adding {:#X} {:#X} to heap", addr, len);
unsafe {
HEAP_ALLOCATOR
.lock()
.init(addr, len);
}
}
}

@ -78,7 +78,10 @@ impl PageTable for ActivePageTable {
} }
impl PageTableExt for ActivePageTable { impl PageTableExt for ActivePageTable {
const TEMP_PAGE_ADDR: usize = KERNEL_OFFSET | 0xcafeb000; // FIXME: the default value 0xcafebe000 is so low that allocation might overwrite it sometimes.
// However, putting it to KERNEL_OFFSET | 0xcafeb000 has unintended effects.
// Someone needs to reconsider this and use an ultimate solution.
// const TEMP_PAGE_ADDR: usize = KERNEL_OFFSET | 0xcafeb000;
} }
impl ActivePageTable { impl ActivePageTable {

@ -1147,9 +1147,9 @@ impl From<Metadata> for Stat {
} }
} }
const SEEK_SET: u8 = 1; const SEEK_SET: u8 = 0;
const SEEK_CUR: u8 = 2; const SEEK_CUR: u8 = 1;
const SEEK_END: u8 = 4; const SEEK_END: u8 = 2;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(C)] #[repr(C)]

@ -2,6 +2,7 @@ use super::*;
use crate::arch::cpu; use crate::arch::cpu;
use core::mem::size_of; use core::mem::size_of;
use core::sync::atomic::{AtomicI32, Ordering}; use core::sync::atomic::{AtomicI32, Ordering};
use crate::consts::USER_STACK_SIZE;
pub fn sys_arch_prctl(code: i32, addr: usize, tf: &mut TrapFrame) -> SysResult { pub fn sys_arch_prctl(code: i32, addr: usize, tf: &mut TrapFrame) -> SysResult {
const ARCH_SET_FS: i32 = 0x1002; const ARCH_SET_FS: i32 = 0x1002;
@ -136,7 +137,10 @@ pub struct SysInfo {
mem_unit: u32, mem_unit: u32,
} }
const RLIMIT_STACK: usize = 3;
const RLIMIT_RSS: usize = 5;
const RLIMIT_NOFILE: usize = 7; const RLIMIT_NOFILE: usize = 7;
const RLIMIT_AS: usize = 9;
pub fn sys_prlimit64( pub fn sys_prlimit64(
pid: usize, pid: usize,
@ -150,6 +154,18 @@ pub fn sys_prlimit64(
pid, resource, new_limit, old_limit pid, resource, new_limit, old_limit
); );
match resource { match resource {
RLIMIT_STACK => {
if !old_limit.is_null() {
proc.vm.check_write_ptr(old_limit)?;
unsafe {
*old_limit = RLimit {
cur: USER_STACK_SIZE as u64,
max: USER_STACK_SIZE as u64,
};
}
}
Ok(0)
}
RLIMIT_NOFILE => { RLIMIT_NOFILE => {
if !old_limit.is_null() { if !old_limit.is_null() {
proc.vm.check_write_ptr(old_limit)?; proc.vm.check_write_ptr(old_limit)?;
@ -161,6 +177,19 @@ pub fn sys_prlimit64(
} }
} }
Ok(0) Ok(0)
},
RLIMIT_RSS | RLIMIT_AS => {
if !old_limit.is_null() {
proc.vm.check_write_ptr(old_limit)?;
unsafe {
// 1GB
*old_limit = RLimit {
cur: 1024 * 1024 * 1024,
max: 1024 * 1024 * 1024,
};
}
}
Ok(0)
} }
_ => Err(SysError::ENOSYS), _ => Err(SysError::ENOSYS),
} }

@ -161,6 +161,15 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
SYS_GETCWD => sys_getcwd(args[0] as *mut u8, args[1]), SYS_GETCWD => sys_getcwd(args[0] as *mut u8, args[1]),
// 80 // 80
SYS_CHDIR => sys_chdir(args[0] as *const u8), SYS_CHDIR => sys_chdir(args[0] as *const u8),
// 90
SYS_CHMOD => {
warn!("sys_chmod is unimplemented");
Ok(0)
}
SYS_FCHMOD => {
warn!("sys_fchmod is unimplemented");
Ok(0)
}
SYS_FCHOWN => { SYS_FCHOWN => {
warn!("sys_fchown is unimplemented"); warn!("sys_fchown is unimplemented");
Ok(0) Ok(0)

@ -7,12 +7,13 @@ print('Paste backtrace here, and then input EOF(Ctrl-D or Ctrl-Z) to get annotat
lines = sys.stdin.readlines() lines = sys.stdin.readlines()
addrline = sys.argv[1] addrline = sys.argv[1]
arch = sys.argv[2] arch = sys.argv[2]
mode = sys.argv[3]
print('--------------------------------------') print('--------------------------------------')
for line in lines: for line in lines:
match = re.search('(#[0-9]+ )(0x[0-9A-F]+)( fp 0x[0-9A-F]+)', line) match = re.search('(#[0-9]+ )(0x[0-9A-F]+)( fp 0x[0-9A-F]+)', line)
if match: if match:
addr = match.group(2) addr = match.group(2)
process = subprocess.run([addrline, '-e', 'target/{0}/debug/rcore'.format(arch), '-f', '-C', addr], capture_output=True) process = subprocess.run([addrline, '-e', 'target/{0}/{1}/rcore'.format(arch, mode), '-f', '-C', addr], capture_output=True)
res = process.stdout.decode('utf-8') res = process.stdout.decode('utf-8')
print('{0}{1}{3} {2}'.format(match.group(1), match.group(2), res.strip(), match.group(3))) print('{0}{1}{3} {2}'.format(match.group(1), match.group(2), res.strip(), match.group(3)))
else: else:

Loading…
Cancel
Save