]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mmap-cache: introduce window_matches_by_addr()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 30 Sep 2023 02:46:42 +0000 (11:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 4 Nov 2023 02:42:19 +0000 (11:42 +0900)
It is similar to window_matches(), but checks the mapped address.
Mostly preparation for later commits.

src/libsystemd/sd-journal/mmap-cache.c

index 9e69e31ba3c5c0cc0a7c54198c70e58a69553bd0..3f22d83b2827d0dc0869792e3c2994342e358a17 100644 (file)
@@ -146,6 +146,16 @@ static bool window_matches(Window *w, MMapFileDescriptor *f, uint64_t offset, si
                 offset + size <= w->offset + w->size;
 }
 
+static bool window_matches_by_addr(Window *w, MMapFileDescriptor *f, void *addr, size_t size) {
+        assert(size > 0);
+
+        return
+                w &&
+                f == w->fd &&
+                (uint8_t*) addr >= (uint8_t*) w->ptr &&
+                (uint8_t*) addr + size <= (uint8_t*) w->ptr + w->size;
+}
+
 static Window* window_add(MMapFileDescriptor *f, uint64_t offset, size_t size, void *ptr) {
         MMapCache *m = mmap_cache_fd_cache(f);
         Window *w;
@@ -403,13 +413,11 @@ static void mmap_cache_process_sigbus(MMapCache *m) {
 
                 ours = false;
                 HASHMAP_FOREACH(f, m->fds) {
-                        LIST_FOREACH(windows, w, f->windows) {
-                                if ((uint8_t*) addr >= (uint8_t*) w->ptr &&
-                                    (uint8_t*) addr < (uint8_t*) w->ptr + w->size) {
+                        LIST_FOREACH(windows, w, f->windows)
+                                if (window_matches_by_addr(w, f, addr, 1)) {
                                         found = ours = f->sigbus = true;
                                         break;
                                 }
-                        }
 
                         if (ours)
                                 break;