vmcompute.go 21 KB

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