Skip to content

Commit

Permalink
定位到问题:由于虚拟行和物理行不是"1虚拟对应1物理",而在refresh_character的时候假设了这个对应关系,
Browse files Browse the repository at this point in the history
导致当1虚拟行对应多个物理行的时候,`self.vlines`的值不正确.从而导致渲染的时候数组下界溢出
(尝试渲染id为56的物理行,但最大56个物理行,因此最大物理行id为55)
  • Loading branch information
fslongjin committed Dec 12, 2023
1 parent b3fc6aa commit 487759e
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 32 deletions.
2 changes: 1 addition & 1 deletion kernel/src/debug/klog/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(super) struct MMDebugLogManager;

impl MMDebugLogManager {
/// 最大的内存分配器日志数量
pub const MAX_ALLOC_LOG_NUM: usize = 100000;
pub const MAX_ALLOC_LOG_NUM: usize = 1000;

/// 记录内存分配器的日志
///
Expand Down
3 changes: 1 addition & 2 deletions kernel/src/driver/tty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ use kdepends::thingbuf::mpsc::{
use crate::libs::rwlock::RwLock;

pub mod init;
// pub mod serial;
pub mod serial;
pub mod tty_device;
pub mod tty_ioctl;
pub mod serial;

pub mod tty_driver;

Expand Down
5 changes: 3 additions & 2 deletions kernel/src/driver/video/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl VideoRefreshManager {
* 将帧缓存区映射到地址SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE处
*/
fn init_frame_buffer(&self) {
kinfo!("Re-mapping VBE frame buffer...");
send_to_default_serial8250_port(b"Re-mapping VBE frame buffer...\n");
let buf_vaddr = VirtAddr::new(
SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE as usize + FRAME_BUFFER_MAPPING_OFFSET as usize,
);
Expand All @@ -104,6 +104,7 @@ impl VideoRefreshManager {
let count = PageFrameCount::new(
page_align_up(frame_buffer_info_graud.buf_size()) / MMArch::PAGE_SIZE,
);
// send_to_default_serial8250_port(format!("paddr: {:#x}, count={count:?}\n", paddr.data()).as_bytes());
let page_flags: PageFlags<MMArch> = PageFlags::new().set_execute(true).set_write(true);

let mut kernel_mapper = KernelMapper::lock();
Expand All @@ -124,7 +125,7 @@ impl VideoRefreshManager {
}
}

kinfo!("VBE frame buffer successfully Re-mapped!");
send_to_default_serial8250_port(b"VBE frame buffer successfully Re-mapped!\n");
}

/**
Expand Down
56 changes: 40 additions & 16 deletions kernel/src/libs/lib_ui/textui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use core::{
intrinsics::unlikely,
ops::{Add, AddAssign, Sub},
panic,
sync::atomic::{AtomicBool, AtomicI32, AtomicU32, Ordering},
sync::atomic::{compiler_fence, AtomicBool, AtomicI32, AtomicU32, Ordering},
};

use super::{
Expand Down Expand Up @@ -390,6 +390,7 @@ impl TextuiCharChromatic {
/// ## 参数
/// -line_id 要放入的真实行号
/// -index 要放入的真实列号
#[inline(never)]
pub fn textui_refresh_character(
&self,
lineid: LineId,
Expand All @@ -406,7 +407,7 @@ impl TextuiCharChromatic {
let mut _binding = textui_framework().metadata.read().buf_info();

let mut buf = TextuiBuf::new(&mut _binding);

// 在缓冲区画出一个字体,每个字体有TEXTUI_CHAR_HEIGHT行,TEXTUI_CHAR_WIDTH列个像素点
for i in 0..TEXTUI_CHAR_HEIGHT {
let start = count;
Expand All @@ -422,6 +423,7 @@ impl TextuiCharChromatic {
}
count = TextuiBuf::get_index_of_next_line(start);
}
// send_to_default_serial8250_port(b"ddd");

return Ok(0);
}
Expand Down Expand Up @@ -687,7 +689,6 @@ impl TextuiWindow {
/// - vline_id 要刷新的虚拟行号
/// - start 起始字符号
/// - count 要刷新的字符数量

fn textui_refresh_characters(
&mut self,
vline_id: LineId,
Expand Down Expand Up @@ -715,9 +716,11 @@ impl TextuiWindow {
let vline = &mut (self.vlines[vline_id.data() as usize]);
let mut i = 0;
let mut index = start_index;

send_to_default_serial8250_port(format!("vid: {}, top:{}\n",vline_id.data(), self.top_vline.data()).as_bytes());
while i < count {
if let TextuiVline::Chromatic(vline) = vline {


vline.chars[index.data() as usize]
.textui_refresh_character(actual_line_id, index)?;

Expand Down Expand Up @@ -877,14 +880,17 @@ impl TextuiWindow {
}

/// 真正向窗口的缓冲区上输入字符的函数(位置为window.cursor.get_y(),window.cursor.get_x())
#[inline(never)]
fn true_textui_putchar_window(
&mut self,
character: char,
frcolor: FontColor,
bkcolor: FontColor,
) -> Result<(), SystemError> {
send_to_default_serial8250_port(&[b'N']);
// 启用彩色字符
if self.flags.contains(WindowFlag::TEXTUI_CHROMATIC) {
send_to_default_serial8250_port(&[b'A']);
// if !self.cursor.get_x().check(-1, self.winsize.col() - 1) {
// panic!("textui window cursor x is wrong")
// }
Expand All @@ -895,9 +901,11 @@ impl TextuiWindow {
let cur_index = self.cursor.get_x().data() as usize;

if let TextuiVline::Chromatic(vline) = self.get_mut_vline(self.cursor.get_y()) {
send_to_default_serial8250_port(b"B");
// vline.is_empty = false;

if let Some(v_char) = vline.chars.get_mut(cur_index) {
send_to_default_serial8250_port(&[b'C']);
v_char.c = Some(character);
v_char.frcolor = frcolor;
v_char.bkcolor = bkcolor;
Expand All @@ -912,7 +920,13 @@ impl TextuiWindow {
if character == '\n' {
send_to_default_serial8250_port(&[b'\r']);
}
self.textui_new_line(self.cursor.get_y())?;

send_to_default_serial8250_port(&[b'F']);
self.textui_new_line(self.cursor.get_y()).map_err(|_| {
send_to_default_serial8250_port(b"gggggg\n\0");
SystemError::ENOMEM
})?;
send_to_default_serial8250_port(&[b'R']);
self.cursor.move_newline(1);
return Ok(());
}
Expand All @@ -921,12 +935,16 @@ impl TextuiWindow {
// LineIndex::new(cur_index as i32),
// 1,
// )?;

send_to_default_serial8250_port(&[b'X']);
self.textui_refresh_characters(self.cursor.get_y(), LineIndex(0), self.winsize.col())?;
send_to_default_serial8250_port(&[b'Y']);
// if !end_index.check(self.winsize.col()) {
// self.textui_new_line(self.cursor.get_y())?;
// self.cursor.move_newline(1);
// }
self.cursor.move_right(1);
send_to_default_serial8250_port(&[b'Z']);
} else {
// todo: 支持纯文本字符
todo!();
Expand Down Expand Up @@ -974,7 +992,7 @@ impl TextuiWindow {
// return Ok(());
// }
// 输出制表符
else if character == '\t' {
if character == '\t' {
if is_enable_window == true {
if let TextuiVline::Chromatic(vline) = self.get_vline(self.cursor.get_y()) {
//打印的空格数(注意将每行分成一个个表格,每个表格为8个字符)
Expand Down Expand Up @@ -1044,6 +1062,8 @@ impl TextuiWindow {
// 输出其他字符
send_to_default_serial8250_port(&[character as u8]);
if is_enable_window == true {
// send_to_default_serial8250_port(&[b'M']);
send_to_default_serial8250_port(&[b'V']);
// if let TextuiVline::Chromatic(vline) = self.get_vline(self.cursor.get_y()) {
// // 如果超过一行则换行
// if vline.end_index.data() >= self.winsize.col() {
Expand All @@ -1052,10 +1072,17 @@ impl TextuiWindow {
// }
// return self.true_textui_putchar_window(character, frcolor, bkcolor);
// }
return self.true_textui_putchar_window(character, frcolor, bkcolor);
compiler_fence(Ordering::SeqCst);
send_to_default_serial8250_port(&[b'K']);
let r = self.true_textui_putchar_window(character, frcolor, bkcolor);
send_to_default_serial8250_port(&[b'D']);

compiler_fence(Ordering::SeqCst);
return r;
}
}

send_to_default_serial8250_port(&[b'J']);
return Ok(());
}
/// 窗口闪烁显示光标
Expand Down Expand Up @@ -1287,8 +1314,8 @@ impl ScmUiFramework for TextUiFramework {
let mut new_buf = textui_framework().metadata.read().buf_info();

new_buf.copy_from_nonoverlapping(&old_buf);
kdebug!("textui change buf_info: old: {:?}", old_buf);
kdebug!("textui change buf_info: new: {:?}", new_buf);
// kdebug!("textui change buf_info: old: {:?}", old_buf);
// kdebug!("textui change buf_info: new: {:?}", new_buf);

return Ok(0);
}
Expand Down Expand Up @@ -1346,7 +1373,7 @@ pub fn textui_putchar(
if unsafe { TEXTUI_IS_INIT } {
return textui_framework()
.current_window
.lock()
.lock_irqsave()
.textui_putchar_window(
character,
fr_color,
Expand Down Expand Up @@ -1377,13 +1404,10 @@ pub fn textui_putstr(
} else {
None
};
let mut guard = window.as_ref().map(|w| w.lock());

// send_to_default_serial8250_port("textui init failedeeeeeeeeeeeeeee.\n\0".as_bytes());

let mut guard = window.as_ref().map(|w| w.lock_irqsave());
for character in string.chars() {
if unsafe { TEXTUI_IS_INIT } {

guard.as_mut().unwrap().textui_putchar_window(
character,
fr_color,
Expand All @@ -1399,15 +1423,15 @@ pub fn textui_putstr(
)?;
}
}

drop(guard);
return Ok(());
}

/// 初始化text ui框架

#[no_mangle]
pub extern "C" fn rs_textui_init() -> i32 {
let r = textui_init().unwrap_or_else(|e| e.to_posix_errno());
let r = textui_init().unwrap_or_else(|e: SystemError| e.to_posix_errno());
if r.is_negative() {
send_to_default_serial8250_port("textui init failed.\n\0".as_bytes());
}
Expand Down
8 changes: 0 additions & 8 deletions kernel/src/mm/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,6 @@ impl<Arch: MemoryManagementArch, F: FrameAllocator> PageMapper<Arch, F> {
// 清空这个页帧
MMArch::write_bytes(MMArch::phys_2_virt(frame).unwrap(), 0, MMArch::PAGE_SIZE);

// 设置页表项的flags
// let flags = Arch::ENTRY_FLAG_READWRITE
// | Arch::ENTRY_FLAG_DEFAULT_TABLE
// | if virt.kind() == PageTableKind::User {
// Arch::ENTRY_FLAG_USER
// } else {
// 0
// };
let flags: PageFlags<MMArch> =
PageFlags::new_page_table(virt.kind() == PageTableKind::User);

Expand Down
1 change: 1 addition & 0 deletions kernel/src/sched/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub extern "C" fn sched_init() {

sched_rt_init();
}

kinfo!("Schedulers initialized");
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/src/sched/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use alloc::{boxed::Box, collections::LinkedList, sync::Arc, vec::Vec};

use crate::{
arch::cpu::current_cpu_id,
driver::tty::serial::serial8250::send_to_default_serial8250_port,
include::bindings::bindings::MAX_CPU_NUM,
kBUG, kdebug,
libs::spinlock::SpinLock,
process::{ProcessControlBlock, ProcessFlags, ProcessManager}, driver::tty::serial::serial8250::send_to_default_serial8250_port,
process::{ProcessControlBlock, ProcessFlags, ProcessManager},
};

use super::{
Expand All @@ -30,7 +31,6 @@ pub unsafe fn sched_rt_init() {
if RT_SCHEDULER_PTR.is_none() {
compiler_fence(Ordering::SeqCst);
RT_SCHEDULER_PTR = Some(Box::new(SchedulerRT::new()));
send_to_default_serial8250_port("textui init failedeeeeeeeeeeeeeee.\n\0".as_bytes());
compiler_fence(Ordering::SeqCst);
} else {
kBUG!("Try to init RT Scheduler twice.");
Expand Down
4 changes: 4 additions & 0 deletions tools/write_disk_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ if [ -d "${GRUB_INSTALL_PATH}" ] || [ "${INSTALL_GRUB_TO_IMAGE}" = "0" ]; then
INSTALL_GRUB_TO_IMAGE="0"
else
mkdir -p ${GRUB_INSTALL_PATH}
fi


if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
cp ${kernel} ${root_folder}/bin/disk_mount/boot/
fi

Expand Down
2 changes: 1 addition & 1 deletion user/dadk/config/relibc-0.1.0.dadk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"depends": [],
"build": {
"build_command": ""
"build_command": "bash init_dragonos_toolchain.sh && DESTDIR=$DADK_BUILD_CACHE_DIR_RELIBC_0_1_0 make install -j $(nproc)"
},
"install": {
"in_dragonos_path": "/usr"
Expand Down

0 comments on commit 487759e

Please sign in to comment.