Browse code

Vendor Microsoft/hcsshim @ v0.8.6

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2019/02/06 02:52:31
Showing 37 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 # the following lines are in sorted order, FYI
2 2
 github.com/Azure/go-ansiterm d6e3b3328b783f23731bc4d058875b0371ff8109
3
-github.com/Microsoft/hcsshim v0.8.3
3
+github.com/Microsoft/hcsshim v0.8.6
4 4
 github.com/Microsoft/go-winio v0.4.11
5 5
 github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
6 6
 github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
... ...
@@ -1,6 +1,8 @@
1 1
 package guestrequest
2 2
 
3
-import "github.com/Microsoft/hcsshim/internal/schema2"
3
+import (
4
+	"github.com/Microsoft/hcsshim/internal/schema2"
5
+)
4 6
 
5 7
 // Arguably, many of these (at least CombinedLayers) should have been generated
6 8
 // by swagger.
... ...
@@ -47,6 +49,19 @@ type LCOWMappedVPMemDevice struct {
47 47
 	MountPath    string `json:"MountPath,omitempty"` // /tmp/pN
48 48
 }
49 49
 
50
+type LCOWNetworkAdapter struct {
51
+	NamespaceID     string `json:",omitempty"`
52
+	ID              string `json:",omitempty"`
53
+	MacAddress      string `json:",omitempty"`
54
+	IPAddress       string `json:",omitempty"`
55
+	PrefixLength    uint8  `json:",omitempty"`
56
+	GatewayAddress  string `json:",omitempty"`
57
+	DNSSuffix       string `json:",omitempty"`
58
+	DNSServerList   string `json:",omitempty"`
59
+	EnableLowMetric bool   `json:",omitempty"`
60
+	EncapOverhead   uint16 `json:",omitempty"`
61
+}
62
+
50 63
 type ResourceType string
51 64
 
52 65
 const (
... ...
@@ -16,11 +16,20 @@ var (
16 16
 	notificationWatcherCallback = syscall.NewCallback(notificationWatcher)
17 17
 
18 18
 	// Notifications for HCS_SYSTEM handles
19
-	hcsNotificationSystemExited          hcsNotification = 0x00000001
20
-	hcsNotificationSystemCreateCompleted hcsNotification = 0x00000002
21
-	hcsNotificationSystemStartCompleted  hcsNotification = 0x00000003
22
-	hcsNotificationSystemPauseCompleted  hcsNotification = 0x00000004
23
-	hcsNotificationSystemResumeCompleted hcsNotification = 0x00000005
19
+	hcsNotificationSystemExited                      hcsNotification = 0x00000001
20
+	hcsNotificationSystemCreateCompleted             hcsNotification = 0x00000002
21
+	hcsNotificationSystemStartCompleted              hcsNotification = 0x00000003
22
+	hcsNotificationSystemPauseCompleted              hcsNotification = 0x00000004
23
+	hcsNotificationSystemResumeCompleted             hcsNotification = 0x00000005
24
+	hcsNotificationSystemCrashReport                 hcsNotification = 0x00000006
25
+	hcsNotificationSystemSiloJobCreated              hcsNotification = 0x00000007
26
+	hcsNotificationSystemSaveCompleted               hcsNotification = 0x00000008
27
+	hcsNotificationSystemRdpEnhancedModeStateChanged hcsNotification = 0x00000009
28
+	hcsNotificationSystemShutdownFailed              hcsNotification = 0x0000000A
29
+	hcsNotificationSystemGetPropertiesCompleted      hcsNotification = 0x0000000B
30
+	hcsNotificationSystemModifyCompleted             hcsNotification = 0x0000000C
31
+	hcsNotificationSystemCrashInitiated              hcsNotification = 0x0000000D
32
+	hcsNotificationSystemGuestConnectionClosed       hcsNotification = 0x0000000E
24 33
 
25 34
 	// Notifications for HCS_PROCESS handles
26 35
 	hcsNotificationProcessExited hcsNotification = 0x00010000
... ...
@@ -50,16 +59,23 @@ func newChannels() notificationChannels {
50 50
 	channels[hcsNotificationSystemResumeCompleted] = make(notificationChannel, 1)
51 51
 	channels[hcsNotificationProcessExited] = make(notificationChannel, 1)
52 52
 	channels[hcsNotificationServiceDisconnect] = make(notificationChannel, 1)
53
+	channels[hcsNotificationSystemCrashReport] = make(notificationChannel, 1)
54
+	channels[hcsNotificationSystemSiloJobCreated] = make(notificationChannel, 1)
55
+	channels[hcsNotificationSystemSaveCompleted] = make(notificationChannel, 1)
56
+	channels[hcsNotificationSystemRdpEnhancedModeStateChanged] = make(notificationChannel, 1)
57
+	channels[hcsNotificationSystemShutdownFailed] = make(notificationChannel, 1)
58
+	channels[hcsNotificationSystemGetPropertiesCompleted] = make(notificationChannel, 1)
59
+	channels[hcsNotificationSystemModifyCompleted] = make(notificationChannel, 1)
60
+	channels[hcsNotificationSystemCrashInitiated] = make(notificationChannel, 1)
61
+	channels[hcsNotificationSystemGuestConnectionClosed] = make(notificationChannel, 1)
62
+
53 63
 	return channels
54 64
 }
65
+
55 66
 func closeChannels(channels notificationChannels) {
56
-	close(channels[hcsNotificationSystemExited])
57
-	close(channels[hcsNotificationSystemCreateCompleted])
58
-	close(channels[hcsNotificationSystemStartCompleted])
59
-	close(channels[hcsNotificationSystemPauseCompleted])
60
-	close(channels[hcsNotificationSystemResumeCompleted])
61
-	close(channels[hcsNotificationProcessExited])
62
-	close(channels[hcsNotificationServiceDisconnect])
67
+	for _, c := range channels {
68
+		close(c)
69
+	}
63 70
 }
64 71
 
65 72
 func notificationWatcher(notificationType hcsNotification, callbackNumber uintptr, notificationStatus uintptr, notificationData *uint16) uintptr {
... ...
@@ -73,6 +73,9 @@ var (
73 73
 	// ErrVmcomputeUnknownMessage is an error encountered guest compute system doesn't support the message
74 74
 	ErrVmcomputeUnknownMessage = syscall.Errno(0xc037010b)
75 75
 
76
+	// ErrVmcomputeUnexpectedExit is an error encountered when the compute system terminates unexpectedly
77
+	ErrVmcomputeUnexpectedExit = syscall.Errno(0xC0370106)
78
+
76 79
 	// ErrNotSupported is an error encountered when hcs doesn't support the request
77 80
 	ErrPlatformNotSupported = errors.New("unsupported platform request")
78 81
 )
... ...
@@ -7,9 +7,14 @@ func logOperationBegin(ctx logrus.Fields, msg string) {
7 7
 }
8 8
 
9 9
 func logOperationEnd(ctx logrus.Fields, msg string, err error) {
10
+	// Copy the log and fields first.
11
+	log := logrus.WithFields(ctx)
10 12
 	if err == nil {
11
-		logrus.WithFields(ctx).Debug(msg)
13
+		log.Debug(msg)
12 14
 	} else {
13
-		logrus.WithFields(ctx).WithError(err).Error(msg)
15
+		// Edit only the copied field data to avoid race conditions on the
16
+		// write.
17
+		log.Data[logrus.ErrorKey] = err
18
+		log.Error(msg)
14 19
 	}
15 20
 }
... ...
@@ -31,9 +31,8 @@ func newProcess(process hcsProcess, processID int, computeSystem *System) *Proce
31 31
 		processID: processID,
32 32
 		system:    computeSystem,
33 33
 		logctx: logrus.Fields{
34
-			logfields.HCSOperation: "",
35
-			logfields.ContainerID:  computeSystem.ID(),
36
-			logfields.ProcessID:    processID,
34
+			logfields.ContainerID: computeSystem.ID(),
35
+			logfields.ProcessID:   processID,
37 36
 		},
38 37
 	}
39 38
 }
... ...
@@ -88,13 +87,12 @@ func (process *Process) SystemID() string {
88 88
 }
89 89
 
90 90
 func (process *Process) logOperationBegin(operation string) {
91
-	process.logctx[logfields.HCSOperation] = operation
92 91
 	logOperationBegin(
93 92
 		process.logctx,
94
-		"hcsshim::Process - Begin Operation")
93
+		operation+" - Begin Operation")
95 94
 }
96 95
 
