Skip to content
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
2 changes: 1 addition & 1 deletion src/windows/WslcSDK/wslcsdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ typedef struct WslcImageInfo
// we should expose this
CHAR name[WSLC_IMAGE_NAME_LENGTH];
uint8_t sha256[32];
uint64_t sizeBytes;
int64_t sizeBytes;
uint64_t createdUnixTime;
} WslcImageInfo;

Expand Down
2 changes: 1 addition & 1 deletion src/windows/common/WSLCContainerLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void WSLCContainerLauncher::SetDefaultStopSignal(WSLCSignal Signal)
m_stopSignal = Signal;
}

void WSLCContainerLauncher::SetShmSize(ULONGLONG ShmSize)
void WSLCContainerLauncher::SetShmSize(int64_t ShmSize)
{
m_shmSize = ShmSize;
}
Expand Down
4 changes: 2 additions & 2 deletions src/windows/common/WSLCContainerLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class WSLCContainerLauncher : private WSLCProcessLauncher
void SetName(std::string&& Name);
void SetEntrypoint(std::vector<std::string>&& entrypoint);
void SetDefaultStopSignal(WSLCSignal Signal);
void SetShmSize(ULONGLONG ShmSize);
void SetShmSize(int64_t ShmSize);
void SetContainerFlags(WSLCContainerFlags Flags);
void SetContainerNetworkName(std::string&& Name);
void SetHostname(std::string&& Hostname);
Expand Down Expand Up @@ -102,7 +102,7 @@ class WSLCContainerLauncher : private WSLCProcessLauncher
std::string m_containerNetworkName;
std::vector<std::string> m_entrypoint;
WSLCSignal m_stopSignal = WSLCSignalNone;
ULONGLONG m_shmSize = 0;
int64_t m_shmSize = 0;
WSLCContainerFlags m_containerFlags = WSLCContainerFlagsNone;
std::string m_hostname;
std::string m_domainname;
Expand Down
65 changes: 51 additions & 14 deletions src/windows/inc/docker_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Module Name:
Abstract:

JSON schema for the docker API.
The documentation for the API can be found at: https://docs.docker.com/reference/api/engine/version/v1.52/#tag/Container
Targets the daemon API version bundled with WSLC's dockerd (currently v25.0.3, API v1.44).
The documentation for the API can be found at: https://docs.docker.com/reference/api/engine/version/v1.44/#tag/Container

--*/

Expand All @@ -22,10 +23,9 @@ namespace wsl::windows::common::docker_schema {
struct CreatedContainer
{
std::string Id;
std::string Name;
std::vector<std::string> Warnings;

NLOHMANN_DEFINE_TYPE_INTRUSIVE(CreatedContainer, Id, Warnings);
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreatedContainer, Id, Warnings);
};

struct ErrorResponse
Expand Down Expand Up @@ -83,7 +83,10 @@ struct Volume
std::string CreatedAt;
std::optional<std::map<std::string, std::string>> Options;
std::optional<std::map<std::string, std::string>> Labels;
std::optional<std::map<std::string, std::string>> Status;
// Docker's wire schema for Status is map[string]any: third-party volume
// drivers may set arbitrary JSON values (numbers, bools, objects), not
// just strings. Use nlohmann::json so deserialization never throws.
std::optional<std::map<std::string, nlohmann::json>> Status;
std::optional<VolumeUsageData> UsageData;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Volume, Name, Driver, Mountpoint, CreatedAt, Options, Labels, Status, UsageData);
Expand Down Expand Up @@ -223,7 +226,9 @@ struct HostConfig
std::optional<std::vector<std::string>> DnsOptions;
std::optional<std::vector<std::string>> Binds;
std::map<std::string, std::string> Tmpfs;
std::optional<ULONGLONG> ShmSize;
// Docker wire type is int64. 0 means "use daemon default" — same as omitting
// the field — so we don't bother with std::optional here.
std::int64_t ShmSize{};
std::optional<std::vector<DeviceMapping>> Devices;

// Per-container resource limits. 0 means "no limit" (Docker default).
Expand Down Expand Up @@ -356,7 +361,7 @@ struct Image
std::string Id;
std::vector<std::string> RepoTags;
std::vector<std::string> RepoDigests;
uint64_t Size{};
int64_t Size{};
int64_t Created{};
std::string ParentId;

Expand Down Expand Up @@ -432,7 +437,7 @@ struct InspectImage
std::string Variant;
std::string Os;
std::string OsVersion;
uint64_t Size{};
int64_t Size{};
std::optional<GraphDriverData> GraphDriver;
std::optional<RootFS> RootFS;
std::optional<std::map<std::string, std::string>> Metadata;
Expand All @@ -455,41 +460,73 @@ struct CreateExec
bool AttachStdout{};
bool AttachStderr{};
bool Tty{};
// Docker wire type is *[2]uint64. Sending an empty array on a TTY exec yields
// a 0x0 console; the field must be omitted entirely when the caller didn't set it.
std::vector<ULONG> ConsoleSize;
std::vector<std::string> Cmd;
std::vector<std::string> Env;
std::optional<std::string> User;
std::string WorkingDir;
std::optional<std::string> DetachKeys;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CreateExec, AttachStdin, AttachStdout, AttachStderr, Tty, ConsoleSize, Cmd, Env, WorkingDir, User, DetachKeys);
};

inline void to_json(nlohmann::json& j, const CreateExec& v)
{
j = nlohmann::json{
{"AttachStdin", v.AttachStdin},
{"AttachStdout", v.AttachStdout},
{"AttachStderr", v.AttachStderr},
{"Tty", v.Tty},
{"Cmd", v.Cmd},
{"Env", v.Env},
{"WorkingDir", v.WorkingDir},
{"User", v.User},
{"DetachKeys", v.DetachKeys},
};

if (!v.ConsoleSize.empty())
{
j["ConsoleSize"] = v.ConsoleSize;
}
}

