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#include "qemu/osdep.h"
26#include <windows.h>
27#include <mmsystem.h>
28#include "sysemu/sysemu.h"
29#include "qemu-options.h"
30
31
32
33
34int setenv(const char *name, const char *value, int overwrite)
35{
36 int result = 0;
37 if (overwrite || !getenv(name)) {
38 size_t length = strlen(name) + strlen(value) + 2;
39 char *string = g_malloc(length);
40 snprintf(string, length, "%s=%s", name, value);
41 result = putenv(string);
42
43
44
45
46
47
48 g_free(string);
49 }
50 return result;
51}
52
53static BOOL WINAPI qemu_ctrl_handler(DWORD type)
54{
55 qemu_system_shutdown_request();
56
57
58
59
60 Sleep(10000);
61
62 return TRUE;
63}
64
65static TIMECAPS mm_tc;
66
67static void os_undo_timer_resolution(void)
68{
69 timeEndPeriod(mm_tc.wPeriodMin);
70}
71
72void os_setup_early_signal_handling(void)
73{
74 SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
75 timeGetDevCaps(&mm_tc, sizeof(mm_tc));
76 timeBeginPeriod(mm_tc.wPeriodMin);
77 atexit(os_undo_timer_resolution);
78}
79
80
81char *os_find_datadir(void)
82{
83 return qemu_get_exec_dir();
84}
85
86void os_set_line_buffering(void)
87{
88 setbuf(stdout, NULL);
89 setbuf(stderr, NULL);
90}
91
92
93
94
95
96void os_parse_cmd_args(int index, const char *optarg)
97{
98 return;
99}
100
101int qemu_create_pidfile(const char *filename)
102{
103 char buffer[128];
104 int len;
105 HANDLE file;
106 OVERLAPPED overlap;
107 BOOL ret;
108 memset(&overlap, 0, sizeof(overlap));
109
110 file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
111 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
112
113 if (file == INVALID_HANDLE_VALUE) {
114 return -1;
115 }
116 len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());
117 ret = WriteFile(file, (LPCVOID)buffer, (DWORD)len,
118 NULL, &overlap);
119 CloseHandle(file);
120 if (ret == 0) {
121 return -1;
122 }
123 return 0;
124}
125