lib.rs 2.5 KB

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