main.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "qemu/osdep.h"
  25. #include "qemu-main.h"
  26. #include "qemu/main-loop.h"
  27. #include "system/replay.h"
  28. #include "system/system.h"
  29. #ifdef CONFIG_SDL
  30. /*
  31. * SDL insists on wrapping the main() function with its own implementation on
  32. * some platforms; it does so via a macro that renames our main function, so
  33. * <SDL.h> must be #included here even with no SDL code called from this file.
  34. */
  35. #include <SDL.h>
  36. #endif
  37. #ifdef CONFIG_DARWIN
  38. #include <CoreFoundation/CoreFoundation.h>
  39. #endif
  40. static void *qemu_default_main(void *opaque)
  41. {
  42. int status;
  43. replay_mutex_lock();
  44. bql_lock();
  45. status = qemu_main_loop();
  46. qemu_cleanup(status);
  47. bql_unlock();
  48. replay_mutex_unlock();
  49. exit(status);
  50. }
  51. int (*qemu_main)(void);
  52. #ifdef CONFIG_DARWIN
  53. static int os_darwin_cfrunloop_main(void)
  54. {
  55. CFRunLoopRun();
  56. g_assert_not_reached();
  57. }
  58. int (*qemu_main)(void) = os_darwin_cfrunloop_main;
  59. #endif
  60. int main(int argc, char **argv)
  61. {
  62. qemu_init(argc, argv);
  63. bql_unlock();
  64. replay_mutex_unlock();
  65. if (qemu_main) {
  66. QemuThread main_loop_thread;
  67. qemu_thread_create(&main_loop_thread, "qemu_main",
  68. qemu_default_main, NULL, QEMU_THREAD_DETACHED);
  69. return qemu_main();
  70. } else {
  71. qemu_default_main(NULL);
  72. g_assert_not_reached();
  73. }
  74. }