db_process.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * db_process.c
  15. *
  16. * This source file contains functions to create a child process and terminate
  17. * the running process. Child does not inherit any objects or memory from its
  18. * parent pricess. A Parent process may not modify the execution of its
  19. * children. It can wait for a child to exit using its handle. Also, parent and
  20. * child may communicate through I/O streams provided by the parent to the child
  21. * at creation.
  22. */
  23. #include "api.h"
  24. #include "pal.h"
  25. #include "pal_debug.h"
  26. #include "pal_defs.h"
  27. #include "pal_error.h"
  28. #include "pal_internal.h"
  29. PAL_HANDLE
  30. DkProcessCreate(PAL_STR uri, PAL_STR* args) {
  31. ENTER_PAL_CALL(DkProcessCreate);
  32. /* DEP 3/22/17: There seems to be a default semantics that
  33. * a NULL URI should replicate the parent. I think we may want
  34. * this to become an error in the future, but keep the behavior
  35. * for now, and make it consistent across hosts. */
  36. if (!uri)
  37. uri = pal_control.executable;
  38. log_stream(uri);
  39. PAL_HANDLE handle = NULL;
  40. int ret = _DkProcessCreate(&handle, uri, args);
  41. if (ret < 0) {
  42. _DkRaiseFailure(-ret);
  43. handle = NULL;
  44. }
  45. TRACE_HEAP(handle);
  46. LEAVE_PAL_CALL_RETURN(handle);
  47. }
  48. noreturn void DkProcessExit(PAL_NUM exitcode) {
  49. ENTER_PAL_CALL(DkProcessExit);
  50. _DkProcessExit(exitcode);
  51. _DkRaiseFailure(PAL_ERROR_NOTKILLABLE);
  52. while (true)
  53. /* nothing */;
  54. LEAVE_PAL_CALL();
  55. }