blob: 61a681f17f1e33f1f293a2e0c8fb3d0f2e584e48 [file] [log] [blame]
Brad Bishop87b3cb82019-11-15 16:35:37 -05001From caf80e220b055dbce259078be96e899dc78ec1d2 Mon Sep 17 00:00:00 2001
2From: Bartosz Brachaczek <b.brachaczek@gmail.com>
3Date: Tue, 12 Nov 2019 14:31:08 +0100
4Subject: [PATCH] Make HgfsConvertFromNtTimeNsec aware of 64-bit time_t on i386
5
6I verified that this function behaves as expected on x86_64, i386 with
732-bit time_t, and i386 with 64-bit time_t for the following values of
8ntTtime:
9
10UNIX_EPOCH-1, UNIX_EPOCH, UNIX_EPOCH+1, UNIX_S32_MAX-1, UNIX_S32_MAX,
11UNIX_S32_MAX+1, UNIX_S32_MAX*2+1
12
13I did not verify whether the use of Div643264 is optimal, performance
14wise.
15
16Upstream-Status: Submitted [https://github.com/vmware/open-vm-tools/pull/387]
17Signed-off-by: Khem Raj <raj.khem@gmail.com>
18---
19 open-vm-tools/lib/hgfs/hgfsUtil.c | 34 +++++++++++++++++--------------
20 1 file changed, 19 insertions(+), 15 deletions(-)
21
22diff --git a/open-vm-tools/lib/hgfs/hgfsUtil.c b/open-vm-tools/lib/hgfs/hgfsUtil.c
23index cc580ab8..49b10040 100644
24--- a/open-vm-tools/lib/hgfs/hgfsUtil.c
25+++ b/open-vm-tools/lib/hgfs/hgfsUtil.c
26@@ -110,23 +110,21 @@ HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
27 uint64 ntTime) // IN: Time in Windows NT format
28 {
29 #ifdef __i386__
30- uint32 sec;
31- uint32 nsec;
32+ uint64 sec64;
33+ uint32 sec32, nsec;
34+#endif
35
36 ASSERT(unixTime);
37- /* We assume that time_t is 32bit */
38- ASSERT_ON_COMPILE(sizeof (unixTime->tv_sec) == 4);
39
40- /* Cap NT time values that are outside of Unix time's range */
41+ if (sizeof (unixTime->tv_sec) == 4) {
42+ /* Cap NT time values that are outside of Unix time's range */
43
44- if (ntTime >= UNIX_S32_MAX) {
45- unixTime->tv_sec = 0x7FFFFFFF;
46- unixTime->tv_nsec = 0;
47- return 1;
48+ if (ntTime >= UNIX_S32_MAX) {
49+ unixTime->tv_sec = 0x7FFFFFFF;
50+ unixTime->tv_nsec = 0;
51+ return 1;
52+ }
53 }
54-#else
55- ASSERT(unixTime);
56-#endif
57
58 if (ntTime < UNIX_EPOCH) {
59 unixTime->tv_sec = 0;
60@@ -135,9 +133,15 @@ HgfsConvertFromNtTimeNsec(struct timespec *unixTime, // OUT: Time in UNIX format
61 }
62
63 #ifdef __i386__
64- Div643232(ntTime - UNIX_EPOCH, 10000000, &sec, &nsec);
65- unixTime->tv_sec = sec;
66- unixTime->tv_nsec = nsec * 100;
67+ if (sizeof (unixTime->tv_sec) == 4) {
68+ Div643232(ntTime - UNIX_EPOCH, 10000000, &sec32, &nsec);
69+ unixTime->tv_sec = sec32;
70+ unixTime->tv_nsec = nsec * 100;
71+ } else {
72+ Div643264(ntTime - UNIX_EPOCH, 10000000, &sec64, &nsec);
73+ unixTime->tv_sec = sec64;
74+ unixTime->tv_nsec = nsec * 100;
75+ }
76 #else
77 unixTime->tv_sec = (ntTime - UNIX_EPOCH) / 10000000;
78 unixTime->tv_nsec = ((ntTime - UNIX_EPOCH) % 10000000) * 100;