memory.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * memory.h
  3. *
  4. * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __MONOLITIHUM_MEMORY_H__
  20. #define __MONOLITIHUM_MEMORY_H__
  21. #include "defs.h"
  22. #include "object.h"
  23. /* Set by the client */
  24. #define MEMORY_FLAG_ACCESSIBLE (1 << 0)
  25. #define MEMORY_FLAG_WRITABLE (1 << 1)
  26. #define MEMORY_FLAG_EXECUTABLE (1 << 2)
  27. #define MEMORY_FLAG_USERMODE (1 << 3)
  28. #define MEMORY_FLAG_STICKY (1 << 4)
  29. #define MEMORY_FLAG_EVICTABLE (1 << 5)
  30. /* Set by the system */
  31. #define MEMORY_FLAG_EVICTED (1 << 29)
  32. #define MEMORY_FLAG_COPY_ON_WRITE (1 << 30)
  33. #define MEMORY_FLAG_FREE (1 << 31)
  34. #define MEMORY_SECTION_WRITABLE (1 << 0)
  35. #define MEMORY_SECTION_DIRECT_WRITE (1 << 1)
  36. typedef dword_t memory_flags_t;
  37. typedef struct
  38. {
  39. uintptr_t used_virtual;
  40. uintptr_t committed;
  41. uintptr_t evicted;
  42. uintptr_t shared;
  43. } memory_stats_t;
  44. typedef struct
  45. {
  46. qword_t address;
  47. qword_t size;
  48. dword_t flags;
  49. } memory_block_info_t;
  50. sysret_t syscall_alloc_memory(handle_t process, void **address, size_t size, dword_t block_flags);
  51. sysret_t syscall_free_memory(handle_t process, void *address);
  52. sysret_t syscall_commit_memory(handle_t process, void *address, dword_t size);
  53. sysret_t syscall_uncommit_memory(handle_t process, void *address, dword_t size);
  54. sysret_t syscall_protect_memory(handle_t process, void *address, size_t size, memory_flags_t flags);
  55. sysret_t syscall_query_memory(handle_t process, void *address, memory_block_info_t *info);
  56. sysret_t syscall_read_memory(handle_t process, void *address, void *buffer, dword_t size);
  57. sysret_t syscall_write_memory(handle_t process, void *address, void *buffer, dword_t size);
  58. sysret_t syscall_create_memory_section(const char *name, handle_t file, size_t size, dword_t flags, handle_t *handle);
  59. sysret_t syscall_open_memory_section(const char *name, handle_t *handle);
  60. sysret_t syscall_map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags);
  61. sysret_t syscall_flush_memory_section(handle_t process, void *address);
  62. #endif