mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
5bd22aef12
So far I haven't found any way to run native Arm64 code on Windows Arm64 without using MSVC. When I build a PE binary from scratch that should be a valid Windows Arm64 program, the OS refuses to run it. Possibly due to requiring additional content like XML manifests or relocation or control flow integrity data that isn't normally required on x64. I've also tried using VirtualAlloc2() to JIT an Arm64 native function, but VirtualAlloc2 always fails with invalid parameter. I tried using MSVC to create an ARM DLL that my x64 emulated program can link at runtime, to pass a function pointer with ARM code, but LoadLibrary() rejects ARM DLLs as invalid exe The only option left, is likely to write a new program like ape/ape-m1.c which can be compiled by MSVC to load and run an AARCH64 ELF executable. The emulated x64 binary would detect emulation using IsWow64Process2 and then drop the loader executable in a temporary folder, and re-launch the original executable, using the Arm64 segments of the cosmocc fat binary.
53 lines
2.1 KiB
C
53 lines
2.1 KiB
C
#ifndef COSMOPOLITAN_LIBC_NT_RUNTIME_H_
|
|
#define COSMOPOLITAN_LIBC_NT_RUNTIME_H_
|
|
#include "libc/nt/struct/overlapped.h"
|
|
#include "libc/nt/thunk/msabi.h"
|
|
#include "libc/nt/typedef/handlerroutine.h"
|
|
|
|
/**
|
|
* @fileoverview NT Obligatory Runtime Functions.
|
|
*
|
|
* These functions are placed in their own file because they're (a)
|
|
* abstracted by the Cosmopolitan runtime; and (b) it helps GCC avoid
|
|
* bloating binaries with debug information the user doesn't need.
|
|
*/
|
|
|
|
#define kNtCpUtf8 65001
|
|
#define kNtInvalidHandleValue -1L
|
|
#define kNtStdInputHandle -10u
|
|
#define kNtStdOutputHandle -11u
|
|
#define kNtStdErrorHandle -12u
|
|
|
|
#define GetCurrentProcess() -1
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
char16_t *GetCommandLine(void) nosideeffect;
|
|
char16_t *GetEnvironmentStrings(void) __wur;
|
|
bool32 FreeEnvironmentStrings(char16_t *) paramsnonnull();
|
|
bool32 ReadFile(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
|
|
uint32_t *lpNumberOfBytesRead,
|
|
struct NtOverlapped *opt_lpOverlapped);
|
|
bool32 WriteFile(int64_t hFile, const void *lpBuffer,
|
|
uint32_t nNumberOfBytesToWrite,
|
|
uint32_t *lpNumberOfBytesWritten,
|
|
struct NtOverlapped *opt_lpOverlapped);
|
|
bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode);
|
|
void TerminateThisProcess(uint32_t dwWaitStatus) wontreturn;
|
|
void ExitProcess(uint32_t uExitCode) wontreturn;
|
|
uint32_t GetLastError(void) nosideeffect;
|
|
bool32 CloseHandle(int64_t hObject) dontthrow dontcallback;
|
|
intptr_t GetStdHandle(uint32_t nStdHandle) nosideeffect;
|
|
bool32 SetStdHandle(uint32_t nStdHandle, int64_t hHandle);
|
|
bool32 SetDefaultDllDirectories(unsigned dirflags);
|
|
bool32 ProcessPrng(void *RandomBuffer, uint32_t RandomBufferLength);
|
|
uint32_t GetModuleFileName(int64_t hModule, char16_t *lpFilename,
|
|
uint32_t nSize);
|
|
bool32 IsWow64Process2(intptr_t hProcess, uint16_t *out_pProcessMachine,
|
|
uint16_t *out_opt_pNativeMachine);
|
|
|
|
#if ShouldUseMsabiAttribute()
|
|
#include "libc/nt/thunk/runtime.inc"
|
|
#endif /* ShouldUseMsabiAttribute() */
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* COSMOPOLITAN_LIBC_NT_RUNTIME_H_ */
|