更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
time_syscall.c 文件参考

浏览源代码.

函数

int SysUtime (const char *path, const struct utimbuf *ptimes)
 
time_t SysTime (time_t *tloc)
 
int SysSetiTimer (int which, const struct itimerval *value, struct itimerval *ovalue)
 
int SysGetiTimer (int which, struct itimerval *value)
 
int SysTimerCreate (clockid_t clockID, struct ksigevent *evp, timer_t *timerID)
 
int SysTimerGettime (timer_t timerID, struct itimerspec *value)
 
int SysTimerSettime (timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue)
 
int SysTimerGetoverrun (timer_t timerID)
 
int SysTimerDelete (timer_t timerID)
 
int SysClockSettime (clockid_t clockID, const struct timespec *tp)
 
int SysClockGettime (clockid_t clockID, struct timespec *tp)
 获取系统时间 更多...
 
int SysClockGetres (clockid_t clockID, struct timespec *tp)
 
int SysClockNanoSleep (clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
 
int SysNanoSleep (const struct timespec *rqtp, struct timespec *rmtp)
 
clock_t SysTimes (struct tms *buf)
 
int SysClockSettime64 (clockid_t clockID, const struct timespec64 *tp)
 
int SysClockGettime64 (clockid_t clockID, struct timespec64 *tp)
 
int SysClockGetres64 (clockid_t clockID, struct timespec64 *tp)
 
int SysClockNanoSleep64 (clockid_t clk, int flags, const struct timespec64 *req, struct timespec64 *rem)
 
int SysTimerGettime64 (timer_t timerID, struct itimerspec64 *value)
 
int SysTimerSettime64 (timer_t timerID, int flags, const struct itimerspec64 *value, struct itimerspec64 *oldValue)
 

函数说明

◆ SysClockGetres()

int SysClockGetres ( clockid_t  clockID,
struct timespec *  tp 
)

在文件 time_syscall.c308 行定义.

309{
310 int ret;
311 struct timespec stp;
312
313 if (tp == NULL) {
314 errno = EINVAL;
315 return -EINVAL;
316 }
317
318 ret = clock_getres(clockID, &stp);
319 if (ret < 0) {
320 return -get_errno();
321 }
322
323 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec))) {
324 errno = EFAULT;
325 return -EFAULT;
326 }
327
328 return ret;
329}
int clock_getres(clockid_t clockID, struct timespec *tp)
Definition: time.c:676
size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len)
从内核空间拷贝到用户空间
Definition: user_copy.c:79
函数调用图:

◆ SysClockGetres64()

int SysClockGetres64 ( clockid_t  clockID,
struct timespec64 *  tp 
)

在文件 time_syscall.c462 行定义.

463{
464 int ret;
465 struct timespec t;
466 struct timespec64 stp;
467
468 if (tp == NULL) {
469 errno = EINVAL;
470 return -EINVAL;
471 }
472
473 ret = clock_getres(clockID, &t);
474 if (ret < 0) {
475 return -get_errno();
476 }
477
478 stp.tv_sec = t.tv_sec;
479 stp.tv_nsec = t.tv_nsec;
480
481 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec64))) {
482 errno = EFAULT;
483 return -EFAULT;
484 }
485
486 return ret;
487}
函数调用图:

◆ SysClockGettime()

int SysClockGettime ( clockid_t  clockID,
struct timespec *  tp 
)

获取系统时间

在文件 time_syscall.c285 行定义.

286{
287 int ret;
288 struct timespec stp;
289
290 if (tp == NULL) {
291 errno = EINVAL;
292 return -EINVAL;
293 }
294
295 ret = clock_gettime(clockID, &stp);
296 if (ret < 0) {
297 return -get_errno();
298 }
299
300 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec))) {
301 errno = EFAULT;
302 return -EFAULT;
303 }
304
305 return ret;
306}
int clock_gettime(clockid_t clockID, struct timespec *tp)
当用户程序进行特定系统调用时(例如clock_gettime(CLOCK_REALTIME_COARSE, &ts)),VDSO代码页会将其拦截;
Definition: time.c:614
函数调用图:

◆ SysClockGettime64()

int SysClockGettime64 ( clockid_t  clockID,
struct timespec64 *  tp 
)

