Skip to content

Expands XLaunchXBE to allow caller to set LaunchData. #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 69 additions & 42 deletions lib/hal/xbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,78 @@

#define KernelMode 0

#define LaunchDataPageSize 0x1000

void XReboot()
{
HalReturnToFirmware(HalRebootRoutine);
HalReturnToFirmware(HalRebootRoutine);
}

int XGetLaunchInfo(unsigned long *launchDataType, const unsigned char **launchData)
{
*launchDataType = LDT_NONE;
*launchData = NULL;

if (LaunchDataPage == NULL) {
LaunchDataPage = MmAllocateContiguousMemory(LaunchDataPageSize);
if (LaunchDataPage == NULL) {
return -1;
}
memset(LaunchDataPage, 0, LaunchDataPageSize);
LaunchDataPage->Header.dwLaunchDataType = LDT_FROM_DASHBOARD;
}

*launchDataType = LaunchDataPage->Header.dwLaunchDataType;
*launchData = LaunchDataPage->LaunchData;
return 0;
}

void XLaunchXBE(const char *xbePath)
{
XLaunchXBEEx(xbePath, NULL);
}

/**
* Launches an XBE. Examples of xbePath might be:
* c:\\blah.xbe
* c:/foo/bar.xbe
* If the XBE is able to be launched, this method will
* not return. If there is a problem, then it return.
*/
void XLaunchXBE(char *xbePath)
void XLaunchXBEEx(const char *xbePath, const void *launchData)
{
#if 0
struct stat statbuf;
if (stat(xbePath, &statbuf) < 0)
return;
#endif

if (LaunchDataPage == NULL)
LaunchDataPage = MmAllocateContiguousMemory(0x1000);

if (LaunchDataPage == NULL)
return;

MmPersistContiguousMemory(LaunchDataPage, 0x1000, TRUE);

memset((void*)LaunchDataPage, 0, 0x1000);

LaunchDataPage->Header.dwLaunchDataType = 0xFFFFFFFF;
LaunchDataPage->Header.dwTitleId = 0;
XConvertDOSFilenameToXBOX(xbePath, LaunchDataPage->Header.szLaunchPath);

// one last thing... xbePath now looks like:
// \Device\Harddisk0\Partition2\blah\doom.xbe
// but it has to look like:
// \Device\Harddisk0\Partition2\blah;doom.xbe
char *lastSlash = strrchr(LaunchDataPage->Header.szLaunchPath, '\\');
if (lastSlash != NULL)
{
*lastSlash = ';';
HalReturnToFirmware(HalQuickRebootRoutine);
}

// if we couldn't find a trailing slash, the conversion to
// the xbox path mustn't have worked, so we will return
if (LaunchDataPage == NULL) {
LaunchDataPage = MmAllocateContiguousMemory(LaunchDataPageSize);
if (LaunchDataPage == NULL) {
return;
}
}

// For ease of debugging.
PLAUNCH_DATA_PAGE launchDataPage = LaunchDataPage;

MmPersistContiguousMemory(launchDataPage, LaunchDataPageSize, TRUE);
memset((void*)launchDataPage, 0, LaunchDataPageSize);

launchDataPage->Header.dwLaunchDataType = LDT_TITLE;
launchDataPage->Header.dwTitleId = CURRENT_XBE_HEADER->CertificateHeader->TitleID;
launchDataPage->Header.dwFlags = 0x0000;

if (!xbePath) {
launchDataPage->Header.dwLaunchDataType = LDT_LAUNCH_DASHBOARD;
} else {
XConvertDOSFilenameToXBOX(xbePath, launchDataPage->Header.szLaunchPath);

// one last thing... xbePath now looks like:
// \Device\Harddisk0\Partition2\blah\doom.xbe
// but it has to look like:
// \Device\Harddisk0\Partition2\blah;doom.xbe
char *lastSlash = strrchr(launchDataPage->Header.szLaunchPath, '\\');
if (!lastSlash) {
// if we couldn't find a trailing slash, the conversion to
// the xbox path mustn't have worked, so we will return
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: What should happen to the LaunchDataPage here? Should the allocation be undone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it should, but I was conservative about preserving the existing behavior which does leave the LDP allocated and persisted.

}

*lastSlash = ';';
}

if (launchData) {
memcpy(launchDataPage->LaunchData, launchData, sizeof(launchDataPage->LaunchData));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If launchData is NULL the LaunchDataPage will still be allocated and point at zero-bytes; is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intentional that LaunchDataPage's LaunchData will be zero bytes (preserving the existing behavior).


HalReturnToFirmware(HalQuickRebootRoutine);
}
30 changes: 29 additions & 1 deletion lib/hal/xbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,35 @@ extern "C"

void XReboot(void);

void XLaunchXBE(char *xbePath);
/**
* Retrieves information persisted by the process that launched the current XBE.
*
* launchDataType will (likely) be one of the LDT_* defines in xboxkrnl.h
*
* Returns non-zero in the case of failure.
*/
int XGetLaunchInfo(unsigned long *launchDataType, const unsigned char **launchData);

/**
* Launches an XBE. Examples of xbePath might be:
* c:\\blah.xbe
* c:/foo/bar.xbe
* If the XBE is able to be launched, this method will
* not return. If there is a problem, then it return.
*/
void XLaunchXBE(const char *xbePath);

/**
* Launches an XBE and sets the LAUNCH_DATA_PAGE's LaunchData, which is
* retrievable by the newly launched process.
*
* Examples of xbePath might be:
* c:\\blah.xbe
* c:/foo/bar.xbe
* If the XBE is able to be launched, this method will
* not return. If there is a problem, then it return.
*/
void XLaunchXBEEx(const char *xbePath, const void *launchData);

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion lib/xboxkrnl/xboxkrnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,9 @@ typedef struct _LAUNCH_DATA_PAGE
UCHAR LaunchData[3072];
} LAUNCH_DATA_PAGE, *PLAUNCH_DATA_PAGE;

#define LDT_LAUNCH_DASHBOARD 1
#define LDT_TITLE 0
#define LDT_LAUNCH_DASHBOARD 1
#define LDT_FROM_DASHBOARD 2
#define LDT_NONE 0xFFFFFFFF

typedef struct _DISPATCHER_HEADER
Expand Down