summaryrefslogtreecommitdiff
blob: 8effafc7182acfaa236f73b67a3004f8175dd061 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
http://bugs.winehq.org/show_bug.cgi?id=29168
Star Wars: The Old Republic game client hangs at intro splash

Generated from wine-1.7.13
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -23,6 +23,10 @@
 
 #include <assert.h>
 #include <stdarg.h>
+
+#include <stdint.h>
+#include <errno.h>
+
 #include <sys/types.h>
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
@@ -69,6 +73,73 @@
 static RTL_BITMAP fls_bitmap;
 static int nb_threads = 1;
 
+
+
+static void update_shared_data_time(void)
+{
+    LARGE_INTEGER now, start, irq;
+
+    NtQuerySystemTime( &now );
+
+    //FIXME("%lld\n", now.QuadPart);
+    
+    irq.QuadPart = (now.QuadPart - server_start_time);
+
+    user_shared_data->InterruptTime.High2Time = irq.HighPart;
+    user_shared_data->InterruptTime.LowPart = irq.LowPart;
+    user_shared_data->InterruptTime.High1Time = irq.HighPart;
+
+    user_shared_data->SystemTime.High2Time = now.HighPart;
+    user_shared_data->SystemTime.LowPart = now.LowPart;
+    user_shared_data->SystemTime.High1Time = now.HighPart;
+
+    start.QuadPart = irq.QuadPart / 10000;
+
+    user_shared_data->u.TickCount.High2Time = start.HighPart;
+    user_shared_data->u.TickCount.LowPart = start.LowPart;
+    user_shared_data->u.TickCount.High1Time = start.HighPart;
+    user_shared_data->TickCountLowDeprecated = start.LowPart;
+}
+
+static void add_timespec(struct timespec* dst, struct timespec* arg)
+{
+    dst->tv_sec += arg->tv_sec;
+    dst->tv_nsec += arg->tv_nsec;
+
+    if(dst->tv_nsec > 999999999) {
+        dst->tv_nsec -= 1000000000;
+        dst->tv_sec++;
+    }
+}
+
+static void* shared_data_thread(void *thread_arg) 
+{
+    struct timespec start, arg;
+    int e;
+
+    e = clock_gettime(CLOCK_MONOTONIC, &start);
+    if(e) {
+        FIXME("Unable to get starting time: %s (%d)\n", strerror(errno), errno);
+        return NULL;
+    }
+
+    arg.tv_sec = 0;
+    arg.tv_nsec = 15600000;
+
+    while(1) {
+        update_shared_data_time();
+        add_timespec(&start, &arg);
+        e = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &start, NULL);
+        if(e) {
+            FIXME("clock_nanosleep failed: %s (%d)\n", strerror(e), e);
+        }
+    }
+
+    return NULL;
+}
+
+
+
 /***********************************************************************
  *           get_unicode_string
  *
@@ -215,11 +286,14 @@
     void *addr;
     SIZE_T size, info_size;
     HANDLE exe_file = 0;
-    LARGE_INTEGER now;
+    //    LARGE_INTEGER now;
     NTSTATUS status;
     struct ntdll_thread_data *thread_data;
     static struct debug_info debug_info;  /* debug info for initial thread */
 
+    pthread_t thread;
+    int s;
+
     virtual_init();
 
     /* reserve space for shared user data */
@@ -316,18 +390,30 @@
     }
 
     /* initialize time values in user_shared_data */
-    NtQuerySystemTime( &now );
+    /*    NtQuerySystemTime( &now );
     user_shared_data->SystemTime.LowPart = now.u.LowPart;
     user_shared_data->SystemTime.High1Time = user_shared_data->SystemTime.High2Time = now.u.HighPart;
     user_shared_data->u.TickCountQuad = (now.QuadPart - server_start_time) / 10000;
     user_shared_data->u.TickCount.High2Time = user_shared_data->u.TickCount.High1Time;
     user_shared_data->TickCountLowDeprecated = user_shared_data->u.TickCount.LowPart;
+    */    
+    
     user_shared_data->TickCountMultiplier = 1 << 24;
+        
+    update_shared_data_time();
 
     fill_cpu_info();
 
     NtCreateKeyedEvent( &keyed_event, GENERIC_READ | GENERIC_WRITE, NULL, 0 );
 
+    if(!(s = pthread_create(&thread, NULL, &shared_data_thread, NULL))) {
+        if(pthread_detach(thread))
+            FIXME("Unable to detach thread\n");
+    } else {
+        FIXME("unable to spawn thread: %s (%d)\n", strerror(s), s);
+    }
+    
+
     return exe_file;
 }