在文件 time_syscall.c435 行定义.

436{
437 int ret;
438 struct timespec t;
439 struct timespec64 stp;
440
441 if (tp == NULL) {
442 errno = EINVAL;
443 return -EINVAL;
444 }
445
446 ret = clock_gettime(clockID, &t);
447 if (ret < 0) {
448 return -get_errno();
449 }
450
451 stp.tv_sec = t.tv_sec;
452 stp.tv_nsec = t.tv_nsec;
453
454 if (LOS_ArchCopyToUser(tp, &stp, sizeof(struct timespec64))) {
455 errno = EFAULT;
456 return -EFAULT;
457 }
458
459 return ret;
460}
函数调用图:

◆ SysClockNanoSleep()

int SysClockNanoSleep ( clockid_t  clk,
int  flags,
const struct timespec *  req,
struct timespec *  rem 
)

在文件 time_syscall.c331 行定义.

332{
333 int ret;
334 struct timespec sreq;
335 struct timespec srem = { 0 };
336
337 if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec))) {
338 errno = EFAULT;
339 return -EFAULT;
340 }
341
342 ret = clock_nanosleep(clk, flags, &sreq, rem ? &srem : NULL);
343 if (ret < 0) {
344 return -get_errno();
345 }
346
347 if (rem && LOS_ArchCopyToUser(rem, &srem, sizeof(struct timespec))) {
348 errno = EFAULT;
349 return -EFAULT;
350 }
351
352 return ret;
353}
int clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
Definition: time.c:718
size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len)
Definition: user_copy.c:58
函数调用图:

◆ SysClockNanoSleep64()

int SysClockNanoSleep64 ( clockid_t  clk,
int  flags,
const struct timespec64 *  req,
struct timespec64 *  rem 
)

在文件 time_syscall.c489 行定义.

490{
491 int ret;
492 struct timespec rq;
493 struct timespec rm = { 0 };
494 struct timespec64 sreq;
495 struct timespec64 srem = { 0 };
496
497 if (!req || LOS_ArchCopyFromUser(&sreq, req, sizeof(struct timespec64))) {
498 errno = EFAULT;
499 return -EFAULT;
500 }
501
502 if (req != NULL) {
503 rq.tv_sec = (sreq.tv_sec > UINT32_MAX) ? UINT32_MAX : sreq.tv_sec;
504 rq.tv_nsec = sreq.tv_nsec;
505 }
506
507 ret = clock_nanosleep(clk, flags, &rq, rem ? &rm : NULL);
508 if (ret < 0) {
509 return -get_errno();
510 }
511
512 if (rem != NULL) {
513 srem.tv_sec = rm.tv_sec;
514 srem.tv_nsec = rm.tv_nsec;
515 if (LOS_ArchCopyToUser(rem, &srem, sizeof(struct timespec64))) {
516 errno = EFAULT;
517 return -EFAULT;
518 }
519 }
520
521 return ret;
522}
函数调用图:

◆ SysClockSettime()

int SysClockSettime ( clockid_t  clockID,
const struct timespec *  tp 
)

在文件 time_syscall.c263 行定义.

264{
265 int ret;
266 struct timespec stp;
267
268 if (tp == NULL) {
269 errno = EINVAL;
270 return -EINVAL;
271 }
272
273 if (LOS_ArchCopyFromUser(&stp, tp, sizeof(struct timespec))) {
274 errno = EFAULT;
275 return -EFAULT;
276 }
277
278 ret = clock_settime(clockID, &stp);
279 if (ret < 0) {
280 return -get_errno();
281 }
282 return ret;
283}
int clock_settime(clockid_t clockID, const struct timespec *tp)
Definition: time.c:452
函数调用图:

◆ SysClockSettime64()

int SysClockSettime64 ( clockid_t  clockID,
const struct timespec64 *  tp 
)

在文件 time_syscall.c405 行定义.

