Support shebang on Windows

Fixes #1010
This commit is contained in:
Justine Tunney 2024-05-20 22:11:42 -07:00
parent a52792c59f
commit cf70a44756
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
8 changed files with 240 additions and 132 deletions

View file

@ -91,9 +91,9 @@ textwindows int sys_execve_nt(const char *program, char *const argv[],
// launch the process
struct NtProcessInformation pi;
int rc = ntspawn(AT_FDCWD, program, argv, envp,
(char *[]){fdspec, maskvar, 0}, 0, 0, hParentProcess,
lpExplicitHandles, dwExplicitHandleCount, &si, &pi);
int rc = ntspawn(&(struct NtSpawnArgs){
AT_FDCWD, program, argv, envp, (char *[]){fdspec, maskvar, 0}, 0, 0,
hParentProcess, lpExplicitHandles, dwExplicitHandleCount, &si, &pi});
__undescribe_fds(hParentProcess, lpExplicitHandles, dwExplicitHandleCount);
if (rc == -1) {
free(fdspec);

View file

@ -344,9 +344,10 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
}
#endif
NTTRACE("STARTING SPAWN");
int spawnrc = ntspawn(AT_FDCWD, GetProgramExecutableName(), args, environ,
(char *[]){forkvar, 0}, dwCreationFlags, 0, 0, 0, 0,
&startinfo, &procinfo);
int spawnrc = ntspawn(&(struct NtSpawnArgs){
AT_FDCWD, GetProgramExecutableName(), args, environ,
(char *[]){forkvar, 0}, dwCreationFlags, 0, 0, 0, 0, &startinfo,
&procinfo});
if (spawnrc != -1) {
CloseHandle(procinfo.hThread);
ok = WriteAll(writer, jb, sizeof(jb)) &&

View file

@ -4,12 +4,25 @@
#include "libc/nt/struct/startupinfo.h"
COSMOPOLITAN_C_START_
void mungentpath(char *);
int mkntcmdline(char16_t[32767], char *const[]);
struct NtSpawnArgs {
int64_t dirhand;
const char *prog;
char *const *argv;
char *const *envp;
char *const *extravars;
uint32_t dwCreationFlags;
const char16_t *opt_lpCurrentDirectory;
int64_t opt_hParentProcess;
int64_t *opt_lpExplicitHandleList;
uint32_t dwExplicitHandleCount;
const struct NtStartupInfo *lpStartupInfo;
struct NtProcessInformation *opt_out_lpProcessInformation;
};
int mkntenvblock(char16_t[32767], char *const[], char *const[], char[32767]);
int ntspawn(int64_t, const char *, char *const[], char *const[], char *const[],
uint32_t, const char16_t *, int64_t, int64_t *, uint32_t,
const struct NtStartupInfo *, struct NtProcessInformation *);
int ntspawn(struct NtSpawnArgs *);
size_t mkntcmdline(char16_t *, char *const[], size_t);
void mungentpath(char *);
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_NTSPAWN_H_ */

View file

@ -382,9 +382,10 @@ static textwindows errno_t posix_spawn_nt_impl(
envp = environ;
if ((fdspec = __describe_fds(fds.p, fds.n, &startinfo, hCreatorProcess,
&lpExplicitHandles, &dwExplicitHandleCount))) {
rc = ntspawn(dirhand, path, argv, envp, (char *[]){fdspec, maskvar, 0},
dwCreationFlags, lpCurrentDirectory, 0, lpExplicitHandles,
dwExplicitHandleCount, &startinfo, &procinfo);
rc = ntspawn(&(struct NtSpawnArgs){
dirhand, path, argv, envp, (char *[]){fdspec, maskvar, 0},
dwCreationFlags, lpCurrentDirectory, 0, lpExplicitHandles,
dwExplicitHandleCount, &startinfo, &procinfo});
}
if (rc == -1) {
err = errno;