File: time.c

package info (click to toggle)
strace 6.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 71,488 kB
  • sloc: ansic: 176,497; sh: 9,675; makefile: 4,133; cpp: 885; awk: 353; perl: 267; exp: 62; sed: 9
file content (75 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * This file is part of time strace test.
 *
 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@strace.io>
 * Copyright (c) 2015-2023 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"
#include "scno.h"

#ifdef __NR_time

# include <errno.h>
# include <stdio.h>
# include <stdint.h>
# include <unistd.h>

typedef kernel_ulong_t kernel_time_t;

static kernel_long_t
k_time(void *p)
{
# if defined __x86_64__ && defined __ILP32__
	register long arg asm("rdi") = (uintptr_t) p;
	kernel_long_t rc;
	asm volatile("syscall\n\t"
		     : "=a"(rc)
		     : "0"(__NR_time), "r"(arg)
		     : "memory", "cc", "r11", "cx");
	if (rc < 0 && rc >= -4095) {
		errno = -rc;
		rc = (kernel_long_t) -1LL;
	}
	return rc;
# else
	const kernel_ulong_t arg = (uintptr_t) p;
	const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
	return syscall(__NR_time, arg, bad, bad, bad, bad, bad);
# endif
}

int
main(void)
{
	TAIL_ALLOC_OBJECT_CONST_PTR(kernel_time_t, p);

	kernel_ulong_t t = k_time(NULL);
	if (t == (kernel_ulong_t) -1ULL)
		perror_msg_and_skip("time");
	printf("time(NULL) = %llu (", (unsigned long long) t);
	print_time_t_nsec(t, 0, 0);
	puts(")");

	t = k_time(p + 1);
	printf("time(%p) = %s\n", p + 1, sprintrc(t));

	t = k_time(p);
	printf("time([%lld", (long long) *p);
	print_time_t_nsec(*p, 0, 1),
	printf("]) = %llu (", (unsigned long long) t);
	print_time_t_nsec(t, 0, 0);
	puts(")");

	puts("+++ exited with 0 +++");
	return 0;
}

#else

SKIP_MAIN_UNDEFINED("__NR_time")

#endif