struct StartExec
{
using TResponse = void;
bool Tty{};
bool Detach{};
// See CreateExec::ConsoleSize.
std::vector<ULONG> ConsoleSize;

NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(StartExec, Tty, Detach, ConsoleSize);
};

inline void to_json(nlohmann::json& j, const StartExec& v)
{
j = nlohmann::json{{"Tty", v.Tty}, {"Detach", v.Detach}};

if (!v.ConsoleSize.empty())
{
j["ConsoleSize"] = v.ConsoleSize;
}
}

enum class ContainerState
{
Unknown,
Created,
Running,
Paused,
Restarting,
Exited,
Removing,
Dead,
Unknown
Dead
};

NLOHMANN_JSON_SERIALIZE_ENUM(
ContainerState,
{
// Unknown is first so unrecognized strings (or missing field) deserialize to Unknown,
// not to whatever the next entry happens to be.
{ContainerState::Unknown, nullptr},
{ContainerState::Created, "created"},
{ContainerState::Running, "running"},
{ContainerState::Paused, "paused"},
Expand Down Expand Up @@ -580,7 +617,7 @@ struct CreateImageProgress
};

// Container stats (GET /containers/{id}/stats?stream=false)
// See: https://docs.docker.com/reference/api/engine/version/v1.52/#tag/Container/operation/ContainerStats
// See: https://docs.docker.com/reference/api/engine/version/v1.44/#tag/Container/operation/ContainerStats
Comment thread
benhillis marked this conversation as resolved.

struct ContainerStatsCpuUsage
{
Expand Down
2 changes: 1 addition & 1 deletion src/windows/inc/wslc_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct InspectImage
std::string Author;
std::string Architecture;
std::string Os;
uint64_t Size{};
int64_t Size{};
std::optional<std::map<std::string, std::string>> Metadata;
std::optional<ImageConfig> Config;

Expand Down
4 changes: 2 additions & 2 deletions src/windows/service/inc/wslc.idl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ typedef struct _WSLCImageInformation
char Image[WSLC_MAX_IMAGE_NAME_LENGTH + 1];
char Hash[256];
char Digest[256];
ULONGLONG Size;
LONGLONG Size; // Matches Docker's int64 image size
LONGLONG Created; // Unix timestamp
char ParentId[256];
} WSLCImageInformation;
Expand Down Expand Up @@ -301,7 +301,7 @@ typedef struct _WSLCContainerOptions
WSLCStringArray DnsSearchDomains;
WSLCStringArray DnsOptions;

ULONGLONG ShmSize;
LONGLONG ShmSize; // Matches Docker's int64 ShmSize; consistent with MemoryBytes/NanoCpus
WSLCContainerNetwork ContainerNetwork;
[unique, size_is(TmpfsCount)] const WSLCTmpfsMount* Tmpfs;
ULONG TmpfsCount;
Expand Down
4 changes: 2 additions & 2 deletions src/windows/wslc/arguments/ArgumentValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ void ValidateMemorySize(const std::vector<std::wstring>& values, const std::wstr
}
}

ULONGLONG GetMemorySizeFromString(const std::wstring& input, const std::wstring& argName)
int64_t GetMemorySizeFromString(const std::wstring& input, const std::wstring& argName)
{
auto parsed = wsl::shared::string::ParseMemorySize(input.c_str());
if (!parsed.has_value())
{
throw ArgumentException(Localization::WSLCCLI_InvalidMemorySizeError(argName, input));
}

return parsed.value();
return static_cast<int64_t>(parsed.value());
}

} // namespace wsl::windows::wslc::validation
2 changes: 1 addition & 1 deletion src/windows/wslc/arguments/ArgumentValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ValidateWSLCSignalFromString(const std::vector<std::wstring>& values, const
WSLCSignal GetWSLCSignalFromString(const std::wstring& input, const std::wstring& argName = {});

void ValidateMemorySize(const std::vector<std::wstring>& values, const std::wstring& argName);
ULONGLONG GetMemorySizeFromString(const std::wstring& input, const std::wstring& argName = {});
int64_t GetMemorySizeFromString(const std::wstring& input, const std::wstring& argName = {});

void ValidateFormatTypeFromString(const std::vector<std::wstring>& values, const std::wstring& argName);
FormatType GetFormatTypeFromString(const std::wstring& input, const std::wstring& argName = {});
Expand Down
2 changes: 1 addition & 1 deletion src/windows/wslc/services/ContainerModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct ContainerOptions
bool TTY = false;
bool PublishAll = false;
WSLCSignal StopSignal = WSLCSignalNone;
std::optional<ULONGLONG> ShmSize{};
std::optional<int64_t> ShmSize{};
bool Gpu = false;
std::vector<std::string> Ports;
std::vector<std::wstring> Volumes;
Expand Down
2 changes: 1 addition & 1 deletion src/windows/wslc/services/ImageModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct ImageInformation
std::optional<std::string> Tag;
std::string Id;
LONGLONG Created{};
ULONGLONG Size{};
int64_t Size{};

NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ImageInformation, Repository, Tag, Id, Created, Size);
};
Expand Down
5 changes: 1 addition & 4 deletions src/windows/wslcsession/WSLCContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,7 @@ std::unique_ptr<WSLCContainerImpl> WSLCContainerImpl::Create(
request.HostConfig.Ulimits = std::move(ulimits);
}

if (containerOptions.ShmSize > 0)
{
request.HostConfig.ShmSize = containerOptions.ShmSize;
}
request.HostConfig.ShmSize = containerOptions.ShmSize;

if (containerOptions.VolumesCount > 0)
{
Expand Down