glibc/sysdeps/mach/msync.c

62 lines
1.9 KiB
C
Raw Normal View History

/* msync -- Synchronize mapped memory to external storage. Mach version.
Copyright (C) 2002-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
Prefer https to http for gnu.org and fsf.org URLs Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 07:40:42 +02:00
<https://www.gnu.org/licenses/>. */
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <mach.h>
hurd: Add remaining cancelation points * hurd/hurdselect.c: Include <sysdep-cancel.h>. (_hurd_select): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/accept4.c: Include <sysdep-cancel.h>. (__libc_accept4): Surround call to __socket_accept with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/connect.c: Include <sysdep-cancel.h>. (__connect): Surround call to __file_name_lookup and __socket_connect with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fdatasync.c: Include <sysdep-cancel.h>. (fdatasync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fsync.c: Include <sysdep-cancel.h>. (fsync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/ioctl.c: Include <sysdep-cancel.h>. (__ioctl): When request is TIOCDRAIN, surround call to send_rpc with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/msync.c: Include <sysdep-cancel.h>. (msync): Surround call to __vm_object_sync with enabling async cancel. * sysdeps/mach/hurd/sigsuspend.c: Include <sysdep-cancel.h>. (__sigsuspend): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/sigwait.c: Include <sysdep-cancel.h>. (__sigwait): Surround wait code with enabling async cancel. * sysdeps/mach/msync.c: Include <sysdep-cancel.h>. (msync): Surround call to __vm_msync with enabling async cancel. * sysdeps/mach/sleep.c: Include <sysdep-cancel.h>. (__sleep): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/usleep.c: Include <sysdep-cancel.h>. (usleep): Surround call to __vm_msync with enabling async cancel.
2020-06-29 00:41:18 +02:00
#include <sysdep-cancel.h>
/* Some Mach variants have vm_msync and some don't. Those that have it
define the VM_SYNC_* bits when we include <mach/mach_types.h>. */
#ifndef VM_SYNC_SYNCHRONOUS
* sysdeps/alpha/fpu/s_cacosf.c: Don't use sysdeps/generic/. * sysdeps/alpha/fpu/s_cacoshf.c: Likewise. * sysdeps/alpha/fpu/s_casinf.c: Likewise. * sysdeps/alpha/fpu/s_casinhf.c: Likewise. * sysdeps/alpha/fpu/s_catanf.c: Likewise. * sysdeps/alpha/fpu/s_catanhf.c: Likewise. * sysdeps/alpha/fpu/s_ccosf.c: Likewise. * sysdeps/alpha/fpu/s_ccoshf.c: Likewise. * sysdeps/alpha/fpu/s_cexpf.c: Likewise. * sysdeps/alpha/fpu/s_clog10f.c: Likewise. * sysdeps/alpha/fpu/s_clogf.c: Likewise. * sysdeps/alpha/fpu/s_cpowf.c: Likewise. * sysdeps/alpha/fpu/s_cprojf.c: Likewise. * sysdeps/alpha/fpu/s_csinf.c: Likewise. * sysdeps/alpha/fpu/s_csinhf.c: Likewise. * sysdeps/alpha/fpu/s_csqrtf.c: Likewise. * sysdeps/alpha/fpu/s_ctanf.c: Likewise. * sysdeps/alpha/fpu/s_ctanhf.c: Likewise. * sysdeps/alpha/libc-tls.c: Likewise. * sysdeps/gnu/glob64.c: Likewise. * sysdeps/gnu/updwtmp.c: Likewise. * sysdeps/gnu/utmp_file.c: Likewise. * sysdeps/i386/bzero.c: Likewise. * sysdeps/i386/ffs.c: Likewise. * sysdeps/i386/i686/ffs.c: Likewise. * sysdeps/i386/memset.c: Likewise. * sysdeps/ia64/fpu/printf_fphex.c: Likewise. * sysdeps/ia64/libc-tls.c: Likewise. * sysdeps/ieee754/ldbl-128/printf_fphex.c: Likewise. * sysdeps/m68k/ffs.c: Likewise. * sysdeps/mach/hurd/getdents.c: Likewise. * sysdeps/mach/hurd/init-posix.c: Likewise. * sysdeps/mach/msync.c: Likewise. * sysdeps/mips/libc-tls.c: Likewise. * sysdeps/posix/profil.c: Likewise. * sysdeps/posix/shm_open.c: Likewise. * sysdeps/posix/shm_unlink.c: Likewise. * sysdeps/posix/sprofil.c: Likewise. * sysdeps/powerpc/ffs.c: Likewise. * sysdeps/rs6000/ffs.c: Likewise. * sysdeps/s390/libc-tls.c: Likewise. * sysdeps/unix/sysv/linux/aio_sigqueue.c: Likewise. * sysdeps/unix/sysv/linux/alpha/glob.c: Likewise. * sysdeps/unix/sysv/linux/alpha/wordexp.c: Likewise. * sysdeps/unix/sysv/linux/ftruncate64.c: Likewise. * sysdeps/unix/sysv/linux/gai_sigqueue.c: Likewise. * sysdeps/unix/sysv/linux/i386/getmsg.c: Likewise. * sysdeps/unix/sysv/linux/i386/getresgid.c: Likewise. * sysdeps/unix/sysv/linux/i386/getresuid.c: Likewise. * sysdeps/unix/sysv/linux/i386/lchown.c: Likewise. * sysdeps/unix/sysv/linux/i386/putmsg.c: Likewise. * sysdeps/unix/sysv/linux/i386/readelflib.c: Likewise. * sysdeps/unix/sysv/linux/i386/setresgid.c: Likewise. * sysdeps/unix/sysv/linux/i386/setresuid.c: Likewise. * sysdeps/unix/sysv/linux/ia64/readelflib.c: Likewise. * sysdeps/unix/sysv/linux/mips/ftruncate64.c: Likewise. * sysdeps/unix/sysv/linux/mips/readelflib.c: Likewise. * sysdeps/unix/sysv/linux/mips/truncate64.c: Likewise. * sysdeps/unix/sysv/linux/mq_close.c: Likewise. * sysdeps/unix/sysv/linux/mq_getattr.c: Likewise. * sysdeps/unix/sysv/linux/mq_notify.c: Likewise. * sysdeps/unix/sysv/linux/mq_open.c: Likewise. * sysdeps/unix/sysv/linux/mq_receive.c: Likewise. * sysdeps/unix/sysv/linux/mq_send.c: Likewise. * sysdeps/unix/sysv/linux/mq_unlink.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/readelflib.c: Likewise. * sysdeps/unix/sysv/linux/s390/readelflib.c: Likewise. * sysdeps/unix/sysv/linux/sched_getaffinity.c: Likewise. * sysdeps/unix/sysv/linux/sched_setaffinity.c: Likewise. * sysdeps/unix/sysv/linux/sigqueue.c: Likewise. * sysdeps/unix/sysv/linux/sigstack.c: Likewise. * sysdeps/unix/sysv/linux/sigtimedwait.c: Likewise. * sysdeps/unix/sysv/linux/sigwaitinfo.c: Likewise. * sysdeps/unix/sysv/linux/sparc/readelflib.c: Likewise. * sysdeps/unix/sysv/linux/truncate64.c: Likewise. * sysdeps/unix/sysv/linux/vfork.c: Likewise. * sysdeps/unix/sysv/linux/x86_64/readelflib.c: Likewise.
2005-12-15 22:13:14 +01:00
# include <misc/msync.c>
#else
/* Synchronize the region starting at ADDR and extending LEN bytes with the
file it maps. Filesystem operations on a file being mapped are
unpredictable before this is done. */
int
Do not use __ptr_t. sys/cdefs.h has a macro __ptr_t, which a few places in glibc use instead of void *. void * is a well-understood standard type for that purpose and in a post-C89 context there is no need for a macro for it; this patch changes those places to use void * directly instead. Unlike __long_double_t, __ptr_t is widely used outside glibc (or at least has many hits on codesearch.debian.net). I don't know how many of those uses would break if sys/cdefs.h ceased to define the macro, but there's enough risk that this patch leaves the definition and just removes the uses within glibc; removal of the definition can be considered separately if desired. Tested for x86_64, and with build-many-glibcs.py. * malloc/mcheck.c (old_free_hook): Use void * instead of __ptr_t. (old_malloc_hook): Likewise. (old_memalign_hook): Likewise. (old_realloc_hook): Likewise. (struct hdr): Likewise. (flood): Likewise. (freehook): Likewise. (mallochook): Likewise. (memalignhook): Likewise. (reallochook): Likewise. (mprobe): Likewise. * malloc/mtrace.c (mallwatch): Likewise. (tr_old_free_hook): Likewise. (tr_old_malloc_hook): Likewise. (tr_old_realloc_hook): Likewise. (tr_old_memalign_hook): Likewise. (tr_where): Likewise. (lock_and_info): Likewise. (tr_freehook): Likewise. (tr_mallochook): Likewise. (tr_reallochook): Likewise. (tr_memalignhook): Likewise. * misc/err.h [!__GNUC_VA_LIST] (__gnuc_va_list): Likewise. * misc/mmap.c (__mmap): Likewise. * misc/mmap64.c (__mmap64): Likewise. * misc/mprotect.c (__mprotect): Likewise. * misc/msync.c (msync): Likewise. * misc/munmap.c (__munmap): Likewise. * posix/posix_madvise.c (posix_madvise): Likewise. * socket/send.c (__send): Likewise. * socket/sendto.c (__sendto): Likewise. * socket/setsockopt.c (__setsockopt): Likewise. * string/memcmp.c (__ptr_t): Remove macro. (MEMCMP): Use void * instead of ptr_t. * string/memrchr.c (__ptr_t): Remove macro. (__memrchr): Use void * instead of ptr_t. * sysdeps/mach/hurd/dl-sysdep.c (__mmap): Likewise. * sysdeps/mach/hurd/mmap.c (__mmap): Likewise. * sysdeps/mach/hurd/mmap64.c (__mmap64): Likewise. * sysdeps/mach/mprotect.c (__mprotect): Likewise. * sysdeps/mach/msync.c (msync): Likewise. * sysdeps/mach/munmap.c (__munmap): Likewise. * sysdeps/mips/bits/setjmp.h (struct __jmp_buf_internal_tag): Likewise. * sysdeps/posix/getcwd.c (__getcwd): Likewise. * sysdeps/powerpc/powerpc32/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc32/power4/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc32/power4/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc32/power6/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc32/power6/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc32/power7/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc32/power7/mempcpy.S (__mempcpy): Likewise. * sysdeps/powerpc/powerpc32/power7/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power4/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/power4/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power6/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/power6/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power7/memcpy.S (memcpy): Likewise. * sysdeps/powerpc/powerpc64/power7/mempcpy.S (__mempcpy): Likewise. * sysdeps/powerpc/powerpc64/power7/memset.S (memset): Likewise. * sysdeps/powerpc/powerpc64/power8/memset.S (memset): Likewise. * sysdeps/tile/memcmp.c (__ptr_t): Remove macro. (MEMCMP): Use void * instead of ptr_t. * sysdeps/unix/sysv/linux/alpha/oldglob.c (old_glob_t): Likewise. * sysdeps/unix/sysv/linux/mmap.c (__mmap): Likewise.
2017-08-08 19:14:49 +02:00
msync (void *addr, size_t len, int flags)
{
vm_sync_t sync_flags = 0;
kern_return_t err;
hurd: Add remaining cancelation points * hurd/hurdselect.c: Include <sysdep-cancel.h>. (_hurd_select): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/accept4.c: Include <sysdep-cancel.h>. (__libc_accept4): Surround call to __socket_accept with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/connect.c: Include <sysdep-cancel.h>. (__connect): Surround call to __file_name_lookup and __socket_connect with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fdatasync.c: Include <sysdep-cancel.h>. (fdatasync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fsync.c: Include <sysdep-cancel.h>. (fsync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/ioctl.c: Include <sysdep-cancel.h>. (__ioctl): When request is TIOCDRAIN, surround call to send_rpc with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/msync.c: Include <sysdep-cancel.h>. (msync): Surround call to __vm_object_sync with enabling async cancel. * sysdeps/mach/hurd/sigsuspend.c: Include <sysdep-cancel.h>. (__sigsuspend): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/sigwait.c: Include <sysdep-cancel.h>. (__sigwait): Surround wait code with enabling async cancel. * sysdeps/mach/msync.c: Include <sysdep-cancel.h>. (msync): Surround call to __vm_msync with enabling async cancel. * sysdeps/mach/sleep.c: Include <sysdep-cancel.h>. (__sleep): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/usleep.c: Include <sysdep-cancel.h>. (usleep): Surround call to __vm_msync with enabling async cancel.
2020-06-29 00:41:18 +02:00
int cancel_oldtype;
if (flags & MS_SYNC)
sync_flags |= VM_SYNC_SYNCHRONOUS;
if (flags & MS_ASYNC)
sync_flags |= VM_SYNC_ASYNCHRONOUS;
if (flags & MS_INVALIDATE)
sync_flags |= VM_SYNC_INVALIDATE;
hurd: Add remaining cancelation points * hurd/hurdselect.c: Include <sysdep-cancel.h>. (_hurd_select): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/accept4.c: Include <sysdep-cancel.h>. (__libc_accept4): Surround call to __socket_accept with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/connect.c: Include <sysdep-cancel.h>. (__connect): Surround call to __file_name_lookup and __socket_connect with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fdatasync.c: Include <sysdep-cancel.h>. (fdatasync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/fsync.c: Include <sysdep-cancel.h>. (fsync): Surround call to __file_sync with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/ioctl.c: Include <sysdep-cancel.h>. (__ioctl): When request is TIOCDRAIN, surround call to send_rpc with enabling async cancel, and use HURD_DPORT_USE_CANCEL instead of HURD_DPORT_USE. * sysdeps/mach/hurd/msync.c: Include <sysdep-cancel.h>. (msync): Surround call to __vm_object_sync with enabling async cancel. * sysdeps/mach/hurd/sigsuspend.c: Include <sysdep-cancel.h>. (__sigsuspend): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/hurd/sigwait.c: Include <sysdep-cancel.h>. (__sigwait): Surround wait code with enabling async cancel. * sysdeps/mach/msync.c: Include <sysdep-cancel.h>. (msync): Surround call to __vm_msync with enabling async cancel. * sysdeps/mach/sleep.c: Include <sysdep-cancel.h>. (__sleep): Surround call to __mach_msg with enabling async cancel. * sysdeps/mach/usleep.c: Include <sysdep-cancel.h>. (usleep): Surround call to __vm_msync with enabling async cancel.
2020-06-29 00:41:18 +02:00
cancel_oldtype = LIBC_CANCEL_ASYNC();
err = __vm_msync (__mach_task_self (),
(vm_address_t) addr, (vm_size_t) len, sync_flags);
LIBC_CANCEL_RESET (cancel_oldtype);
if (err)
{
errno = err;
return -1;
}
return 0;
}
#endif