mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 14:43:23 +00:00
Write time to user only if addr is not zero
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
8f51259a10
commit
a18fc9eb25
@ -6,8 +6,15 @@ use crate::{log_syscall_entry, prelude::*, time::SystemTime, util::write_val_to_
|
||||
pub fn sys_time(tloc: Vaddr) -> Result<SyscallReturn> {
|
||||
log_syscall_entry!(SYS_TIME);
|
||||
debug!("tloc = 0x{tloc:x}");
|
||||
let now = SystemTime::now();
|
||||
let now_as_secs = now.duration_since(&SystemTime::UNIX_EPOCH)?.as_secs();
|
||||
write_val_to_user(tloc, &now_as_secs)?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
|
||||
let now_as_secs = {
|
||||
let now = SystemTime::now();
|
||||
now.duration_since(&SystemTime::UNIX_EPOCH)?.as_secs()
|
||||
};
|
||||
|
||||
if tloc != 0 {
|
||||
write_val_to_user(tloc, &now_as_secs)?;
|
||||
}
|
||||
|
||||
Ok(SyscallReturn::Return(now_as_secs as _))
|
||||
}
|
||||
|
Reference in New Issue
Block a user