mirror of
https://github.com/NixOS/nix
synced 2025-07-05 20:41:47 +02:00
Merge pull request #10678 from nix-windows/windows-substitution-goal
Start building the scheduler for Windows
This commit is contained in:
commit
d0c7da131f
25 changed files with 285 additions and 94 deletions
|
@ -206,11 +206,11 @@ MakeError(SystemError, Error);
|
|||
*
|
||||
* Throw this, but prefer not to catch this, and catch `SystemError`
|
||||
* instead. This allows implementations to freely switch between this
|
||||
* and `WinError` without breaking catch blocks.
|
||||
* and `windows::WinError` without breaking catch blocks.
|
||||
*
|
||||
* However, it is permissible to catch this and rethrow so long as
|
||||
* certain conditions are not met (e.g. to catch only if `errNo =
|
||||
* EFooBar`). In that case, try to also catch the equivalent `WinError`
|
||||
* EFooBar`). In that case, try to also catch the equivalent `windows::WinError`
|
||||
* code.
|
||||
*
|
||||
* @todo Rename this to `PosixError` or similar. At this point Windows
|
||||
|
@ -248,7 +248,9 @@ public:
|
|||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
class WinError;
|
||||
namespace windows {
|
||||
class WinError;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -258,7 +260,7 @@ class WinError;
|
|||
*/
|
||||
using NativeSysError =
|
||||
#ifdef _WIN32
|
||||
WinError
|
||||
windows::WinError
|
||||
#else
|
||||
SysError
|
||||
#endif
|
||||
|
|
|
@ -136,7 +136,7 @@ size_t FdSource::readUnbuffered(char * data, size_t len)
|
|||
checkInterrupt();
|
||||
if (!::ReadFile(fd, data, len, &n, NULL)) {
|
||||
_good = false;
|
||||
throw WinError("ReadFile when FdSource::readUnbuffered");
|
||||
throw windows::WinError("ReadFile when FdSource::readUnbuffered");
|
||||
}
|
||||
#else
|
||||
ssize_t n;
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
using namespace nix::windows;
|
||||
|
||||
std::string readFile(HANDLE handle)
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
using namespace nix::windows;
|
||||
|
||||
std::string getUserName()
|
||||
{
|
||||
// Get the required buffer size
|
||||
|
|
43
src/libutil/windows/windows-async-pipe.cc
Normal file
43
src/libutil/windows/windows-async-pipe.cc
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "windows-async-pipe.hh"
|
||||
#include "windows-error.hh"
|
||||
|
||||
namespace nix::windows {
|
||||
|
||||
void AsyncPipe::createAsyncPipe(HANDLE iocp)
|
||||
{
|
||||
// std::cerr << (format("-----AsyncPipe::createAsyncPipe(%x)") % iocp) << std::endl;
|
||||
|
||||
buffer.resize(0x1000);
|
||||
memset(&overlapped, 0, sizeof(overlapped));
|
||||
|
||||
std::string pipeName = fmt("\\\\.\\pipe\\nix-%d-%p", GetCurrentProcessId(), (void *) this);
|
||||
|
||||
readSide = CreateNamedPipeA(
|
||||
pipeName.c_str(), PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, PIPE_UNLIMITED_INSTANCES, 0, 0,
|
||||
INFINITE, NULL);
|
||||
if (!readSide)
|
||||
throw WinError("CreateNamedPipeA(%s)", pipeName);
|
||||
|
||||
HANDLE hIocp = CreateIoCompletionPort(readSide.get(), iocp, (ULONG_PTR) (readSide.get()) ^ 0x5555, 0);
|
||||
if (hIocp != iocp)
|
||||
throw WinError("CreateIoCompletionPort(%x[%s], %x, ...) returned %x", readSide.get(), pipeName, iocp, hIocp);
|
||||
|
||||
if (!ConnectNamedPipe(readSide.get(), &overlapped) && GetLastError() != ERROR_IO_PENDING)
|
||||
throw WinError("ConnectNamedPipe(%s)", pipeName);
|
||||
|
||||
SECURITY_ATTRIBUTES psa2 = {0};
|
||||
psa2.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||
psa2.bInheritHandle = TRUE;
|
||||
|
||||
writeSide = CreateFileA(pipeName.c_str(), GENERIC_WRITE, 0, &psa2, OPEN_EXISTING, 0, NULL);
|
||||
if (!readSide)
|
||||
throw WinError("CreateFileA(%s)", pipeName);
|
||||
}
|
||||
|
||||
void AsyncPipe::close()
|
||||
{
|
||||
readSide.close();
|
||||
writeSide.close();
|
||||
}
|
||||
|
||||
}
|
20
src/libutil/windows/windows-async-pipe.hh
Normal file
20
src/libutil/windows/windows-async-pipe.hh
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "file-descriptor.hh"
|
||||
|
||||
namespace nix::windows {
|
||||
|
||||
class AsyncPipe
|
||||
{
|
||||
public:
|
||||
AutoCloseFD writeSide, readSide;
|
||||
OVERLAPPED overlapped;
|
||||
DWORD got;
|
||||
std::vector<unsigned char> buffer;
|
||||
|
||||
void createAsyncPipe(HANDLE iocp);
|
||||
void close();
|
||||
};
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
namespace nix {
|
||||
namespace nix::windows {
|
||||
|
||||
std::string WinError::renderError(DWORD lastError)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "error.hh"
|
||||
|
||||
namespace nix {
|
||||
namespace nix::windows {
|
||||
|
||||
/**
|
||||
* Windows Error type.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue