-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Partial SDK implementation #14214
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
Partial SDK implementation #14214
Changes from all commits
694443e
437a912
4216049
cb3f04d
5fca876
243d358
ca94797
6ca21d3
d15c57e
694734e
3181022
37e9a89
877bf26
4557def
7f800ed
d33a7fa
144d00c
bc357c7
0bdb1df
f542a14
c65c4a2
61f1c5e
32d797b
713dff4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| ProgressCallback.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of a type that implements IProgressCallback. | ||
|
|
||
| --*/ | ||
| #include "precomp.h" | ||
| #include "ProgressCallback.h" | ||
|
|
||
| using namespace std::string_view_literals; | ||
|
|
||
| namespace { | ||
| WslcImageProgressStatus ConvertStatus(LPCSTR Status) | ||
| { | ||
| #define WSLC_STRING_TO_STATUS_MAPPING(_status_, _string_) \ | ||
| if (_string_##sv == Status) \ | ||
| { \ | ||
| return _status_; \ | ||
| } | ||
|
|
||
| // TODO: Mapping engine strings to status values seems fragile. | ||
| // WSLA is intentionally avoiding this kind of thing for localization of engine strings, which amounts to the same | ||
| // thing. If we keep this, a test should be added to explicitly validate that each status is returned properly. | ||
| WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_PULLING, "Pulling fs layer"); | ||
| WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_WAITING, "Waiting"); | ||
| WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_DOWNLOADING, "Downloading"); | ||
| WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_VERIFYING, "Verifying Checksum"); | ||
| WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_EXTRACTING, "Extracting"); | ||
| WSLC_STRING_TO_STATUS_MAPPING(WSLC_IMAGE_PROGRESS_STATUS_COMPLETE, "Pull complete"); | ||
|
|
||
| return WSLC_IMAGE_PROGRESS_STATUS_UNKNOWN; | ||
| } | ||
| } // namespace | ||
|
|
||
| ProgressCallback::ProgressCallback(WslcContainerImageProgressCallback callback, PVOID context) : | ||
| m_callback(callback), m_context(context) | ||
| { | ||
| } | ||
|
|
||
| HRESULT STDMETHODCALLTYPE ProgressCallback::OnProgress(LPCSTR Status, LPCSTR Id, ULONGLONG Current, ULONGLONG Total) | ||
| { | ||
| if (m_callback) | ||
| { | ||
| WslcImageProgressMessage message{}; | ||
|
|
||
| message.id = Id; | ||
| message.status = ConvertStatus(Status); | ||
| message.detail.current = Current; | ||
| message.detail.total = Total; | ||
|
|
||
| m_callback(&message, m_context); | ||
| } | ||
|
|
||
| return S_OK; | ||
| } | ||
|
|
||
| winrt::com_ptr<ProgressCallback> ProgressCallback::CreateIf(const WslcPullImageOptions* options) | ||
| { | ||
| if (options->progressCallback) | ||
| { | ||
| return winrt::make_self<ProgressCallback>(options->progressCallback, options->progressCallbackContext); | ||
| } | ||
| else | ||
| { | ||
| return nullptr; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| ProgressCallback.h | ||
|
|
||
| Abstract: | ||
|
|
||
| Header for a type that implements IProgressCallback. | ||
|
|
||
| --*/ | ||
| #pragma once | ||
| #include "wslaservice.h" | ||
| #include "wslcsdkprivate.h" | ||
| #include <winrt/base.h> | ||
|
|
||
| struct ProgressCallback : public winrt::implements<ProgressCallback, IProgressCallback> | ||
| { | ||
| ProgressCallback(WslcContainerImageProgressCallback callback, PVOID context); | ||
|
|
||
| // IProgressCallback | ||
| HRESULT STDMETHODCALLTYPE OnProgress(LPCSTR Status, LPCSTR Id, ULONGLONG Current, ULONGLONG Total) override; | ||
|
|
||
| // Creates a ProgressCallback if the options provides a callback. | ||
| static winrt::com_ptr<ProgressCallback> CreateIf(const WslcPullImageOptions* options); | ||
|
|
||
| private: | ||
| WslcContainerImageProgressCallback m_callback = nullptr; | ||
| PVOID m_context = nullptr; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| TerminationCallback.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| Implementation of a type that implements ITerminationCallback. | ||
|
|
||
| --*/ | ||
| #include "precomp.h" | ||
| #include "TerminationCallback.h" | ||
|
|
||
| namespace { | ||
| WslcSessionTerminationReason ConvertReason(WSLAVirtualMachineTerminationReason Reason) | ||
| { | ||
| switch (Reason) | ||
| { | ||
| case WSLAVirtualMachineTerminationReasonShutdown: | ||
| return WSLC_SESSION_TERMINATION_REASON_SHUTDOWN; | ||
| case WSLAVirtualMachineTerminationReasonCrashed: | ||
| return WSLC_SESSION_TERMINATION_REASON_CRASHED; | ||
| default: | ||
| return WSLC_SESSION_TERMINATION_REASON_UNKNOWN; | ||
| } | ||
| } | ||
| } // namespace | ||
|
|
||
| TerminationCallback::TerminationCallback(WslcSessionTerminationCallback callback, PVOID context) : | ||
| m_callback(callback), m_context(context) | ||
| { | ||
| } | ||
|
|
||
| // TODO: Details from the runtime are dropped; should the SDK callback function be updated to include the reasons string? | ||
| HRESULT STDMETHODCALLTYPE TerminationCallback::OnTermination(WSLAVirtualMachineTerminationReason Reason, LPCWSTR) | ||
| { | ||
| if (m_callback) | ||
| { | ||
| m_callback(ConvertReason(Reason), m_context); | ||
| } | ||
|
|
||
| return S_OK; | ||
| } | ||
|
|
||
| winrt::com_ptr<TerminationCallback> TerminationCallback::CreateIf(const WSLC_SESSION_OPTIONS_INTERNAL* options) | ||
| { | ||
| if (options->terminationCallback) | ||
| { | ||
| return winrt::make_self<TerminationCallback>(options->terminationCallback, options->terminationCallbackContext); | ||
| } | ||
| else | ||
| { | ||
| return nullptr; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||
| /*++ | ||||||
|
|
||||||
| Copyright (c) Microsoft. All rights reserved. | ||||||
|
|
||||||
| Module Name: | ||||||
|
|
||||||
| TerminationCallback.h | ||||||
|
|
||||||
| Abstract: | ||||||
|
|
||||||
| Header for a type that implements ITerminationCallback. | ||||||
|
|
||||||
| --*/ | ||||||
| #pragma once | ||||||
| #include "wslaservice.h" | ||||||
| #include "wslcsdkprivate.h" | ||||||
|
||||||
| #include "wslcsdkprivate.h" | |
| #include "WslcsdkPrivate.h" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||
| /*++ | ||||||
|
|
||||||
| Copyright (c) Microsoft. All rights reserved. | ||||||
|
|
||||||
| Module Name: | ||||||
|
|
||||||
| WslcSDKPrivate.cpp | ||||||
|
|
||||||
| Abstract: | ||||||
|
|
||||||
| This file contains the private WSL Container SDK implementations. | ||||||
|
|
||||||
| --*/ | ||||||
| #include "precomp.h" | ||||||
|
|
||||||
| #include "wslcsdkprivate.h" | ||||||
|
||||||
| #include "wslcsdkprivate.h" | |
| #include "WslcsdkPrivate.h" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ typedef struct WSLC_SESSION_OPTIONS_INTERNAL | |
| PCWSTR storagePath; | ||
|
|
||
| uint32_t cpuCount; | ||
| uint64_t memoryMb; | ||
| uint32_t memoryMb; | ||
| uint32_t timeoutMS; | ||
|
|
||
| WslcVhdRequirements vhdRequirements; | ||
|
|
@@ -42,13 +42,17 @@ static_assert( | |
| __alignof(WSLC_SESSION_OPTIONS_INTERNAL) == WSLC_SESSION_OPTIONS_ALIGNMENT, | ||
| "WSLC_SESSION_OPTIONS_INTERNAL alignment mismatch"); | ||
|
|
||
| static_assert(std::is_trivial_v<WSLC_SESSION_OPTIONS_INTERNAL>, "WSLC_SESSION_OPTIONS_INTERNAL must be trivial"); | ||
|
|
||
| WSLC_SESSION_OPTIONS_INTERNAL* GetInternalType(WslcSessionSettings* settings); | ||
|
|
||
| // PROCESS DEFINITIONS | ||
| typedef struct WSLC_CONTAINER_PROCESS_OPTIONS_INTERNAL | ||
| { | ||
| PCSTR executable; // path to executable inside container | ||
| PCSTR* commandLine; | ||
| PCSTR const* commandLine; | ||
| uint32_t commandLineCount; | ||
| PCSTR* environment; | ||
| PCSTR const* environment; | ||
| uint32_t environmentCount; | ||
| PCSTR currentDirectory; | ||
| } WSLC_CONTAINER_PROCESS_OPTIONS_INTERNAL; | ||
|
|
@@ -60,6 +64,11 @@ static_assert( | |
| __alignof(WSLC_CONTAINER_PROCESS_OPTIONS_INTERNAL) == WSLC_CONTAINER_PROCESS_OPTIONS_ALIGNMENT, | ||
| "WSLC_CONTAINER_PROCESS_OPTIONS_INTERNAL must be 8-byte aligned"); | ||
|
|
||
| static_assert( | ||
| std::is_trivial_v<WSLC_CONTAINER_PROCESS_OPTIONS_INTERNAL>, "WSLC_CONTAINER_PROCESS_OPTIONS_INTERNAL must be trivial"); | ||
|
|
||
| WSLC_CONTAINER_PROCESS_OPTIONS_INTERNAL* GetInternalType(WslcProcessSettings* settings); | ||
|
|
||
| // CONTAINER DEFINITIONS | ||
| typedef struct WSLC_CONTAINER_OPTIONS_INTERNAL | ||
| { | ||
|
|
@@ -76,24 +85,47 @@ typedef struct WSLC_CONTAINER_OPTIONS_INTERNAL | |
| WslcContainerFlags containerFlags; | ||
|
|
||
| } WSLC_CONTAINER_OPTIONS_INTERNAL; | ||
|
|
||
| static_assert( | ||
| sizeof(WSLC_CONTAINER_OPTIONS_INTERNAL) == WSLC_CONTAINER_OPTIONS_SIZE, "WSLC_CONTAINER_OPTIONS_INTERNAL must be 80 bytes"); | ||
| static_assert( | ||
| __alignof(WSLC_CONTAINER_OPTIONS_INTERNAL) == WSLC_CONTAINER_OPTIONS_ALIGNMENT, | ||
| "WSLC_CONTAINER_OPTIONS_INTERNAL must be 8-byte aligned"); | ||
|
|
||
| static_assert(std::is_trivial_v<WSLC_CONTAINER_OPTIONS_INTERNAL>, "WSLC_CONTAINER_OPTIONS_INTERNAL must be trivial"); | ||
|
|
||
| WSLC_CONTAINER_OPTIONS_INTERNAL* GetInternalType(WslcContainerSettings* settings); | ||
|
|
||
| // Use to allocate the actual objects on the heap to keep it alive. | ||
| struct WslcSessionImpl | ||
| { | ||
| wil::com_ptr<IWSLASessionManager> sessionManager; | ||
| wil::com_ptr<IWSLASession> session; | ||
| wil::com_ptr<ITerminationCallback> terminationCallback; | ||
| }; | ||
|
|
||
| WslcSessionImpl* GetInternalType(WslcSession handle); | ||
|
|
||
| struct WslcContainerImpl | ||
| { | ||
| wil::com_ptr<IWSLAContainer> container; | ||
| }; | ||
|
|
||
| WslcContainerImpl* GetInternalType(WslcContainer handle); | ||
|
|
||
| struct WslcProcessImpl | ||
| { | ||
| wil::com_ptr<IWSLAProcess> process; | ||
| }; | ||
|
|
||
| WslcProcessImpl* GetInternalType(WslcProcess handle); | ||
|
|
||
| // Converts to the internal type and returns an error on null input. | ||
| #define WSLC_GET_INTERNAL_TYPE(_input_) \ | ||
| GetInternalType(_input_); \ | ||
| RETURN_HR_IF_NULL(E_POINTER, _input_) | ||
|
|
||
|
Comment on lines
+122
to
+126
|
||
| // Converts to a unique_ptr of the internal type and returns an error on null input. | ||
| // Use for Release functions to clean up the implementation object on return. | ||
| #define WSLC_GET_INTERNAL_TYPE_FOR_RELEASE(_input_) \ | ||
| std::unique_ptr<std::remove_pointer_t<decltype(GetInternalType(_input_))>>{GetInternalType(_input_)}; \ | ||
| RETURN_HR_IF_NULL(E_POINTER, _input_)\ | ||
|
Comment on lines
+127
to
+131
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Header include casing is inconsistent with the actual filename (
WslcsdkPrivate.h). Using#include "wslcsdkprivate.h"can break builds on case-sensitive filesystems/tools. Please match the on-disk casing consistently across the project.