vmcompute.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. package vmcompute
  2. import (
  3. gcontext "context"
  4. "syscall"
  5. "time"
  6. "github.com/Microsoft/hcsshim/internal/interop"
  7. "github.com/Microsoft/hcsshim/internal/log"
  8. "github.com/Microsoft/hcsshim/internal/logfields"
  9. "github.com/Microsoft/hcsshim/internal/oc"
  10. "github.com/Microsoft/hcsshim/internal/timeout"
  11. "go.opencensus.io/trace"
  12. )
  13. //go:generate go run ../../mksyscall_windows.go -output zsyscall_windows.go vmcompute.go
  14. //sys hcsEnumerateComputeSystems(query string, computeSystems **uint16, result **uint16) (hr error) = vmcompute.HcsEnumerateComputeSystems?
  15. //sys hcsCreateComputeSystem(id string, configuration string, identity syscall.Handle, computeSystem *HcsSystem, result **uint16) (hr error) = vmcompute.HcsCreateComputeSystem?
  16. //sys hcsOpenComputeSystem(id string, computeSystem *HcsSystem, result **uint16) (hr error) = vmcompute.HcsOpenComputeSystem?
  17. //sys hcsCloseComputeSystem(computeSystem HcsSystem) (hr error) = vmcompute.HcsCloseComputeSystem?
  18. //sys hcsStartComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsStartComputeSystem?
  19. //sys hcsShutdownComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsShutdownComputeSystem?
  20. //sys hcsTerminateComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsTerminateComputeSystem?
  21. //sys hcsPauseComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsPauseComputeSystem?
  22. //sys hcsResumeComputeSystem(computeSystem HcsSystem, options string, result **uint16) (hr error) = vmcompute.HcsResumeComputeSystem?
  23. //sys hcsGetComputeSystemProperties(computeSystem HcsSystem, propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetComputeSystemProperties?
  24. //sys hcsModifyComputeSystem(computeSystem HcsSystem, configuration string, result **uint16) (hr error) = vmcompute.HcsModifyComputeSystem?
  25. //sys hcsRegisterComputeSystemCallback(computeSystem HcsSystem, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) = vmcompute.HcsRegisterComputeSystemCallback?
  26. //sys hcsUnregisterComputeSystemCallback(callbackHandle HcsCallback) (hr error) = vmcompute.HcsUnregisterComputeSystemCallback?
  27. //sys hcsCreateProcess(computeSystem HcsSystem, processParameters string, processInformation *HcsProcessInformation, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsCreateProcess?
  28. //sys hcsOpenProcess(computeSystem HcsSystem, pid uint32, process *HcsProcess, result **uint16) (hr error) = vmcompute.HcsOpenProcess?
  29. //sys hcsCloseProcess(process HcsProcess) (hr error) = vmcompute.HcsCloseProcess?
  30. //sys hcsTerminateProcess(process HcsProcess, result **uint16) (hr error) = vmcompute.HcsTerminateProcess?
  31. //sys hcsSignalProcess(process HcsProcess, options string, result **uint16) (hr error) = vmcompute.HcsSignalProcess?
  32. //sys hcsGetProcessInfo(process HcsProcess, processInformation *HcsProcessInformation, result **uint16) (hr error) = vmcompute.HcsGetProcessInfo?
  33. //sys hcsGetProcessProperties(process HcsProcess, processProperties **uint16, result **uint16) (hr error) = vmcompute.HcsGetProcessProperties?
  34. //sys hcsModifyProcess(process HcsProcess, settings string, result **uint16) (hr error) = vmcompute.HcsModifyProcess?
  35. //sys hcsGetServiceProperties(propertyQuery string, properties **uint16, result **uint16) (hr error) = vmcompute.HcsGetServiceProperties?
  36. //sys hcsRegisterProcessCallback(process HcsProcess, callback uintptr, context uintptr, callbackHandle *HcsCallback) (hr error) = vmcompute.HcsRegisterProcessCallback?
  37. //sys hcsUnregisterProcessCallback(callbackHandle HcsCallback) (hr error) = vmcompute.HcsUnregisterProcessCallback?
  38. // errVmcomputeOperationPending is an error encountered when the operation is being completed asynchronously
  39. const errVmcomputeOperationPending = syscall.Errno(0xC0370103)
  40. // HcsSystem is the handle associated with a created compute system.
  41. type HcsSystem syscall.Handle
  42. // HcsProcess is the handle associated with a created process in a compute
  43. // system.
  44. type HcsProcess syscall.Handle
  45. // HcsCallback is the handle associated with the function to call when events
  46. // occur.
  47. type HcsCallback syscall.Handle
  48. // HcsProcessInformation is the structure used when creating or getting process
  49. // info.
  50. type HcsProcessInformation struct {
  51. // ProcessId is the pid of the created process.
  52. ProcessId uint32
  53. reserved uint32
  54. // StdInput is the handle associated with the stdin of the process.
  55. StdInput syscall.Handle
  56. // StdOutput is the handle associated with the stdout of the process.
  57. StdOutput syscall.Handle
  58. // StdError is the handle associated with the stderr of the process.
  59. StdError syscall.Handle
  60. }
  61. func execute(ctx gcontext.Context, timeout time.Duration, f func() error) error {
  62. if timeout > 0 {
  63. var cancel gcontext.CancelFunc
  64. ctx, cancel = gcontext.WithTimeout(ctx, timeout)
  65. defer cancel()
  66. }
  67. done := make(chan error, 1)
  68. go func() {
  69. done <- f()
  70. }()
  71. select {
  72. case <-ctx.Done():
  73. if ctx.Err() == gcontext.DeadlineExceeded {
  74. log.G(ctx).WithField(logfields.Timeout, timeout).
  75. 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.")
  76. }
  77. return ctx.Err()
  78. case err := <-done:
  79. return err
  80. }
  81. }
  82. func HcsEnumerateComputeSystems(ctx gcontext.Context, query string) (computeSystems, result string, hr error) {
  83. ctx, span := trace.StartSpan(ctx, "HcsEnumerateComputeSystems")
  84. defer span.End()
  85. defer func() {
  86. if result != "" {
  87. span.AddAttributes(trace.StringAttribute("result", result))
  88. }
  89. oc.SetSpanStatus(span, hr)
  90. }()
  91. span.AddAttributes(trace.StringAttribute("query", query))
  92. return computeSystems, result, execute(ctx, timeout.SyscallWatcher, func() error {
  93. var (
  94. computeSystemsp *uint16
  95. resultp *uint16
  96. )
  97. err := hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
  98. if computeSystemsp != nil {
  99. computeSystems = interop.ConvertAndFreeCoTaskMemString(computeSystemsp)
  100. }
  101. if resultp != nil {
  102. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  103. }
  104. return err
  105. })
  106. }
  107. func HcsCreateComputeSystem(ctx gcontext.Context, id string, configuration string, identity syscall.Handle) (computeSystem HcsSystem, result string, hr error) {
  108. ctx, span := trace.StartSpan(ctx, "HcsCreateComputeSystem")
  109. defer span.End()
  110. defer func() {
  111. if result != "" {
  112. span.AddAttributes(trace.StringAttribute("result", result))
  113. }
  114. if hr != errVmcomputeOperationPending {
  115. oc.SetSpanStatus(span, hr)
  116. }
  117. }()
  118. span.AddAttributes(
  119. trace.StringAttribute("id", id),
  120. trace.StringAttribute("configuration", configuration))
  121. return computeSystem, result, execute(ctx, timeout.SystemCreate, func() error {
  122. var resultp *uint16
  123. err := hcsCreateComputeSystem(id, configuration, identity, &computeSystem, &resultp)
  124. if resultp != nil {
  125. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  126. }
  127. return err
  128. })
  129. }
  130. func HcsOpenComputeSystem(ctx gcontext.Context, id string) (computeSystem HcsSystem, result string, hr error) {
  131. ctx, span := trace.StartSpan(ctx, "HcsOpenComputeSystem")
  132. defer span.End()
  133. defer func() {
  134. if result != "" {
  135. span.AddAttributes(trace.StringAttribute("result", result))
  136. }
  137. oc.SetSpanStatus(span, hr)
  138. }()
  139. return computeSystem, result, execute(ctx, timeout.SyscallWatcher, func() error {
  140. var resultp *uint16
  141. err := hcsOpenComputeSystem(id, &computeSystem, &resultp)
  142. if resultp != nil {
  143. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  144. }
  145. return err
  146. })
  147. }
  148. func HcsCloseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem) (hr error) {
  149. ctx, span := trace.StartSpan(ctx, "HcsCloseComputeSystem")
  150. defer span.End()
  151. defer func() { oc.SetSpanStatus(span, hr) }()
  152. return execute(ctx, timeout.SyscallWatcher, func() error {
  153. return hcsCloseComputeSystem(computeSystem)
  154. })
  155. }
  156. func HcsStartComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  157. ctx, span := trace.StartSpan(ctx, "HcsStartComputeSystem")
  158. defer span.End()
  159. defer func() {
  160. if result != "" {
  161. span.AddAttributes(trace.StringAttribute("result", result))
  162. }
  163. if hr != errVmcomputeOperationPending {
  164. oc.SetSpanStatus(span, hr)
  165. }
  166. }()
  167. span.AddAttributes(trace.StringAttribute("options", options))
  168. return result, execute(ctx, timeout.SystemStart, func() error {
  169. var resultp *uint16
  170. err := hcsStartComputeSystem(computeSystem, options, &resultp)
  171. if resultp != nil {
  172. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  173. }
  174. return err
  175. })
  176. }
  177. func HcsShutdownComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  178. ctx, span := trace.StartSpan(ctx, "HcsShutdownComputeSystem")
  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.SyscallWatcher, func() error {
  190. var resultp *uint16
  191. err := hcsShutdownComputeSystem(computeSystem, options, &resultp)
  192. if resultp != nil {
  193. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  194. }
  195. return err
  196. })
  197. }
  198. func HcsTerminateComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  199. ctx, span := trace.StartSpan(ctx, "HcsTerminateComputeSystem")
  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 := hcsTerminateComputeSystem(computeSystem, options, &resultp)
  213. if resultp != nil {
  214. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  215. }
  216. return err
  217. })
  218. }
  219. func HcsPauseComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  220. ctx, span := trace.StartSpan(ctx, "HcsPauseComputeSystem")
  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.SystemPause, func() error {
  232. var resultp *uint16
  233. err := hcsPauseComputeSystem(computeSystem, options, &resultp)
  234. if resultp != nil {
  235. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  236. }
  237. return err
  238. })
  239. }
  240. func HcsResumeComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, options string) (result string, hr error) {
  241. ctx, span := trace.StartSpan(ctx, "HcsResumeComputeSystem")
  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.SystemResume, func() error {
  253. var resultp *uint16
  254. err := hcsResumeComputeSystem(computeSystem, options, &resultp)
  255. if resultp != nil {
  256. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  257. }
  258. return err
  259. })
  260. }
  261. func HcsGetComputeSystemProperties(ctx gcontext.Context, computeSystem HcsSystem, propertyQuery string) (properties, result string, hr error) {
  262. ctx, span := trace.StartSpan(ctx, "HcsGetComputeSystemProperties")
  263. defer span.End()
  264. defer func() {
  265. if result != "" {
  266. span.AddAttributes(trace.StringAttribute("result", result))
  267. }
  268. oc.SetSpanStatus(span, hr)
  269. }()
  270. span.AddAttributes(trace.StringAttribute("propertyQuery", propertyQuery))
  271. return properties, result, execute(ctx, timeout.SyscallWatcher, func() error {
  272. var (
  273. propertiesp *uint16
  274. resultp *uint16
  275. )
  276. err := hcsGetComputeSystemProperties(computeSystem, propertyQuery, &propertiesp, &resultp)
  277. if propertiesp != nil {
  278. properties = interop.ConvertAndFreeCoTaskMemString(propertiesp)
  279. }
  280. if resultp != nil {
  281. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  282. }
  283. return err
  284. })
  285. }
  286. func HcsModifyComputeSystem(ctx gcontext.Context, computeSystem HcsSystem, configuration string) (result string, hr error) {
  287. ctx, span := trace.StartSpan(ctx, "HcsModifyComputeSystem")
  288. defer span.End()
  289. defer func() {
  290. if result != "" {
  291. span.AddAttributes(trace.StringAttribute("result", result))
  292. }
  293. oc.SetSpanStatus(span, hr)
  294. }()
  295. span.AddAttributes(trace.StringAttribute("configuration", configuration))
  296. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  297. var resultp *uint16
  298. err := hcsModifyComputeSystem(computeSystem, configuration, &resultp)
  299. if resultp != nil {
  300. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  301. }
  302. return err
  303. })
  304. }
  305. func HcsRegisterComputeSystemCallback(ctx gcontext.Context, computeSystem HcsSystem, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) {
  306. ctx, span := trace.StartSpan(ctx, "HcsRegisterComputeSystemCallback")
  307. defer span.End()
  308. defer func() { oc.SetSpanStatus(span, hr) }()
  309. return callbackHandle, execute(ctx, timeout.SyscallWatcher, func() error {
  310. return hcsRegisterComputeSystemCallback(computeSystem, callback, context, &callbackHandle)
  311. })
  312. }
  313. func HcsUnregisterComputeSystemCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) {
  314. ctx, span := trace.StartSpan(ctx, "HcsUnregisterComputeSystemCallback")
  315. defer span.End()
  316. defer func() { oc.SetSpanStatus(span, hr) }()
  317. return execute(ctx, timeout.SyscallWatcher, func() error {
  318. return hcsUnregisterComputeSystemCallback(callbackHandle)
  319. })
  320. }
  321. func HcsCreateProcess(ctx gcontext.Context, computeSystem HcsSystem, processParameters string) (processInformation HcsProcessInformation, process HcsProcess, result string, hr error) {
  322. ctx, span := trace.StartSpan(ctx, "HcsCreateProcess")
  323. defer span.End()
  324. defer func() {
  325. if result != "" {
  326. span.AddAttributes(trace.StringAttribute("result", result))
  327. }
  328. oc.SetSpanStatus(span, hr)
  329. }()
  330. span.AddAttributes(trace.StringAttribute("processParameters", processParameters))
  331. return processInformation, process, result, execute(ctx, timeout.SyscallWatcher, func() error {
  332. var resultp *uint16
  333. err := hcsCreateProcess(computeSystem, processParameters, &processInformation, &process, &resultp)
  334. if resultp != nil {
  335. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  336. }
  337. return err
  338. })
  339. }
  340. func HcsOpenProcess(ctx gcontext.Context, computeSystem HcsSystem, pid uint32) (process HcsProcess, result string, hr error) {
  341. ctx, span := trace.StartSpan(ctx, "HcsOpenProcess")
  342. defer span.End()
  343. defer func() {
  344. if result != "" {
  345. span.AddAttributes(trace.StringAttribute("result", result))
  346. }
  347. oc.SetSpanStatus(span, hr)
  348. }()
  349. span.AddAttributes(trace.Int64Attribute("pid", int64(pid)))
  350. return process, result, execute(ctx, timeout.SyscallWatcher, func() error {
  351. var resultp *uint16
  352. err := hcsOpenProcess(computeSystem, pid, &process, &resultp)
  353. if resultp != nil {
  354. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  355. }
  356. return err
  357. })
  358. }
  359. func HcsCloseProcess(ctx gcontext.Context, process HcsProcess) (hr error) {
  360. ctx, span := trace.StartSpan(ctx, "HcsCloseProcess")
  361. defer span.End()
  362. defer func() { oc.SetSpanStatus(span, hr) }()
  363. return execute(ctx, timeout.SyscallWatcher, func() error {
  364. return hcsCloseProcess(process)
  365. })
  366. }
  367. func HcsTerminateProcess(ctx gcontext.Context, process HcsProcess) (result string, hr error) {
  368. ctx, span := trace.StartSpan(ctx, "HcsTerminateProcess")
  369. defer span.End()
  370. defer func() {
  371. if result != "" {
  372. span.AddAttributes(trace.StringAttribute("result", result))
  373. }
  374. oc.SetSpanStatus(span, hr)
  375. }()
  376. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  377. var resultp *uint16
  378. err := hcsTerminateProcess(process, &resultp)
  379. if resultp != nil {
  380. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  381. }
  382. return err
  383. })
  384. }
  385. func HcsSignalProcess(ctx gcontext.Context, process HcsProcess, options string) (result string, hr error) {
  386. ctx, span := trace.StartSpan(ctx, "HcsSignalProcess")
  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.StringAttribute("options", options))
  395. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  396. var resultp *uint16
  397. err := hcsSignalProcess(process, options, &resultp)
  398. if resultp != nil {
  399. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  400. }
  401. return err
  402. })
  403. }
  404. func HcsGetProcessInfo(ctx gcontext.Context, process HcsProcess) (processInformation HcsProcessInformation, result string, hr error) {
  405. ctx, span := trace.StartSpan(ctx, "HcsGetProcessInfo")
  406. defer span.End()
  407. defer func() {
  408. if result != "" {
  409. span.AddAttributes(trace.StringAttribute("result", result))
  410. }
  411. oc.SetSpanStatus(span, hr)
  412. }()
  413. return processInformation, result, execute(ctx, timeout.SyscallWatcher, func() error {
  414. var resultp *uint16
  415. err := hcsGetProcessInfo(process, &processInformation, &resultp)
  416. if resultp != nil {
  417. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  418. }
  419. return err
  420. })
  421. }
  422. func HcsGetProcessProperties(ctx gcontext.Context, process HcsProcess) (processProperties, result string, hr error) {
  423. ctx, span := trace.StartSpan(ctx, "HcsGetProcessProperties")
  424. defer span.End()
  425. defer func() {
  426. if result != "" {
  427. span.AddAttributes(trace.StringAttribute("result", result))
  428. }
  429. oc.SetSpanStatus(span, hr)
  430. }()
  431. return processProperties, result, execute(ctx, timeout.SyscallWatcher, func() error {
  432. var (
  433. processPropertiesp *uint16
  434. resultp *uint16
  435. )
  436. err := hcsGetProcessProperties(process, &processPropertiesp, &resultp)
  437. if processPropertiesp != nil {
  438. processProperties = interop.ConvertAndFreeCoTaskMemString(processPropertiesp)
  439. }
  440. if resultp != nil {
  441. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  442. }
  443. return err
  444. })
  445. }
  446. func HcsModifyProcess(ctx gcontext.Context, process HcsProcess, settings string) (result string, hr error) {
  447. ctx, span := trace.StartSpan(ctx, "HcsModifyProcess")
  448. defer span.End()
  449. defer func() {
  450. if result != "" {
  451. span.AddAttributes(trace.StringAttribute("result", result))
  452. }
  453. oc.SetSpanStatus(span, hr)
  454. }()
  455. span.AddAttributes(trace.StringAttribute("settings", settings))
  456. return result, execute(ctx, timeout.SyscallWatcher, func() error {
  457. var resultp *uint16
  458. err := hcsModifyProcess(process, settings, &resultp)
  459. if resultp != nil {
  460. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  461. }
  462. return err
  463. })
  464. }
  465. func HcsGetServiceProperties(ctx gcontext.Context, propertyQuery string) (properties, result string, hr error) {
  466. ctx, span := trace.StartSpan(ctx, "HcsGetServiceProperties")
  467. defer span.End()
  468. defer func() {
  469. if result != "" {
  470. span.AddAttributes(trace.StringAttribute("result", result))
  471. }
  472. oc.SetSpanStatus(span, hr)
  473. }()
  474. span.AddAttributes(trace.StringAttribute("propertyQuery", propertyQuery))
  475. return properties, result, execute(ctx, timeout.SyscallWatcher, func() error {
  476. var (
  477. propertiesp *uint16
  478. resultp *uint16
  479. )
  480. err := hcsGetServiceProperties(propertyQuery, &propertiesp, &resultp)
  481. if propertiesp != nil {
  482. properties = interop.ConvertAndFreeCoTaskMemString(propertiesp)
  483. }
  484. if resultp != nil {
  485. result = interop.ConvertAndFreeCoTaskMemString(resultp)
  486. }
  487. return err
  488. })
  489. }
  490. func HcsRegisterProcessCallback(ctx gcontext.Context, process HcsProcess, callback uintptr, context uintptr) (callbackHandle HcsCallback, hr error) {
  491. ctx, span := trace.StartSpan(ctx, "HcsRegisterProcessCallback")
  492. defer span.End()
  493. defer func() { oc.SetSpanStatus(span, hr) }()
  494. return callbackHandle, execute(ctx, timeout.SyscallWatcher, func() error {
  495. return hcsRegisterProcessCallback(process, callback, context, &callbackHandle)
  496. })
  497. }
  498. func HcsUnregisterProcessCallback(ctx gcontext.Context, callbackHandle HcsCallback) (hr error) {
  499. ctx, span := trace.StartSpan(ctx, "HcsUnregisterProcessCallback")
  500. defer span.End()
  501. defer func() { oc.SetSpanStatus(span, hr) }()
  502. return execute(ctx, timeout.SyscallWatcher, func() error {
  503. return hcsUnregisterProcessCallback(callbackHandle)
  504. })
  505. }