serenity.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <Kernel/API/POSIX/futex.h>
  8. #include <Kernel/API/POSIX/serenity.h>
  9. #include <stdio.h>
  10. #include <sys/cdefs.h>
  11. #include <time.h>
  12. #include <unistd.h>
  13. __BEGIN_DECLS
  14. int disown(pid_t);
  15. int profiling_enable(pid_t, uint64_t);
  16. int profiling_disable(pid_t);
  17. int profiling_free_buffer(pid_t);
  18. int futex(uint32_t* userspace_address, int futex_op, uint32_t value, const struct timespec* timeout, uint32_t* userspace_address2, uint32_t value3);
  19. #ifndef ALWAYS_INLINE
  20. # define ALWAYS_INLINE inline __attribute__((always_inline))
  21. # define ALWAYS_INLINE_SERENITY_H
  22. #endif
  23. static ALWAYS_INLINE int futex_wait(uint32_t* userspace_address, uint32_t value, const struct timespec* abstime, int clockid, int process_shared)
  24. {
  25. int op;
  26. if (abstime) {
  27. // NOTE: FUTEX_WAIT takes a relative timeout, so use FUTEX_WAIT_BITSET instead!
  28. op = FUTEX_WAIT_BITSET;
  29. if (clockid == CLOCK_REALTIME || clockid == CLOCK_REALTIME_COARSE)
  30. op |= FUTEX_CLOCK_REALTIME;
  31. } else {
  32. op = FUTEX_WAIT;
  33. }
  34. return futex(userspace_address, op | (process_shared ? 0 : FUTEX_PRIVATE_FLAG), value, abstime, NULL, FUTEX_BITSET_MATCH_ANY);
  35. }
  36. static ALWAYS_INLINE int futex_wake(uint32_t* userspace_address, uint32_t count, int process_shared)
  37. {
  38. return futex(userspace_address, FUTEX_WAKE | (process_shared ? 0 : FUTEX_PRIVATE_FLAG), count, NULL, NULL, 0);
  39. }
  40. #ifdef ALWAYS_INLINE_SERENITY_H
  41. # undef ALWAYS_INLINE
  42. #endif
  43. int purge(int mode);
  44. int perf_event(int type, uintptr_t arg1, uintptr_t arg2);
  45. int perf_register_string(char const* string, size_t string_length);
  46. int get_stack_bounds(uintptr_t* user_stack_base, size_t* user_stack_size);
  47. int anon_create(size_t size, int options);
  48. int serenity_readlink(char const* path, size_t path_length, char* buffer, size_t buffer_size);
  49. int getkeymap(char* name_buffer, size_t name_buffer_size, uint32_t* map, uint32_t* shift_map, uint32_t* alt_map, uint32_t* altgr_map, uint32_t* shift_altgr_map);
  50. int setkeymap(char const* name, uint32_t const* map, uint32_t* const shift_map, uint32_t const* alt_map, uint32_t const* altgr_map, uint32_t const* shift_altgr_map);
  51. uint16_t internet_checksum(void const* ptr, size_t count);
  52. int emuctl(uintptr_t command, uintptr_t arg0, uintptr_t arg1);
  53. int serenity_open(char const* path, size_t path_length, int options, ...);
  54. __END_DECLS