Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mmap_cache.h 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2013-2018 The strace developers.
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. */
  6. #ifndef STRACE_MMAP_CACHE_H
  7. # define STRACE_MMAP_CACHE_H
  8. /*
  9. * Keep a sorted array of cache entries,
  10. * so that we can binary search through it.
  11. */
  12. struct mmap_cache_t {
  13. struct mmap_cache_entry_t *entry;
  14. void (*free_fn)(struct tcb *, const char *caller);
  15. unsigned int size;
  16. unsigned int generation;
  17. };
  18. struct mmap_cache_entry_t {
  19. /**
  20. * example entry:
  21. * 7fabbb09b000-7fabbb09f000 r-xp 00179000 fc:00 1180246 /lib/libc-2.11.1.so
  22. *
  23. * start_addr is 0x7fabbb09b000
  24. * end_addr is 0x7fabbb09f000
  25. * mmap_offset is 0x179000
  26. * protections is MMAP_CACHE_PROT_READABLE|MMAP_CACHE_PROT_EXECUTABLE
  27. * major is 0xfc
  28. * minor is 0x00
  29. * binary_filename is "/lib/libc-2.11.1.so"
  30. */
  31. unsigned long start_addr;
  32. unsigned long end_addr;
  33. unsigned long mmap_offset;
  34. unsigned char protections;
  35. unsigned long major, minor;
  36. char *binary_filename;
  37. };
  38. enum mmap_cache_protection {
  39. MMAP_CACHE_PROT_READABLE = 1 << 0,
  40. MMAP_CACHE_PROT_WRITABLE = 1 << 1,
  41. MMAP_CACHE_PROT_EXECUTABLE = 1 << 2,
  42. MMAP_CACHE_PROT_SHARED = 1 << 3,
  43. };
  44. enum mmap_cache_rebuild_result {
  45. MMAP_CACHE_REBUILD_NOCACHE,
  46. MMAP_CACHE_REBUILD_READY,
  47. MMAP_CACHE_REBUILD_RENEWED,
  48. };
  49. typedef bool (*mmap_cache_search_fn)(struct mmap_cache_entry_t *, void *);
  50. extern void
  51. mmap_cache_enable(void);
  52. extern enum mmap_cache_rebuild_result
  53. mmap_cache_rebuild_if_invalid(struct tcb *, const char *caller);
  54. extern struct mmap_cache_entry_t *
  55. mmap_cache_search(struct tcb *, unsigned long ip);
  56. extern struct mmap_cache_entry_t *
  57. mmap_cache_search_custom(struct tcb *, mmap_cache_search_fn, void *);
  58. #endif /* !STRACE_MMAP_CACHE_H */