406{
407 int ret;
408 struct timespec t;
409 struct timespec64 stp;
410
411 if (tp == NULL) {
412 errno = EINVAL;
413 return -EINVAL;
414 }
415
416 if (LOS_ArchCopyFromUser(&stp, tp, sizeof(struct timespec64))) {
417 errno = EFAULT;
418 return -EFAULT;
419 }
420
421 if (stp.tv_sec > UINT32_MAX) {
422 errno = ENOSYS;
423 return -ENOSYS;
424 }
425 t.tv_sec = stp.tv_sec;
426 t.tv_nsec = stp.tv_nsec;
427
428 ret = clock_settime(clockID, &t);
429 if (ret < 0) {
430 return -get_errno();
431 }
432 return ret;
433}
函数调用图:

◆ SysGetiTimer()

int SysGetiTimer ( int  which,
struct itimerval *  value 
)

在文件 time_syscall.c137 行定义.

138{
139 int ret;
140 struct itimerval svalue;
141
142 if (value == NULL) {
143 errno = EINVAL;
144 return -EINVAL;
145 }
146
147 ret = getitimer(which, &svalue);
148 if (ret < 0) {
149 return -get_errno();
150 }
151
152 if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerval))) {
153 errno = EFAULT;
154 return -EFAULT;
155 }
156
157 return ret;
158}
int getitimer(int which, struct itimerval *value)
Definition: time.c:1172
函数调用图:

◆ SysNanoSleep()

int SysNanoSleep ( const struct timespec *  rqtp,
struct timespec *  rmtp 
)

在文件 time_syscall.c355 行定义.

356{
357 int ret;
358 struct timespec srqtp;
359 struct timespec srmtp;
360
361 if (!rqtp || LOS_ArchCopyFromUser(&srqtp, rqtp, sizeof(struct timespec))) {
362 errno = EFAULT;
363 return -EFAULT;
364 }
365
366 if (rmtp && LOS_ArchCopyFromUser(&srmtp, rmtp, sizeof(struct timespec))) {
367 errno = EFAULT;
368 return -EFAULT;
369 }
370
371 ret = nanosleep(&srqtp, rmtp ? &srmtp : NULL);
372 if (ret < 0) {
373 return -get_errno();
374 }
375
376 if (rmtp && LOS_ArchCopyToUser(rmtp, &srmtp, sizeof(struct timespec))) {
377 errno = EFAULT;
378 return -EFAULT;
379 }
380
381 return ret;
382}
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
Definition: time.c:1068
函数调用图:

◆ SysSetiTimer()

int SysSetiTimer ( int  which,
const struct itimerval *  value,
struct itimerval *  ovalue 
)

在文件 time_syscall.c108 行定义.

109{
110 int ret;
111 struct itimerval svalue;
112 struct itimerval sovalue;
113
114 if (value == NULL) {
115 errno = EINVAL;
116 return -EINVAL;
117 }
118
119 if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerval))) {
120 errno = EFAULT;
121 return -EFAULT;
122 }
123
124 ret = setitimer(which, &svalue, &sovalue);
125 if (ret < 0) {
126 return -get_errno();
127 }
128
129 if (ovalue && LOS_ArchCopyToUser(ovalue, &sovalue, sizeof(struct itimerval))) {
130 errno = EFAULT;
131 return -EFAULT;
132 }
133
134 return ret;
135}
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
Definition: time.c:1117
函数调用图:

◆ SysTime()

time_t SysTime ( time_t *  tloc)

在文件 time_syscall.c90 行定义.

91{
92 int ret;
93 time_t stloc;
94
95 ret = time(tloc ? &stloc : NULL);
96 if (ret < 0) {
97 return -get_errno();
98 }
99
100 if (tloc && LOS_ArchCopyToUser(tloc, &stloc, sizeof(time_t))) {
101 errno = EFAULT;
102 ret = -EFAULT;
103 }
104
105 return ret;
106}
time_t time(time_t *t)
Definition: time.c:1224
函数调用图:

◆ SysTimerCreate()

int SysTimerCreate ( clockid_t  clockID,
struct ksigevent evp,
timer_t *  timerID 
)

在文件 time_syscall.c160 行定义.

