修改用户应用
parent
021722883d
commit
c8c00b3c9e
@ -1,28 +1,28 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
#[macro_use]
|
use user_lib::*;
|
||||||
extern crate user_lib;
|
|
||||||
|
|
||||||
const LEN: usize = 100;
|
const LEN: usize = 100;
|
||||||
|
|
||||||
|
static mut S: [u64; LEN] = [0u64; LEN];
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() -> i32 {
|
unsafe fn main() -> i32 {
|
||||||
let p = 3u64;
|
let p = 3u64;
|
||||||
let m = 998244353u64;
|
let m = 998244353u64;
|
||||||
let iter: usize = 20000000;
|
let iter: usize = 300000;
|
||||||
let mut s = [0u64; LEN];
|
|
||||||
let mut cur = 0usize;
|
let mut cur = 0usize;
|
||||||
s[cur] = 1;
|
S[cur] = 1;
|
||||||
for i in 1..=iter {
|
for i in 1..=iter {
|
||||||
let next = if cur + 1 == LEN { 0 } else { cur + 1 };
|
let next = if cur + 1 == LEN { 0 } else { cur + 1 };
|
||||||
s[next] = s[cur] * p % m;
|
S[next] = S[cur] * p % m;
|
||||||
cur = next;
|
cur = next;
|
||||||
if i % 1000000 == 0 {
|
if i % 10000 == 0 {
|
||||||
println!("power_3 [{}/{}]", i, iter);
|
println!("power_3 [{}/{}]", i, iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{}^{} = {}(MOD {})", p, iter, s[cur], m);
|
println!("{}^{} = {}(MOD {})", p, iter, S[cur], m);
|
||||||
println!("Test power_3 OK!");
|
println!("Test power_3 OK!");
|
||||||
0
|
0
|
||||||
}
|
}
|
@ -1,28 +1,28 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
#[macro_use]
|
use user_lib::*;
|
||||||
extern crate user_lib;
|
|
||||||
|
|
||||||
const LEN: usize = 100;
|
const LEN: usize = 100;
|
||||||
|
|
||||||
|
static mut S: [u64; LEN] = [0u64; LEN];
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() -> i32 {
|
unsafe fn main() -> i32 {
|
||||||
let p = 5u64;
|
let p = 5u64;
|
||||||
let m = 998244353u64;
|
let m = 998244353u64;
|
||||||
let iter: usize = 14000000;
|
let iter: usize = 210000;
|
||||||
let mut s = [0u64; LEN];
|
|
||||||
let mut cur = 0usize;
|
let mut cur = 0usize;
|
||||||
s[cur] = 1;
|
S[cur] = 1;
|
||||||
for i in 1..=iter {
|
for i in 1..=iter {
|
||||||
let next = if cur + 1 == LEN { 0 } else { cur + 1 };
|
let next = if cur + 1 == LEN { 0 } else { cur + 1 };
|
||||||
s[next] = s[cur] * p % m;
|
S[next] = S[cur] * p % m;
|
||||||
cur = next;
|
cur = next;
|
||||||
if i % 1000000 == 0 {
|
if i % 10000 == 0 {
|
||||||
println!("power_5 [{}/{}]", i, iter);
|
println!("power_5 [{}/{}]", i, iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{}^{} = {}(MOD {})", p, iter, s[cur], m);
|
println!("{}^{} = {}(MOD {})", p, iter, S[cur], m);
|
||||||
println!("Test power_5 OK!");
|
println!("Test power_5 OK!");
|
||||||
0
|
0
|
||||||
}
|
}
|
@ -1,28 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate user_lib;
|
|
||||||
|
|
||||||
const LEN: usize = 100;
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
fn main() -> i32 {
|
|
||||||
let p = 7u64;
|
|
||||||
let m = 998244353u64;
|
|
||||||
let iter: usize = 16000000;
|
|
||||||
let mut s = [0u64; LEN];
|
|
||||||
let mut cur = 0usize;
|
|
||||||
s[cur] = 1;
|
|
||||||
for i in 1..=iter {
|
|
||||||
let next = if cur + 1 == LEN { 0 } else { cur + 1 };
|
|
||||||
s[next] = s[cur] * p % m;
|
|
||||||
cur = next;
|
|
||||||
if i % 1000000 == 0 {
|
|
||||||
println!("power_7 [{}/{}]", i, iter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!("{}^{} = {}(MOD {})", p, iter, s[cur], m);
|
|
||||||
println!("Test power_7 OK!");
|
|
||||||
0
|
|
||||||
}
|
|
@ -1,18 +1,16 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
#[macro_use]
|
use user_lib::*;
|
||||||
extern crate user_lib;
|
use user_lib::syscall::*;
|
||||||
|
|
||||||
use user_lib::syscall::{sys_get_time, sys_yield};
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() -> i32 {
|
fn main() -> i32 {
|
||||||
let current_timer = sys_get_time();
|
let current_timer = sys_get_time();
|
||||||
let wait_for = current_timer + 3000;
|
let wait_for = current_timer + 3000;
|
||||||
loop {
|
while sys_get_time() < wait_for {
|
||||||
|
sys_yield();
|
||||||
}
|
}
|
||||||
println!("Test sleep OK!");
|
println!("Test sleep OK!");
|
||||||
0
|
0
|
||||||
}
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use user_lib::*;
|
||||||
|
|
||||||
|
use core::ptr::{null_mut, read_volatile};
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
fn main() -> i32 {
|
||||||
|
return 0;
|
||||||
|
// println!("\nload_fault APP running...\n");
|
||||||
|
// println!("Into Test load_fault, we will insert an invalid load operation...");
|
||||||
|
// println!("Kernel should kill this application!");
|
||||||
|
// unsafe {
|
||||||
|
// let _i = read_volatile(null_mut::<u8>());
|
||||||
|
// }
|
||||||
|
// 0
|
||||||
|
}
|
@ -1,18 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate user_lib;
|
|
||||||
|
|
||||||
use user_lib::syscall::{sys_get_time, sys_yield};
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
fn main() -> i32 {
|
|
||||||
let current_timer = sys_get_time();
|
|
||||||
let wait_for = current_timer + 3000;
|
|
||||||
while sys_get_time() < wait_for {
|
|
||||||
// sys_yield(); loop太快,防止每次切换时间小于1ms, 这里注释, 但是还是不对, 模拟器的时间不准,cpu频率不对, 这个用户应用统计的怎么都不够3000ms
|
|
||||||
}
|
|
||||||
println!("Test sleep OK!");
|
|
||||||
0
|
|
||||||
}
|
|
@ -0,0 +1,16 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
use core::ptr::{null_mut, read_volatile};
|
||||||
|
use user_lib::*;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
fn main() -> i32 {
|
||||||
|
return 0;
|
||||||
|
// println!("\nload_fault APP running...\n");
|
||||||
|
// println!("Into Test load_fault, we will insert an invalid load operation...");
|
||||||
|
// println!("Kernel should kill this application!");
|
||||||
|
// unsafe {
|
||||||
|
// let _i = read_volatile(null_mut::<u8>());
|
||||||
|
// }
|
||||||
|
// 0
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use core::ptr::slice_from_raw_parts_mut;
|
||||||
|
use user_lib::*;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
fn main() -> i32 {
|
||||||
|
return 0;
|
||||||
|
// println!("Test sbrk start.");
|
||||||
|
// const PAGE_SIZE: usize = 0x1000;
|
||||||
|
// let origin_brk = sbrk(0);
|
||||||
|
// println!("origin break point = {:x}", origin_brk);
|
||||||
|
// let brk = sbrk(PAGE_SIZE as i32);
|
||||||
|
// if brk != origin_brk {
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
// let brk = sbrk(0);
|
||||||
|
// println!("one page allocated, break point = {:x}", brk);
|
||||||
|
// println!("try write to allocated page");
|
||||||
|
// let new_page = unsafe {
|
||||||
|
// &mut *slice_from_raw_parts_mut(origin_brk as usize as *const u8 as *mut u8, PAGE_SIZE)
|
||||||
|
// };
|
||||||
|
// for pos in 0..PAGE_SIZE {
|
||||||
|
// new_page[pos] = 1;
|
||||||
|
// }
|
||||||
|
// println!("write ok");
|
||||||
|
// sbrk(PAGE_SIZE as i32 * 10);
|
||||||
|
// let brk = sbrk(0);
|
||||||
|
// println!("10 page allocated, break point = {:x}", brk);
|
||||||
|
// sbrk(PAGE_SIZE as i32 * -11);
|
||||||
|
// let brk = sbrk(0);
|
||||||
|
// println!("11 page DEALLOCATED, break point = {:x}", brk);
|
||||||
|
// println!("try DEALLOCATED more one page, should be failed.");
|
||||||
|
// let ret = sbrk(PAGE_SIZE as i32 * -1);
|
||||||
|
// if ret != -1 {
|
||||||
|
// println!("Test sbrk failed!");
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
// println!("Test sbrk almost OK!");
|
||||||
|
// println!("now write to deallocated page, should cause page fault.");
|
||||||
|
// for pos in 0..PAGE_SIZE {
|
||||||
|
// new_page[pos] = 2;
|
||||||
|
// }
|
||||||
|
// 0
|
||||||
|
}
|
Loading…
Reference in New Issue