1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 3 #if HAVE_VALGRIND_MEMCHECK_H 4 #include <valgrind/memcheck.h> 5 #endif 6 7 #include <fcntl.h> 8 #include <malloc.h> 9 #include <sys/mman.h> 10 #include <sys/prctl.h> 11 12 /* When we include libgen.h because we need dirname() we immediately 13 * undefine basename() since libgen.h defines it as a macro to the POSIX 14 * version which is really broken. We prefer GNU basename(). */ 15 #include <libgen.h> 16 #undef basename 17 18 #include "alloc-util.h" 19 #include "bus-internal.h" 20 #include "bus-kernel.h" 21 #include "bus-label.h" 22 #include "bus-message.h" 23 #include "capability-util.h" 24 #include "fd-util.h" 25 #include "fileio.h" 26 #include "format-util.h" 27 #include "memfd-util.h" 28 #include "parse-util.h" 29 #include "stdio-util.h" 30 #include "string-util.h" 31 #include "strv.h" 32 #include "user-util.h" 33 #include "memory-util.h" 34 close_and_munmap(int fd,void * address,size_t size)35void close_and_munmap(int fd, void *address, size_t size) { 36 if (size > 0) 37 assert_se(munmap(address, PAGE_ALIGN(size)) >= 0); 38 39 safe_close(fd); 40 } 41 bus_flush_memfd(sd_bus * b)42void bus_flush_memfd(sd_bus *b) { 43 assert(b); 44 45 for (unsigned i = 0; i < b->n_memfd_cache; i++) 46 close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped); 47 } 48