PsCreateSystemThreadEx: OPTIONAL is on the wrong parameter

Open Beginner friendly
#809 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
api

Research direction

Read the PsCreateSystemThreadEx declaration in lib/xboxkrnl/xboxkrnl.h and compare its OPTIONAL annotations with the kernel behavior described in the issue. Update the annotations so SystemRoutine is required and StartRoutine is optional; the issue says nxdk’s CreateThread in lib/winapi/thread.c passes both. Done when the declaration reflects that contract.

Written by the indexing model from the issue text.

Description

In lib/xboxkrnl/xboxkrnl.h, PsCreateSystemThreadEx marks SystemRoutine as OPTIONAL and StartRoutine as required. The kernel uses them the other way round:

  • The new thread always starts by calling SystemRoutine, so it must not be NULL. See for example nboxkrnl, src/ke/thread.cpp (call ecx // SystemRoutine should never return).
  • StartRoutine and StartContext are only passed on to SystemRoutine as arguments, so StartRoutine may be NULL when the system routine doesn't use it.

RadWolfie reported this in the xbox_kernel_test_suite (Cxbx-Reloaded/xbox_kernel_test_suite#130).

nxdk's own CreateThread (lib/winapi/thread.c) always passes both, so no existing nxdk caller is affected. Only the annotation is wrong:

    IN PKSTART_ROUTINE StartRoutine OPTIONAL,
    IN PVOID StartContext,
    IN BOOLEAN CreateSuspended,
    IN BOOLEAN DebuggerThread,
    IN PKSYSTEM_ROUTINE SystemRoutine
Dominant language
C
Stars
600
Forks
97
Avg merge
11h 48m
Merged PRs (30d)
2

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from XboxDev/nxdk

All issues in XboxDev/nxdk

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.