xref: /qemu/os-win32.c (revision 0f9668e0)
119113504SJes Sorensen /*
219113504SJes Sorensen  * os-win32.c
319113504SJes Sorensen  *
419113504SJes Sorensen  * Copyright (c) 2003-2008 Fabrice Bellard
519113504SJes Sorensen  * Copyright (c) 2010 Red Hat, Inc.
619113504SJes Sorensen  *
719113504SJes Sorensen  * Permission is hereby granted, free of charge, to any person obtaining a copy
819113504SJes Sorensen  * of this software and associated documentation files (the "Software"), to deal
919113504SJes Sorensen  * in the Software without restriction, including without limitation the rights
1019113504SJes Sorensen  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1119113504SJes Sorensen  * copies of the Software, and to permit persons to whom the Software is
1219113504SJes Sorensen  * furnished to do so, subject to the following conditions:
1319113504SJes Sorensen  *
1419113504SJes Sorensen  * The above copyright notice and this permission notice shall be included in
1519113504SJes Sorensen  * all copies or substantial portions of the Software.
1619113504SJes Sorensen  *
1719113504SJes Sorensen  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1819113504SJes Sorensen  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919113504SJes Sorensen  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2019113504SJes Sorensen  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2119113504SJes Sorensen  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2219113504SJes Sorensen  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2319113504SJes Sorensen  * THE SOFTWARE.
2419113504SJes Sorensen  */
25a8d25326SMarkus Armbruster 
26d38ea87aSPeter Maydell #include "qemu/osdep.h"
2719113504SJes Sorensen #include <windows.h>
280727b867SPaolo Bonzini #include <mmsystem.h>
29*54d31236SMarkus Armbruster #include "sysemu/runstate.h"
3019113504SJes Sorensen 
qemu_ctrl_handler(DWORD type)3169bd73b1SJes Sorensen static BOOL WINAPI qemu_ctrl_handler(DWORD type)
3269bd73b1SJes Sorensen {
33cf83f140SEric Blake     qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_SIGNAL);
34b75a0282SPavel Dovgaluk     /* Windows 7 kills application when the function returns.
35b75a0282SPavel Dovgaluk        Sleep here to give QEMU a try for closing.
36b75a0282SPavel Dovgaluk        Sleep period is 10000ms because Windows kills the program
37b75a0282SPavel Dovgaluk        after 10 seconds anyway. */
38b75a0282SPavel Dovgaluk     Sleep(10000);
39b75a0282SPavel Dovgaluk 
4069bd73b1SJes Sorensen     return TRUE;
4169bd73b1SJes Sorensen }
4269bd73b1SJes Sorensen 
430727b867SPaolo Bonzini static TIMECAPS mm_tc;
440727b867SPaolo Bonzini 
os_undo_timer_resolution(void)450727b867SPaolo Bonzini static void os_undo_timer_resolution(void)
460727b867SPaolo Bonzini {
470727b867SPaolo Bonzini     timeEndPeriod(mm_tc.wPeriodMin);
480727b867SPaolo Bonzini }
490727b867SPaolo Bonzini 
os_setup_early_signal_handling(void)50fe98ac14SJes Sorensen void os_setup_early_signal_handling(void)
5169bd73b1SJes Sorensen {
5269bd73b1SJes Sorensen     SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
530727b867SPaolo Bonzini     timeGetDevCaps(&mm_tc, sizeof(mm_tc));
540727b867SPaolo Bonzini     timeBeginPeriod(mm_tc.wPeriodMin);
550727b867SPaolo Bonzini     atexit(os_undo_timer_resolution);
5669bd73b1SJes Sorensen }
576170540bSJes Sorensen 
os_set_line_buffering(void)586650b710SStefan Weil void os_set_line_buffering(void)
596650b710SStefan Weil {
606650b710SStefan Weil     setbuf(stdout, NULL);
616650b710SStefan Weil     setbuf(stderr, NULL);
626650b710SStefan Weil }
63