serenity.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <Kernel/API/Syscall.h>
  27. #include <errno.h>
  28. #include <serenity.h>
  29. extern "C" {
  30. int disown(pid_t pid)
  31. {
  32. int rc = syscall(SC_disown, pid);
  33. __RETURN_WITH_ERRNO(rc, rc, -1);
  34. }
  35. int module_load(const char* path, size_t path_length)
  36. {
  37. int rc = syscall(SC_module_load, path, path_length);
  38. __RETURN_WITH_ERRNO(rc, rc, -1);
  39. }
  40. int module_unload(const char* name, size_t name_length)
  41. {
  42. int rc = syscall(SC_module_unload, name, name_length);
  43. __RETURN_WITH_ERRNO(rc, rc, -1);
  44. }
  45. int profiling_enable(pid_t pid)
  46. {
  47. int rc = syscall(SC_profiling_enable, pid);
  48. __RETURN_WITH_ERRNO(rc, rc, -1);
  49. }
  50. int profiling_disable(pid_t pid)
  51. {
  52. int rc = syscall(SC_profiling_disable, pid);
  53. __RETURN_WITH_ERRNO(rc, rc, -1);
  54. }
  55. int futex(int32_t* userspace_address, int futex_op, int32_t value, const struct timespec* timeout)
  56. {
  57. Syscall::SC_futex_params params { userspace_address, futex_op, value, timeout };
  58. int rc = syscall(SC_futex, &params);
  59. __RETURN_WITH_ERRNO(rc, rc, -1);
  60. }
  61. int purge(int mode)
  62. {
  63. int rc = syscall(SC_purge, mode);
  64. __RETURN_WITH_ERRNO(rc, rc, -1);
  65. }
  66. int perf_event(int type, uintptr_t arg1, FlatPtr arg2)
  67. {
  68. int rc = syscall(SC_perf_event, type, arg1, arg2);
  69. __RETURN_WITH_ERRNO(rc, rc, -1);
  70. }
  71. void* shbuf_get(int shbuf_id, size_t* size)
  72. {
  73. ssize_t rc = syscall(SC_shbuf_get, shbuf_id, size);
  74. if (rc < 0 && -rc < EMAXERRNO) {
  75. errno = -rc;
  76. return (void*)-1;
  77. }
  78. return (void*)rc;
  79. }
  80. int shbuf_release(int shbuf_id)
  81. {
  82. int rc = syscall(SC_shbuf_release, shbuf_id);
  83. __RETURN_WITH_ERRNO(rc, rc, -1);
  84. }
  85. int shbuf_create(int size, void** buffer)
  86. {
  87. int rc = syscall(SC_shbuf_create, size, buffer);
  88. __RETURN_WITH_ERRNO(rc, rc, -1);
  89. }
  90. int shbuf_allow_pid(int shbuf_id, pid_t peer_pid)
  91. {
  92. int rc = syscall(SC_shbuf_allow_pid, shbuf_id, peer_pid);
  93. __RETURN_WITH_ERRNO(rc, rc, -1);
  94. }
  95. int get_stack_bounds(uintptr_t* user_stack_base, size_t* user_stack_size)
  96. {
  97. int rc = syscall(SC_get_stack_bounds, user_stack_base, user_stack_size);
  98. __RETURN_WITH_ERRNO(rc, rc, -1);
  99. }
  100. int anon_create(size_t size, int options)
  101. {
  102. int rc = syscall(SC_anon_create, size, options);
  103. __RETURN_WITH_ERRNO(rc, rc, -1);
  104. }
  105. }