Skip to content
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

don't forget about ARM32 #3

Open
wmjb opened this issue Nov 2, 2024 · 5 comments
Open

don't forget about ARM32 #3

wmjb opened this issue Nov 2, 2024 · 5 comments
Labels
arm Issue related to 32-bit ARM enhancement New feature or request

Comments

@wmjb
Copy link

wmjb commented Nov 2, 2024

can there be support for windows ARM32? it's very much alive with the surface RT1 and 2 devices that run windows 10 15035 and the community would like to see this. maybe this will be useful https://arm.syscall.sh/

@trungnt2910
Copy link
Owner

trungnt2910 commented Nov 2, 2024

Yes, as mentioned in this X post.

ARM32 support is a priority in this iteration. Since the whole effort is to study Project Astoria, a ARM32 bringup is needed to load the driver on Windows 10 Mobile.

My uncommitted code builds well for ARM32 after some MSBuild hacks. I have binaries lying on my disk, but no compatible devices to test on.

@trungnt2910
Copy link
Owner

maybe this will be useful https://arm.syscall.sh/

Yes, the uname trap is handled in my uncommitted code:

extern "C"
VOID
MapLxssSystemCallHook(
    _In_ PPS_PICO_SYSTEM_CALL_INFORMATION pSyscallInfo
)
{
    struct old_utsname {
        char sysname[65];
        char nodename[65];
        char release[65];
        char version[65];
        char machine[65];
    }* pUtsName = NULL;

    // Check for SYS_uname
#ifdef _M_X64
    if (pSyscallInfo->TrapFrame->Rax == 63)
    {
        pUtsName = (old_utsname*)pSyscallInfo->TrapFrame->Rdi;
    }
#elif defined(_M_ARM64)
    if (pSyscallInfo->TrapFrame->X8 == 160)
    {
        pUtsName = (old_utsname*)pSyscallInfo->TrapFrame->X0;
    }
#elif defined(_M_IX86)
    if (pSyscallInfo->TrapFrame->Eax == 122)
    {
        pUtsName = (old_utsname*)pSyscallInfo->TrapFrame->Ebx;
    }
#elif defined(_M_ARM)
    if (pSyscallInfo->R7 == 122)
    {
        pUtsName = (old_utsname*)pSyscallInfo->TrapFrame->R0;
    }
#else
#error Detect the syscall arguments for this architecture!
#endif

    // Compared to the old checks, this will miss `uname` calls where the argument is NULL.
    // However, we do not intend to intercept such calls anyway.
    if (pUtsName != NULL)
    {
        Logger::LogTrace("uname(", pUtsName, ")");
    }

    MaLxssOriginalDispatchSystemCall(pSyscallInfo);

    if (pUtsName != NULL
        // Also check for a success return value.
        // Otherwise, pUtsName may be an invalid pointer.
#ifdef _M_X64
        && pSyscallInfo->TrapFrame->Rax == 0)
#elif defined(_M_ARM64)
        && pSyscallInfo->TrapFrame->X0 == 0)
#elif defined(_M_IX86)
        && pSyscallInfo->TrapFrame->Eax == 0)
#elif defined(_M_ARM)
        && pSyscallInfo->TrapFrame->R0 == 0)
#else
#error Detect the syscall return value for this architecture!
#endif
    {
        // We should be in the context of the calling process.
        // Therefore, it is safe to access the raw pointers.

        Logger::LogTrace("pUtsName->sysname  ", (PCSTR)pUtsName->sysname);
        Logger::LogTrace("pUtsName->nodename ", (PCSTR)pUtsName->nodename);
        Logger::LogTrace("pUtsName->release  ", (PCSTR)pUtsName->release);
        Logger::LogTrace("pUtsName->version  ", (PCSTR)pUtsName->version);
        Logger::LogTrace("pUtsName->machine  ", (PCSTR)pUtsName->machine);

        strcpy(pUtsName->sysname, "Monika");
        // "Microsoft" (case sensitive) is required.
        // Otherwise, Microsoft's `init` will detect the kernel as WSL2.
        strncpy(pUtsName->release, MONIKA_KERNEL_VERSION "-Monika-Microsoft",
            sizeof(pUtsName->release));
        strncpy(pUtsName->version,
            "#" MONIKA_KERNEL_BUILD_NUMBER "-Just-Monika " MONIKA_KERNEL_TIMESTAMP,
            sizeof(pUtsName->version));
    }
}

Once again, I have nothing to test this on. Let me know if you're interested so that I could send some test builds and/or source tarballs.

@wmjb
Copy link
Author

wmjb commented Nov 2, 2024

I am ready to test.

@wmjb
Copy link
Author

wmjb commented Nov 2, 2024

attempting to compile myself i've modified ntddk.h to include the extra registers and added defines for arm, only got one issue left lxmonika\src\reality.cpp(418,1): error C3493: 'Copy' cannot be implicitly captured because no default capture mode has been specified

@trungnt2910 trungnt2910 added enhancement New feature or request arm Issue related to 32-bit ARM labels Nov 3, 2024
@trungnt2910
Copy link
Owner

attempting to compile myself

Ahh, the source code up here is outdated. Try the staging branch instead.

You'll also need to follow specific installation instructions before the monika.exe CLI supports the new driver load strategy.

trungnt2910 added a commit that referenced this issue Nov 3, 2024
The previous trampoline was tested on a simulator but for normal,
non-Thumb mode.

This commit marks the first successful boot of `lxmonika` on 32-bit
ARM Windows. See #3.
trungnt2910 added a commit that referenced this issue Nov 5, 2024
The previous trampoline was tested on a simulator but for normal,
non-Thumb mode.

This commit marks the first successful boot of `lxmonika` on 32-bit
ARM Windows. See #3.
trungnt2910 added a commit that referenced this issue Nov 13, 2024
The previous trampoline was tested on a simulator but for normal,
non-Thumb mode.

This commit marks the first successful boot of `lxmonika` on 32-bit
ARM Windows. See #3.
trungnt2910 added a commit that referenced this issue Nov 14, 2024
The previous trampoline was tested on a simulator but for normal,
non-Thumb mode.

This commit marks the first successful boot of `lxmonika` on 32-bit
ARM Windows. See #3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arm Issue related to 32-bit ARM enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants