153a5a1b3Sopenharmony_ci#ifndef foopulseshmhfoo
253a5a1b3Sopenharmony_ci#define foopulseshmhfoo
353a5a1b3Sopenharmony_ci
453a5a1b3Sopenharmony_ci/***
553a5a1b3Sopenharmony_ci  This file is part of PulseAudio.
653a5a1b3Sopenharmony_ci
753a5a1b3Sopenharmony_ci  Copyright 2006 Lennart Poettering
853a5a1b3Sopenharmony_ci
953a5a1b3Sopenharmony_ci  PulseAudio is free software; you can redistribute it and/or modify
1053a5a1b3Sopenharmony_ci  it under the terms of the GNU Lesser General Public License as
1153a5a1b3Sopenharmony_ci  published by the Free Software Foundation; either version 2.1 of the
1253a5a1b3Sopenharmony_ci  License, or (at your option) any later version.
1353a5a1b3Sopenharmony_ci
1453a5a1b3Sopenharmony_ci  PulseAudio is distributed in the hope that it will be useful, but
1553a5a1b3Sopenharmony_ci  WITHOUT ANY WARRANTY; without even the implied warranty of
1653a5a1b3Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1753a5a1b3Sopenharmony_ci  Lesser General Public License for more details.
1853a5a1b3Sopenharmony_ci
1953a5a1b3Sopenharmony_ci  You should have received a copy of the GNU Lesser General Public
2053a5a1b3Sopenharmony_ci  License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
2153a5a1b3Sopenharmony_ci***/
2253a5a1b3Sopenharmony_ci
2353a5a1b3Sopenharmony_ci#include <sys/types.h>
2453a5a1b3Sopenharmony_ci
2553a5a1b3Sopenharmony_ci#include <pulsecore/macro.h>
2653a5a1b3Sopenharmony_ci#include <pulsecore/mem.h>
2753a5a1b3Sopenharmony_ci
2853a5a1b3Sopenharmony_citypedef struct pa_shm {
2953a5a1b3Sopenharmony_ci    pa_mem_type_t type;
3053a5a1b3Sopenharmony_ci    unsigned id;
3153a5a1b3Sopenharmony_ci    void *ptr;
3253a5a1b3Sopenharmony_ci    size_t size;
3353a5a1b3Sopenharmony_ci
3453a5a1b3Sopenharmony_ci    /* Only for type = PA_MEM_TYPE_SHARED_POSIX */
3553a5a1b3Sopenharmony_ci    bool do_unlink:1;
3653a5a1b3Sopenharmony_ci
3753a5a1b3Sopenharmony_ci    /* Only for type = PA_MEM_TYPE_SHARED_MEMFD
3853a5a1b3Sopenharmony_ci     *
3953a5a1b3Sopenharmony_ci     * To avoid fd leaks, we keep this fd open only until we pass it
4053a5a1b3Sopenharmony_ci     * to the other PA endpoint over unix domain socket.
4153a5a1b3Sopenharmony_ci     *
4253a5a1b3Sopenharmony_ci     * When we don't have ownership for the memfd fd in question (e.g.
4353a5a1b3Sopenharmony_ci     * pa_shm_attach()), or the file descriptor has now been closed,
4453a5a1b3Sopenharmony_ci     * this is set to -1.
4553a5a1b3Sopenharmony_ci     *
4653a5a1b3Sopenharmony_ci     * For the special case of a global mempool, we keep this fd
4753a5a1b3Sopenharmony_ci     * always open. Check comments on top of pa_mempool_new() for
4853a5a1b3Sopenharmony_ci     * rationale. */
4953a5a1b3Sopenharmony_ci    int fd;
5053a5a1b3Sopenharmony_ci} pa_shm;
5153a5a1b3Sopenharmony_ci
5253a5a1b3Sopenharmony_ciint pa_shm_create_rw(pa_shm *m, pa_mem_type_t type, size_t size, mode_t mode);
5353a5a1b3Sopenharmony_ciint pa_shm_attach(pa_shm *m, pa_mem_type_t type, unsigned id, int memfd_fd, bool writable);
5453a5a1b3Sopenharmony_ci
5553a5a1b3Sopenharmony_civoid pa_shm_punch(pa_shm *m, size_t offset, size_t size);
5653a5a1b3Sopenharmony_ci
5753a5a1b3Sopenharmony_civoid pa_shm_free(pa_shm *m);
5853a5a1b3Sopenharmony_ci
5953a5a1b3Sopenharmony_ciint pa_shm_cleanup(void);
6053a5a1b3Sopenharmony_ci
6153a5a1b3Sopenharmony_ci#endif
62