Signed-off-by: John Howard <John.Howard@microsoft.com>
| ... | ... |
@@ -12,7 +12,7 @@ clone git github.com/go-check/check 64131543e7896d5bcc6bd5a76287eb75ea96c673 |
| 12 | 12 |
clone git github.com/gorilla/context 14f550f51a |
| 13 | 13 |
clone git github.com/gorilla/mux e444e69cbd |
| 14 | 14 |
clone git github.com/kr/pty 5cf931ef8f |
| 15 |
-clone git github.com/microsoft/hcsshim 2f540b26beafc3d4aded4fc9799af261a1a91352 |
|
| 15 |
+clone git github.com/microsoft/hcsshim f674a70f1306dbe20b3a516bedd3285d85db60d9 |
|
| 16 | 16 |
clone git github.com/mistifyio/go-zfs v2.1.1 |
| 17 | 17 |
clone git github.com/natefinch/npipe 0938d701e50e580f5925c773055eb6d6b32a0cbc |
| 18 | 18 |
clone git github.com/tchap/go-patricia v2.1.0 |
| ... | ... |
@@ -23,19 +23,6 @@ func CreateComputeSystem(id string, configuration string) error {
|
| 23 | 23 |
return err |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
- /* |
|
| 27 |
- Example configuration JSON below. RootDevicePath MUST use \\ not \ as path |
|
| 28 |
- separator. TODO Windows: Update this JSON sample with final API. |
|
| 29 |
- |
|
| 30 |
- {
|
|
| 31 |
- "SystemType" : "Container", |
|
| 32 |
- "Name" : "ContainerName", |
|
| 33 |
- "RootDevicePath" : "C:\\Containers\\test", |
|
| 34 |
- "IsDummy" : true |
|
| 35 |
- } |
|
| 36 |
- |
|
| 37 |
- */ |
|
| 38 |
- |
|
| 39 | 26 |
// Convert id to uint16 pointers for calling the procedure |
| 40 | 27 |
idp, err := syscall.UTF16PtrFromString(id) |
| 41 | 28 |
if err != nil {
|
| ... | ... |
@@ -54,7 +54,7 @@ func CreateProcessInComputeSystem(id string, params CreateProcessParams) (proces |
| 54 | 54 |
|
| 55 | 55 |
paramsJson, err := json.Marshal(params) |
| 56 | 56 |
if err != nil {
|
| 57 |
- err = fmt.Errorf(title+" - Failed to marshall params %s %s", params, err) |
|
| 57 |
+ err = fmt.Errorf(title+" - Failed to marshall params %v %s", params, err) |
|
| 58 | 58 |
return 0, err |
| 59 | 59 |
} |
| 60 | 60 |
|
| ... | ... |
@@ -79,7 +79,7 @@ func CreateProcessInComputeSystem(id string, params CreateProcessParams) (proces |
| 79 | 79 |
use(unsafe.Pointer(paramsJsonp)) |
| 80 | 80 |
|
| 81 | 81 |
if r1 != 0 {
|
| 82 |
- err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s id=%s params=%s", r1, syscall.Errno(r1), id, params) |
|
| 82 |
+ err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s id=%s params=%v", r1, syscall.Errno(r1), id, params) |
|
| 83 | 83 |
logrus.Error(err) |
| 84 | 84 |
return 0, err |
| 85 | 85 |
} |
| ... | ... |
@@ -75,7 +75,7 @@ func GetLayerMountPath(info DriverInfo, id string) (string, error) {
|
| 75 | 75 |
use(unsafe.Pointer(idp)) |
| 76 | 76 |
|
| 77 | 77 |
if r1 != 0 {
|
| 78 |
- err = fmt.Errorf(title+" - Second Win32 API call returned error r1=%d errno=%d id=%s flavour=%d", |
|
| 78 |
+ err = fmt.Errorf(title+" - Second Win32 API call returned error r1=%d err=%s id=%s flavour=%d", |
|
| 79 | 79 |
r1, syscall.Errno(r1), id, info.Flavour) |
| 80 | 80 |
logrus.Error(err) |
| 81 | 81 |
return "", err |
| 82 | 82 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,53 @@ |
| 0 |
+package hcsshim |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "syscall" |
|
| 5 |
+ "unsafe" |
|
| 6 |
+ |
|
| 7 |
+ "github.com/Sirupsen/logrus" |
|
| 8 |
+) |
|
| 9 |
+ |
|
| 10 |
+func GetSharedBaseImages() (imageData string, err error) {
|
|
| 11 |
+ title := "hcsshim::GetSharedBaseImages " |
|
| 12 |
+ |
|
| 13 |
+ // Load the DLL and get a handle to the procedure we need |
|
| 14 |
+ dll, proc, err := loadAndFind(procGetSharedBaseImages) |
|
| 15 |
+ if dll != nil {
|
|
| 16 |
+ defer dll.Release() |
|
| 17 |
+ } |
|
| 18 |
+ if err != nil {
|
|
| 19 |
+ return |
|
| 20 |
+ } |
|
| 21 |
+ |
|
| 22 |
+ // Load the OLE DLL and get a handle to the CoTaskMemFree procedure |
|
| 23 |
+ dll2, proc2, err := loadAndFindFromDll(oleDLLName, procCoTaskMemFree) |
|
| 24 |
+ if dll2 != nil {
|
|
| 25 |
+ defer dll2.Release() |
|
| 26 |
+ } |
|
| 27 |
+ if err != nil {
|
|
| 28 |
+ return |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ var output uintptr |
|
| 32 |
+ |
|
| 33 |
+ // Call the procedure again |
|
| 34 |
+ logrus.Debugf("Calling proc")
|
|
| 35 |
+ r1, _, _ := proc.Call( |
|
| 36 |
+ uintptr(unsafe.Pointer(&output))) |
|
| 37 |
+ |
|
| 38 |
+ if r1 != 0 {
|
|
| 39 |
+ err = fmt.Errorf(title+" - Win32 API call returned error r1=%d errno=%s", |
|
| 40 |
+ r1, syscall.Errno(r1)) |
|
| 41 |
+ logrus.Error(err) |
|
| 42 |
+ return |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ // Defer the cleanup of the memory using CoTaskMemFree |
|
| 46 |
+ defer proc2.Call(output) |
|
| 47 |
+ |
|
| 48 |
+ imageData = syscall.UTF16ToString((*[1 << 30]uint16)(unsafe.Pointer(output))[:]) |
|
| 49 |
+ logrus.Debugf(title+" - succeeded output=%s", imageData) |
|
| 50 |
+ |
|
| 51 |
+ return |
|
| 52 |
+} |
| ... | ... |
@@ -26,43 +26,55 @@ const ( |
| 26 | 26 |
procResizeConsoleInComputeSystem = "ResizeConsoleInComputeSystem" |
| 27 | 27 |
|
| 28 | 28 |
// Storage related functions in the shim DLL |
| 29 |
- procLayerExists = "LayerExists" |
|
| 30 |
- procCreateLayer = "CreateLayer" |
|
| 31 |
- procDestroyLayer = "DestroyLayer" |
|
| 32 |
- procActivateLayer = "ActivateLayer" |
|
| 33 |
- procDeactivateLayer = "DeactivateLayer" |
|
| 34 |
- procGetLayerMountPath = "GetLayerMountPath" |
|
| 35 |
- procCopyLayer = "CopyLayer" |
|
| 36 |
- procCreateSandboxLayer = "CreateSandboxLayer" |
|
| 37 |
- procPrepareLayer = "PrepareLayer" |
|
| 38 |
- procUnprepareLayer = "UnprepareLayer" |
|
| 39 |
- procExportLayer = "ExportLayer" |
|
| 40 |
- procImportLayer = "ImportLayer" |
|
| 29 |
+ procLayerExists = "LayerExists" |
|
| 30 |
+ procCreateLayer = "CreateLayer" |
|
| 31 |
+ procDestroyLayer = "DestroyLayer" |
|
| 32 |
+ procActivateLayer = "ActivateLayer" |
|
| 33 |
+ procDeactivateLayer = "DeactivateLayer" |
|
| 34 |
+ procGetLayerMountPath = "GetLayerMountPath" |
|
| 35 |
+ procCopyLayer = "CopyLayer" |
|
| 36 |
+ procCreateSandboxLayer = "CreateSandboxLayer" |
|
| 37 |
+ procPrepareLayer = "PrepareLayer" |
|
| 38 |
+ procUnprepareLayer = "UnprepareLayer" |
|
| 39 |
+ procExportLayer = "ExportLayer" |
|
| 40 |
+ procImportLayer = "ImportLayer" |
|
| 41 |
+ procGetSharedBaseImages = "GetBaseImages" |
|
| 42 |
+ |
|
| 43 |
+ // Name of the standard OLE dll |
|
| 44 |
+ oleDLLName = "Ole32.dll" |
|
| 45 |
+ |
|
| 46 |
+ // Utility functions |
|
| 47 |
+ procCoTaskMemFree = "CoTaskMemFree" |
|
| 41 | 48 |
) |
| 42 | 49 |
|
| 43 |
-// loadAndFind finds a procedure in the DLL. Note we do NOT do lazy loading as |
|
| 50 |
+// loadAndFindFromDll finds a procedure in the given DLL. Note we do NOT do lazy loading as |
|
| 44 | 51 |
// go is particularly unfriendly in the case of a mismatch. By that - it panics |
| 45 | 52 |
// if a function can't be found. By explicitly loading, we can control error |
| 46 | 53 |
// handling gracefully without the daemon terminating. |
| 47 |
-func loadAndFind(procedure string) (dll *syscall.DLL, proc *syscall.Proc, err error) {
|
|
| 48 |
- |
|
| 49 |
- logrus.Debugf("hcsshim::loadAndFind %s", procedure)
|
|
| 54 |
+func loadAndFindFromDll(dllName, procedure string) (dll *syscall.DLL, proc *syscall.Proc, err error) {
|
|
| 55 |
+ logrus.Debugf("hcsshim::loadAndFindFromDll %s %s", dllName, procedure)
|
|
| 50 | 56 |
|
| 51 |
- dll, err = syscall.LoadDLL(shimDLLName) |
|
| 57 |
+ dll, err = syscall.LoadDLL(dllName) |
|
| 52 | 58 |
if err != nil {
|
| 53 |
- err = fmt.Errorf("Failed to load %s - error %s", shimDLLName, err)
|
|
| 59 |
+ err = fmt.Errorf("Failed to load %s - error %s", dllName, err)
|
|
| 54 | 60 |
logrus.Error(err) |
| 55 |
- return nil, nil, err |
|
| 61 |
+ return |
|
| 56 | 62 |
} |
| 57 | 63 |
|
| 58 | 64 |
proc, err = dll.FindProc(procedure) |
| 59 | 65 |
if err != nil {
|
| 60 |
- err = fmt.Errorf("Failed to find %s in %s", procedure, shimDLLName)
|
|
| 66 |
+ err = fmt.Errorf("Failed to find %s in %s", procedure, dllName)
|
|
| 61 | 67 |
logrus.Error(err) |
| 62 |
- return nil, nil, err |
|
| 68 |
+ return |
|
| 63 | 69 |
} |
| 64 | 70 |
|
| 65 |
- return dll, proc, nil |
|
| 71 |
+ return |
|
| 72 |
+} |
|
| 73 |
+ |
|
| 74 |
+// loadAndFind finds a procedure in the shim DLL. |
|
| 75 |
+func loadAndFind(procedure string) (*syscall.DLL, *syscall.Proc, error) {
|
|
| 76 |
+ |
|
| 77 |
+ return loadAndFindFromDll(shimDLLName, procedure) |
|
| 66 | 78 |
} |
| 67 | 79 |
|
| 68 | 80 |
// use is a no-op, but the compiler cannot see that it is. |