Skip to content

feat: 支持动态链接 #910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
740c6ff
fix(mm):优化extract中对before和after VMA映射情况的判断 (#802) (#803)
Jomocool May 3, 2024
62da39b
feat(mm):添加MAP_FIXED处理 (#804)
Jomocool May 3, 2024
35ae1f6
feat(mm):添加MAP_FIXED处理 (#805)
Jomocool May 3, 2024
9bf53ec
feat(elf): [WIP] Dynamic link support (#806)
chiichen May 3, 2024
80ca935
20240524 3:40
MemoryShore May 23, 2024
d1d0aca
20240527 0010
MemoryShore May 26, 2024
33e9f0b
修复mmap未延迟分配内存的问题
MemoryShore May 27, 2024
8eb687c
Merge branch 'patch-add-file-mapping' into patch-fix-mmap
MemoryShore May 28, 2024
9261cb7
Revert "Merge branch 'patch-add-file-mapping' into patch-fix-mmap"
MemoryShore May 28, 2024
aff3316
20240528 1800
MemoryShore May 28, 2024
653180e
Revert "Revert "Merge branch 'patch-add-file-mapping' into patch-fix-…
MemoryShore May 28, 2024
c4149d8
Merge branch 'patch-fix-mmap-revert' into patch-add-file-mapping
MemoryShore May 28, 2024
91222a3
Merge branch 'master' into patch-add-file-mapping
MemoryShore May 28, 2024
4e9f577
update-20240529-0347
MemoryShore May 28, 2024
95c37e4
update 20240604 0233
MemoryShore Jun 3, 2024
f1ad5b3
update 20240606 1800
MemoryShore Jun 6, 2024
d7211d0
update 20240607 0200
MemoryShore Jun 6, 2024
62ec0e0
update 20240617 1747
MemoryShore Jun 17, 2024
3ac055a
重写页面保护标志的构造逻辑
MemoryShore Jun 18, 2024
7fd7c6e
update20240620 1726
MemoryShore Jun 20, 2024
d2a37ed
Merge remote-tracking branch 'origin' into patch-add-file-mapping
MemoryShore Jun 23, 2024
00183e0
添加Riscv64的protection_map
MemoryShore Jun 23, 2024
5ef4037
简单实现fat文件系统的文件映射,添加msync系统调用
MemoryShore Jun 24, 2024
98c9be5
trait FileSystem增加统一接口
MemoryShore Jun 25, 2024
d5b5718
MountFS实现文件映射相关接口
MemoryShore Jun 25, 2024
eee564d
格式化代码
MemoryShore Jun 25, 2024
b5aca56
Merge branch 'master' into patch-add-file-mapping
MemoryShore Jun 29, 2024
34c585e
pagecache存储方式由HashMap改为XArray
MemoryShore Jul 2, 2024
90644bf
Merge branch 'master' into patch-add-file-mapping
MemoryShore Jul 16, 2024
2558777
使用读写锁包装Page结构体
MemoryShore Jul 24, 2024
c9e790b
PageCache由存放物理地址改为直接存放页面
MemoryShore Jul 24, 2024
8f338fb
优化protection_map的初始化方式
MemoryShore Jul 24, 2024
a6ff58c
添加shrink_list方法释放页面
MemoryShore Jul 26, 2024
535b702
Merge branch 'master' into patch-add-file-mapping
MemoryShore Jul 26, 2024
9ba2fa3
添加页面回收机制
MemoryShore Jul 28, 2024
38f4df0
Merge branch 'master' into patch-add-file-mapping
MemoryShore Jul 28, 2024
d7e76ec
添加页面回收内核线程
MemoryShore Jul 30, 2024
2f6b28d
缺页中断使用的锁修改为irq_save; 添加脏页回写机制
MemoryShore Aug 6, 2024
732a6d7
优化代码结构,添加部分注释
MemoryShore Aug 10, 2024
cc19c94
Merge branch 'master' into patch-add-file-mapping
MemoryShore Aug 19, 2024
b5aea85
优化PageCache的创建
MemoryShore Aug 22, 2024
bd48a3d
Merge branch 'master' into feat-dynamic-link
MemoryShore Aug 28, 2024
1a627e4
将入口点改为链接器;修正链接器加载地址
MemoryShore Aug 28, 2024
d6a5341
Merge branch 'master' into patch-add-file-mapping
MemoryShore Aug 28, 2024
baae979
Merge branch 'patch-add-file-mapping' into feat-dynamic-link
MemoryShore Aug 28, 2024
d8cde6e
修复合并错误
MemoryShore Aug 28, 2024
10d64ec
Merge branch 'patch-add-file-mapping' into feat-dynamic-link
MemoryShore Aug 28, 2024
e13cf39
修复do_cow_page死锁问题
MemoryShore Aug 28, 2024
94f1324
将PageFaultMessage中的地址对齐
MemoryShore Aug 28, 2024
ed782e6
Merge branch 'patch-add-file-mapping' into feat-dynamic-link
MemoryShore Aug 28, 2024
16c4232
auxv添加随机数指针;修复AtType序号错误
MemoryShore Aug 28, 2024
421d3ae
简单实现用户栈的16字节对齐
MemoryShore Aug 28, 2024
2207c1c
通过check fmt
MemoryShore Aug 29, 2024
6c4958b
完善用户栈的字节对齐机制
MemoryShore Aug 30, 2024
fae0f7a
通过riscv64编译
MemoryShore Aug 30, 2024
bacf498
修改测试程序路径
MemoryShore Aug 30, 2024
9aaa1b0
添加动态库libgcc_s.so.1
MemoryShore Aug 30, 2024
c966d61
feat: 初步支持动态链接程序运行 (#908)
MemoryShore Sep 2, 2024
9ee2f64
Revert "feat: 初步支持动态链接程序运行 (#908)" (#966)
chiichen Oct 10, 2024
5b912a4
Merge pull request #965 from MemoryShore/feat-dynamic-link
chiichen Oct 10, 2024
07d95d2
Merge branch 'master' into feat-dynamic-link
chiichen Oct 10, 2024
19b5fd6
Merge remote-tracking branch 'remote/master' into feat-dynamic-link
chiichen Oct 13, 2024
08146c9
chore: format & sync master
chiichen Oct 13, 2024
dee3798
chore: remove dead code
chiichen Oct 13, 2024
2edd19b
chore: sync Cargo.toml
chiichen Oct 13, 2024
aad25d7
修复启动时panic错误
MemoryShore Oct 14, 2024
95f0a3c
Merge pull request #979 from MemoryShore/feat-dynamic-link
chiichen Oct 15, 2024
25e31a4
chore: cp /lib to /lib64
chiichen Oct 19, 2024
a756e6d
refactor(user/app): switch from musl to glibc
chiichen Oct 19, 2024
5786e87
chore: remove test_glibc
chiichen Oct 20, 2024
71ec314
chore(user/app): musl to glibc
chiichen Oct 20, 2024
25bc042
feat: use prebuilt glibc
chiichen Oct 20, 2024
8ac8cf6
feat: build glibc from source using latest stable glibc source archiv…
chiichen Oct 29, 2024
be0407d
chore: remove redundant log in elf.rs
chiichen Oct 31, 2024
3e674df
chore: use rand() to init random_num
chiichen Oct 31, 2024
9c1ca44
把rand_bytes提取为公共的方法
fslongjin Nov 11, 2024
182a355
chore: downgrade glibc version from 2.40 to 2.35
chiichen Nov 11, 2024
c157070
Merge branch 'feat-dynamic-link' of https://github.com/DragonOS-Commu…
fslongjin Nov 11, 2024
380b4c0
Merge remote-tracking branch 'origin/master' into feat-dynamic-link
chiichen Dec 5, 2024
e1581cf
fix: compile error
chiichen Dec 6, 2024
89b19ff
Merge branch 'master' into feat-dynamic-link
fslongjin Apr 27, 2025
4543b78
fix: 修复set_robust_list函数对大小判断不正确的问题
fslongjin Apr 28, 2025
6a6bedd
fix: 修复glibc判断内核版本过老的bug
fslongjin Apr 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kernel/src/arch/x86_64/mm/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl X86_64MMArch {
address.data(),
flags
);
log::error!("fault rip: {:#x}", regs.rip);
let pid = ProcessManager::current_pid();
let mut info =
SigInfo::new(Signal::SIGSEGV, 0, SigCode::User, SigType::Kill(pid));
Expand Down
10 changes: 8 additions & 2 deletions kernel/src/arch/x86_64/process/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl Syscall {
}

/// ## 用于控制和查询与体系结构相关的进程特定选项
/// https://code.dragonos.org.cn/xref/linux-6.6.21/arch/x86/kernel/process_64.c#913
pub fn arch_prctl(option: usize, arg2: usize) -> Result<usize, SystemError> {
let pcb = ProcessManager::current_pcb();
if let Err(SystemError::EINVAL) = Self::do_arch_prctl_64(&pcb, option, arg2, true) {
Expand Down Expand Up @@ -109,8 +110,13 @@ impl Syscall {
}

#[allow(dead_code)]
pub fn do_arch_prctl_common(_option: usize, _arg2: usize) -> Result<usize, SystemError> {
todo!("do_arch_prctl_common not unimplemented");
pub fn do_arch_prctl_common(option: usize, arg2: usize) -> Result<usize, SystemError> {
// Don't use 0x3001-0x3004 because of old glibcs
if (0x3001..=0x3004).contains(&option) {
return Err(SystemError::EINVAL);
}

todo!("do_arch_prctl_common not unimplemented, option: {}, arg2: {}", option, arg2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/arch/x86_64/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub extern "sysv64" fn syscall_handler(frame: &mut TrapFrame) {
mfence();
let pid = ProcessManager::current_pcb().pid();
let show = false;
// let show = if syscall_num != SYS_SCHED && pid.data() >= 7 {
// let show = if syscall_num != SYS_SCHED && pid.data() >= 9{
// true
// } else {
// false
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/debug/panic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod hook;
pub mod hook;
use alloc::boxed::Box;
use cfg_if::cfg_if;

Expand Down
1 change: 1 addition & 0 deletions kernel/src/driver/base/device/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl DeviceManager {
/// - Err(SystemError): 匹配过程中出现意外错误,没有匹配成功
///
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/base/dd.c#899
#[inline(never)]
fn do_device_attach_driver(
&self,
driver: &Arc<dyn Driver>,
Expand Down
1 change: 1 addition & 0 deletions kernel/src/driver/base/device/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl dyn Driver {
/// ## 注意
///
/// 这里的默认实现很低效,请为特定的驱动自行实现高效的查询
#[inline(never)]
pub fn find_device_by_name(&self, name: &str) -> Option<Arc<dyn Device>> {
if let Some(r) = self.__find_device_by_name_fast(name) {
return Some(r);
Expand Down
4 changes: 1 addition & 3 deletions kernel/src/driver/char/virtio_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn virtio_console(
log::debug!(
"virtio_console: dev_id: {:?}, parent: {:?}",
dev_id,
dev_parent
dev_parent.as_ref().map(|x|x.name())
);
let device = VirtIOConsoleDevice::new(transport, dev_id.clone());
if device.is_none() {
Expand Down Expand Up @@ -560,9 +560,7 @@ impl Driver for VirtIOConsoleDriver {
virtio_con_dev.dev_id(),
);
}
log::debug!("virtio console: add_device: to lock inner");
let mut inner = self.inner();
log::debug!("virtio console: add_device: inner.locked");
let dev_name = inner.alloc_id();
if dev_name.is_none() {
panic!("Failed to allocate ID for VirtIO console device: '{:?}', virtio console device limit exceeded.", virtio_con_dev.dev_id())
Expand Down
7 changes: 6 additions & 1 deletion kernel/src/driver/pci/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,12 @@ pub fn pci_init() {
let common_header = box_pci_device.common_header();
match box_pci_device.header_type() {
HeaderType::Standard if common_header.status & 0x10 != 0 => {
info!("Found pci standard device with class code ={} subclass={} status={:#x} cap_pointer={:#x} vendor={:#x}, device id={:#x},bdf={}", common_header.class_code, common_header.subclass, common_header.status, box_pci_device.as_standard_device().unwrap().capabilities_pointer,common_header.vendor_id, common_header.device_id,common_header.bus_device_function);
info!(
"Found pci standard device with class code ={} subclass={}, bdf={}",
common_header.class_code,
common_header.subclass,
common_header.bus_device_function
);
}
HeaderType::Standard => {
info!(
Expand Down
1 change: 1 addition & 0 deletions kernel/src/driver/tty/tty_ldisc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl TtyLdiscManager {
/// ### 参数
/// - tty:需要设置的tty
/// - o_tty: other tty 用于pty pair
#[inline(never)]
pub fn ldisc_setup(tty: Arc<TtyCore>, o_tty: Option<Arc<TtyCore>>) -> Result<(), SystemError> {
let ld = tty.ldisc();

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/driver/virtio/sysfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl VirtIODeviceManager {
dev.set_virtio_device_index(virtio_index);
dev.set_device_name(format!("virtio{}", virtio_index.data()));

log::debug!("virtio_device_add: dev: {:?}", dev);
log::debug!("virtio_device_add: dev: {:?}", dev.name());
// 添加设备到设备管理器
device_manager().add_device(dev.clone() as Arc<dyn Device>)?;
let r = device_manager()
Expand Down
1 change: 0 additions & 1 deletion kernel/src/filesystem/fat/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,6 @@ impl IndexNode for LockedFATInode {
let page_cache = self.0.lock().page_cache.clone();
if let Some(page_cache) = page_cache {
let r = page_cache.lock_irqsave().read(offset, &mut buf[0..len]);
// self.0.lock_irqsave().update_metadata();
return r;
} else {
return self.read_direct(offset, len, buf, data);
Expand Down
11 changes: 10 additions & 1 deletion kernel/src/filesystem/page_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ impl InnerPageCache {
/// - `Ok(usize)` 成功读取的长度
/// - `Err(SystemError)` 失败返回错误码
pub fn read(&mut self, offset: usize, buf: &mut [u8]) -> Result<usize, SystemError> {
let inode = self
let inode: Arc<dyn IndexNode> = self
.page_cache_ref
.upgrade()
.unwrap()
.inode
.upgrade()
.unwrap();

let file_size = inode.metadata().unwrap().size;

let len = if offset < file_size as usize {
Expand Down Expand Up @@ -174,6 +175,7 @@ impl InnerPageCache {
for (page_index, count) in not_exist {
// TODO 这里使用buffer避免多次读取磁盘,将来引入异步IO直接写入页面,减少内存开销和拷贝
let mut page_buf = vec![0u8; MMArch::PAGE_SIZE * count];

inode.read_sync(page_index * MMArch::PAGE_SIZE, page_buf.as_mut())?;

self.create_pages(page_index, page_buf.as_mut())?;
Expand Down Expand Up @@ -341,6 +343,13 @@ impl PageCache {
}

pub fn lock_irqsave(&self) -> SpinLockGuard<InnerPageCache> {
if self.inner.is_locked() {
log::error!("page cache already locked");
}
self.inner.lock_irqsave()
}

pub fn is_locked(&self) -> bool {
self.inner.is_locked()
}
}
Loading
Loading