db_process.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. LEAVE_PAL_CALL_RETURN(handle);
  46. }
  47. noreturn void DkProcessExit(PAL_NUM exitcode) {
  48. ENTER_PAL_CALL(DkProcessExit);
  49. _DkProcessExit(exitcode);
  50. _DkRaiseFailure(PAL_ERROR_NOTKILLABLE);
  51. while (true)
  52. /* nothing */;
  53. LEAVE_PAL_CALL();
  54. }