lib.rs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 crash;
  25. pub mod prepare;
  26. pub mod resolve;
  27. #[cfg(all(windows, feature = "diagnostics"))]
  28. mod stacks;
  29. #[cfg(windows)]
  30. mod threads;
  31. #[cfg(windows)]
  32. mod thunks;
  33. #[cfg(windows)]
  34. mod tls;
  35. #[cfg(windows)]
  36. mod windows;
  37. #[cfg(windows)]
  38. pub use crash::{
  39. locate, log_crash, log_crashes_to, note_title_output, report_crashes, report_unhandled,
  40. };
  41. #[cfg(all(windows, feature = "diagnostics"))]
  42. pub use crash::save_on_crash;
  43. pub use prepare::{PrepareError, PreparedImage, prepare};
  44. pub use resolve::{ImportResolver, Provenance, Resolution};
  45. #[cfg(all(windows, feature = "diagnostics"))]
  46. pub use stacks::{dump_stacks, dump_stacks_on_schedule};
  47. #[cfg(windows)]
  48. pub use threads::disable_thread_calls;
  49. #[cfg(windows)]
  50. pub use thunks::{UnimplementedPolicy, unimplemented_call_count};
  51. #[cfg(windows)]
  52. pub use windows::{
  53. BindReport, LoadedImage, MissingImport, WithTitleDlls, load, load_title_dll, load_title_dlls,
  54. };
  55. /// `DLL_PROCESS_ATTACH`, for TLS callbacks.
  56. pub const DLL_PROCESS_ATTACH: u32 = 1;
  57. /// `DLL_PROCESS_DETACH`.
  58. pub const DLL_PROCESS_DETACH: u32 = 0;