espidf_memmap.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "platform_api_vmcore.h"
  6. #include "platform_api_extension.h"
  7. void *
  8. os_mmap(void *hint, size_t size, int prot, int flags)
  9. {
  10. if (prot & MMAP_PROT_EXEC) {
  11. // Memory allocation with MALLOC_CAP_EXEC will return 4-byte aligned
  12. // Reserve extra 4 byte to fixup alignment and size for the pointer to
  13. // the originally allocated address
  14. void *buf_origin =
  15. heap_caps_malloc(size + 4 + sizeof(uintptr_t), MALLOC_CAP_EXEC);
  16. if (!buf_origin) {
  17. return NULL;
  18. }
  19. void *buf_fixed = buf_origin + sizeof(void *);
  20. if ((uintptr_t)buf_fixed & (uintptr_t)0x7) {
  21. buf_fixed = (void *)((uintptr_t)(buf_fixed + 4) & (~(uintptr_t)7));
  22. }
  23. uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t);
  24. *addr_field = (uintptr_t)buf_origin;
  25. return buf_fixed;
  26. }
  27. else {
  28. return os_malloc(size);
  29. }
  30. }
  31. void
  32. os_munmap(void *addr, size_t size)
  33. {
  34. // We don't need special handling of the executable allocations
  35. // here, free() of esp-idf handles it properly
  36. return os_free(addr);
  37. }
  38. int
  39. os_mprotect(void *addr, size_t size, int prot)
  40. {
  41. return 0;
  42. }
  43. void
  44. os_dcache_flush()
  45. {}