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

Variants for Windows with working run-scripts #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compat/dir_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ void dir_mutex_lock(int dfd)
if(dir_mutex_enabled)
pthread_mutex_lock(&dir_mutex);

// AT_FDCWD
if (dfd == -100)
return;

if(fchdir(dfd) < 0) {
perror("fchdir");
fprintf(stderr, "tup error: Failed to fchdir in a compat wrapper function.\n");
fprintf(stderr, "tup error: Failed to fchdir in a compat wrapper function at %p.\n", __builtin_return_address(0));
exit(1);
}
}
Expand Down
30 changes: 21 additions & 9 deletions src/compat/fstatat.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,39 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "tup/compat.h"
#include "dir_mutex.h"
#ifdef _WIN32
#include "open_notify.h"
#endif

int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags)
{
int rc;

#ifdef _WINDOWS
char cwd[PATH_MAX];
getcwd(cwd, PATH_MAX);
#endif
dir_mutex_lock(dirfd);
// No symlinks on windows...
if(flags & AT_SYMLINK_NOFOLLOW) {
#ifdef _WIN32
open_notify(ACCESS_READ, pathname);
#endif
#if defined(_WIN64)
rc = _stat64(pathname, buf);
#elif defined(_WIN32)
rc = _stat32(pathname, buf);
#else
rc = lstat(pathname, buf);
} else {
#ifdef _WIN32
open_notify(ACCESS_READ, pathname);
#endif
} else {
#if defined(_WIN64)
rc = _stat64(pathname, buf);
#elif defined(_WIN32)
rc = _stat32(pathname, buf);
#else
rc = stat(pathname, buf);
#endif
}
#ifdef _WINDOWS
chdir(cwd);
#endif
dir_mutex_unlock();
return rc;
}
9 changes: 8 additions & 1 deletion src/compat/mkdirat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include "tup/compat.h"
#include "dir_mutex.h"

#ifdef _WIN32
Expand All @@ -31,11 +32,17 @@
int mkdirat(int dirfd, const char *pathname, mode_t mode)
{
int rc;

#ifdef _WINDOWS
char cwd[PATH_MAX];
getcwd(cwd, PATH_MAX);
#endif
if(mode) {/* for win32 */}

dir_mutex_lock(dirfd);
rc = mkdir(pathname, mode);
#ifdef _WINDOWS
chdir(cwd);
#endif
dir_mutex_unlock();
return rc;
}
9 changes: 8 additions & 1 deletion src/compat/openat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include "tup/compat.h"
#include "dir_mutex.h"

int openat(int dirfd, const char *pathname, int flags, ...)
{
int fd;
mode_t mode = 0;

#ifdef _WINDOWS
char cwd[PATH_MAX];
getcwd(cwd, PATH_MAX);
#endif
dir_mutex_lock(dirfd);
if(flags & O_CREAT) {
va_list ap;
Expand All @@ -37,6 +41,9 @@ int openat(int dirfd, const char *pathname, int flags, ...)
va_end(ap);
}
fd = open(pathname, flags, mode);
#ifdef _WINDOWS
chdir(cwd);
#endif
dir_mutex_unlock();
return fd;
}
9 changes: 8 additions & 1 deletion src/compat/unlinkat.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "tup/compat.h"
#include "dir_mutex.h"

int unlinkat(int dirfd, const char *pathname, int flags)
{
int rc;

#ifdef _WINDOWS
char cwd[PATH_MAX];
getcwd(cwd, PATH_MAX);
#endif
dir_mutex_lock(dirfd);
if(flags == AT_REMOVEDIR)
rc = rmdir(pathname);
else
rc = unlink(pathname);
#ifdef _WINDOWS
chdir(cwd);
#endif
dir_mutex_unlock();
return rc;
}
5 changes: 5 additions & 0 deletions src/compat/win32/wow64.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#ifdef _WIN64
#ifndef tup_win32_wow64_h
#define tup_win32_wow64_h
#define WOW64_CONTEXT_i386 0x00010000
#define WOW64_CONTEXT_CONTROL (WOW64_CONTEXT_i386 | __MSABI_LONG(0x00000001))

#define WOW64_MAXIMUM_SUPPORTED_EXTENSION 512
#define WOW64_SIZE_OF_80387_REGISTERS 80

BOOL WINAPI Wow64GetThreadContext(HANDLE hThread, PWOW64_CONTEXT lpContext);
BOOL WINAPI Wow64SetThreadContext(HANDLE hThread, const WOW64_CONTEXT *lpContext);

#endif
#endif
Loading