user.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2023 Agustina Arzille.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * Definitions for userspace.
  18. */
  19. #ifndef KERN_USER_H
  20. #define KERN_USER_H
  21. #include <stdbool.h>
  22. #include <stdint.h>
  23. #include <machine/pmap.h>
  24. #include <kern/task.h>
  25. struct ipc_iov_iter;
  26. // Test that an address is accessible for the current task.
  27. static inline bool
  28. user_check_range (const void *addr, size_t size)
  29. {
  30. return (
  31. #if PMAP_START_ADDRESS > 0
  32. (uintptr_t)addr >= PMAP_START_ADDRESS &&
  33. #else
  34. 1 &&
  35. #endif
  36. ((uintptr_t)addr + size < PMAP_END_ADDRESS));
  37. }
  38. // Copy bytes to userspace.
  39. int user_copy_to (void *udst, const void *src, size_t size);
  40. // Copy bytes from userspace.
  41. int user_copy_from (void *dst, const void *usrc, size_t size);
  42. // Same as above, only these operate on iovecs.
  43. ssize_t user_copyv_to (struct ipc_iov_iter *udst, struct ipc_iov_iter *src);
  44. ssize_t user_copyv_from (struct ipc_iov_iter *dst, struct ipc_iov_iter *usrc);
  45. #endif