1 /* 2 * QEMU System Emulator 3 * 4 * Copyright (c) 2003-2020 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 */ 24 25 #include "qemu/osdep.h" 26 #include "qemu-main.h" 27 #include "qemu/main-loop.h" 28 #include "system/system.h" 29 30 #ifdef CONFIG_SDL 31 /* 32 * SDL insists on wrapping the main() function with its own implementation on 33 * some platforms; it does so via a macro that renames our main function, so 34 * <SDL.h> must be #included here even with no SDL code called from this file. 35 */ 36 #include <SDL.h> 37 #endif 38 39 #ifdef CONFIG_DARWIN 40 #include <CoreFoundation/CoreFoundation.h> 41 #endif 42 43 static void *qemu_default_main(void *opaque) 44 { 45 int status; 46 47 bql_lock(); 48 status = qemu_main_loop(); 49 qemu_cleanup(status); 50 bql_unlock(); 51 52 exit(status); 53 } 54 55 int (*qemu_main)(void); 56 57 #ifdef CONFIG_DARWIN 58 static int os_darwin_cfrunloop_main(void) 59 { 60 CFRunLoopRun(); 61 g_assert_not_reached(); 62 } 63 int (*qemu_main)(void) = os_darwin_cfrunloop_main; 64 #endif 65 66 int main(int argc, char **argv) 67 { 68 qemu_init(argc, argv); 69 bql_unlock(); 70 if (qemu_main) { 71 QemuThread main_loop_thread; 72 qemu_thread_create(&main_loop_thread, "qemu_main", 73 qemu_default_main, NULL, QEMU_THREAD_DETACHED); 74 return qemu_main(); 75 } else { 76 qemu_default_main(NULL); 77 g_assert_not_reached(); 78 } 79 } 80