161{
162 int ret;
163 timer_t stimerID;
164 struct ksigevent ksevp;
165
166 if (timerID == NULL) {
167 errno = EINVAL;
168 return -EINVAL;
169 }
170
171 if (evp && LOS_ArchCopyFromUser(&ksevp, evp, sizeof(struct ksigevent))) {
172 errno = EFAULT;
173 return -EFAULT;
174 }
175
176 ret = OsTimerCreate(clockID, evp ? &ksevp : NULL, &stimerID);
177 if (ret < 0) {
178 return -get_errno();
179 }
180
181 if (LOS_ArchCopyToUser(timerID, &stimerID, sizeof(timer_t))) {
182 errno = EFAULT;
183 return -EFAULT;
184 }
185
186 return ret;
187}
int OsTimerCreate(clockid_t, struct ksigevent *__restrict, timer_t *__restrict)
Definition: time.c:842
函数调用图:

◆ SysTimerDelete()

int SysTimerDelete ( timer_t  timerID)

在文件 time_syscall.c252 行定义.

253{
254 int ret;
255
256 ret = timer_delete(timerID);
257 if (ret < 0) {
258 return -get_errno();
259 }
260 return ret;
261}
int timer_delete(timer_t timerID)
Definition: time.c:897
函数调用图:

◆ SysTimerGetoverrun()

int SysTimerGetoverrun ( timer_t  timerID)

在文件 time_syscall.c241 行定义.

242{
243 int ret;
244
245 ret = timer_getoverrun(timerID);
246 if (ret < 0) {
247 return -get_errno();
248 }
249 return ret;
250}
int timer_getoverrun(timer_t timerID)
Definition: time.c:1024
函数调用图:

◆ SysTimerGettime()

int SysTimerGettime ( timer_t  timerID,
struct itimerspec *  value 
)

在文件 time_syscall.c189 行定义.

190{
191 int ret;
192 struct itimerspec svalue;
193
194 if (value == NULL) {
195 errno = EINVAL;
196 return -EINVAL;
197 }
198
199 ret = timer_gettime(timerID, &svalue);
200 if (ret < 0) {
201 return -get_errno();
202 }
203
204 if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerspec))) {
205 errno = EFAULT;
206 return -EFAULT;
207 }
208
209 return ret;
210}
int timer_gettime(timer_t timerID, struct itimerspec *value)
Definition: time.c:995
函数调用图:

◆ SysTimerGettime64()

int SysTimerGettime64 ( timer_t  timerID,
struct itimerspec64 *  value 
)

在文件 time_syscall.c524 行定义.

525{
526 int ret;
527 struct itimerspec val;
528 struct itimerspec64 svalue;
529
530 if (value == NULL) {
531 errno = EINVAL;
532 return -EINVAL;
533 }
534
535 ret = timer_gettime(timerID, &val);
536 if (ret < 0) {
537 return -get_errno();
538 }
539
540 svalue.it_interval.tv_sec = val.it_interval.tv_sec;
541 svalue.it_interval.tv_nsec = val.it_interval.tv_nsec;
542 svalue.it_value.tv_sec = val.it_value.tv_sec;
543 svalue.it_value.tv_nsec = val.it_value.tv_nsec;
544
545 if (LOS_ArchCopyToUser(value, &svalue, sizeof(struct itimerspec64))) {
546 errno = EFAULT;
547 return -EFAULT;
548 }
549
550 return ret;
551}
函数调用图:

◆ SysTimerSettime()

int SysTimerSettime ( timer_t  timerID,
int  flags,
const struct itimerspec *  value,
struct itimerspec *  oldValue 
)

在文件 time_syscall.c212 行定义.

213{
214 int ret;
215 struct itimerspec svalue;
216 struct itimerspec soldValue;
217
218 if (value == NULL) {
219 errno = EINVAL;
220 return -EINVAL;
221 }
222
223 if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerspec))) {
224 errno = EFAULT;
225 return -EFAULT;
226 }
227
228 ret = timer_settime(timerID, flags, &svalue, &soldValue);
229 if (ret < 0) {
230 return -get_errno();
231 }
232
233 if (oldValue && LOS_ArchCopyToUser(oldValue, &soldValue, sizeof(struct itimerspec))) {
234 errno = EFAULT;
235 return -EFAULT;
236 }
237
238 return ret;
239}
int timer_settime(timer_t timerID, int flags, const struct itimerspec *value, struct itimerspec *oldValue)
Definition: time.c:929
函数调用图:

◆ SysTimerSettime64()

