lib.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //! Runs a title's original x86-64 code natively, inside our process.
  2. //!
  3. //! Xbox Series X|S executables are x86-64 PE32+ images built for a Zen 2
  4. //! CPU, so the machine code needs no translation. What differs is the
  5. //! platform underneath, so the loader's job is to:
  6. //!
  7. //! 1. [`prepare()`] a lightly patched copy of the image (pure, portable): mark
  8. //! it as a DLL, remove its entry point and import directory, and detach
  9. //! its TLS callbacks, so the Windows loader maps it, relocates it,
  10. //! allocates its static TLS and registers its unwind tables, but runs
  11. //! none of its code and resolves none of its imports;
  12. //! 2. load that copy as a real module (debuggers, profilers, crash dumps
  13. //! and stack walks all see it); this step is Windows-only;
  14. //! 3. map the DLLs the title ships beside it the same way
  15. //! (`load_title_dlls`);
  16. //! 4. bind every import ourselves through an [`ImportResolver`], our
  17. //! runtime (`victory-hle`), the host or the title's DLLs, and route
  18. //! anything unresolved to a generated stub that reports exactly what
  19. //! was called;
  20. //! 5. initialise the title's DLLs, then run TLS callbacks and the entry
  21. //! point on a thread with the stack size the image asks for; from then
  22. //! on, pass every thread start and end on to the attached images.
  23. #[cfg(windows)]
  24. mod console_insn;
  25. mod crash;
  26. pub mod prepare;
  27. pub mod resolve;
  28. #[cfg(all(windows, feature = "diagnostics"))]
  29. mod stacks;
  30. #[cfg(windows)]
  31. mod threads;
  32. #[cfg(windows)]
  33. mod thunks;
  34. #[cfg(windows)]
  35. mod tls;
  36. #[cfg(windows)]
  37. mod windows;
  38. #[cfg(windows)]
  39. pub use crash::{
  40. locate, log_crash, log_crashes_to, note_title_output, report_crashes, report_unhandled,
  41. };
  42. #[cfg(all(windows, feature = "diagnostics"))]
  43. pub use crash::save_on_crash;
  44. pub use prepare::{PrepareError, PreparedImage, prepare};
  45. pub use resolve::{ImportResolver, Provenance, Resolution};
  46. #[cfg(all(windows, feature = "diagnostics"))]
  47. pub use stacks::{dump_stacks, dump_stacks_on_schedule};
  48. #[cfg(windows)]
  49. pub use threads::disable_thread_calls;
  50. #[cfg(windows)]
  51. pub use thunks::{UnimplementedPolicy, unimplemented_call_count};
  52. #[cfg(windows)]
  53. pub use windows::{
  54. BindReport, LoadedImage, MissingImport, WithTitleDlls, load, load_title_dll, load_title_dlls,
  55. };
  56. /// `DLL_PROCESS_ATTACH`, for TLS callbacks.
  57. pub const DLL_PROCESS_ATTACH: u32 = 1;
  58. /// `DLL_PROCESS_DETACH`.
  59. pub const DLL_PROCESS_DETACH: u32 = 0;