97
-func (process *Process) logOperationEnd(err error) {
96
+func (process *Process) logOperationEnd(operation string, err error) {
98 97
 	var result string
99 98
 	if err == nil {
100 99
 		result = "Success"
... ...
@@ -104,9 +102,8 @@ func (process *Process) logOperationEnd(err error) {
104 104
 
105 105
 	logOperationEnd(
106 106
 		process.logctx,
107
-		"hcsshim::Process - End Operation - "+result,
107
+		operation+" - End Operation - "+result,
108 108
 		err)
109
-	process.logctx[logfields.HCSOperation] = ""
110 109
 }
111 110
 
112 111
 // Signal signals the process with `options`.
... ...
@@ -116,7 +113,7 @@ func (process *Process) Signal(options guestrequest.SignalProcessOptions) (err e
116 116
 
117 117
 	operation := "hcsshim::Process::Signal"
118 118
 	process.logOperationBegin(operation)
119
-	defer process.logOperationEnd(err)
119
+	defer func() { process.logOperationEnd(operation, err) }()
120 120
 
121 121
 	if process.handle == 0 {
122 122
 		return makeProcessError(process, operation, ErrAlreadyClosed, nil)
... ...
@@ -130,10 +127,9 @@ func (process *Process) Signal(options guestrequest.SignalProcessOptions) (err e
130 130
 	optionsStr := string(optionsb)
131 131
 
132 132
 	var resultp *uint16
133
-	completed := false
134
-	go syscallWatcher(process.logctx, &completed)
135
-	err = hcsSignalProcess(process.handle, optionsStr, &resultp)
136
-	completed = true
133
+	syscallWatcher(process.logctx, func() {
134
+		err = hcsSignalProcess(process.handle, optionsStr, &resultp)
135
+	})
137 136
 	events := processHcsResult(resultp)
138 137
 	if err != nil {
139 138
 		return makeProcessError(process, operation, err, events)
... ...
@@ -149,17 +145,16 @@ func (process *Process) Kill() (err error) {
149 149
 
150 150
 	operation := "hcsshim::Process::Kill"
151 151
 	process.logOperationBegin(operation)
152
-	defer process.logOperationEnd(err)
152
+	defer func() { process.logOperationEnd(operation, err) }()
153 153
 
154 154
 	if process.handle == 0 {
155 155
 		return makeProcessError(process, operation, ErrAlreadyClosed, nil)
156 156
 	}
157 157
 
158 158
 	var resultp *uint16
159
-	completed := false
160
-	go syscallWatcher(process.logctx, &completed)
161
-	err = hcsTerminateProcess(process.handle, &resultp)
162
-	completed = true
159
+	syscallWatcher(process.logctx, func() {
160
+		err = hcsTerminateProcess(process.handle, &resultp)
161
+	})
163 162
 	events := processHcsResult(resultp)
164 163
 	if err != nil {
165 164
 		return makeProcessError(process, operation, err, events)
... ...
@@ -172,7 +167,7 @@ func (process *Process) Kill() (err error) {
172 172
 func (process *Process) Wait() (err error) {
173 173
 	operation := "hcsshim::Process::Wait"
174 174
 	process.logOperationBegin(operation)
175
-	defer process.logOperationEnd(err)
175
+	defer func() { process.logOperationEnd(operation, err) }()
176 176
 
177 177
 	err = waitForNotification(process.callbackNumber, hcsNotificationProcessExited, nil)
178 178
 	if err != nil {
... ...
@@ -187,7 +182,7 @@ func (process *Process) Wait() (err error) {
187 187
 func (process *Process) WaitTimeout(timeout time.Duration) (err error) {
188 188
 	operation := "hcssshim::Process::WaitTimeout"
189 189
 	process.logOperationBegin(operation)
190
-	defer process.logOperationEnd(err)
190
+	defer func() { process.logOperationEnd(operation, err) }()
191 191
 
192 192
 	err = waitForNotification(process.callbackNumber, hcsNotificationProcessExited, &timeout)
193 193
 	if err != nil {
... ...
@@ -204,7 +199,7 @@ func (process *Process) ResizeConsole(width, height uint16) (err error) {
204 204
 
205 205
 	operation := "hcsshim::Process::ResizeConsole"
206 206
 	process.logOperationBegin(operation)
207
-	defer process.logOperationEnd(err)
207
+	defer func() { process.logOperationEnd(operation, err) }()
208 208
 
209 209
 	if process.handle == 0 {
210 210
 		return makeProcessError(process, operation, ErrAlreadyClosed, nil)
... ...
@@ -241,7 +236,7 @@ func (process *Process) Properties() (_ *ProcessStatus, err error) {
241 241
 
242 242
 	operation := "hcsshim::Process::Properties"
243 243
 	process.logOperationBegin(operation)
244
-	defer process.logOperationEnd(err)
244
+	defer func() { process.logOperationEnd(operation, err) }()
245 245
 
246 246
 	if process.handle == 0 {
247 247
 		return nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
... ...
@@ -251,10 +246,9 @@ func (process *Process) Properties() (_ *ProcessStatus, err error) {
251 251
 		resultp     *uint16
252 252
 		propertiesp *uint16
253 253
 	)
254
-	completed := false
255
-	go syscallWatcher(process.logctx, &completed)
256
-	err = hcsGetProcessProperties(process.handle, &propertiesp, &resultp)
257
-	completed = true
254
+	syscallWatcher(process.logctx, func() {
255
+		err = hcsGetProcessProperties(process.handle, &propertiesp, &resultp)
256
+	})
258 257
 	events := processHcsResult(resultp)
259 258
 	if err != nil {
260 259
 		return nil, makeProcessError(process, operation, err, events)
... ...
@@ -278,7 +272,7 @@ func (process *Process) Properties() (_ *ProcessStatus, err error) {
278 278
 func (process *Process) ExitCode() (_ int, err error) {
279 279
 	operation := "hcsshim::Process::ExitCode"
280 280
 	process.logOperationBegin(operation)
281
-	defer process.logOperationEnd(err)
281
+	defer func() { process.logOperationEnd(operation, err) }()
282 282
 
283 283
 	properties, err := process.Properties()
284 284
 	if err != nil {
... ...
@@ -305,7 +299,7 @@ func (process *Process) Stdio() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadClo
305 305
 
306 306
 	operation := "hcsshim::Process::Stdio"
307 307
 	process.logOperationBegin(operation)
308
-	defer process.logOperationEnd(err)
308
+	defer func() { process.logOperationEnd(operation, err) }()
309 309
 
310 310
 	if process.handle == 0 {
311 311
 		return nil, nil, nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
... ...
@@ -349,7 +343,7 @@ func (process *Process) CloseStdin() (err error) {
349 349
 
350 350
 	operation := "hcsshim::Process::CloseStdin"
351 351
 	process.logOperationBegin(operation)
352
-	defer process.logOperationEnd(err)
352
+	defer func() { process.logOperationEnd(operation, err) }()
353 353
 
354 354
 	if process.handle == 0 {
355 355
 		return makeProcessError(process, operation, ErrAlreadyClosed, nil)
... ...
@@ -387,7 +381,7 @@ func (process *Process) Close() (err error) {
387 387
 
388 388
 	operation := "hcsshim::Process::Close"
389 389
 	process.logOperationBegin(operation)
390
-	defer process.logOperationEnd(err)
390
+	defer func() { process.logOperationEnd(operation, err) }()
391 391
 
392 392
 	// Don't double free this
393 393
 	if process.handle == 0 {
... ...
@@ -49,20 +49,18 @@ func newSystem(id string) *System {
49 49
 	return &System{
50 50
 		id: id,
51 51
 		logctx: logrus.Fields{
52
-			logfields.HCSOperation: "",
53
-			logfields.ContainerID:  id,
52
+			logfields.ContainerID: id,
54 53
 		},
55 54
 	}
56 55
 }
57 56
 
58 57
 func (computeSystem *System) logOperationBegin(operation string) {
59
-	computeSystem.logctx[logfields.HCSOperation] = operation
60 58
 	logOperationBegin(
61 59
 		computeSystem.logctx,
62
-		"hcsshim::ComputeSystem - Begin Operation")
60
+		operation+" - Begin Operation")
63 61
 }
64 62
 
65
-func (computeSystem *System) logOperationEnd(err error) {
63
+func (computeSystem *System) logOperationEnd(operation string, err error) {
66 64
 	var result string
67 65
 	if err == nil {
68 66
 		result = "Success"
... ...
@@ -72,9 +70,8 @@ func (computeSystem *System) logOperationEnd(err error) {
72 72
 
73 73
 	logOperationEnd(
74 74
 		computeSystem.logctx,
75
-		"hcsshim::ComputeSystem - End Operation - "+result,
75
+		operation+" - End Operation - "+result,
76 76
 		err)
77
-	computeSystem.logctx[logfields.HCSOperation] = ""
78 77
 }
79 78
 
80 79
 // CreateComputeSystem creates a new compute system with the given configuration but does not start it.
... ...
@@ -83,7 +80,7 @@ func CreateComputeSystem(id string, hcsDocumentInterface interface{}) (_ *System
83 83
 
84 84
 	computeSystem := newSystem(id)
85 85
 	computeSystem.logOperationBegin(operation)
86
-	defer computeSystem.logOperationEnd(err)
86
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
87 87
 
88 88
 	hcsDocumentB, err := json.Marshal(hcsDocumentInterface)
89 89
 	if err != nil {
... ...
@@ -97,13 +94,13 @@ func CreateComputeSystem(id string, hcsDocumentInterface interface{}) (_ *System
97 97
 		Debug("HCS ComputeSystem Document")
98 98
 
99 99
 	var (
100
-		resultp  *uint16
101
-		identity syscall.Handle
100
+		resultp     *uint16
101
+		identity    syscall.Handle
102
+		createError error
102 103
 	)
103
-	completed := false
104
-	go syscallWatcher(computeSystem.logctx, &completed)
105
-	createError := hcsCreateComputeSystem(id, hcsDocument, identity, &computeSystem.handle, &resultp)
106
-	completed = true
104
+	syscallWatcher(computeSystem.logctx, func() {
105
+		createError = hcsCreateComputeSystem(id, hcsDocument, identity, &computeSystem.handle, &resultp)
106
+	})
107 107
 
108 108
 	if createError == nil || IsPending(createError) {
109 109
 		if err = computeSystem.registerCallback(); err != nil {
... ...
@@ -133,7 +130,13 @@ func OpenComputeSystem(id string) (_ *System, err error) {
133 133
 
134 134
 	computeSystem := newSystem(id)
135 135
 	computeSystem.logOperationBegin(operation)
136
-	defer computeSystem.logOperationEnd(err)
136
+	defer func() {
137
+		if IsNotExist(err) {
138
+			computeSystem.logOperationEnd(operation, nil)
139
+		} else {
140
+			computeSystem.logOperationEnd(operation, err)
141
+		}
142
+	}()
137 143
 
138 144
 	var (
139 145
 		handle  hcsSystem
... ...
@@ -157,12 +160,10 @@ func OpenComputeSystem(id string) (_ *System, err error) {
157 157
 // GetComputeSystems gets a list of the compute systems on the system that match the query
158 158
 func GetComputeSystems(q schema1.ComputeSystemQuery) (_ []schema1.ContainerProperties, err error) {
159 159
 	operation := "hcsshim::GetComputeSystems"
160
-	fields := logrus.Fields{
161
-		logfields.HCSOperation: operation,
162
-	}
160
+	fields := logrus.Fields{}
163 161
 	logOperationBegin(
164 162
 		fields,
165
-		"hcsshim::ComputeSystem - Begin Operation")
163
+		operation+" - Begin Operation")
166 164
 
167 165
 	defer func() {
168 166
 		var result string
... ...
@@ -174,7 +175,7 @@ func GetComputeSystems(q schema1.ComputeSystemQuery) (_ []schema1.ContainerPrope
174 174
 
175 175
 		logOperationEnd(
176 176
 			fields,
177
-			"hcsshim::ComputeSystem - End Operation - "+result,
177
+			operation+" - End Operation - "+result,
178 178
 			err)
179 179
 	}()
180 180
 
... ...
@@ -193,10 +194,10 @@ func GetComputeSystems(q schema1.ComputeSystemQuery) (_ []schema1.ContainerPrope
193 193
 		resultp         *uint16
194 194
 		computeSystemsp *uint16
195 195
 	)
196
-	completed := false
197
-	go syscallWatcher(fields, &completed)
198
-	err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
199
-	completed = true
196
+
197
+	syscallWatcher(fields, func() {
198
+		err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
199
+	})
200 200
 	events := processHcsResult(resultp)
201 201
 	if err != nil {
202 202
 		return nil, &HcsError{Op: operation, Err: err, Events: events}
... ...
@@ -221,7 +222,7 @@ func (computeSystem *System) Start() (err error) {
221 221
 
222 222
 	operation := "hcsshim::ComputeSystem::Start"
223 223
 	computeSystem.logOperationBegin(operation)
224
-	defer computeSystem.logOperationEnd(err)
224
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
225 225
 
226 226
 	if computeSystem.handle == 0 {
227 227
 		return makeSystemError(computeSystem, "Start", "", ErrAlreadyClosed, nil)
... ...
@@ -254,10 +255,9 @@ func (computeSystem *System) Start() (err error) {
254 254
 	}
255 255
 
256 256
 	var resultp *uint16
257
-	completed := false
258
-	go syscallWatcher(computeSystem.logctx, &completed)
259
-	err = hcsStartComputeSystem(computeSystem.handle, "", &resultp)
260
-	completed = true
257
+	syscallWatcher(computeSystem.logctx, func() {
258
+		err = hcsStartComputeSystem(computeSystem.handle, "", &resultp)
259
+	})
261 260
 	events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
262 261
 	if err != nil {
263 262
 		return makeSystemError(computeSystem, "Start", "", err, events)
... ...
@@ -279,17 +279,22 @@ func (computeSystem *System) Shutdown() (err error) {
279 279
 
280 280
 	operation := "hcsshim::ComputeSystem::Shutdown"
281 281
 	computeSystem.logOperationBegin(operation)
282
-	defer computeSystem.logOperationEnd(err)
282
+	defer func() {
283
+		if IsAlreadyStopped(err) {
284
+			computeSystem.logOperationEnd(operation, nil)
285
+		} else {
286
+			computeSystem.logOperationEnd(operation, err)
287
+		}
288
+	}()
283 289
 
284 290
 	if computeSystem.handle == 0 {
285 291
 		return makeSystemError(computeSystem, "Shutdown", "", ErrAlreadyClosed, nil)
286 292
 	}
287 293
 
288 294
 	var resultp *uint16
289
-	completed := false
290
-	go syscallWatcher(computeSystem.logctx, &completed)
291
-	err = hcsShutdownComputeSystem(computeSystem.handle, "", &resultp)
292
-	completed = true
295
+	syscallWatcher(computeSystem.logctx, func() {
296
+		err = hcsShutdownComputeSystem(computeSystem.handle, "", &resultp)
297
+	})
293 298
 	events := processHcsResult(resultp)
294 299
 	if err != nil {
295 300
 		return makeSystemError(computeSystem, "Shutdown", "", err, events)
... ...
@@ -306,19 +311,24 @@ func (computeSystem *System) Terminate() (err error) {
306 306
 
307 307
 	operation := "hcsshim::ComputeSystem::Terminate"
308 308
 	computeSystem.logOperationBegin(operation)
309
-	defer computeSystem.logOperationEnd(err)
309
+	defer func() {
310
+		if IsPending(err) {
311
+			computeSystem.logOperationEnd(operation, nil)
312
+		} else {
313
+			computeSystem.logOperationEnd(operation, err)
314
+		}
315
+	}()
310 316
 
311 317
 	if computeSystem.handle == 0 {
312 318
 		return makeSystemError(computeSystem, "Terminate", "", ErrAlreadyClosed, nil)
313 319
 	}
314 320
 
315 321
 	var resultp *uint16
316
-	completed := false
317
-	go syscallWatcher(computeSystem.logctx, &completed)
318
-	err = hcsTerminateComputeSystem(computeSystem.handle, "", &resultp)
319
-	completed = true
322
+	syscallWatcher(computeSystem.logctx, func() {
323
+		err = hcsTerminateComputeSystem(computeSystem.handle, "", &resultp)
324
+	})
320 325
 	events := processHcsResult(resultp)
321
-	if err != nil {
326
+	if err != nil && err != ErrVmcomputeAlreadyStopped {
322 327
 		return makeSystemError(computeSystem, "Terminate", "", err, events)
323 328
 	}
324 329
 
... ...
@@ -329,7 +339,7 @@ func (computeSystem *System) Terminate() (err error) {
329 329
 func (computeSystem *System) Wait() (err error) {
330 330
 	operation := "hcsshim::ComputeSystem::Wait"
331 331
 	computeSystem.logOperationBegin(operation)
332
-	defer computeSystem.logOperationEnd(err)
332
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
333 333
 
334 334
 	err = waitForNotification(computeSystem.callbackNumber, hcsNotificationSystemExited, nil)
335 335
 	if err != nil {
... ...
@@ -339,12 +349,27 @@ func (computeSystem *System) Wait() (err error) {
339 339
 	return nil
340 340
 }
341 341
 
342
+// WaitExpectedError synchronously waits for the compute system to shutdown or
343
+// terminate, and ignores the passed error if it occurs.
344
+func (computeSystem *System) WaitExpectedError(expected error) (err error) {
345
+	operation := "hcsshim::ComputeSystem::WaitExpectedError"
346
+	computeSystem.logOperationBegin(operation)
347
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
348
+
349
+	err = waitForNotification(computeSystem.callbackNumber, hcsNotificationSystemExited, nil)
350
+	if err != nil && getInnerError(err) != expected {
351
+		return makeSystemError(computeSystem, "WaitExpectedError", "", err, nil)
352
+	}
353
+
354
+	return nil
355
+}
356
+
342 357
 // WaitTimeout synchronously waits for the compute system to terminate or the duration to elapse.
343 358
 // If the timeout expires, IsTimeout(err) == true
344 359
 func (computeSystem *System) WaitTimeout(timeout time.Duration) (err error) {
345 360
 	operation := "hcsshim::ComputeSystem::WaitTimeout"
346 361
 	computeSystem.logOperationBegin(operation)
347
-	defer computeSystem.logOperationEnd(err)
362
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
348 363
 
349 364
 	err = waitForNotification(computeSystem.callbackNumber, hcsNotificationSystemExited, &timeout)
350 365
 	if err != nil {
... ...
@@ -360,7 +385,7 @@ func (computeSystem *System) Properties(types ...schema1.PropertyType) (_ *schem
360 360
 
361 361
 	operation := "hcsshim::ComputeSystem::Properties"
362 362
 	computeSystem.logOperationBegin(operation)
363
-	defer computeSystem.logOperationEnd(err)
363
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
364 364
 
365 365
 	queryj, err := json.Marshal(schema1.PropertyQuery{types})
366 366
 	if err != nil {
... ...
@@ -372,10 +397,9 @@ func (computeSystem *System) Properties(types ...schema1.PropertyType) (_ *schem
372 372
 		Debug("HCS ComputeSystem Properties Query")
373 373
 
374 374
 	var resultp, propertiesp *uint16
375
-	completed := false
376
-	go syscallWatcher(computeSystem.logctx, &completed)
377
-	err = hcsGetComputeSystemProperties(computeSystem.handle, string(queryj), &propertiesp, &resultp)
378
-	completed = true
375
+	syscallWatcher(computeSystem.logctx, func() {
376
+		err = hcsGetComputeSystemProperties(computeSystem.handle, string(queryj), &propertiesp, &resultp)
377
+	})
379 378
 	events := processHcsResult(resultp)
380 379
 	if err != nil {
381 380
 		return nil, makeSystemError(computeSystem, "Properties", "", err, events)
... ...
@@ -400,17 +424,16 @@ func (computeSystem *System) Pause() (err error) {
400 400
 
401 401
 	operation := "hcsshim::ComputeSystem::Pause"
402 402
 	computeSystem.logOperationBegin(operation)
403
-	defer computeSystem.logOperationEnd(err)
403
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
404 404
 
405 405
 	if computeSystem.handle == 0 {
406 406
 		return makeSystemError(computeSystem, "Pause", "", ErrAlreadyClosed, nil)
407 407
 	}
408 408
 
409 409
 	var resultp *uint16
410
-	completed := false
411
-	go syscallWatcher(computeSystem.logctx, &completed)
412
-	err = hcsPauseComputeSystem(computeSystem.handle, "", &resultp)
413
-	completed = true
410
+	syscallWatcher(computeSystem.logctx, func() {
411
+		err = hcsPauseComputeSystem(computeSystem.handle, "", &resultp)
412
+	})
414 413
 	events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
415 414
 	if err != nil {
416 415
 		return makeSystemError(computeSystem, "Pause", "", err, events)
... ...
@@ -426,17 +449,16 @@ func (computeSystem *System) Resume() (err error) {
426 426
 
427 427
 	operation := "hcsshim::ComputeSystem::Resume"
428 428
 	computeSystem.logOperationBegin(operation)
429
-	defer computeSystem.logOperationEnd(err)
429
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
430 430
 
431 431
 	if computeSystem.handle == 0 {
432 432
 		return makeSystemError(computeSystem, "Resume", "", ErrAlreadyClosed, nil)
433 433
 	}
434 434
 
435 435
 	var resultp *uint16
436
-	completed := false
437
-	go syscallWatcher(computeSystem.logctx, &completed)
438
-	err = hcsResumeComputeSystem(computeSystem.handle, "", &resultp)
439
-	completed = true
436
+	syscallWatcher(computeSystem.logctx, func() {
437
+		err = hcsResumeComputeSystem(computeSystem.handle, "", &resultp)
438
+	})
440 439
 	events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
441 440
 	if err != nil {
442 441
 		return makeSystemError(computeSystem, "Resume", "", err, events)
... ...
@@ -452,7 +474,7 @@ func (computeSystem *System) CreateProcess(c interface{}) (_ *Process, err error
452 452
 
453 453
 	operation := "hcsshim::ComputeSystem::CreateProcess"
454 454
 	computeSystem.logOperationBegin(operation)
455
-	defer computeSystem.logOperationEnd(err)
455
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
456 456
 
457 457
 	var (
458 458
 		processInfo   hcsProcessInformation
... ...
@@ -475,10 +497,9 @@ func (computeSystem *System) CreateProcess(c interface{}) (_ *Process, err error
475 475
 		WithField(logfields.JSON, configuration).
476 476
 		Debug("HCS ComputeSystem Process Document")
477 477
 
478
-	completed := false
479
-	go syscallWatcher(computeSystem.logctx, &completed)
480
-	err = hcsCreateProcess(computeSystem.handle, configuration, &processInfo, &processHandle, &resultp)
481
-	completed = true
478
+	syscallWatcher(computeSystem.logctx, func() {
479
+		err = hcsCreateProcess(computeSystem.handle, configuration, &processInfo, &processHandle, &resultp)
480
+	})
482 481
 	events := processHcsResult(resultp)
483 482
 	if err != nil {
484 483
 		return nil, makeSystemError(computeSystem, "CreateProcess", configuration, err, events)
... ...
@@ -513,7 +534,7 @@ func (computeSystem *System) OpenProcess(pid int) (_ *Process, err error) {
513 513
 
514 514
 	operation := "hcsshim::ComputeSystem::OpenProcess"
515 515
 	computeSystem.logOperationBegin(operation)
516
-	defer computeSystem.logOperationEnd(err)
516
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
517 517
 
518 518
 	var (
519 519
 		processHandle hcsProcess
... ...
@@ -524,10 +545,9 @@ func (computeSystem *System) OpenProcess(pid int) (_ *Process, err error) {
524 524
 		return nil, makeSystemError(computeSystem, "OpenProcess", "", ErrAlreadyClosed, nil)
525 525
 	}
526 526
 
527
-	completed := false
528
-	go syscallWatcher(computeSystem.logctx, &completed)
529
-	err = hcsOpenProcess(computeSystem.handle, uint32(pid), &processHandle, &resultp)
530
-	completed = true
527
+	syscallWatcher(computeSystem.logctx, func() {
528
+		err = hcsOpenProcess(computeSystem.handle, uint32(pid), &processHandle, &resultp)
529
+	})
531 530
 	events := processHcsResult(resultp)
532 531
 	if err != nil {
533 532
 		return nil, makeSystemError(computeSystem, "OpenProcess", "", err, events)
... ...
@@ -548,7 +568,7 @@ func (computeSystem *System) Close() (err error) {
548 548
 
549 549
 	operation := "hcsshim::ComputeSystem::Close"
550 550
 	computeSystem.logOperationBegin(operation)
551
-	defer computeSystem.logOperationEnd(err)
551
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
552 552
 
553 553
 	// Don't double free this
554 554
 	if computeSystem.handle == 0 {
... ...
@@ -559,10 +579,9 @@ func (computeSystem *System) Close() (err error) {
559 559
 		return makeSystemError(computeSystem, "Close", "", err, nil)
560 560
 	}
561 561
 
562
-	completed := false
563
-	go syscallWatcher(computeSystem.logctx, &completed)
564
-	err = hcsCloseComputeSystem(computeSystem.handle)
565
-	completed = true
562
+	syscallWatcher(computeSystem.logctx, func() {
563
+		err = hcsCloseComputeSystem(computeSystem.handle)
564
+	})
566 565
 	if err != nil {
567 566
 		return makeSystemError(computeSystem, "Close", "", err, nil)
568 567
 	}
... ...
@@ -636,7 +655,7 @@ func (computeSystem *System) Modify(config interface{}) (err error) {
636 636
 
637 637
 	operation := "hcsshim::ComputeSystem::Modify"
638 638
 	computeSystem.logOperationBegin(operation)
639
-	defer computeSystem.logOperationEnd(err)
639
+	defer func() { computeSystem.logOperationEnd(operation, err) }()
640 640
 
641 641
 	if computeSystem.handle == 0 {
642 642
 		return makeSystemError(computeSystem, "Modify", "", ErrAlreadyClosed, nil)
... ...
@@ -654,10 +673,9 @@ func (computeSystem *System) Modify(config interface{}) (err error) {
654 654
 		Debug("HCS ComputeSystem Modify Document")
655 655
 
656 656
 	var resultp *uint16
657
-	completed := false
658
-	go syscallWatcher(computeSystem.logctx, &completed)
659
-	err = hcsModifyComputeSystem(computeSystem.handle, requestString, &resultp)
660
-	completed = true
657
+	syscallWatcher(computeSystem.logctx, func() {
658
+		err = hcsModifyComputeSystem(computeSystem.handle, requestString, &resultp)
659
+	})
661 660
 	events := processHcsResult(resultp)
662 661
 	if err != nil {
663 662
 		return makeSystemError(computeSystem, "Modify", requestString, err, events)
... ...
@@ -1,7 +1,7 @@
1 1
 package hcs
2 2
 
3 3
 import (
4
-	"time"
4
+	"context"
5 5
 
6 6
 	"github.com/Microsoft/hcsshim/internal/logfields"
7 7
 	"github.com/Microsoft/hcsshim/internal/timeout"
... ...
@@ -17,17 +17,25 @@ import (
17 17
 //
18 18
 // Usage is:
19 19
 //
20
-// completed := false
21
-// go syscallWatcher(context, &completed)
22
-// <syscall>
23
-// completed = true
20
+// syscallWatcher(logContext, func() {
21
+//    err = <syscall>(args...)
22
+// })
24 23
 //
25
-func syscallWatcher(context logrus.Fields, syscallCompleted *bool) {
26
-	time.Sleep(timeout.SyscallWatcher)
27
-	if *syscallCompleted {
28
-		return
24
+
25
+func syscallWatcher(logContext logrus.Fields, syscallLambda func()) {
26
+	ctx, cancel := context.WithTimeout(context.Background(), timeout.SyscallWatcher)
27
+	defer cancel()
28
+	go watchFunc(ctx, logContext)
29
+	syscallLambda()
30
+}
31
+
32
+func watchFunc(ctx context.Context, logContext logrus.Fields) {
33
+	select {
34
+	case <-ctx.Done():
35
+		if ctx.Err() != context.Canceled {
36
+			logrus.WithFields(logContext).
37
+				WithField(logfields.Timeout, timeout.SyscallWatcher).
38
+				Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. If it appears to be making no forward progress, obtain the stacks and see if there is a syscall stuck in the platform API for a significant length of time.")
39
+		}
29 40
 	}
30
-	logrus.WithFields(context).
31
-		WithField(logfields.Timeout, timeout.SyscallWatcher).
32
-		Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. If it appears to be making no forward progress, obtain the stacks and see if there is a syscall stuck in the platform API for a significant length of time.")
33 41
 }
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"syscall"
7 7
 	"unsafe"
8 8
 
9
-	"github.com/Microsoft/hcsshim/internal/interop"
10 9
 	"golang.org/x/sys/windows"
11 10
 )
12 11
 
... ...
@@ -81,7 +80,10 @@ func _hcsEnumerateComputeSystems(query *uint16, computeSystems **uint16, result
81 81
 	}
82 82
 	r0, _, _ := syscall.Syscall(procHcsEnumerateComputeSystems.Addr(), 3, uintptr(unsafe.Pointer(query)), uintptr(unsafe.Pointer(computeSystems)), uintptr(unsafe.Pointer(result)))
83 83
 	if int32(r0) < 0 {
84
-		hr = interop.Win32FromHresult(r0)
84
+		if r0&0x1fff0000 == 0x00070000 {
85
+			r0 &= 0xffff
86
+		}
87
+		hr = syscall.Errno(r0)
85 88
 	}
86 89
 	return
87 90
 }
... ...
@@ -106,7 +108,10 @@ func _hcsCreateComputeSystem(id *uint16, configuration *uint16, identity syscall
106 106
 	}
107 107
 	r0, _, _ := syscall.Syscall6(procHcsCreateComputeSystem.Addr(), 5, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(configuration)), uintptr(identity), uintptr(unsafe.Pointer(computeSystem)), uintptr(unsafe.Pointer(result)), 0)
108 108
 	if int32(r0) < 0 {
109
-		hr = interop.Win32FromHresult(r0)
109
+		if r0&0x1fff0000 == 0x00070000 {
110
+			r0 &= 0xffff
111
+		}
112
+		hr = syscall.Errno(r0)
110 113
 	}
111 114
 	return
112 115
 }
... ...
@@ -126,7 +131,10 @@ func _hcsOpenComputeSystem(id *uint16, computeSystem *hcsSystem, result **uint16
126 126
 	}
127 127
 	r0, _, _ := syscall.Syscall(procHcsOpenComputeSystem.Addr(), 3, uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(computeSystem)), uintptr(unsafe.Pointer(result)))
128 128
 	if int32(r0) < 0 {
129
-		hr = interop.Win32FromHresult(r0)
129
+		if r0&0x1fff0000 == 0x00070000 {
130
+			r0 &= 0xffff
131
+		}
132
+		hr = syscall.Errno(r0)
130 133
 	}
131 134
 	return
132 135
 }
... ...
@@ -137,7 +145,10 @@ func hcsCloseComputeSystem(computeSystem hcsSystem) (hr error) {
137 137
 	}
138 138
 	r0, _, _ := syscall.Syscall(procHcsCloseComputeSystem.Addr(), 1, uintptr(computeSystem), 0, 0)
139 139
 	if int32(r0) < 0 {
140
-		hr = interop.Win32FromHresult(r0)
140
+		if r0&0x1fff0000 == 0x00070000 {
141
+			r0 &= 0xffff
142
+		}
143
+		hr = syscall.Errno(r0)
141 144
 	}
142 145
 	return
143 146
 }
... ...
@@ -157,7 +168,10 @@ func _hcsStartComputeSystem(computeSystem hcsSystem, options *uint16, result **u
157 157
 	}
158 158
 	r0, _, _ := syscall.Syscall(procHcsStartComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
159 159
 	if int32(r0) < 0 {
160
-		hr = interop.Win32FromHresult(r0)
160
+		if r0&0x1fff0000 == 0x00070000 {
161
+			r0 &= 0xffff
162
+		}
163
+		hr = syscall.Errno(r0)
161 164
 	}
162 165
 	return
163 166
 }
... ...
@@ -177,7 +191,10 @@ func _hcsShutdownComputeSystem(computeSystem hcsSystem, options *uint16, result
177 177
 	}
178 178
 	r0, _, _ := syscall.Syscall(procHcsShutdownComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
179 179
 	if int32(r0) < 0 {
180
-		hr = interop.Win32FromHresult(r0)
180
+		if r0&0x1fff0000 == 0x00070000 {
181
+			r0 &= 0xffff
182
+		}
183
+		hr = syscall.Errno(r0)
181 184
 	}
182 185
 	return
183 186
 }
... ...
@@ -197,7 +214,10 @@ func _hcsTerminateComputeSystem(computeSystem hcsSystem, options *uint16, result
197 197
 	}
198 198
 	r0, _, _ := syscall.Syscall(procHcsTerminateComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
199 199
 	if int32(r0) < 0 {
200
-		hr = interop.Win32FromHresult(r0)
200
+		if r0&0x1fff0000 == 0x00070000 {
201
+			r0 &= 0xffff
202
+		}
203
+		hr = syscall.Errno(r0)
201 204
 	}
202 205
 	return
203 206
 }
... ...
@@ -217,7 +237,10 @@ func _hcsPauseComputeSystem(computeSystem hcsSystem, options *uint16, result **u
217 217
 	}
218 218
 	r0, _, _ := syscall.Syscall(procHcsPauseComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
219 219
 	if int32(r0) < 0 {
220
-		hr = interop.Win32FromHresult(r0)
220
+		if r0&0x1fff0000 == 0x00070000 {
221
+			r0 &= 0xffff
222
+		}
223
+		hr = syscall.Errno(r0)
221 224
 	}
222 225
 	return
223 226
 }
... ...
@@ -237,7 +260,10 @@ func _hcsResumeComputeSystem(computeSystem hcsSystem, options *uint16, result **
237 237
 	}
238 238
 	r0, _, _ := syscall.Syscall(procHcsResumeComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
239 239
 	if int32(r0) < 0 {
240
-		hr = interop.Win32FromHresult(r0)
240
+		if r0&0x1fff0000 == 0x00070000 {
241
+			r0 &= 0xffff
242
+		}
243
+		hr = syscall.Errno(r0)
241 244
 	}
242 245
 	return
243 246
 }
... ...
@@ -257,7 +283,10 @@ func _hcsGetComputeSystemProperties(computeSystem hcsSystem, propertyQuery *uint
257 257
 	}
258 258
 	r0, _, _ := syscall.Syscall6(procHcsGetComputeSystemProperties.Addr(), 4, uintptr(computeSystem), uintptr(unsafe.Pointer(propertyQuery)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)), 0, 0)
259 259
 	if int32(r0) < 0 {
260
-		hr = interop.Win32FromHresult(r0)
260
+		if r0&0x1fff0000 == 0x00070000 {
261
+			r0 &= 0xffff
262
+		}
263
+		hr = syscall.Errno(r0)
261 264
 	}
262 265
 	return
263 266
 }
... ...
@@ -277,7 +306,10 @@ func _hcsModifyComputeSystem(computeSystem hcsSystem, configuration *uint16, res
277 277
 	}
278 278
 	r0, _, _ := syscall.Syscall(procHcsModifyComputeSystem.Addr(), 3, uintptr(computeSystem), uintptr(unsafe.Pointer(configuration)), uintptr(unsafe.Pointer(result)))
279 279
 	if int32(r0) < 0 {
280
-		hr = interop.Win32FromHresult(r0)
280
+		if r0&0x1fff0000 == 0x00070000 {
281
+			r0 &= 0xffff
282
+		}
283
+		hr = syscall.Errno(r0)
281 284
 	}
282 285
 	return
283 286
 }
... ...
@@ -288,7 +320,10 @@ func hcsRegisterComputeSystemCallback(computeSystem hcsSystem, callback uintptr,
288 288
 	}
289 289
 	r0, _, _ := syscall.Syscall6(procHcsRegisterComputeSystemCallback.Addr(), 4, uintptr(computeSystem), uintptr(callback), uintptr(context), uintptr(unsafe.Pointer(callbackHandle)), 0, 0)
290 290
 	if int32(r0) < 0 {
291
-		hr = interop.Win32FromHresult(r0)
291
+		if r0&0x1fff0000 == 0x00070000 {
292
+			r0 &= 0xffff
293
+		}
294
+		hr = syscall.Errno(r0)
292 295
 	}
293 296
 	return
294 297
 }
... ...
@@ -299,7 +334,10 @@ func hcsUnregisterComputeSystemCallback(callbackHandle hcsCallback) (hr error) {
299 299
 	}
300 300
 	r0, _, _ := syscall.Syscall(procHcsUnregisterComputeSystemCallback.Addr(), 1, uintptr(callbackHandle), 0, 0)
301 301
 	if int32(r0) < 0 {
302
-		hr = interop.Win32FromHresult(r0)
302
+		if r0&0x1fff0000 == 0x00070000 {
303
+			r0 &= 0xffff
304
+		}
305
+		hr = syscall.Errno(r0)
303 306
 	}
304 307
 	return
305 308
 }
... ...
@@ -319,7 +357,10 @@ func _hcsCreateProcess(computeSystem hcsSystem, processParameters *uint16, proce
319 319
 	}
320 320
 	r0, _, _ := syscall.Syscall6(procHcsCreateProcess.Addr(), 5, uintptr(computeSystem), uintptr(unsafe.Pointer(processParameters)), uintptr(unsafe.Pointer(processInformation)), uintptr(unsafe.Pointer(process)), uintptr(unsafe.Pointer(result)), 0)
321 321
 	if int32(r0) < 0 {
322
-		hr = interop.Win32FromHresult(r0)
322
+		if r0&0x1fff0000 == 0x00070000 {
323
+			r0 &= 0xffff
324
+		}
325
+		hr = syscall.Errno(r0)
323 326
 	}
324 327
 	return
325 328
 }
... ...
@@ -330,7 +371,10 @@ func hcsOpenProcess(computeSystem hcsSystem, pid uint32, process *hcsProcess, re
330 330
 	}
331 331
 	r0, _, _ := syscall.Syscall6(procHcsOpenProcess.Addr(), 4, uintptr(computeSystem), uintptr(pid), uintptr(unsafe.Pointer(process)), uintptr(unsafe.Pointer(result)), 0, 0)
332 332
 	if int32(r0) < 0 {
333
-		hr = interop.Win32FromHresult(r0)
333
+		if r0&0x1fff0000 == 0x00070000 {
334
+			r0 &= 0xffff
335
+		}
336
+		hr = syscall.Errno(r0)
334 337
 	}
335 338
 	return
336 339
 }
... ...
@@ -341,7 +385,10 @@ func hcsCloseProcess(process hcsProcess) (hr error) {
341 341
 	}
342 342
 	r0, _, _ := syscall.Syscall(procHcsCloseProcess.Addr(), 1, uintptr(process), 0, 0)
343 343
 	if int32(r0) < 0 {
344
-		hr = interop.Win32FromHresult(r0)
344
+		if r0&0x1fff0000 == 0x00070000 {
345
+			r0 &= 0xffff
346
+		}
347
+		hr = syscall.Errno(r0)
345 348
 	}
346 349
 	return
347 350
 }
... ...
@@ -352,7 +399,10 @@ func hcsTerminateProcess(process hcsProcess, result **uint16) (hr error) {
352 352
 	}
353 353
 	r0, _, _ := syscall.Syscall(procHcsTerminateProcess.Addr(), 2, uintptr(process), uintptr(unsafe.Pointer(result)), 0)
354 354
 	if int32(r0) < 0 {
355
-		hr = interop.Win32FromHresult(r0)
355
+		if r0&0x1fff0000 == 0x00070000 {
356
+			r0 &= 0xffff
357
+		}
358
+		hr = syscall.Errno(r0)
356 359
 	}
357 360
 	return
358 361
 }
... ...
@@ -372,7 +422,10 @@ func _hcsSignalProcess(process hcsProcess, options *uint16, result **uint16) (hr
372 372
 	}
373 373
 	r0, _, _ := syscall.Syscall(procHcsTerminateProcess.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(options)), uintptr(unsafe.Pointer(result)))
374 374
 	if int32(r0) < 0 {
375
-		hr = interop.Win32FromHresult(r0)
375
+		if r0&0x1fff0000 == 0x00070000 {
376
+			r0 &= 0xffff
377
+		}
378
+		hr = syscall.Errno(r0)
376 379
 	}
377 380
 	return
378 381
 }
... ...
@@ -383,7 +436,10 @@ func hcsGetProcessInfo(process hcsProcess, processInformation *hcsProcessInforma
383 383
 	}
384 384
 	r0, _, _ := syscall.Syscall(procHcsGetProcessInfo.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(processInformation)), uintptr(unsafe.Pointer(result)))
385 385
 	if int32(r0) < 0 {
386
-		hr = interop.Win32FromHresult(r0)
386
+		if r0&0x1fff0000 == 0x00070000 {
387
+			r0 &= 0xffff
388
+		}
389
+		hr = syscall.Errno(r0)
387 390
 	}
388 391
 	return
389 392
 }
... ...
@@ -394,7 +450,10 @@ func hcsGetProcessProperties(process hcsProcess, processProperties **uint16, res
394 394
 	}
395 395
 	r0, _, _ := syscall.Syscall(procHcsGetProcessProperties.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(processProperties)), uintptr(unsafe.Pointer(result)))
396 396
 	if int32(r0) < 0 {
397
-		hr = interop.Win32FromHresult(r0)
397
+		if r0&0x1fff0000 == 0x00070000 {
398
+			r0 &= 0xffff
399
+		}
400
+		hr = syscall.Errno(r0)
398 401
 	}
399 402
 	return
400 403
 }
... ...
@@ -414,7 +473,10 @@ func _hcsModifyProcess(process hcsProcess, settings *uint16, result **uint16) (h
414 414
 	}
415 415
 	r0, _, _ := syscall.Syscall(procHcsModifyProcess.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(settings)), uintptr(unsafe.Pointer(result)))
416 416
 	if int32(r0) < 0 {
417
-		hr = interop.Win32FromHresult(r0)
417
+		if r0&0x1fff0000 == 0x00070000 {
418
+			r0 &= 0xffff
419
+		}
420
+		hr = syscall.Errno(r0)
418 421
 	}
419 422
 	return
420 423
 }
... ...
@@ -434,7 +496,10 @@ func _hcsGetServiceProperties(propertyQuery *uint16, properties **uint16, result
434 434
 	}
435 435
 	r0, _, _ := syscall.Syscall(procHcsGetServiceProperties.Addr(), 3, uintptr(unsafe.Pointer(propertyQuery)), uintptr(unsafe.Pointer(properties)), uintptr(unsafe.Pointer(result)))
436 436
 	if int32(r0) < 0 {
437
-		hr = interop.Win32FromHresult(r0)
437
+		if r0&0x1fff0000 == 0x00070000 {
438
+			r0 &= 0xffff
439
+		}
440
+		hr = syscall.Errno(r0)
438 441
 	}
439 442
 	return
440 443
 }
... ...
@@ -445,7 +510,10 @@ func hcsRegisterProcessCallback(process hcsProcess, callback uintptr, context ui
445 445
 	}
446 446
 	r0, _, _ := syscall.Syscall6(procHcsRegisterProcessCallback.Addr(), 4, uintptr(process), uintptr(callback), uintptr(context), uintptr(unsafe.Pointer(callbackHandle)), 0, 0)
447 447
 	if int32(r0) < 0 {
448
-		hr = interop.Win32FromHresult(r0)
448
+		if r0&0x1fff0000 == 0x00070000 {
449
+			r0 &= 0xffff
450
+		}
451
+		hr = syscall.Errno(r0)
449 452
 	}
450 453
 	return
451 454
 }
... ...
@@ -456,7 +524,10 @@ func hcsUnregisterProcessCallback(callbackHandle hcsCallback) (hr error) {
456 456
 	}
457 457
 	r0, _, _ := syscall.Syscall(procHcsUnregisterProcessCallback.Addr(), 1, uintptr(callbackHandle), 0, 0)
458 458
 	if int32(r0) < 0 {
459
-		hr = interop.Win32FromHresult(r0)
459
+		if r0&0x1fff0000 == 0x00070000 {
460
+			r0 &= 0xffff
461
+		}
462
+		hr = syscall.Errno(r0)
460 463
 	}
461 464
 	return
462 465
 }
... ...
@@ -36,10 +36,6 @@ func New(err error, title, rest string) error {
36 36
 	return &HcsError{title, rest, err}
37 37
 }
38 38
 
39
-func Errorf(err error, title, format string, a ...interface{}) error {
40
-	return New(err, title, fmt.Sprintf(format, a...))
41
-}
42
-
43 39
 func Win32FromError(err error) uint32 {
44 40
 	if herr, ok := err.(*HcsError); ok {
45 41
 		return Win32FromError(herr.Err)
... ...
@@ -23,7 +23,9 @@ type HNSEndpoint struct {
23 23
 	DisableICC         bool              `json:",omitempty"`
24 24
 	PrefixLength       uint8             `json:",omitempty"`
25 25
 	IsRemoteEndpoint   bool              `json:",omitempty"`
26
+	EnableLowMetric    bool              `json:",omitempty"`
26 27
 	Namespace          *Namespace        `json:",omitempty"`
28
+	EncapOverhead      uint16            `json:",omitempty"`
27 29
 }
28 30
 
29 31
 //SystemType represents the type of the system on which actions are done
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"syscall"
7 7
 	"unsafe"
8 8
 
9
-	"github.com/Microsoft/hcsshim/internal/interop"
10 9
 	"golang.org/x/sys/windows"
11 10
 )
12 11
 
... ...
@@ -68,7 +67,10 @@ func __hnsCall(method *uint16, path *uint16, object *uint16, response **uint16)
68 68
 	}
69 69
 	r0, _, _ := syscall.Syscall6(procHNSCall.Addr(), 4, uintptr(unsafe.Pointer(method)), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(object)), uintptr(unsafe.Pointer(response)), 0, 0)
70 70
 	if int32(r0) < 0 {
71
-		hr = interop.Win32FromHresult(r0)
71
+		if r0&0x1fff0000 == 0x00070000 {
72
+			r0 &= 0xffff
73
+		}
74
+		hr = syscall.Errno(r0)
72 75
 	}
73 76
 	return
74 77
 }
... ...
@@ -5,9 +5,9 @@ import (
5 5
 	"unsafe"
6 6
 )
7 7
 
8
-//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go interop.go
8
+//go:generate go run ../../mksyscall_windows.go -output zsyscall_windows.go interop.go
9 9
 
10
-//sys coTaskMemFree(buffer unsafe.Pointer) = ole32.CoTaskMemFree
10
+//sys coTaskMemFree(buffer unsafe.Pointer) = api_ms_win_core_com_l1_1_0.CoTaskMemFree
11 11
 
12 12
 func ConvertAndFreeCoTaskMemString(buffer *uint16) string {
13 13
 	str := syscall.UTF16ToString((*[1 << 29]uint16)(unsafe.Pointer(buffer))[:])
... ...
@@ -1,4 +1,4 @@
1
-// Code generated by 'go generate'; DO NOT EDIT.
1
+// Code generated mksyscall_windows.exe DO NOT EDIT
2 2
 
3 3
 package interop
4 4
 
... ...
@@ -37,9 +37,9 @@ func errnoErr(e syscall.Errno) error {
37 37
 }
38 38
 
39 39
 var (
40
-	modole32 = windows.NewLazySystemDLL("ole32.dll")
40
+	modapi_ms_win_core_com_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-com-l1-1-0.dll")
41 41
 
42
-	procCoTaskMemFree = modole32.NewProc("CoTaskMemFree")
42
+	procCoTaskMemFree = modapi_ms_win_core_com_l1_1_0.NewProc("CoTaskMemFree")
43 43
 )
44 44
 
45 45
 func coTaskMemFree(buffer unsafe.Pointer) {
... ...
@@ -26,11 +26,6 @@ const (
26 26
 	Uint32       = "uint32"
27 27
 	Uint64       = "uint64"
28 28
 
29
-	// HCS
30
-
31
-	HCSOperation       = "hcs-op"
32
-	HCSOperationResult = "hcs-op-result"
33
-
34 29
 	// runhcs
35 30
 
36 31
 	VMShimOperation = "vmshim-op"
... ...
@@ -87,7 +87,7 @@ func OpenRoot(path string) (*os.File, error) {
87 87
 
88 88
 func ntRelativePath(path string) ([]uint16, error) {
89 89
 	path = filepath.Clean(path)
90
-	if strings.Contains(":", path) {
90
+	if strings.Contains(path, ":") {
91 91
 		// Since alternate data streams must follow the file they
92 92
 		// are attached to, finding one here (out of order) is invalid.
93 93
 		return nil, errors.New("path contains invalid character `:`")
... ...
@@ -20,6 +20,13 @@ type Plan9Share struct {
20 20
 
21 21
 	Port int32 `json:"Port,omitempty"`
22 22
 
23
+	// Flags are marked private. Until they are exported correctly
24
+	//
25
+	// ReadOnly      0x00000001
26
+	// LinuxMetadata 0x00000004
27
+	// CaseSensitive 0x00000008
28
+	Flags int32 `json:"Flags,omitempty"`
29
+
23 30
 	ReadOnly bool `json:"ReadOnly,omitempty"`
24 31
 
25 32
 	UseShareRootIdentity bool `json:"UseShareRootIdentity,omitempty"`
... ...
@@ -11,6 +11,9 @@ package hcsschema
11 11
 
12 12
 type VirtualMachine struct {
13 13
 
14
+	// StopOnReset is private in the schema. If regenerated need to put back.
15
+	StopOnReset bool `json:"StopOnReset,omitempty"`
16
+
14 17
 	Chipset *Chipset `json:"Chipset,omitempty"`
15 18
 
16 19
 	ComputeTopology *Topology `json:"ComputeTopology,omitempty"`
... ...
@@ -9,17 +9,24 @@ import (
9 9
 // For a read/write layer, the mounted filesystem will appear as a volume on the
10 10
 // host, while a read-only layer is generally expected to be a no-op.
11 11
 // An activated layer must later be deactivated via DeactivateLayer.
12
-func ActivateLayer(path string) error {
13
-	title := "hcsshim::ActivateLayer "
14
-	logrus.Debugf(title+"path %s", path)
12
+func ActivateLayer(path string) (err error) {
13
+	title := "hcsshim::ActivateLayer"
14
+	fields := logrus.Fields{
15
+		"path": path,
16
+	}
17
+	logrus.WithFields(fields).Debug(title)
18
+	defer func() {
19
+		if err != nil {
20
+			fields[logrus.ErrorKey] = err
21
+			logrus.WithFields(fields).Error(err)
22
+		} else {
23
+			logrus.WithFields(fields).Debug(title + " - succeeded")
24
+		}
25
+	}()
15 26
 
16
-	err := activateLayer(&stdDriverInfo, path)
27
+	err = activateLayer(&stdDriverInfo, path)
17 28
 	if err != nil {
18
-		err = hcserror.Errorf(err, title, "path=%s", path)
19
-		logrus.Error(err)
20
-		return err
29
+		return hcserror.New(err, title+" - failed", "")
21 30
 	}
22
-
23
-	logrus.Debugf(title+" - succeeded path=%s", path)
24 31
 	return nil
25 32
 }
... ...
@@ -7,17 +7,25 @@ import (
7 7
 
8 8
 // CreateLayer creates a new, empty, read-only layer on the filesystem based on
9 9
 // the parent layer provided.
10
-func CreateLayer(path, parent string) error {
11
-	title := "hcsshim::CreateLayer "
12
-	logrus.Debugf(title+"ID %s parent %s", path, parent)
10
+func CreateLayer(path, parent string) (err error) {
11
+	title := "hcsshim::CreateLayer"
12
+	fields := logrus.Fields{
13
+		"parent": parent,
14
+		"path":   path,
15
+	}
16
+	logrus.WithFields(fields).Debug(title)
17
+	defer func() {
18
+		if err != nil {
19
+			fields[logrus.ErrorKey] = err
20
+			logrus.WithFields(fields).Error(err)
21
+		} else {
22
+			logrus.WithFields(fields).Debug(title + " - succeeded")
23
+		}
24
+	}()
13 25
 
14
-	err := createLayer(&stdDriverInfo, path, parent)
26
+	err = createLayer(&stdDriverInfo, path, parent)
15 27
 	if err != nil {
16
-		err = hcserror.Errorf(err, title, "path=%s parent=%s", path, parent)
17
-		logrus.Error(err)
18
-		return err
28
+		return hcserror.New(err, title+" - failed", "")
19 29
 	}
20
-
21
-	logrus.Debugf(title+"- succeeded path=%s parent=%s", path, parent)
22 30
 	return nil
23 31
 }
... ...
@@ -9,9 +9,20 @@ import (
9 9
 // This requires both the id of the direct parent layer, as well as the full list
10 10
 // of paths to all parent layers up to the base (and including the direct parent
11 11
 // whose id was provided).
12
-func CreateScratchLayer(path string, parentLayerPaths []string) error {
13
-	title := "hcsshim::CreateScratchLayer "
14
-	logrus.Debugf(title+"path %s", path)
12
+func CreateScratchLayer(path string, parentLayerPaths []string) (err error) {
13
+	title := "hcsshim::CreateScratchLayer"
14
+	fields := logrus.Fields{
15
+		"path": path,
16
+	}
17
+	logrus.WithFields(fields).Debug(title)
18
+	defer func() {
19
+		if err != nil {
20
+			fields[logrus.ErrorKey] = err
21
+			logrus.WithFields(fields).Error(err)
22
+		} else {
23
+			logrus.WithFields(fields).Debug(title + " - succeeded")
24
+		}
25
+	}()
15 26
 
16 27
 	// Generate layer descriptors
17 28
 	layers, err := layerPathsToDescriptors(parentLayerPaths)
... ...
@@ -21,11 +32,7 @@ func CreateScratchLayer(path string, parentLayerPaths []string) error {
21 21
 
22 22
 	err = createSandboxLayer(&stdDriverInfo, path, 0, layers)
23 23
 	if err != nil {
24
-		err = hcserror.Errorf(err, title, "path=%s", path)
25
-		logrus.Error(err)
26
-		return err
24
+		return hcserror.New(err, title+" - failed", "")
27 25
 	}
28
-
29
-	logrus.Debugf(title+"- succeeded path=%s", path)
30 26
 	return nil
31 27
 }
... ...
@@ -6,17 +6,24 @@ import (
6 6
 )
7 7
 
8 8
 // DeactivateLayer will dismount a layer that was mounted via ActivateLayer.
9
-func DeactivateLayer(path string) error {
10
-	title := "hcsshim::DeactivateLayer "
11
-	logrus.Debugf(title+"path %s", path)
9
+func DeactivateLayer(path string) (err error) {
10
+	title := "hcsshim::DeactivateLayer"
11
+	fields := logrus.Fields{
12
+		"path": path,
13
+	}
14
+	logrus.WithFields(fields).Debug(title)
15
+	defer func() {
16
+		if err != nil {
17
+			fields[logrus.ErrorKey] = err
18
+			logrus.WithFields(fields).Error(err)
19
+		} else {
20
+			logrus.WithFields(fields).Debug(title + " - succeeded")
21
+		}
22
+	}()
12 23
 
13
-	err := deactivateLayer(&stdDriverInfo, path)
24
+	err = deactivateLayer(&stdDriverInfo, path)
14 25
 	if err != nil {
15
-		err = hcserror.Errorf(err, title, "path=%s", path)
16
-		logrus.Error(err)
17
-		return err
26
+		return hcserror.New(err, title+"- failed", "")
18 27
 	}
19
-
20
-	logrus.Debugf(title+"succeeded path=%s", path)
21 28
 	return nil
22 29
 }
... ...
@@ -7,17 +7,24 @@ import (
7 7
 
8 8
 // DestroyLayer will remove the on-disk files representing the layer with the given
9 9
 // path, including that layer's containing folder, if any.
10
-func DestroyLayer(path string) error {
11
-	title := "hcsshim::DestroyLayer "
12
-	logrus.Debugf(title+"path %s", path)
10
+func DestroyLayer(path string) (err error) {
11
+	title := "hcsshim::DestroyLayer"
12
+	fields := logrus.Fields{
13
+		"path": path,
14
+	}
15
+	logrus.WithFields(fields).Debug(title)
16
+	defer func() {
17
+		if err != nil {
18
+			fields[logrus.ErrorKey] = err
19
+			logrus.WithFields(fields).Error(err)
20
+		} else {
21
+			logrus.WithFields(fields).Debug(title + " - succeeded")
22
+		}
23
+	}()
13 24
 
14
-	err := destroyLayer(&stdDriverInfo, path)
25
+	err = destroyLayer(&stdDriverInfo, path)
15 26
 	if err != nil {
16
-		err = hcserror.Errorf(err, title, "path=%s", path)
17
-		logrus.Error(err)
18
-		return err
27
+		return hcserror.New(err, title+" - failed", "")
19 28
 	}
20
-
21
-	logrus.Debugf(title+"succeeded path=%s", path)
22 29
 	return nil
23 30
 }
... ...
@@ -6,17 +6,25 @@ import (
6 6
 )
7 7
 
8 8
 // ExpandScratchSize expands the size of a layer to at least size bytes.
9
-func ExpandScratchSize(path string, size uint64) error {
10
-	title := "hcsshim::ExpandScratchSize "
11
-	logrus.Debugf(title+"path=%s size=%d", path, size)
9
+func ExpandScratchSize(path string, size uint64) (err error) {
10
+	title := "hcsshim::ExpandScratchSize"
11
+	fields := logrus.Fields{
12
+		"path": path,
13
+		"size": size,
14
+	}
15
+	logrus.WithFields(fields).Debug(title)
16
+	defer func() {
17
+		if err != nil {
18
+			fields[logrus.ErrorKey] = err
19
+			logrus.WithFields(fields).Error(err)
20
+		} else {
21
+			logrus.WithFields(fields).Debug(title + " - succeeded")
22
+		}
23
+	}()
12 24
 
13
-	err := expandSandboxSize(&stdDriverInfo, path, size)
25
+	err = expandSandboxSize(&stdDriverInfo, path, size)
14 26
 	if err != nil {
15
-		err = hcserror.Errorf(err, title, "path=%s size=%d", path, size)
16
-		logrus.Error(err)
17
-		return err
27
+		return hcserror.New(err, title+" - failed", "")
18 28
 	}
19
-
20
-	logrus.Debugf(title+"- succeeded path=%s size=%d", path, size)
21 29
 	return nil
22 30
 }
... ...
@@ -14,9 +14,21 @@ import (
14 14
 // format includes any metadata required for later importing the layer (using
15 15
 // ImportLayer), and requires the full list of parent layer paths in order to
16 16
 // perform the export.
17
-func ExportLayer(path string, exportFolderPath string, parentLayerPaths []string) error {
18
-	title := "hcsshim::ExportLayer "
19
-	logrus.Debugf(title+"path %s folder %s", path, exportFolderPath)
17
+func ExportLayer(path string, exportFolderPath string, parentLayerPaths []string) (err error) {
18
+	title := "hcsshim::ExportLayer"
19
+	fields := logrus.Fields{
20
+		"path":             path,
21
+		"exportFolderPath": exportFolderPath,
22
+	}
23
+	logrus.WithFields(fields).Debug(title)
24
+	defer func() {
25
+		if err != nil {
26
+			fields[logrus.ErrorKey] = err
27
+			logrus.WithFields(fields).Error(err)
28
+		} else {
29
+			logrus.WithFields(fields).Debug(title + " - succeeded")
30
+		}
31
+	}()
20 32
 
21 33
 	// Generate layer descriptors
22 34
 	layers, err := layerPathsToDescriptors(parentLayerPaths)
... ...
@@ -26,12 +38,8 @@ func ExportLayer(path string, exportFolderPath string, parentLayerPaths []string
26 26
 
27 27
 	err = exportLayer(&stdDriverInfo, path, exportFolderPath, layers)
28 28
 	if err != nil {
29
-		err = hcserror.Errorf(err, title, "path=%s folder=%s", path, exportFolderPath)
30
-		logrus.Error(err)
31
-		return err
29
+		return hcserror.New(err, title+" - failed", "")
32 30
 	}
33
-
34
-	logrus.Debugf(title+"succeeded path=%s folder=%s", path, exportFolderPath)
35 31
 	return nil
36 32
 }
37 33
 
... ...
@@ -11,20 +11,29 @@ import (
11 11
 // the path at which that layer can be accessed.  This path may be a volume path
12 12
 // if the layer is a mounted read-write layer, otherwise it is expected to be the
13 13
 // folder path at which the layer is stored.
14
-func GetLayerMountPath(path string) (string, error) {
15
-	title := "hcsshim::GetLayerMountPath "
16
-	logrus.Debugf(title+"path %s", path)
14
+func GetLayerMountPath(path string) (_ string, err error) {
15
+	title := "hcsshim::GetLayerMountPath"
16
+	fields := logrus.Fields{
17
+		"path": path,
18
+	}
19
+	logrus.WithFields(fields).Debug(title)
20
+	defer func() {
21
+		if err != nil {
22
+			fields[logrus.ErrorKey] = err
23
+			logrus.WithFields(fields).Error(err)
24
+		} else {
25
+			logrus.WithFields(fields).Debug(title + " - succeeded")
26
+		}
27
+	}()
17 28
 
18 29
 	var mountPathLength uintptr
19 30
 	mountPathLength = 0
20 31
 
21 32
 	// Call the procedure itself.
22
-	logrus.Debugf("Calling proc (1)")
23
-	err := getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
33
+	logrus.WithFields(fields).Debug("Calling proc (1)")
34
+	err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
24 35
 	if err != nil {
25
-		err = hcserror.Errorf(err, title, "(first call) path=%s", path)
26
-		logrus.Error(err)
27
-		return "", err
36
+		return "", hcserror.New(err, title+" - failed", "(first call)")
28 37
 	}
29 38
 
30 39
 	// Allocate a mount path of the returned length.
... ...
@@ -35,15 +44,13 @@ func GetLayerMountPath(path string) (string, error) {
35 35
 	mountPathp[0] = 0
36 36
 
37 37
 	// Call the procedure again
38
-	logrus.Debugf("Calling proc (2)")
38
+	logrus.WithFields(fields).Debug("Calling proc (2)")
39 39
 	err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
40 40
 	if err != nil {
41
-		err = hcserror.Errorf(err, title, "(second call) path=%s", path)
42
-		logrus.Error(err)
43
-		return "", err
41
+		return "", hcserror.New(err, title+" - failed", "(second call)")
44 42
 	}
45 43
 
46 44
 	mountPath := syscall.UTF16ToString(mountPathp[0:])
47
-	logrus.Debugf(title+"succeeded path=%s mountPath=%s", path, mountPath)
45
+	fields["mountPath"] = mountPath
48 46
 	return mountPath, nil
49 47
 }
... ...
@@ -10,17 +10,20 @@ import (
10 10
 // image store and return descriptive info about those images for the purpose
11 11
 // of registering them with the graphdriver, graph, and tagstore.
12 12
 func GetSharedBaseImages() (imageData string, err error) {
13
-	title := "hcsshim::GetSharedBaseImages "
13
+	title := "hcsshim::GetSharedBaseImages"
14
+	logrus.Debug(title)
15
+	defer func() {
16
+		if err != nil {
17
+			logrus.WithError(err).Error(err)
18
+		} else {
19
+			logrus.WithField("imageData", imageData).Debug(title + " - succeeded")
20
+		}
21
+	}()
14 22
 
15
-	logrus.Debugf("Calling proc")
16 23
 	var buffer *uint16
17 24
 	err = getBaseImages(&buffer)
18 25
 	if err != nil {
19
-		err = hcserror.New(err, title, "")
20
-		logrus.Error(err)
21
-		return
26
+		return "", hcserror.New(err, title+" - failed", "")
22 27
 	}
23
-	imageData = interop.ConvertAndFreeCoTaskMemString(buffer)
24
-	logrus.Debugf(title+" - succeeded output=%s", imageData)
25
-	return
28
+	return interop.ConvertAndFreeCoTaskMemString(buffer), nil
26 29
 }
... ...
@@ -1,24 +1,30 @@
1 1
 package wclayer
2 2
 
3 3
 import (
4
-	"fmt"
5
-
6 4
 	"github.com/Microsoft/hcsshim/internal/hcserror"
7 5
 	"github.com/sirupsen/logrus"
8 6
 )
9 7
 
10 8
 // GrantVmAccess adds access to a file for a given VM
11
-func GrantVmAccess(vmid string, filepath string) error {
12
-	title := fmt.Sprintf("hcsshim::GrantVmAccess id:%s path:%s ", vmid, filepath)
13
-	logrus.Debugf(title)
9
+func GrantVmAccess(vmid string, filepath string) (err error) {
10
+	title := "hcsshim::GrantVmAccess"
11
+	fields := logrus.Fields{
12
+		"vm-id": vmid,
13
+		"path":  filepath,
14
+	}
15
+	logrus.WithFields(fields).Debug(title)
16
+	defer func() {
17
+		if err != nil {
18
+			fields[logrus.ErrorKey] = err
19
+			logrus.WithFields(fields).Error(err)
20
+		} else {
21
+			logrus.WithFields(fields).Debug(title + " - succeeded")
22
+		}
23
+	}()
14 24
 
15
-	err := grantVmAccess(vmid, filepath)
25
+	err = grantVmAccess(vmid, filepath)
16 26
 	if err != nil {
17
-		err = hcserror.Errorf(err, title, "path=%s", filepath)
18
-		logrus.Error(err)
19
-		return err
27
+		return hcserror.New(err, title+" - failed", "")
20 28
 	}
21
-
22
-	logrus.Debugf(title + " - succeeded")
23 29
 	return nil
24 30
 }
... ...
@@ -15,9 +15,21 @@ import (
15 15
 // that into a layer with the id layerId.  Note that in order to correctly populate
16 16
 // the layer and interperet the transport format, all parent layers must already
17 17
 // be present on the system at the paths provided in parentLayerPaths.
18
-func ImportLayer(path string, importFolderPath string, parentLayerPaths []string) error {
19
-	title := "hcsshim::ImportLayer "
20
-	logrus.Debugf(title+"path %s folder %s", path, importFolderPath)
18
+func ImportLayer(path string, importFolderPath string, parentLayerPaths []string) (err error) {
19
+	title := "hcsshim::ImportLayer"
20
+	fields := logrus.Fields{
21
+		"path":             path,
22
+		"importFolderPath": importFolderPath,
23
+	}
24
+	logrus.WithFields(fields).Debug(title)
25
+	defer func() {
26
+		if err != nil {
27
+			fields[logrus.ErrorKey] = err
28
+			logrus.WithFields(fields).Error(err)
29
+		} else {
30
+			logrus.WithFields(fields).Debug(title + " - succeeded")
31
+		}
32
+	}()
21 33
 
22 34
 	// Generate layer descriptors
23 35
 	layers, err := layerPathsToDescriptors(parentLayerPaths)
... ...
@@ -27,12 +39,8 @@ func ImportLayer(path string, importFolderPath string, parentLayerPaths []string
27 27
 
28 28
 	err = importLayer(&stdDriverInfo, path, importFolderPath, layers)
29 29
 	if err != nil {
30
-		err = hcserror.Errorf(err, title, "path=%s folder=%s", path, importFolderPath)
31
-		logrus.Error(err)
32
-		return err
30
+		return hcserror.New(err, title+" - failed", "")
33 31
 	}
34
-
35
-	logrus.Debugf(title+"succeeded path=%s folder=%s", path, importFolderPath)
36 32
 	return nil
37 33
 }
38 34
 
... ...
@@ -7,19 +7,27 @@ import (
7 7
 
8 8
 // LayerExists will return true if a layer with the given id exists and is known
9 9
 // to the system.
10
-func LayerExists(path string) (bool, error) {
11
-	title := "hcsshim::LayerExists "
12
-	logrus.Debugf(title+"path %s", path)
10
+func LayerExists(path string) (_ bool, err error) {
11
+	title := "hcsshim::LayerExists"
12
+	fields := logrus.Fields{
13
+		"path": path,
14
+	}
15
+	logrus.WithFields(fields).Debug(title)
16
+	defer func() {
17
+		if err != nil {
18
+			fields[logrus.ErrorKey] = err
19
+			logrus.WithFields(fields).Error(err)
20
+		} else {
21
+			logrus.WithFields(fields).Debug(title + " - succeeded")
22
+		}
23
+	}()
13 24
 
14 25
 	// Call the procedure itself.
15 26
 	var exists uint32
16
-	err := layerExists(&stdDriverInfo, path, &exists)
27
+	err = layerExists(&stdDriverInfo, path, &exists)
17 28
 	if err != nil {
18
-		err = hcserror.Errorf(err, title, "path=%s", path)
19
-		logrus.Error(err)
20
-		return false, err
29
+		return false, hcserror.New(err, title+" - failed", "")
21 30
 	}
22
-
23
-	logrus.Debugf(title+"succeeded path=%s exists=%d", path, exists)
31
+	fields["layer-exists"] = exists != 0
24 32
 	return exists != 0, nil
25 33
 }
... ...
@@ -75,13 +75,13 @@ func layerPathsToDescriptors(parentLayerPaths []string) ([]WC_LAYER_DESCRIPTOR,
75 75
 	for i := 0; i < len(parentLayerPaths); i++ {
76 76
 		g, err := LayerID(parentLayerPaths[i])
77 77
 		if err != nil {
78
-			logrus.Debugf("Failed to convert name to guid %s", err)
78
+			logrus.WithError(err).Debug("Failed to convert name to guid")
79 79
 			return nil, err
80 80
 		}
81 81
 
82 82
 		p, err := syscall.UTF16PtrFromString(parentLayerPaths[i])
83 83
 		if err != nil {
84
-			logrus.Debugf("Failed conversion of parentLayerPath to pointer %s", err)
84
+			logrus.WithError(err).Debug("Failed conversion of parentLayerPath to pointer")
85 85
 			return nil, err
86 86
 		}
87 87
 
... ...
@@ -10,15 +10,25 @@ import (
10 10
 // Host Compute Service, ensuring GUIDs generated with the same string are common
11 11
 // across all clients.
12 12
 func NameToGuid(name string) (id guid.GUID, err error) {
13
-	title := "hcsshim::NameToGuid "
13
+	title := "hcsshim::NameToGuid"
14
+	fields := logrus.Fields{
15
+		"name": name,
16
+	}
17
+	logrus.WithFields(fields).Debug(title)
18
+	defer func() {
19
+		if err != nil {
20
+			fields[logrus.ErrorKey] = err
21
+			logrus.WithFields(fields).Error(err)
22
+		} else {
23
+			logrus.WithFields(fields).Debug(title + " - succeeded")
24
+		}
25
+	}()
14 26
 
15 27
 	err = nameToGuid(name, &id)
16 28
 	if err != nil {
17
-		err = hcserror.Errorf(err, title, "name=%s", name)
18
-		logrus.Error(err)
29
+		err = hcserror.New(err, title+" - failed", "")
19 30
 		return
20 31
 	}
21
-
22
-	logrus.Debugf(title+"name:%s guid:%s", name, id.String())
32
+	fields["guid"] = id.String()
23 33
 	return
24 34
 }
... ...
@@ -14,9 +14,20 @@ var prepareLayerLock sync.Mutex
14 14
 // parent layers, and is necessary in order to view or interact with the layer
15 15
 // as an actual filesystem (reading and writing files, creating directories, etc).
16 16
 // Disabling the filter must be done via UnprepareLayer.
17
-func PrepareLayer(path string, parentLayerPaths []string) error {
18
-	title := "hcsshim::PrepareLayer "
19
-	logrus.Debugf(title+"path %s", path)
17
+func PrepareLayer(path string, parentLayerPaths []string) (err error) {
18
+	title := "hcsshim::PrepareLayer"
19
+	fields := logrus.Fields{
20
+		"path": path,
21
+	}
22
+	logrus.WithFields(fields).Debug(title)
23
+	defer func() {
24
+		if err != nil {
25
+			fields[logrus.ErrorKey] = err
26
+			logrus.WithFields(fields).Error(err)
27
+		} else {
28
+			logrus.WithFields(fields).Debug(title + " - succeeded")
29
+		}
30
+	}()
20 31
 
21 32
 	// Generate layer descriptors
22 33
 	layers, err := layerPathsToDescriptors(parentLayerPaths)
... ...
@@ -30,11 +41,7 @@ func PrepareLayer(path string, parentLayerPaths []string) error {
30 30
 	defer prepareLayerLock.Unlock()
31 31
 	err = prepareLayer(&stdDriverInfo, path, layers)
32 32
 	if err != nil {
33
-		err = hcserror.Errorf(err, title, "path=%s", path)
34
-		logrus.Error(err)
35
-		return err
33
+		return hcserror.New(err, title+" - failed", "")
36 34
 	}
37
-
38
-	logrus.Debugf(title+"succeeded path=%s", path)
39 35
 	return nil
40 36
 }
... ...
@@ -7,17 +7,24 @@ import (
7 7
 
8 8
 // UnprepareLayer disables the filesystem filter for the read-write layer with
9 9
 // the given id.
10
-func UnprepareLayer(path string) error {
11
-	title := "hcsshim::UnprepareLayer "
12
-	logrus.Debugf(title+"path %s", path)
10
+func UnprepareLayer(path string) (err error) {
11
+	title := "hcsshim::UnprepareLayer"
12
+	fields := logrus.Fields{
13
+		"path": path,
14
+	}
15
+	logrus.WithFields(fields).Debug(title)
16
+	defer func() {
17
+		if err != nil {
18
+			fields[logrus.ErrorKey] = err
19
+			logrus.WithFields(fields).Error(err)
20
+		} else {
21
+			logrus.WithFields(fields).Debug(title + " - succeeded")
22
+		}
23
+	}()
13 24
 
14
-	err := unprepareLayer(&stdDriverInfo, path)
25
+	err = unprepareLayer(&stdDriverInfo, path)
15 26
 	if err != nil {
16
-		err = hcserror.Errorf(err, title, "path=%s", path)
17
-		logrus.Error(err)
18
-		return err
27
+		return hcserror.New(err, title+" - failed", "")
19 28
 	}
20
-
21
-	logrus.Debugf(title+"succeeded path=%s", path)
22 29
 	return nil
23 30
 }
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"syscall"
7 7
 	"unsafe"
8 8
 
9
-	"github.com/Microsoft/hcsshim/internal/interop"
10 9
 	"golang.org/x/sys/windows"
11 10
 )
12 11
 
... ...
@@ -75,7 +74,10 @@ func _activateLayer(info *driverInfo, id *uint16) (hr error) {
75 75
 	}
76 76
 	r0, _, _ := syscall.Syscall(procActivateLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
77 77
 	if int32(r0) < 0 {
78
-		hr = interop.Win32FromHresult(r0)
78
+		if r0&0x1fff0000 == 0x00070000 {
79
+			r0 &= 0xffff
80
+		}
81
+		hr = syscall.Errno(r0)
79 82
 	}
80 83
 	return
81 84
 }
... ...
@@ -104,7 +106,10 @@ func _copyLayer(info *driverInfo, srcId *uint16, dstId *uint16, descriptors []WC
104 104
 	}
105 105
 	r0, _, _ := syscall.Syscall6(procCopyLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(srcId)), uintptr(unsafe.Pointer(dstId)), uintptr(unsafe.Pointer(_p2)), uintptr(len(descriptors)), 0)
106 106
 	if int32(r0) < 0 {
107
-		hr = interop.Win32FromHresult(r0)
107
+		if r0&0x1fff0000 == 0x00070000 {
108
+			r0 &= 0xffff
109
+		}
110
+		hr = syscall.Errno(r0)
108 111
 	}
109 112
 	return
110 113
 }
... ...
@@ -129,7 +134,10 @@ func _createLayer(info *driverInfo, id *uint16, parent *uint16) (hr error) {
129 129
 	}
130 130
 	r0, _, _ := syscall.Syscall(procCreateLayer.Addr(), 3, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(parent)))
131 131
 	if int32(r0) < 0 {
132
-		hr = interop.Win32FromHresult(r0)
132
+		if r0&0x1fff0000 == 0x00070000 {
133
+			r0 &= 0xffff
134
+		}
135
+		hr = syscall.Errno(r0)
133 136
 	}
134 137
 	return
135 138
 }
... ...
@@ -153,7 +161,10 @@ func _createSandboxLayer(info *driverInfo, id *uint16, parent uintptr, descripto
153 153
 	}
154 154
 	r0, _, _ := syscall.Syscall6(procCreateSandboxLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(parent), uintptr(unsafe.Pointer(_p1)), uintptr(len(descriptors)), 0)
155 155
 	if int32(r0) < 0 {
156
-		hr = interop.Win32FromHresult(r0)
156
+		if r0&0x1fff0000 == 0x00070000 {
157
+			r0 &= 0xffff
158
+		}
159
+		hr = syscall.Errno(r0)
157 160
 	}
158 161
 	return
159 162
 }
... ...
@@ -173,7 +184,10 @@ func _expandSandboxSize(info *driverInfo, id *uint16, size uint64) (hr error) {
173 173
 	}
174 174
 	r0, _, _ := syscall.Syscall(procExpandSandboxSize.Addr(), 3, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(size))
175 175
 	if int32(r0) < 0 {
176
-		hr = interop.Win32FromHresult(r0)
176
+		if r0&0x1fff0000 == 0x00070000 {
177
+			r0 &= 0xffff
178
+		}
179
+		hr = syscall.Errno(r0)
177 180
 	}
178 181
 	return
179 182
 }
... ...
@@ -193,7 +207,10 @@ func _deactivateLayer(info *driverInfo, id *uint16) (hr error) {
193 193
 	}
194 194
 	r0, _, _ := syscall.Syscall(procDeactivateLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
195 195
 	if int32(r0) < 0 {
196
-		hr = interop.Win32FromHresult(r0)
196
+		if r0&0x1fff0000 == 0x00070000 {
197
+			r0 &= 0xffff
198
+		}
199
+		hr = syscall.Errno(r0)
197 200
 	}
198 201
 	return
199 202
 }
... ...
@@ -213,7 +230,10 @@ func _destroyLayer(info *driverInfo, id *uint16) (hr error) {
213 213
 	}
214 214
 	r0, _, _ := syscall.Syscall(procDestroyLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
215 215
 	if int32(r0) < 0 {
216
-		hr = interop.Win32FromHresult(r0)
216
+		if r0&0x1fff0000 == 0x00070000 {
217
+			r0 &= 0xffff
218
+		}
219
+		hr = syscall.Errno(r0)
217 220
 	}
218 221
 	return
219 222
 }
... ...
@@ -242,7 +262,10 @@ func _exportLayer(info *driverInfo, id *uint16, path *uint16, descriptors []WC_L
242 242
 	}
243 243
 	r0, _, _ := syscall.Syscall6(procExportLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(_p2)), uintptr(len(descriptors)), 0)
244 244
 	if int32(r0) < 0 {
245
-		hr = interop.Win32FromHresult(r0)
245
+		if r0&0x1fff0000 == 0x00070000 {
246
+			r0 &= 0xffff
247
+		}
248
+		hr = syscall.Errno(r0)
246 249
 	}
247 250
 	return
248 251
 }
... ...
@@ -262,7 +285,10 @@ func _getLayerMountPath(info *driverInfo, id *uint16, length *uintptr, buffer *u
262 262
 	}
263 263
 	r0, _, _ := syscall.Syscall6(procGetLayerMountPath.Addr(), 4, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(length)), uintptr(unsafe.Pointer(buffer)), 0, 0)
264 264
 	if int32(r0) < 0 {
265
-		hr = interop.Win32FromHresult(r0)
265
+		if r0&0x1fff0000 == 0x00070000 {
266
+			r0 &= 0xffff
267
+		}
268
+		hr = syscall.Errno(r0)
266 269
 	}
267 270
 	return
268 271
 }
... ...
@@ -273,7 +299,10 @@ func getBaseImages(buffer **uint16) (hr error) {
273 273
 	}
274 274
 	r0, _, _ := syscall.Syscall(procGetBaseImages.Addr(), 1, uintptr(unsafe.Pointer(buffer)), 0, 0)
275 275
 	if int32(r0) < 0 {
276
-		hr = interop.Win32FromHresult(r0)
276
+		if r0&0x1fff0000 == 0x00070000 {
277
+			r0 &= 0xffff
278
+		}
279
+		hr = syscall.Errno(r0)
277 280
 	}
278 281
 	return
279 282
 }
... ...
@@ -302,7 +331,10 @@ func _importLayer(info *driverInfo, id *uint16, path *uint16, descriptors []WC_L
302 302
 	}
303 303
 	r0, _, _ := syscall.Syscall6(procImportLayer.Addr(), 5, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(_p2)), uintptr(len(descriptors)), 0)
304 304
 	if int32(r0) < 0 {
305
-		hr = interop.Win32FromHresult(r0)
305
+		if r0&0x1fff0000 == 0x00070000 {
306
+			r0 &= 0xffff
307
+		}
308
+		hr = syscall.Errno(r0)
306 309
 	}
307 310
 	return
308 311
 }
... ...
@@ -322,7 +354,10 @@ func _layerExists(info *driverInfo, id *uint16, exists *uint32) (hr error) {
322 322
 	}
323 323
 	r0, _, _ := syscall.Syscall(procLayerExists.Addr(), 3, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(exists)))
324 324
 	if int32(r0) < 0 {
325
-		hr = interop.Win32FromHresult(r0)
325
+		if r0&0x1fff0000 == 0x00070000 {
326
+			r0 &= 0xffff
327
+		}
328
+		hr = syscall.Errno(r0)
326 329
 	}
327 330
 	return
328 331
 }
... ...
@@ -342,7 +377,10 @@ func _nameToGuid(name *uint16, guid *_guid) (hr error) {
342 342
 	}
343 343
 	r0, _, _ := syscall.Syscall(procNameToGuid.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(guid)), 0)
344 344
 	if int32(r0) < 0 {
345
-		hr = interop.Win32FromHresult(r0)
345
+		if r0&0x1fff0000 == 0x00070000 {
346
+			r0 &= 0xffff
347
+		}
348
+		hr = syscall.Errno(r0)
346 349
 	}
347 350
 	return
348 351
 }
... ...
@@ -366,7 +404,10 @@ func _prepareLayer(info *driverInfo, id *uint16, descriptors []WC_LAYER_DESCRIPT
366 366
 	}
367 367
 	r0, _, _ := syscall.Syscall6(procPrepareLayer.Addr(), 4, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), uintptr(unsafe.Pointer(_p1)), uintptr(len(descriptors)), 0, 0)
368 368
 	if int32(r0) < 0 {
369
-		hr = interop.Win32FromHresult(r0)
369
+		if r0&0x1fff0000 == 0x00070000 {
370
+			r0 &= 0xffff
371
+		}
372
+		hr = syscall.Errno(r0)
370 373
 	}
371 374
 	return
372 375
 }
... ...
@@ -386,7 +427,10 @@ func _unprepareLayer(info *driverInfo, id *uint16) (hr error) {
386 386
 	}
387 387
 	r0, _, _ := syscall.Syscall(procUnprepareLayer.Addr(), 2, uintptr(unsafe.Pointer(info)), uintptr(unsafe.Pointer(id)), 0)
388 388
 	if int32(r0) < 0 {
389
-		hr = interop.Win32FromHresult(r0)
389
+		if r0&0x1fff0000 == 0x00070000 {
390
+			r0 &= 0xffff
391
+		}
392
+		hr = syscall.Errno(r0)
390 393
 	}
391 394
 	return
392 395
 }
... ...
@@ -406,7 +450,10 @@ func _processBaseImage(path *uint16) (hr error) {
406 406
 	}
407 407
 	r0, _, _ := syscall.Syscall(procProcessBaseImage.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
408 408
 	if int32(r0) < 0 {
409
-		hr = interop.Win32FromHresult(r0)
409
+		if r0&0x1fff0000 == 0x00070000 {
410
+			r0 &= 0xffff
411
+		}
412
+		hr = syscall.Errno(r0)
410 413
 	}
411 414
 	return
412 415
 }
... ...
@@ -426,7 +473,10 @@ func _processUtilityImage(path *uint16) (hr error) {
426 426
 	}
427 427
 	r0, _, _ := syscall.Syscall(procProcessUtilityImage.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
428 428
 	if int32(r0) < 0 {
429
-		hr = interop.Win32FromHresult(r0)
429
+		if r0&0x1fff0000 == 0x00070000 {
430
+			r0 &= 0xffff
431
+		}
432
+		hr = syscall.Errno(r0)
430 433
 	}
431 434
 	return
432 435
 }
... ...
@@ -451,7 +501,10 @@ func _grantVmAccess(vmid *uint16, filepath *uint16) (hr error) {
451 451
 	}
452 452
 	r0, _, _ := syscall.Syscall(procGrantVmAccess.Addr(), 2, uintptr(unsafe.Pointer(vmid)), uintptr(unsafe.Pointer(filepath)), 0)
453 453
 	if int32(r0) < 0 {
454
-		hr = interop.Win32FromHresult(r0)
454
+		if r0&0x1fff0000 == 0x00070000 {
455
+			r0 &= 0xffff
456
+		}
457
+		hr = syscall.Errno(r0)
455 458
 	}
456 459
 	return
457 460
 }
458 461
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+github.com/blang/semver v3.1.0
1
+github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
2
+github.com/containerd/go-runc 5a6d9f37cfa36b15efba46dc7ea349fa9b7143c3
3
+github.com/hashicorp/errwrap 7554cd9344cec97297fa6649b055a8c98c2a1e55
4
+github.com/hashicorp/go-multierror ed905158d87462226a13fe39ddf685ea65f1c11f
5
+github.com/konsorten/go-windows-terminal-sequences v1.0.1
6
+github.com/linuxkit/virtsock 8e79449dea0735c1c056d814934dd035734cc97c
7
+github.com/Microsoft/go-winio 16cfc975803886a5e47c4257a24c8d8c52e178b2
8
+github.com/Microsoft/opengcs v0.3.9
9
+github.com/opencontainers/runtime-spec eba862dc2470385a233c7507392675cbeadf7353
10
+github.com/opencontainers/runtime-tools 1d69bd0f9c39677d0630e50664fbc3154ae61b88
11
+github.com/pkg/errors v0.8.1
12
+github.com/sirupsen/logrus v1.3.0
13
+github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16
14
+github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
15
+github.com/xeipuuv/gojsonpointer 4e3ac2762d5f479393488629ee9370b50873b3a6
16
+github.com/xeipuuv/gojsonreference bd5ef7bd5415a7ac448318e64f11a24cd21e594b
17
+github.com/xeipuuv/gojsonschema 1d523034197ff1f222f6429836dd36a2457a1874
18
+golang.org/x/crypto ff983b9c42bc9fbf91556e191cc8efb585c16908
19
+golang.org/x/sync 37e7f081c4d4c64e13b10787722085407fe5d15f
20
+golang.org/x/sys e5ecc2a6747ce8d4af18ed98b3de5ae30eb3a5bb
0 21
\ No newline at end of file
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"syscall"
7 7
 	"unsafe"
8 8
 
9
-	"github.com/Microsoft/hcsshim/internal/interop"
10 9
 	"golang.org/x/sys/windows"
11 10
 )
12 11
 
... ...
@@ -46,7 +45,10 @@ var (
46 46
 func SetCurrentThreadCompartmentId(compartmentId uint32) (hr error) {
47 47
 	r0, _, _ := syscall.Syscall(procSetCurrentThreadCompartmentId.Addr(), 1, uintptr(compartmentId), 0, 0)
48 48
 	if int32(r0) < 0 {
49
-		hr = interop.Win32FromHresult(r0)
49
+		if r0&0x1fff0000 == 0x00070000 {
50
+			r0 &= 0xffff
51
+		}
52
+		hr = syscall.Errno(r0)
50 53
 	}
51 54
 	return
52 55
 }