Implement SDK Import and shared file spec#14451
Implement SDK Import and shared file spec#14451JohnMcPMS merged 11 commits intomicrosoft:feature/wsl-for-appsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a shared “image file specifier” to the WSLC SDK so Load and Import can accept either a file path or a (HANDLE, length) pair, and implements WslcImportSessionImage end-to-end.
Changes:
- Introduces
WslcImageFileSpecifier/WslcImageFileContentand updatesWslcLoadImageOptions/WslcImportImageOptionsto use it. - Implements
WslcImportSessionImageand refactorsWslcLoadSessionImageto normalize inputs via a shared resolver. - Updates/extends Windows SDK tests to cover load/import via both path and handle+length, plus negative cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/windows/WslcSdkTests.cpp | Updates Load tests to use imageFile specifier; adds new Import coverage (path + handle). |
| src/windows/WslcSDK/wslcsdk.h | Adds shared file specifier structs and updates public option structs (Import/Load). |
| src/windows/WslcSDK/wslcsdk.cpp | Implements Import and adds a shared resolver that converts path → handle+length for runtime calls. |
There was a problem hiding this comment.
Pull request overview
This PR extends the WSLC SDK image import/load APIs to accept a shared “file specifier” (path or HANDLE+length) and wires up the previously unimplemented WslcImportSessionImage to the underlying session runtime, with updated SDK tests to validate both input modes.
Changes:
- Introduces
WslcImageFileSpecifier/WslcImageFileContentand updatesWslcLoadImageOptionsandWslcImportImageOptionsto use the shared file spec. - Implements
WslcImportSessionImageand normalizes both Import/Load to HANDLE+length via a shared resolver. - Updates/expands Windows SDK tests for Load and new Import coverage (path and handle variants, plus negative cases).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/windows/WslcSdkTests.cpp | Updates Load tests to use the shared file specifier and adds new Import tests (positive + negative). |
| src/windows/WslcSDK/wslcsdk.h | Adds the shared image file spec structs and updates Import/Load option structs accordingly. |
| src/windows/WslcSDK/wslcsdk.cpp | Implements Import and adds ImageFileResolver to normalize path/handle inputs for Import and Load. |
There was a problem hiding this comment.
Pull request overview
This PR updates the WSLC SDK image load/import APIs to support both file-path and HANDLE+length inputs, and implements image import by normalizing inputs to a shared HANDLE+length path used by the runtime.
Changes:
- Implement
WslcImportSessionImageand add...FromFileentrypoints for both Import and Load. - Refactor file input handling via a shared resolver that normalizes file paths to HANDLE+length.
- Update SDK tests to cover the new Import/Load entrypoints and negative cases.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WslcSdkTests.cpp | Updates tests to use new Load/Import APIs and adds new Import coverage. |
| src/windows/WslcSDK/wslcsdk.h | Changes public SDK API signatures for Load/Import and adds ...FromFile declarations. |
| src/windows/WslcSDK/wslcsdk.def | Exports the new ...FromFile SDK entrypoints. |
| src/windows/WslcSDK/wslcsdk.cpp | Implements Import and adds shared file normalization logic + new ...FromFile functions. |
| src/windows/WslcSDK/ProgressCallback.h | Makes progress callback creation safe when options == nullptr. |
|
|
||
| // Negative: zero ContentLength must fail. | ||
| VERIFY_ARE_EQUAL(WslcImportSessionImage(m_defaultSession, "zero-length:test", GetCurrentThreadEffectiveToken(), 0, &opts, nullptr), E_INVALIDARG); | ||
| } |
There was a problem hiding this comment.
nit: We should validate that fail with E_FAIL or similar if the caller tries to important an invalid file
There was a problem hiding this comment.
Added duplicate of the load version... and it successfully fails even though load still "succeeds" despite their very common code paths...
There was a problem hiding this comment.
Hmm what do you mean by 'load still "succeeds" ' ? Are you saying that there are code paths where we don't correctly detect errors ?
There was a problem hiding this comment.
The test LoadImageNonTar and new ImportImageNonTar pass the current executable/module to construct the image. Import fails as expected. Load has always not failed, but not had any effect on the image list either.
If I shell into the session and run docker load with bad files it does return error strings. But when we call the engine it is just returning a 200 while ignoring the input (when I last debugged it).
There was a problem hiding this comment.
Ok this is a runtime bug. I'll look into it
There was a problem hiding this comment.
Here's the fix for that broken behavior: https://github.com/microsoft/WSL/pull/14483/changes
Feel free to merge now and do this as a followup once the runtime fix is merged
OneBlue
left a comment
There was a problem hiding this comment.
LGTM, one nit question in the tests
| VERIFY_ARE_EQUAL(WslcLoadSessionImage(m_defaultSession, INVALID_HANDLE_VALUE, 1, &opts, nullptr), E_INVALIDARG); | ||
|
|
||
| // Negative: zero ContentLength must fail. | ||
| VERIFY_ARE_EQUAL(WslcLoadSessionImage(m_defaultSession, GetCurrentThreadEffectiveToken(), 0, &opts, nullptr), E_INVALIDARG); |
There was a problem hiding this comment.
What's the reason for passing GetCurrentThreadEffectiveToken() ? Are we just trying to get any valid handle here ?
There was a problem hiding this comment.
Yes, because GetCurrentProcess uses INVALID_HANDLE_VALUE as its pseudo-handle and I wanted something that I knew would be guaranteed to be a real HANDLE.
Summary of the Pull Request
Allow both Import and Load to take in file path or HANDLE and implement Import.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Move both Import and Load options to use a shared file specification structure that can accept a path or HANDLE+length. Add image name to import options. Implement Import and Load using a shared path to normalize to HANDLE+length for runtime usage.
Validation Steps Performed
New tests.