Skip to content

POSIX subsystem scaffold, NT syscall wrappers, shell UI fixes, and console-logon utility#3

Open
thepanoc95 wants to merge 1 commit into
mainfrom
codex/fix-build-problem-in-librent.shell-80jfkh
Open

POSIX subsystem scaffold, NT syscall wrappers, shell UI fixes, and console-logon utility#3
thepanoc95 wants to merge 1 commit into
mainfrom
codex/fix-build-problem-in-librent.shell-80jfkh

Conversation

@thepanoc95

Copy link
Copy Markdown
Owner

Motivation

  • Provide a user-mode POSIX subsystem scaffold and avoid kernel image patching by implementing a supported DLL/driver companion and ABI for POSIX translation.
  • Expose a small set of NT-native wrapper entry points so consumers can route syscalls through NTOS2NDHandleSyscall from user code.
  • Fix and simplify WinUI shell components (StartMenu, SystemTray, MainWindow, App) and add a convenience PowerShell utility to toggle console-style logon by renaming authui.dll.

Description

  • Add POSIX subsystem scaffold under ntos2nd/posix/ including a user-mode runtime (posixsubsystem.c), kernel stub driver (posixsubsys_driver.c), ABI header (posix_abi.h), and exports file (posixsubsystem.def), and wire installation into CMakeLists.txt as posixsubsystem with header install.
  • Implement NT syscall wrappers in ntos2nd/NTCall.c and declare them in the new header ntos2nd/NTCall.h (wrappers: NtCloseWrap, NtOpenProcessWrap, NtReadFileWrap, NtWriteFileWrap, NtAllocateVirtualMemoryWrap), and document coverage in ntos2nd/README.md.
  • Update WinUI shell: fix App unhandled exception signature, replace Windows.System.ProcessLauncher usage with a local TryLaunch helper using Process.Start, wire SystemTray and StartMenu into MainWindow, adjust XAML namespaces and remove DropShadow attribute, and ensure timer/type references compile (System.Timers.Timer).
  • Add utils/Enable-ConsoleLogon.ps1 to toggle/restore authui.dll for console-style logon (supports offline -WindowsRoot and -Restore) and update top-level README.md with a short utilities section and usage examples.

Testing

  • Built the WinUI shell project with dotnet build mswindows/shell and the shell assembly compiles successfully (no build errors).
  • Built the native runtime with CMake using cmake --build build for ntos2nd and the new posixsubsystem target and ntos2nd link succeeded.
  • Ran unit/integration tests with ctest in the ntos2nd test tree and reported tests passed (no failing tests).

Codex Task

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a POSIX subsystem scaffold, including a user-mode runtime DLL, a stub kernel driver, and documentation outlining the architectural strategy. It also adds several NT syscall wrappers in ntos2nd, a utility script for toggling console logon, and various UI improvements to the shell components. Feedback highlights a bug in the POSIX runtime where Win32 error codes are incorrectly passed to an NTSTATUS translation function, and a permission issue in the PowerShell utility regarding system file ownership. Additionally, improvements were suggested for type safety in the syscall wrapper headers and safer string handling in the POSIX process spawning logic.

Comment on lines +43 to +44
resp->ntstatus = (int32_t)GetLastError();
return PosixTranslateNtStatusToErrno(resp->ntstatus);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The PosixTranslateNtStatusToErrno function is designed to handle NTSTATUS values (e.g., 0xC0000008), but it is being passed a Win32 error code from GetLastError(). Win32 error codes (like ERROR_FILE_NOT_FOUND = 2) do not match the NTSTATUS constants used in the switch statement, which will cause most errors to fall through to the default case (EIO). You should either use a Win32-to-NTSTATUS mapping or update the translation function to handle Win32 error codes.

Comment on lines +38 to +41
if ($PSCmdlet.ShouldProcess($Path, "Rename to $disabledPath")) {
Rename-Item -LiteralPath $Path -NewName ([System.IO.Path]::GetFileName($disabledPath)) -ErrorAction Stop
Write-Host "Disabled: $Path"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Renaming system binaries like authui.dll in System32 typically fails with 'Access Denied' even for Administrators because these files are owned by TrustedInstaller. To successfully rename them, the script needs to take ownership and modify the ACLs first. Consider using takeown.exe and icacls.exe before attempting the rename.

    if ($PSCmdlet.ShouldProcess($Path, "Rename to $disabledPath")) {
        # Take ownership and grant permissions to allow renaming system files
        $null = takeown.exe /f $Path /a
        $null = icacls.exe $Path /grant "*S-1-5-32-544:F" # Administrators group SID
        Rename-Item -LiteralPath $Path -NewName ([System.IO.Path]::GetFileName($disabledPath)) -ErrorAction Stop
        Write-Host "Disabled: $Path"
    }

Comment thread ntos2nd/NTCall.h
Comment on lines +8 to +10
NTSTATUS NTAPI NtOpenProcessWrap(PHANDLE ProcessHandle, ACCESS_MASK DesiredAccess, void* ObjectAttributes, void* ClientId);
NTSTATUS NTAPI NtReadFileWrap(HANDLE FileHandle, HANDLE Event, PVOID ApcRoutine, PVOID ApcContext, void* IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key);
NTSTATUS NTAPI NtWriteFileWrap(HANDLE FileHandle, HANDLE Event, PVOID ApcRoutine, PVOID ApcContext, void* IoStatusBlock, const VOID* Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The function prototypes in this header use void* for parameters that have specific types in the implementation (e.g., POBJECT_ATTRIBUTES, PCLIENT_ID, PIO_STATUS_BLOCK in NTCall.c). This reduces type safety for consumers of the header. It is recommended to use the specific types, potentially by moving the type definitions to a shared header included by both files.

Comment on lines +34 to +38
strncat(cmdLine, req->path, sizeof(cmdLine) - 1);
if (req->argv_blob[0]) {
strncat(cmdLine, " ", sizeof(cmdLine) - strlen(cmdLine) - 1);
strncat(cmdLine, req->argv_blob, sizeof(cmdLine) - strlen(cmdLine) - 1);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The construction of cmdLine using strncat is slightly inconsistent. While the first call (line 34) is safe because the buffer was just zeroed, the subsequent calls correctly use sizeof(cmdLine) - strlen(cmdLine) - 1. For better maintainability and to prevent potential overflows if the code is refactored, all strncat calls should use the remaining buffer size calculation. Additionally, ensure that req->path and req->argv_blob are null-terminated before concatenation to avoid reading past the source buffers.

    char cmdLine[4096];
    cmdLine[0] = '\0';
    strncat(cmdLine, req->path, sizeof(cmdLine) - strlen(cmdLine) - 1);
    if (req->argv_blob[0]) {
        strncat(cmdLine, " ", sizeof(cmdLine) - strlen(cmdLine) - 1);
        strncat(cmdLine, req->argv_blob, sizeof(cmdLine) - strlen(cmdLine) - 1);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant