/*1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2019 Kyle Evans <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice(s), this list of conditions and the following disclaimer as10* the first lines of this file unmodified other than the possible11* addition of one or more copyright notices.12* 2. Redistributions in binary form must reproduce the above copyright13* notice(s), this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR20* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE21* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,27* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/2930#include <sys/param.h>31#include <sys/filio.h>32#include <sys/mman.h>3334#include <errno.h>35#include <fcntl.h>36#include <string.h>37#include <unistd.h>3839#include "libc_private.h"4041__weak_reference(shm_open, _shm_open);42__weak_reference(shm_open, __sys_shm_open);4344int45shm_open(const char *path, int flags, mode_t mode)46{47return (__sys_shm_open2(path, flags | O_CLOEXEC, mode, 0, NULL));48}4950int51shm_create_largepage(const char *path, int flags, int psind, int alloc_policy,52mode_t mode)53{54struct shm_largepage_conf slc;55int error, fd, saved_errno;5657fd = __sys_shm_open2(path, flags | O_CREAT, mode, SHM_LARGEPAGE, NULL);58if (fd == -1)59return (-1);6061memset(&slc, 0, sizeof(slc));62slc.psind = psind;63slc.alloc_policy = alloc_policy;64error = ioctl(fd, FIOSSHMLPGCNF, &slc);65if (error == -1) {66saved_errno = errno;67close(fd);68errno = saved_errno;69return (-1);70}71return (fd);72}737475