Skip to content

Commit

Permalink
dmnt.gen2: enable attach to arbitrary program id
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite authored and SciresM committed Oct 12, 2023
1 parent 92a8c8e commit 159f8d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace ams::pm::dmnt {
Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id);
Result GetApplicationProcessId(os::ProcessId *out_process_id);
Result HookToCreateApplicationProcess(os::NativeHandle *out_handle);
Result HookToCreateProcess(os::NativeHandle *out_handle, const ncm::ProgramId program_id);
Result AtmosphereGetProcessInfo(os::NativeHandle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id);

#if defined(ATMOSPHERE_OS_HORIZON)
Expand Down
7 changes: 7 additions & 0 deletions libraries/libstratosphere/source/pm/pm_dmnt_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ namespace ams::pm::dmnt {
R_SUCCEED();
}

Result HookToCreateProcess(os::NativeHandle *out_handle, const ncm::ProgramId program_id) {
Event evt;
R_TRY(pmdmntHookToCreateProcess(std::addressof(evt), static_cast<u64>(program_id)));
*out_handle = evt.revent;
R_SUCCEED();
}

Result AtmosphereGetProcessInfo(os::NativeHandle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id) {
*out_handle = os::InvalidNativeHandle;
*out_loc = {};
Expand Down
19 changes: 17 additions & 2 deletions stratosphere/dmnt.gen2/source/dmnt2_gdb_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2105,9 +2105,24 @@ namespace ams::dmnt {
ParsePrefix(command, "0x");

/* Decode program id. */
const u64 program_id = DecodeHex(command);
const ncm::ProgramId program_id(DecodeHex(command));

AppendReplyFormat(reply_cur, reply_end, "[TODO] wait for program id 0x%lx\n", program_id);
/* Wait for the process to be created. */
{
/* Get hook to creation of process with program id. */
os::NativeHandle h;
R_ABORT_UNLESS(pm::dmnt::HookToCreateProcess(std::addressof(h), program_id));

/* Wait for event. */
os::SystemEvent hook_event(h, true, os::InvalidNativeHandle, false, os::EventClearMode_AutoClear);
hook_event.Wait();
}

/* Get process id. */
R_ABORT_UNLESS(pm::dmnt::GetProcessId(std::addressof(m_wait_process_id), program_id));

/* Note that we're attaching. */
AppendReplyFormat(reply_cur, reply_end, "Send `attach 0x%lx` to attach.\n", m_wait_process_id.value);
} else {
std::memcpy(m_reply_cur, command, std::strlen(command) + 1);
AppendReplyFormat(reply_cur, reply_end, "Unknown command `%s`\n", m_reply_cur);
Expand Down

0 comments on commit 159f8d3

Please sign in to comment.