mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-21 08:26:30 +00:00
Remove the lazy_static
dependency
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
5313689d6f
commit
f762eb8913
@ -360,3 +360,7 @@ macro_rules! log_syscall_entry {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn init() {
|
||||
uname::init();
|
||||
}
|
||||
|
@ -1,29 +1,13 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use spin::Once;
|
||||
|
||||
use super::SyscallReturn;
|
||||
use crate::prelude::*;
|
||||
|
||||
// We don't use the real name and version of our os here. Instead, we pick up fake values witch is the same as the ones of linux.
|
||||
// The values are used to fool glibc since glibc will check the version and os name.
|
||||
lazy_static! {
|
||||
/// used to fool glibc
|
||||
static ref SYS_NAME: CString = CString::new("Linux").unwrap();
|
||||
static ref NODE_NAME: CString = CString::new("WHITLEY").unwrap();
|
||||
static ref RELEASE: CString = CString::new("5.13.0").unwrap();
|
||||
static ref VERSION: CString = CString::new("5.13.0").unwrap();
|
||||
static ref MACHINE: CString = CString::new("x86_64").unwrap();
|
||||
static ref DOMAIN_NAME: CString = CString::new("").unwrap();
|
||||
static ref UTS_NAME: UtsName = {
|
||||
let mut uts_name = UtsName::new();
|
||||
copy_cstring_to_u8_slice(&SYS_NAME, &mut uts_name.sysname);
|
||||
copy_cstring_to_u8_slice(&NODE_NAME, &mut uts_name.nodename);
|
||||
copy_cstring_to_u8_slice(&RELEASE, &mut uts_name.release);
|
||||
copy_cstring_to_u8_slice(&VERSION, &mut uts_name.version);
|
||||
copy_cstring_to_u8_slice(&MACHINE, &mut uts_name.machine);
|
||||
copy_cstring_to_u8_slice(&DOMAIN_NAME, &mut uts_name.domainname);
|
||||
uts_name
|
||||
};
|
||||
}
|
||||
static UTS_NAME: Once<UtsName> = Once::new();
|
||||
|
||||
const UTS_FIELD_LEN: usize = 65;
|
||||
|
||||
@ -51,14 +35,28 @@ impl UtsName {
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_cstring_to_u8_slice(src: &CStr, dst: &mut [u8]) {
|
||||
let src = src.to_bytes_with_nul();
|
||||
let len = src.len().min(dst.len());
|
||||
dst[..len].copy_from_slice(&src[..len]);
|
||||
pub(super) fn init() {
|
||||
UTS_NAME.call_once(|| {
|
||||
let copy_slice = |src: &[u8], dst: &mut [u8]| {
|
||||
let len = src.len().min(dst.len());
|
||||
dst[..len].copy_from_slice(&src[..len]);
|
||||
};
|
||||
|
||||
let mut uts_name = UtsName::new();
|
||||
copy_slice(b"Linux", &mut uts_name.sysname);
|
||||
copy_slice(b"WHITLEY", &mut uts_name.nodename);
|
||||
copy_slice(b"5.13.0", &mut uts_name.release);
|
||||
copy_slice(b"5.13.0", &mut uts_name.version);
|
||||
copy_slice(b"x86_64", &mut uts_name.machine);
|
||||
copy_slice(b"", &mut uts_name.domainname);
|
||||
|
||||
uts_name
|
||||
});
|
||||
}
|
||||
|
||||
pub fn sys_uname(old_uname_addr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("old uname addr = 0x{:x}", old_uname_addr);
|
||||
ctx.user_space().write_val(old_uname_addr, &*UTS_NAME)?;
|
||||
ctx.user_space()
|
||||
.write_val(old_uname_addr, UTS_NAME.get().unwrap())?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
}
|
||||
|
Reference in New Issue
Block a user