]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-bus/bus-kernel.c
90fc60afbde232d5efb28a8f6d0c88cfdcf7e34a
[thirdparty/systemd.git] / src / libsystemd / sd-bus / bus-kernel.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <sys/mman.h>
4
5 #include "bus-kernel.h"
6 #include "bus-internal.h"
7 #include "fd-util.h"
8 #include "memory-util.h"
9
10 void close_and_munmap(int fd, void *address, size_t size) {
11 if (size > 0) {
12 size = PAGE_ALIGN(size);
13 assert(size < SIZE_MAX);
14 assert_se(munmap(address, size) >= 0);
15 }
16
17 safe_close(fd);
18 }
19
20 void bus_flush_memfd(sd_bus *b) {
21 assert(b);
22
23 for (unsigned i = 0; i < b->n_memfd_cache; i++)
24 close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
25 }