memory.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #define MEMORY_BLOCK_ACCESSIBLE (1 << 0)
  23. #define MEMORY_BLOCK_WRITABLE (1 << 1)
  24. #define MEMORY_BLOCK_EXECUTABLE (1 << 2)
  25. #define MEMORY_BLOCK_USERMODE (1 << 3)
  26. #define MEMORY_BLOCK_EVICTABLE (1 << 29)
  27. #define MEMORY_BLOCK_COPY_ON_WRITE (1 << 30)
  28. #define MEMORY_BLOCK_FREE (1 << 31)
  29. #define MEMORY_SECTION_WRITABLE (1 << 0)
  30. #define MEMORY_SECTION_DIRECT_WRITE (1 << 1)
  31. typedef struct
  32. {
  33. uintptr_t used_virtual;
  34. uintptr_t committed;
  35. uintptr_t evicted;
  36. uintptr_t shared;
  37. } memory_stats_t;
  38. typedef struct
  39. {
  40. qword_t address;
  41. qword_t size;
  42. dword_t flags;
  43. } memory_block_info_t;
  44. sysret_t syscall_alloc_memory(handle_t process, void **address, size_t size, dword_t block_flags);
  45. sysret_t syscall_free_memory(handle_t process, void *address);
  46. sysret_t syscall_commit_memory(handle_t process, void *address, dword_t size);
  47. sysret_t syscall_uncommit_memory(handle_t process, void *address, dword_t size);
  48. sysret_t syscall_set_memory_flags(handle_t process, void *address, dword_t flags);
  49. sysret_t syscall_query_memory(handle_t process, void *address, memory_block_info_t *info);
  50. sysret_t syscall_read_memory(handle_t process, void *address, void *buffer, dword_t size);
  51. sysret_t syscall_write_memory(handle_t process, void *address, void *buffer, dword_t size);
  52. sysret_t syscall_create_memory_section(const char *name, handle_t file, size_t size, dword_t flags, handle_t *handle);
  53. sysret_t syscall_open_memory_section(const char *name, handle_t *handle);
  54. sysret_t syscall_map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags);
  55. sysret_t syscall_flush_memory_section(handle_t process, void *address);
  56. #endif