]> granicus.if.org Git - strace/blobdiff - defs.h
mmap_cache: add function to enable mmap_cache
[strace] / defs.h
diff --git a/defs.h b/defs.h
index 742db9a90aab6403dcd5e034a5e8d63c49591003..afcefcd8229bd82e9a713311f844cbdf7d49995b 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -2,7 +2,7 @@
  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
- * Copyright (c) 2001-2017 The strace developers.
+ * Copyright (c) 2001-2018 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -217,11 +217,12 @@ struct tcb {
        struct timeval dtime;   /* Delta for system time usage */
        struct timeval etime;   /* Syscall entry time */
 
-#ifdef USE_LIBUNWIND
-       struct UPT_info *libunwind_ui;
        struct mmap_cache_t *mmap_cache;
        unsigned int mmap_cache_size;
        unsigned int mmap_cache_generation;
+
+#ifdef USE_LIBUNWIND
+       struct UPT_info *libunwind_ui;
        struct queue_t *queue;
 #endif
 };
@@ -407,6 +408,17 @@ extern kernel_ulong_t get_rt_sigframe_addr(struct tcb *);
  *             is valid; NULL otherwise.
  */
 extern const char *syscall_name(kernel_ulong_t scno);
+/**
+ * Convert a syscall name to the corresponding (shuffled) syscall number.
+ *
+ * @param s     Syscall name.
+ * @param p     Personality.
+ * @param start From which position in syscall entry table resume the search.
+ * @return      Shuffled syscall number (ready to use against sysent_vec)
+ *              if syscall name is found; -1 otherwise.
+ */
+extern kernel_long_t scno_by_name(const char *s, unsigned p,
+                                 kernel_long_t start);
 /**
  * Shuffle syscall numbers so that we don't have huge gaps in syscall table.
  * The shuffling should be an involution: shuffle_scno(shuffle_scno(n)) == n.
@@ -705,11 +717,52 @@ extern void tv_div(struct timeval *, const struct timeval *, int);
 extern void unwind_init(void);
 extern void unwind_tcb_init(struct tcb *);
 extern void unwind_tcb_fin(struct tcb *);
-extern void unwind_cache_invalidate(struct tcb *);
 extern void unwind_print_stacktrace(struct tcb *);
 extern void unwind_capture_stacktrace(struct tcb *);
 #endif
 
+/*
+ * Keep a sorted array of cache entries,
+ * so that we can binary search through it.
+ */
+struct mmap_cache_t {
+       /**
+        * example entry:
+        * 7fabbb09b000-7fabbb09f000 r-xp 00179000 fc:00 1180246 /lib/libc-2.11.1.so
+        *
+        * start_addr  is 0x7fabbb09b000
+        * end_addr    is 0x7fabbb09f000
+        * mmap_offset is 0x179000
+        * protections is MMAP_CACHE_PROT_READABLE|MMAP_CACHE_PROT_EXECUTABLE
+        * binary_filename is "/lib/libc-2.11.1.so"
+        */
+       unsigned long start_addr;
+       unsigned long end_addr;
+       unsigned long mmap_offset;
+       unsigned char protections;
+       char *binary_filename;
+};
+
+enum mmap_cache_protection {
+       MMAP_CACHE_PROT_READABLE   = 1 << 0,
+       MMAP_CACHE_PROT_WRITABLE   = 1 << 1,
+       MMAP_CACHE_PROT_EXECUTABLE = 1 << 2,
+       MMAP_CACHE_PROT_SHARED     = 1 << 3,
+};
+
+enum mmap_cache_rebuild_result {
+       MMAP_CACHE_REBUILD_NOCACHE,
+       MMAP_CACHE_REBUILD_READY,
+       MMAP_CACHE_REBUILD_RENEWED,
+};
+
+extern void mmap_cache_enable(void);
+extern bool mmap_cache_is_enabled(void);
+extern void mmap_cache_invalidate(struct tcb *tcp);
+extern void mmap_cache_delete(struct tcb *tcp, const char *caller);
+extern enum mmap_cache_rebuild_result mmap_cache_rebuild_if_invalid(struct tcb *tcp, const char *caller);
+extern struct mmap_cache_t *mmap_cache_search(struct tcb *tcp, unsigned long ip);
+
 static inline int
 printstrn(struct tcb *tcp, kernel_ulong_t addr, kernel_ulong_t len)
 {