int SysTimerSettime64 ( timer_t  timerID,
int  flags,
const struct itimerspec64 *  value,
struct itimerspec64 *  oldValue 
)

在文件 time_syscall.c553 行定义.

554{
555 int ret;
556 struct itimerspec val;
557 struct itimerspec oldVal;
558 struct itimerspec64 svalue;
559 struct itimerspec64 soldValue;
560
561 if (value == NULL) {
562 errno = EINVAL;
563 return -EINVAL;
564 }
565
566 if (LOS_ArchCopyFromUser(&svalue, value, sizeof(struct itimerspec64))) {
567 errno = EFAULT;
568 return -EFAULT;
569 }
570
571 if (svalue.it_interval.tv_sec > UINT32_MAX || svalue.it_value.tv_sec > UINT32_MAX) {
572 errno = ENOSYS;
573 return -ENOSYS;
574 }
575
576 val.it_interval.tv_sec = svalue.it_interval.tv_sec;
577 val.it_interval.tv_nsec = svalue.it_interval.tv_nsec;
578 val.it_value.tv_sec = svalue.it_value.tv_sec;
579 val.it_value.tv_nsec = svalue.it_value.tv_nsec;
580
581 ret = timer_settime(timerID, flags, &val, oldValue ? &oldVal : NULL);
582 if (ret < 0) {
583 return -get_errno();
584 }
585
586 if (oldValue != NULL) {
587 soldValue.it_interval.tv_sec = oldVal.it_interval.tv_sec;
588 soldValue.it_interval.tv_nsec = oldVal.it_interval.tv_nsec;
589 soldValue.it_value.tv_sec = oldVal.it_value.tv_sec;
590 soldValue.it_value.tv_nsec = oldVal.it_value.tv_nsec;
591
592 if (LOS_ArchCopyToUser(oldValue, &soldValue, sizeof(struct itimerspec64))) {
593 errno = EFAULT;
594 return -EFAULT;
595 }
596 }
597
598 return ret;
599}
函数调用图:

◆ SysTimes()

clock_t SysTimes ( struct tms *  buf)

在文件 time_syscall.c384 行定义.

385{
386 clock_t ret;
387 struct tms sbuf;
388
389 if (buf == NULL) {
390 errno = EFAULT;
391 return -EFAULT;
392 }
393 ret = times(&sbuf);
394 if (ret == -1) {
395 return -get_errno();
396 }
397 if (LOS_ArchCopyToUser(buf, &sbuf, sizeof(struct tms))) {
398 errno = EFAULT;
399 return -EFAULT;
400 }
401
402 return ret;
403}
clock_t times(struct tms *buf)
Definition: time.c:1107
函数调用图:

◆ SysUtime()

int SysUtime ( const char *  path,
const struct utimbuf *  ptimes 
)

在文件 time_syscall.c45 行定义.

46{
47 int ret;
48 char *spath = NULL;
49 struct utimbuf sptimes;
50
51 if (path == NULL) {
52 errno = EINVAL;
53 return -EINVAL;
54 }
55
56 spath = LOS_MemAlloc(m_aucSysMem0, PATH_MAX + 1);
57 if (spath == NULL) {
58 errno = ENOMEM;
59 return -ENOMEM;
60 }
61
62 ret = LOS_StrncpyFromUser(spath, path, PATH_MAX + 1);
63 if (ret == -EFAULT) {
65 return ret;
66 } else if (ret > PATH_MAX) {
68 PRINT_ERR("%s[%d], path exceeds maxlen: %d\n", __FUNCTION__, __LINE__, PATH_MAX);
69 return -ENAMETOOLONG;
70 }
71 spath[ret] = '\0';
72
73 if (ptimes && LOS_ArchCopyFromUser(&sptimes, ptimes, sizeof(struct utimbuf))) {
75 errno = EFAULT;
76 return -EFAULT;
77 }
78
79 ret = utime(spath, ptimes ? &sptimes : NULL);
80 if (ret < 0) {
81 ret = -get_errno();
82 }
83
85
86 return ret;
87}
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
Definition: los_memory.c:107
INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
int utime(const char *path, const struct utimbuf *ptimes)
Definition: vfs_utime.c:50
函数调用图: