vmcompute.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. //go:build windows
  2. package vmcompute
  3. import (
  4. gcontext "context"
  5. "syscall"
  6. "time"
  7. "github.com/sirupsen/logrus"
  8. "go.opencensus.io/trace"
  9. "github.com/Microsoft/hcsshim/internal/interop"
  10. "github.com/Microsoft/hcsshim/internal/log"
  11. "github.com/Microsoft/hcsshim/internal/logfields"
  12. "github.com/Microsoft/hcsshim/internal/oc"
  13. "github.com/Microsoft/hcsshim/internal/timeout"
  14. )
  15. //go:generate go run github.com/Microsoft/go-winio/tools/mkwinsyscall -output zsyscall_windows.go vmcompute.go
  16. //sys hcsEnumerateComputeSystems(query string, computeSystems **uint16, result **uint16) (hr error) = vmcompute.HcsEnumerateComputeSystems?
  17. //sys hcsCreateComputeSystem(id string, configuration string, identity syscall.Handle, computeSystem *HcsSystem, result **uint16) (hr error) = vmcompute.HcsCreateComputeSystem?
  18. //sys hcsOpenComputeSystem(id string, computeSystem *HcsSystem, result **uint16) (hr error) = vmcompute.HcsOpenComputeSystem?
  19. //sys hcsCloseComputeSystem(computeSystem HcsSystem) (hr error) = vmcompute.HcsCloseComputeSystem?
  20. //sys hcsStartComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsStartComputeSystem?
  21. //sys hcsShutdownComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsShutdownComputeSystem?
  22. //sys hcsTerminateComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsTerminateComputeSystem?
  23. //sys hcsPauseComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsPauseComputeSystem?
  24. //sys hcsResumeComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsResumeComputeSystem?
  25. //sys hcsGetComputeSystemProperties(computeSystem HcsSystem, propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetComputeSystemProperties?
  26. //sys hcsModifyComputeSystem(computeSystem HcsSystem, configuration string, result **uint16) (hr error) = vmcompute.HcsModifyComputeSystem?
  27. //sys hcsModifyServiceSettings(settings string, result **uint16) (hr error) = vmcompute.HcsModifyServiceSettings?
  28. //sys hcsRegisterComputeSystemCallback(computeSystem HcsSystem, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) = vmcompute.HcsRegisterComputeSystemCallback?
  29. //sys hcsUnregisterComputeSystemCallback(callbackHandle HcsCallback) (hr error) = vmcompute.HcsUnregisterComputeSystemCallback?
  30. //sys hcsSaveComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsSaveComputeSystem?
  31. //sys hcsCreateProcess(computeSystem HcsSystem, processParameters string, processInformation *HcsProcessInformation, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsCreateProcess?
  32. //sys hcsOpenProcess(computeSystem HcsSystem, pid uint32, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsOpenProcess?
  33. //sys hcsCloseProcess(process HcsProcess) (hr error) = vmcompute.HcsCloseProcess?
  34. //sys hcsTerminateProcess(process HcsProcess, result **uint16) (hr error) = vmcompute.HcsTerminateProcess?
  35. //sys hcsSignalProcess(process HcsProcess, options string, result **uint16) (hr error) = vmcompute.HcsSignalProcess?
  36. //sys hcsGetProcessInfo(process HcsProcess, processInformation *HcsProcessInformation, result **uint16) (hr error) = vmcompute.HcsGetProcessInfo?
  37. //sys hcsGetProcessProperties(process HcsProcess, processProperties **uint16, result **uint16) (hr error) = vmcompute.HcsGetProcessProperties?
  38. //sys hcsModifyProcess(process HcsProcess, settings string, result **uint16) (hr error) = vmcompute.HcsModifyProcess?
  39. //sys hcsGetServiceProperties(propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetServiceProperties?
  40. //sys hcsRegisterProcessCallback(process HcsProcess, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) = vmcompute.HcsRegisterProcessCallback?
  41. //sys hcsUnregisterProcessCallback(callbackHandle HcsCallback) (hr error) = vmcompute.HcsUnregisterProcessCallback?
  42. // errVmcomputeOperationPending is an error encountered when the operation is being completed asynchronously
  43. const errVmcomputeOperationPending = syscall.Errno(0xC0370103)
  44. // HcsSystem is the handle associated with a created compute system.
  45. type HcsSystem syscall.Handle
  46. // HcsProcess is the handle associated with a created process in a compute
  47. // system.
  48. type HcsProcess syscall.Handle
  49. // HcsCallback is the handle associated with the function to call when events
  50. // occur.
  51. type HcsCallback syscall.Handle
  52. // HcsProcessInformation is the structure used when creating or getting process
  53. // info.
  54. type HcsProcessInformation struct {
  55. // ProcessId is the pid of the created process.
  56. ProcessId uint32
  57. _ uint32 // reserved padding
  58. // StdInput is the handle associated with the stdin of the process.
  59. StdInput syscall.Handle
  60. // StdOutput is the handle associated with the stdout of the process.
  61. StdOutput syscall.Handle
  62. // StdError is the handle associated with the stderr of the process.
  63. StdError syscall.Handle
  64. }
  65. func execute(ctx gcontext.Context, timeout time.Duration, f func() error) error {
  66. now := time.Now()
  67. if timeout > 0 {
  68. var cancel gcontext.CancelFunc
  69. ctx, cancel = gcontext.WithTimeout(ctx, timeout)
  70. defer cancel()
  71. }
  72. // if ctx already has prior deadlines, the shortest timeout takes precedence and is used.
  73. // find the true timeout for reporting
  74. //
  75. // this is mostly an issue with (*UtilityVM).Start(context.Context), which sets its
  76. // own (2 minute) timeout.
  77. deadline, ok := ctx.Deadline()
  78. trueTimeout := timeout
  79. if ok {
  80. trueTimeout = deadline.Sub(now)
  81. log.G(ctx).WithFields(logrus.Fields{
  82. logfields.Timeout: trueTimeout,
  83. "desiredTimeout": timeout,
  84. }).Trace("Executing syscall with deadline")
  85. }
  86. done := make(chan error, 1)
  87. go func() {
  88. done <- f()
  89. }()
  90. select {
  91. case <-ctx.Done():
  92. if ctx.Err() == gcontext.DeadlineExceeded {
  93. log.G(ctx).WithField(logfields.Timeout, trueTimeout).
  94. Warning("Syscall did not complete within operation timeout. This may indicate a platform issue. " +
  95. "If it appears to be making no forward progress, obtain the stacks and see if there is a syscall " +
  96. "stuck in the platform API for a significant length of time.")
  97. }
  98. return ctx.Err()
  99. case err := <-done:
  100. return err
  101. }
  102. }
  103. func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSystems, result string, hr error) {
  104. ctx, span := oc.StartSpan(ctx, "HcsEnumerateComputeSystems")
  105. defer span.End()
  106. defer func() {
  107. if result != "" {
  108. span.AddAttributes(trace.StringAttribute("result", result))
  109. }
  110. oc.SetSpanStatus(span, hr)
  111. }()
  112. span.AddAttributes(trace.StringAttribute("query", query))
  113. return computeSystems, result, execute(ctx, timeout.SyscallWatcher, func() error {
  114. var (
  115. computeSystemsp *uint16
  116. resultp *uint16
  117. )
  118. err := hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
  119. if computeSystemsp != nil {
  120. computeSystems = interop.ConvertAndFreeCoTaskMemString(computeSystemsp)
  121. }
  122. if resultp != nil {
  123. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  124. }
  125. return err
  126. })
  127. }
  128. func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration string, identity syscall.Handle) (computeSystem HcsSystem, result string, hr error) {
  129. ctx, span := oc.StartSpan(ctx, "HcsCreateComputeSystem")
  130. defer span.End()
  131. defer func() {
  132. if result != "" {
  133. span.AddAttributes(trace.StringAttribute("result", result))
  134. }
  135. if hr != errVmcomputeOperationPending {
  136. oc.SetSpanStatus(span, hr)
  137. }
  138. }()
  139. span.AddAttributes(
  140. trace.StringAttribute("id", id),
  141. trace.StringAttribute("configuration", configuration))
  142. return computeSystem, result, execute(ctx, timeout.SystemCreate, func() error {
  143. var resultp *uint16
  144. err := hcsCreateComputeSystem(id, configuration, identity, &computeSystem, &resultp)
  145. if resultp != nil {
  146. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  147. }
  148. return err
  149. })
  150. }
  151. func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSystem, result string, hr error) {
  152. ctx, span := oc.StartSpan(ctx, "HcsOpenComputeSystem")
  153. defer span.End()
  154. defer func() {
  155. if result != "" {
  156. span.AddAttributes(trace.StringAttribute("result", result))
  157. }
  158. oc.SetSpanStatus(span, hr)
  159. }()
  160. return computeSystem, result, execute(ctx, timeout.SyscallWatcher, func() error {
  161. var resultp *uint16
  162. err := hcsOpenComputeSystem(id, &computeSystem, &resultp)
  163. if resultp != nil {
  164. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  165. }
  166. return err
  167. })
  168. }
  169. func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr error) {
  170. ctx, span := oc.StartSpan(ctx, "HcsCloseComputeSystem")
  171. defer span.End()
  172. defer func() { oc.SetSpanStatus(span, hr) }()
  173. return execute(ctx, timeout.SyscallWatcher, func() error {
  174. return hcsCloseComputeSystem(computeSystem)
  175. })
  176. }
  177. func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  178. ctx, span := oc.StartSpan(ctx, "HcsStartComputeSystem")
  179. defer span.End()
  180. defer func() {
  181. if result != "" {
  182. span.AddAttributes(trace.StringAttribute("result", result))
  183. }
  184. if hr != errVmcomputeOperationPending {
  185. oc.SetSpanStatus(span, hr)
  186. }
  187. }()
  188. span.AddAttributes(trace.StringAttribute("options", options))
  189. return result, execute(ctx, timeout.SystemStart, func() error {
  190. var resultp *uint16
  191. err := hcsStartComputeSystem(computeSystem, options, &resultp)
  192. if resultp != nil {
  193. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  194. }
  195. return err
  196. })
  197. }
  198. func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  199. ctx, span := oc.StartSpan(ctx, "HcsShutdownComputeSystem")
  200. defer span.End()
  201. defer func() {
  202. if result != "" {
  203. span.AddAttributes(trace.StringAttribute("result", result))
  204. }
  205. if hr != errVmcomputeOperationPending {
  206. oc.SetSpanStatus(span, hr)
  207. }
  208. }()
  209. span.AddAttributes(trace.StringAttribute("options", options))
  210. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  211. var resultp *uint16
  212. err := hcsShutdownComputeSystem(computeSystem, options, &resultp)
  213. if resultp != nil {
  214. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  215. }
  216. return err
  217. })
  218. }
  219. func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  220. ctx, span := oc.StartSpan(ctx, "HcsTerminateComputeSystem")
  221. defer span.End()
  222. defer func() {
  223. if result != "" {
  224. span.AddAttributes(trace.StringAttribute("result", result))
  225. }
  226. if hr != errVmcomputeOperationPending {
  227. oc.SetSpanStatus(span, hr)
  228. }
  229. }()
  230. span.AddAttributes(trace.StringAttribute("options", options))
  231. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  232. var resultp *uint16
  233. err := hcsTerminateComputeSystem(computeSystem, options, &resultp)
  234. if resultp != nil {
  235. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  236. }
  237. return err
  238. })
  239. }
  240. func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  241. ctx, span := oc.StartSpan(ctx, "HcsPauseComputeSystem")
  242. defer span.End()
  243. defer func() {
  244. if result != "" {
  245. span.AddAttributes(trace.StringAttribute("result", result))
  246. }
  247. if hr != errVmcomputeOperationPending {
  248. oc.SetSpanStatus(span, hr)
  249. }
  250. }()
  251. span.AddAttributes(trace.StringAttribute("options", options))
  252. return result, execute(ctx, timeout.SystemPause, func() error {
  253. var resultp *uint16
  254. err := hcsPauseComputeSystem(computeSystem, options, &resultp)
  255. if resultp != nil {
  256. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  257. }
  258. return err
  259. })
  260. }
  261. func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  262. ctx, span := oc.StartSpan(ctx, "HcsResumeComputeSystem")
  263. defer span.End()
  264. defer func() {
  265. if result != "" {
  266. span.AddAttributes(trace.StringAttribute("result", result))
  267. }
  268. if hr != errVmcomputeOperationPending {
  269. oc.SetSpanStatus(span, hr)
  270. }
  271. }()
  272. span.AddAttributes(trace.StringAttribute("options", options))
  273. return result, execute(ctx, timeout.SystemResume, func() error {
  274. var resultp *uint16
  275. err := hcsResumeComputeSystem(computeSystem, options, &resultp)
  276. if resultp != nil {
  277. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  278. }
  279. return err
  280. })
  281. }
  282. func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem, propertyQuery string) (properties, result string, hr error) {
  283. ctx, span := oc.StartSpan(ctx, "HcsGetComputeSystemProperties")
  284. defer span.End()
  285. defer func() {
  286. if result != "" {
  287. span.AddAttributes(trace.StringAttribute("result", result))
  288. }
  289. oc.SetSpanStatus(span, hr)
  290. }()
  291. span.AddAttributes(trace.StringAttribute("propertyQuery", propertyQuery))
  292. return properties, result, execute(ctx, timeout.SyscallWatcher, func() error {
  293. var (
  294. propertiesp *uint16
  295. resultp *uint16
  296. )
  297. err := hcsGetComputeSystemProperties(computeSystem, propertyQuery, &propertiesp, &resultp)
  298. if propertiesp != nil {
  299. properties = interop.ConvertAndFreeCoTaskMemString(propertiesp)
  300. }
  301. if resultp != nil {
  302. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  303. }
  304. return err
  305. })
  306. }
  307. func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, configuration string) (result string, hr error) {
  308. ctx, span := oc.StartSpan(ctx, "HcsModifyComputeSystem")
  309. defer span.End()
  310. defer func() {
  311. if result != "" {
  312. span.AddAttributes(trace.StringAttribute("result", result))
  313. }
  314. oc.SetSpanStatus(span, hr)
  315. }()
  316. span.AddAttributes(trace.StringAttribute("configuration", configuration))
  317. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  318. var resultp *uint16
  319. err := hcsModifyComputeSystem(computeSystem, configuration, &resultp)
  320. if resultp != nil {
  321. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  322. }
  323. return err
  324. })
  325. }
  326. func HcsModifyServiceSettings(ctx gcontext.Context, settings string) (result string, hr error) {
  327. ctx, span := oc.StartSpan(ctx, "HcsModifyServiceSettings")
  328. defer span.End()
  329. defer func() {
  330. if result != "" {
  331. span.AddAttributes(trace.StringAttribute("result", result))
  332. }
  333. oc.SetSpanStatus(span, hr)
  334. }()
  335. span.AddAttributes(trace.StringAttribute("settings", settings))
  336. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  337. var resultp *uint16
  338. err := hcsModifyServiceSettings(settings, &resultp)
  339. if resultp != nil {
  340. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  341. }
  342. return err
  343. })
  344. }
  345. func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSystem, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) {
  346. ctx, span := oc.StartSpan(ctx, "HcsRegisterComputeSystemCallback")
  347. defer span.End()
  348. defer func() { oc.SetSpanStatus(span, hr) }()
  349. return callbackHandle, execute(ctx, timeout.SyscallWatcher, func() error {
  350. return hcsRegisterComputeSystemCallback(computeSystem, callback, context, &callbackHandle)
  351. })
  352. }
  353. func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) {
  354. ctx, span := oc.StartSpan(ctx, "HcsUnregisterComputeSystemCallback")
  355. defer span.End()
  356. defer func() { oc.SetSpanStatus(span, hr) }()
  357. return execute(ctx, timeout.SyscallWatcher, func() error {
  358. return hcsUnregisterComputeSystemCallback(callbackHandle)
  359. })
  360. }
  361. func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processParameters string) (processInformation HcsProcessInformation, process HcsProcess, result string, hr error) {
  362. ctx, span := oc.StartSpan(ctx, "HcsCreateProcess")
  363. defer span.End()
  364. defer func() {
  365. if result != "" {
  366. span.AddAttributes(trace.StringAttribute("result", result))
  367. }
  368. oc.SetSpanStatus(span, hr)
  369. }()
  370. if span.IsRecordingEvents() {
  371. // wont handle v1 process parameters
  372. if s, err := log.ScrubProcessParameters(processParameters); err == nil {
  373. span.AddAttributes(trace.StringAttribute("processParameters", s))
  374. }
  375. }
  376. return processInformation, process, result, execute(ctx, timeout.SyscallWatcher, func() error {
  377. var resultp *uint16
  378. err := hcsCreateProcess(computeSystem, processParameters, &processInformation, &process, &resultp)
  379. if resultp != nil {
  380. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  381. }
  382. return err
  383. })
  384. }
  385. func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) (process HcsProcess, result string, hr error) {
  386. ctx, span := oc.StartSpan(ctx, "HcsOpenProcess")
  387. defer span.End()
  388. defer func() {
  389. if result != "" {
  390. span.AddAttributes(trace.StringAttribute("result", result))
  391. }
  392. oc.SetSpanStatus(span, hr)
  393. }()
  394. span.AddAttributes(trace.Int64Attribute("pid", int64(pid)))
  395. return process, result, execute(ctx, timeout.SyscallWatcher, func() error {
  396. var resultp *uint16
  397. err := hcsOpenProcess(computeSystem, pid, &process, &resultp)
  398. if resultp != nil {
  399. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  400. }
  401. return err
  402. })
  403. }
  404. func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) {
  405. ctx, span := oc.StartSpan(ctx, "HcsCloseProcess")
  406. defer span.End()
  407. defer func() { oc.SetSpanStatus(span, hr) }()
  408. return execute(ctx, timeout.SyscallWatcher, func() error {
  409. return hcsCloseProcess(process)
  410. })
  411. }
  412. func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result string, hr error) {
  413. ctx, span := oc.StartSpan(ctx, "HcsTerminateProcess")
  414. defer span.End()
  415. defer func() {
  416. if result != "" {
  417. span.AddAttributes(trace.StringAttribute("result", result))
  418. }
  419. oc.SetSpanStatus(span, hr)
  420. }()
  421. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  422. var resultp *uint16
  423. err := hcsTerminateProcess(process, &resultp)
  424. if resultp != nil {
  425. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  426. }
  427. return err
  428. })
  429. }
  430. func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) (result string, hr error) {
  431. ctx, span := oc.StartSpan(ctx, "HcsSignalProcess")
  432. defer span.End()
  433. defer func() {
  434. if result != "" {
  435. span.AddAttributes(trace.StringAttribute("result", result))
  436. }
  437. oc.SetSpanStatus(span, hr)
  438. }()
  439. span.AddAttributes(trace.StringAttribute("options", options))
  440. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  441. var resultp *uint16
  442. err := hcsSignalProcess(process, options, &resultp)
  443. if resultp != nil {
  444. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  445. }
  446. return err
  447. })
  448. }
  449. func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInformation HcsProcessInformation, result string, hr error) {
  450. ctx, span := oc.StartSpan(ctx, "HcsGetProcessInfo")
  451. defer span.End()
  452. defer func() {
  453. if result != "" {
  454. span.AddAttributes(trace.StringAttribute("result", result))
  455. }
  456. oc.SetSpanStatus(span, hr)
  457. }()
  458. return processInformation, result, execute(ctx, timeout.SyscallWatcher, func() error {
  459. var resultp *uint16
  460. err := hcsGetProcessInfo(process, &processInformation, &resultp)
  461. if resultp != nil {
  462. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  463. }
  464. return err
  465. })
  466. }
  467. func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processProperties, result string, hr error) {
  468. ctx, span := oc.StartSpan(ctx, "HcsGetProcessProperties")
  469. defer span.End()
  470. defer func() {
  471. if result != "" {
  472. span.AddAttributes(trace.StringAttribute("result", result))
  473. }
  474. oc.SetSpanStatus(span, hr)
  475. }()
  476. return processProperties, result, execute(ctx, timeout.SyscallWatcher, func() error {
  477. var (
  478. processPropertiesp *uint16
  479. resultp *uint16
  480. )
  481. err := hcsGetProcessProperties(process, &processPropertiesp, &resultp)
  482. if processPropertiesp != nil {
  483. processProperties = interop.ConvertAndFreeCoTaskMemString(processPropertiesp)
  484. }
  485. if resultp != nil {
  486. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  487. }
  488. return err
  489. })
  490. }
  491. func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) (result string, hr error) {
  492. ctx, span := oc.StartSpan(ctx, "HcsModifyProcess")
  493. defer span.End()
  494. defer func() {
  495. if result != "" {
  496. span.AddAttributes(trace.StringAttribute("result", result))
  497. }
  498. oc.SetSpanStatus(span, hr)
  499. }()
  500. span.AddAttributes(trace.StringAttribute("settings", settings))
  501. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  502. var resultp *uint16
  503. err := hcsModifyProcess(process, settings, &resultp)
  504. if resultp != nil {
  505. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  506. }
  507. return err
  508. })
  509. }
  510. func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (properties, result string, hr error) {
  511. ctx, span := oc.StartSpan(ctx, "HcsGetServiceProperties")
  512. defer span.End()
  513. defer func() {
  514. if result != "" {
  515. span.AddAttributes(trace.StringAttribute("result", result))
  516. }
  517. oc.SetSpanStatus(span, hr)
  518. }()
  519. span.AddAttributes(trace.StringAttribute("propertyQuery", propertyQuery))
  520. return properties, result, execute(ctx, timeout.SyscallWatcher, func() error {
  521. var (
  522. propertiesp *uint16
  523. resultp *uint16
  524. )
  525. err := hcsGetServiceProperties(propertyQuery, &propertiesp, &resultp)
  526. if propertiesp != nil {
  527. properties = interop.ConvertAndFreeCoTaskMemString(propertiesp)
  528. }
  529. if resultp != nil {
  530. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  531. }
  532. return err
  533. })
  534. }
  535. func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) {
  536. ctx, span := oc.StartSpan(ctx, "HcsRegisterProcessCallback")
  537. defer span.End()
  538. defer func() { oc.SetSpanStatus(span, hr) }()
  539. return callbackHandle, execute(ctx, timeout.SyscallWatcher, func() error {
  540. return hcsRegisterProcessCallback(process, callback, context, &callbackHandle)
  541. })
  542. }
  543. func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) {
  544. ctx, span := oc.StartSpan(ctx, "HcsUnregisterProcessCallback")
  545. defer span.End()
  546. defer func() { oc.SetSpanStatus(span, hr) }()
  547. return execute(ctx, timeout.SyscallWatcher, func() error {
  548. return hcsUnregisterProcessCallback(callbackHandle)
  549. })
  550. }
  551. func HcsSaveComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  552. ctx, span := oc.StartSpan(ctx, "HcsSaveComputeSystem")
  553. defer span.End()
  554. defer func() {
  555. if result != "" {
  556. span.AddAttributes(trace.StringAttribute("result", result))
  557. }
  558. if hr != errVmcomputeOperationPending {
  559. oc.SetSpanStatus(span, hr)
  560. }
  561. }()
  562. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  563. var resultp *uint16
  564. err := hcsSaveComputeSystem(computeSystem, options, &resultp)
  565. if resultp != nil {
  566. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  567. }
  568. return err
  569. })
  570. }