SysMman.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2016-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #ifndef _WIN32
  18. #include <sys/mman.h>
  19. // MAP_ANONYMOUS is named MAP_ANON on OSX/BSD.
  20. #if defined(__APPLE__) || defined(__FreeBSD__)
  21. #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
  22. #define MAP_ANONYMOUS MAP_ANON
  23. #endif
  24. #endif
  25. #else
  26. #include <cstdint>
  27. #include <sys/types.h>
  28. #define MAP_ANONYMOUS 1
  29. #define MAP_ANON MAP_ANONYMOUS
  30. #define MAP_SHARED 2
  31. #define MAP_PRIVATE 4
  32. #define MAP_POPULATE 8
  33. #define MAP_NORESERVE 16
  34. #define MAP_FIXED 32
  35. #define MAP_FAILED ((void*)-1)
  36. #define PROT_NONE 0
  37. #define PROT_READ 1
  38. #define PROT_WRITE 2
  39. #define PROT_EXEC 4
  40. #define MADV_NORMAL 0
  41. #define MADV_DONTNEED 0
  42. #define MADV_SEQUENTIAL 0
  43. extern "C" {
  44. int madvise(const void* addr, size_t len, int advise);
  45. int mlock(const void* addr, size_t len);
  46. void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t off);
  47. int mprotect(void* addr, size_t size, int prot);
  48. int munlock(const void* addr, size_t length);
  49. int munmap(void* addr, size_t length);
  50. }
  51. #endif