pal_api.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef __WAMR_PAL_API_H__
  6. #define __WAMR_PAL_API_H__
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*
  11. * WAMR PAL API version number
  12. */
  13. #define WAMR_PAL_VERSION 2
  14. /*
  15. * @brief Get version of WAMR PAL API
  16. *
  17. * @retval If > 0, then success; otherwise, it is an invalid version.
  18. */
  19. int
  20. wamr_pal_get_version(void);
  21. /*
  22. * WAMR PAL attributes
  23. */
  24. typedef struct wamr_pal_attr {
  25. // WAMR instance directory.
  26. //
  27. // The default value is "."; that is, the current working directory
  28. const char *instance_dir;
  29. // Log level.
  30. //
  31. // Specifies the log verbose level (0 to 5, default is 2)
  32. // large level with more log
  33. //
  34. const char *log_level;
  35. } wamr_pal_attr_t;
  36. /* clang-format off */
  37. #define WAMR_PAL_ATTR_INITVAL { \
  38. .instance_dir = ".", \
  39. .log_level = 2 \
  40. }
  41. /* clang-format on */
  42. /*
  43. * The struct which consists of file descriptors of standard I/O
  44. */
  45. typedef struct wamr_stdio_fds {
  46. int stdin_fd;
  47. int stdout_fd;
  48. int stderr_fd;
  49. } wamr_stdio_fds_t;
  50. /*
  51. * The struct which consists of arguments needed by wamr_pal_create_process
  52. */
  53. struct wamr_pal_create_process_args {
  54. // Path to new process.
  55. //
  56. // The path of the command which will be created as a new process.
  57. //
  58. // Mandatory field. Must not be NULL.
  59. const char *path;
  60. // Arguments array pass to new process.
  61. //
  62. // The arguments to the command. By convention, the argv[0] should be the
  63. // program name. And the last element of the array must be NULL to indicate
  64. // the length of array.
  65. //
  66. // Mandatory field. Must not be NULL.
  67. const char **argv;
  68. // Untrusted environment variable array pass to new process.
  69. //
  70. // The untrusted env vars to the command. And the last element of the array
  71. // must be NULL to indicate the end of the array.
  72. //
  73. // Optional field.
  74. const char **env;
  75. // File descriptors of the redirected standard I/O (i.e., stdin, stdout,
  76. // stderr)
  77. //
  78. // If set to NULL, will use the original standard I/O file descriptors.
  79. //
  80. // Optional field.
  81. const struct wamr_stdio_fds *stdio;
  82. // Output. Pid of new process in libos.
  83. //
  84. // If wamr_pal_create_process returns success, pid of the new process will
  85. // be updated.
  86. //
  87. // Mandatory field. Must not be NULL.
  88. int *pid;
  89. };
  90. /*
  91. * The struct which consists of arguments needed by wamr_pal_exec
  92. */
  93. struct wamr_pal_exec_args {
  94. // Pid of new process created with wamr_pal_create_process.
  95. //
  96. // Mandatory field.
  97. int pid;
  98. // Output. The exit status of the command. The semantic of
  99. // this value follows the one described in wait(2) man
  100. // page. For example, if the program terminated normally,
  101. // then WEXITSTATUS(exit_status) gives the value returned
  102. // from a main function.
  103. //
  104. // Mandatory field. Must not be NULL.
  105. int *exit_value;
  106. };
  107. int
  108. wamr_pal_init(const struct wamr_pal_attr *args);
  109. int
  110. wamr_pal_create_process(struct wamr_pal_create_process_args *args);
  111. int
  112. wamr_pal_destroy(void);
  113. int
  114. wamr_pal_exec(struct wamr_pal_exec_args *args);
  115. int
  116. wamr_pal_kill(int pid, int sig);
  117. int
  118. pal_get_version(void);
  119. int
  120. pal_init(const struct wamr_pal_attr *attr);
  121. int
  122. pal_create_process(struct wamr_pal_create_process_args *args);
  123. int
  124. pal_exec(struct wamr_pal_exec_args *args);
  125. int
  126. pal_kill(int pid, int sig);
  127. int
  128. pal_destroy(void);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif /* __WAMR_PAL_API_H__ */