File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -156,7 +156,26 @@ pub fn sys_get_time(_ts: *mut TimeVal, _tz: usize) -> isize {
156156 "kernel:pid[{}] sys_get_time NOT IMPLEMENTED" ,
157157 current_task( ) . unwrap( ) . process. upgrade( ) . unwrap( ) . getpid( )
158158 ) ;
159- -1
159+
160+ // 1. 为内核空间获取当前任务的根页表
161+ let page_table_token = current_user_token ( ) ;
162+ let page_table = PageTable :: from_token ( page_table_token) ;
163+
164+ // 2. 将用户态指针转为虚拟地址(usize),计算 TimeVal 结构体的地址范围
165+ let ts_va_start = ts as usize ; // TimeVal 起始虚拟地址
166+ let ts_va_end = ts_va_start + core:: mem:: size_of :: < TimeVal > ( ) ; // 结束虚拟地址(含结构体大小)
167+ let current_va = ts_va_start;
168+
169+ // 3. 读取硬件时间
170+ let us = get_time_us ( ) ;
171+ let ( sec, usec) = ( us / 1_000_000 , us % 1_000_000 ) ;
172+ let time_val = TimeVal { sec, usec } ;
173+ // 将 TimeVal 转为字节数组,方便后续写入物理内存
174+ let time_val_bytes = unsafe { core:: slice:: from_raw_parts ( & time_val as * const _ as * const u8 , core:: mem:: size_of :: < TimeVal > ( ) ) } ;
175+
176+
177+ // 4. 遍历 TimeVal 地址范围,按页翻译并写入数据(处理跨页,虽结构体小但兼容通用情况)
178+ translated_and_write ( current_va, ts_va_end, & page_table, time_val_bytes)
160179}
161180
162181/// mmap syscall
You can’t perform that action at this time.
0 commit comments