Skip to content
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

实现uname系统调用 #614

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dragonos_kernel"
version = "0.1.0"
version = "0.1.9"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
53 changes: 53 additions & 0 deletions kernel/src/process/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,51 @@ use crate::{
},
};

//参考资料:https://code.dragonos.org.cn/xref/linux-6.1.9/include/uapi/linux/utsname.h#17
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct PosixOldUtsName {
pub sysname: [u8; 65],
pub nodename: [u8; 65],
pub release: [u8; 65],
pub version: [u8; 65],
pub machine: [u8; 65],
}

impl PosixOldUtsName {
pub fn new() -> Self {
const SYS_NAME: &[u8] = b"DragonOS";
const NODENAME: &[u8] = b"DragonOS";
const RELEASE: &[u8] = env!("CARGO_PKG_VERSION").as_bytes();
const VERSION: &[u8] = env!("CARGO_PKG_VERSION").as_bytes();

#[cfg(target_arch = "x86_64")]
const MACHINE: &[u8] = b"x86_64";

#[cfg(target_arch = "aarch64")]
const MACHINE: &[u8] = b"aarch64";

#[cfg(target_arch = "riscv64")]
const MACHINE: &[u8] = b"riscv64";

let mut r = Self {
sysname: [0; 65],
nodename: [0; 65],
release: [0; 65],
version: [0; 65],
machine: [0; 65],
};

r.sysname[0..SYS_NAME.len()].copy_from_slice(SYS_NAME);
r.nodename[0..NODENAME.len()].copy_from_slice(NODENAME);
r.release[0..RELEASE.len()].copy_from_slice(RELEASE);
r.version[0..VERSION.len()].copy_from_slice(VERSION);
r.machine[0..MACHINE.len()].copy_from_slice(MACHINE);

return r;
}
}

impl Syscall {
pub fn fork(frame: &TrapFrame) -> Result<usize, SystemError> {
ProcessManager::fork(frame, CloneFlags::empty()).map(|pid| pid.into())
Expand Down Expand Up @@ -341,4 +386,12 @@ impl Syscall {
}
}
}

pub fn uname(name: *mut PosixOldUtsName) -> Result<usize, SystemError> {
let mut writer =
UserBufferWriter::new(name, core::mem::size_of::<PosixOldUtsName>(), true)?;
writer.copy_one_to_user(&PosixOldUtsName::new(), 0)?;

return Ok(0);
}
}
7 changes: 5 additions & 2 deletions kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{
libs::align::page_align_up,
mm::{verify_area, MemoryManagementArch, VirtAddr},
net::syscall::SockAddr,
process::{fork::CloneFlags, Pid},
process::{fork::CloneFlags, syscall::PosixOldUtsName, Pid},
time::{
syscall::{PosixTimeZone, PosixTimeval},
TimeSpec,
Expand Down Expand Up @@ -1031,7 +1031,10 @@ impl Syscall {
}

SYS_SCHED_YIELD => Self::sched_yield(),

SYS_UNAME => {
let name = args[0] as *mut PosixOldUtsName;
Self::uname(name)
}
_ => panic!("Unsupported syscall ID: {}", syscall_num),
};

Expand Down
1 change: 1 addition & 0 deletions kernel/src/syscall/syscall_num.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define SYS_EXIT 60
#define SYS_WAIT4 61
#define SYS_KILL 62
#define SYS_UNAME 63

#define SYS_FCNTL 72

Expand Down
Loading