|
543 | 543 | containerOptions.VolumesCount = static_cast<ULONG>(internalContainerSettings->volumesCount); |
544 | 544 | } |
545 | 545 |
|
546 | | - std::unique_ptr<WSLCPortMapping[]> convertedPorts; |
547 | | - if (internalContainerSettings->ports && internalContainerSettings->portsCount) |
548 | | - { |
549 | | - convertedPorts = std::make_unique<WSLCPortMapping[]>(internalContainerSettings->portsCount); |
550 | | - for (uint32_t i = 0; i < internalContainerSettings->portsCount; ++i) |
551 | | - { |
552 | | - const WslcContainerPortMapping& internalPort = internalContainerSettings->ports[i]; |
553 | | - WSLCPortMapping& convertedPort = convertedPorts[i]; |
554 | | - |
555 | | - convertedPort.HostPort = internalPort.windowsPort; |
556 | | - convertedPort.ContainerPort = internalPort.containerPort; |
557 | | - |
558 | | - // TODO: Ipv6 & custom binding address support. |
559 | | - convertedPort.Family = AF_INET; |
560 | | - |
561 | | - // TODO: Consider using standard protocol numbers instead of our own enum. |
562 | | - convertedPort.Protocol = internalPort.protocol == WSLC_PORT_PROTOCOL_TCP ? IPPROTO_TCP : IPPROTO_UDP; |
563 | | - convertedPort.BindingAddress = "127.0.0.1"; |
564 | | - } |
565 | | - containerOptions.Ports = convertedPorts.get(); |
566 | | - containerOptions.PortsCount = static_cast<ULONG>(internalContainerSettings->portsCount); |
567 | | - } |
568 | | - |
569 | | - containerOptions.ContainerNetwork.ContainerNetworkType = internalContainerSettings->networking; |
570 | | - |
571 | | - // TODO: No user access |
572 | | - // containerOptions.Entrypoint; |
573 | | - // containerOptions.Labels; |
574 | | - // containerOptions.LabelsCount; |
575 | | - // containerOptions.StopSignal; |
576 | | - // containerOptions.ShmSize; |
577 | | - |
578 | | - if (SUCCEEDED(errorInfoWrapper.CaptureResult(internalSession->session->CreateContainer(&containerOptions, &result->container)))) |
579 | | - { |
580 | | - wsl::windows::common::security::ConfigureForCOMImpersonation(result->container.get()); |
581 | | - |
582 | | - if (IOCallback::HasIOCallback(internalContainerSettings->initProcessOptions)) |
583 | | - { |
584 | | - result->ioCallbackOptions = internalContainerSettings->initProcessOptions->ioCallbacks; |
585 | | - } |
586 | | - |
587 | | - *container = reinterpret_cast<WslcContainer>(result.release()); |
588 | | - } |
589 | | - |
590 | | - return errorInfoWrapper; |
591 | | -} |
592 | | -CATCH_RETURN(); |
593 | | - |
594 | | -STDAPI WslcStartContainer(_In_ WslcContainer container, _In_ WslcContainerStartFlags flags, _Outptr_opt_result_z_ PWSTR* errorMessage) |
595 | | -try |
596 | | -{ |
597 | | - RETURN_HR_IF_NULL(E_POINTER, container); |
598 | | - *container = nullptr; |
599 | | - ErrorInfoWrapper errorInfoWrapper{errorMessage}; |
600 | | - auto internalSession = CheckAndGetInternalType(session); |
601 | | - RETURN_HR_IF_NULL(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), internalSession->session); |
602 | | - auto internalContainerSettings = CheckAndGetInternalType(containerSettings); |
603 | | - |
604 | | - auto result = std::make_unique<WslcContainerImpl>(); |
605 | | - |
606 | | - WSLCContainerOptions containerOptions{}; |
607 | | - containerOptions.Image = internalContainerSettings->image; |
608 | | - containerOptions.Name = internalContainerSettings->runtimeName; |
609 | | - containerOptions.HostName = internalContainerSettings->HostName; |
610 | | - containerOptions.DomainName = internalContainerSettings->DomainName; |
611 | | - containerOptions.Flags = ConvertFlags(internalContainerSettings->containerFlags); |
612 | | - |
613 | | - CopyProcessSettingsToRuntime(containerOptions.InitProcessOptions, internalContainerSettings->initProcessOptions); |
614 | | - |
615 | | - std::unique_ptr<WSLCVolume[]> convertedVolumes; |
616 | | - if (internalContainerSettings->volumes && internalContainerSettings->volumesCount) |
617 | | - { |
618 | | - convertedVolumes = std::make_unique<WSLCVolume[]>(internalContainerSettings->volumesCount); |
619 | | - for (uint32_t i = 0; i < internalContainerSettings->volumesCount; ++i) |
620 | | - { |
621 | | - const WslcContainerVolume& internalVolume = internalContainerSettings->volumes[i]; |
622 | | - WSLCVolume& convertedVolume = convertedVolumes[i]; |
623 | | - |
624 | | - convertedVolume.HostPath = internalVolume.windowsPath; |
625 | | - convertedVolume.ContainerPath = internalVolume.containerPath; |
626 | | - convertedVolume.ReadOnly = internalVolume.readOnly; |
627 | | - } |
628 | | - containerOptions.Volumes = convertedVolumes.get(); |
629 | | - containerOptions.VolumesCount = static_cast<ULONG>(internalContainerSettings->volumesCount); |
630 | | - } |
631 | | - |
632 | 546 | std::unique_ptr<WSLCPortMapping[]> convertedPorts; |
633 | 547 | std::vector<std::string> bindingAddressStrings; |
634 | 548 | if (internalContainerSettings->ports && internalContainerSettings->portsCount) |
|
699 | 613 | } |
700 | 614 | CATCH_RETURN(); |
701 | 615 |
|
| 616 | +STDAPI WslcStartContainer(_In_ WslcContainer container, _In_ WslcContainerStartFlags flags, _Outptr_opt_result_z_ PWSTR* errorMessage) |
| 617 | +try |
| 618 | +{ |
| 619 | + ErrorInfoWrapper errorInfoWrapper{errorMessage}; |
| 620 | + auto internalType = CheckAndGetInternalType(container); |
| 621 | + RETURN_HR_IF_NULL(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), internalType->container); |
| 622 | + |
| 623 | + bool hasIOCallback = IOCallback::HasIOCallback(internalType->ioCallbackOptions); |
| 624 | + // If callbacks were provided, ATTACH must be used. |
| 625 | + // TODO: Consider if we should just override flags when callbacks were provided instead. |
| 626 | + RETURN_HR_IF(E_INVALIDARG, WI_IsFlagClear(flags, WSLC_CONTAINER_START_FLAG_ATTACH) && hasIOCallback); |
| 627 | + |
| 628 | + if (SUCCEEDED(errorInfoWrapper.CaptureResult(internalType->container->Start(ConvertFlags(flags), nullptr)))) |
| 629 | + { |
| 630 | + if (hasIOCallback) |
| 631 | + { |
| 632 | + wil::com_ptr<IWSLCProcess> process; |
| 633 | + RETURN_IF_FAILED(internalType->container->GetInitProcess(&process)); |
| 634 | + wsl::windows::common::security::ConfigureForCOMImpersonation(process.get()); |
| 635 | + internalType->ioCallbacks = std::make_shared<IOCallback>(process.get(), internalType->ioCallbackOptions); |
| 636 | + } |
| 637 | + } |
| 638 | + |
| 639 | + return errorInfoWrapper; |
| 640 | +} |
| 641 | +CATCH_RETURN(); |
| 642 | + |
702 | 643 | STDAPI WslcSetContainerSettingsFlags(_In_ WslcContainerSettings* containerSettings, _In_ WslcContainerFlags flags) |
703 | 644 | try |
704 | 645 | { |
|
0 commit comments