lib.rs 2.5 KB

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