]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/msync.c
1 /* msync -- Synchronize mapped memory to external storage. Mach version.
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <sys/types.h>
23 #include <hurd/hurd.h>
25 /* Synchronize the region starting at ADDR and extending LEN bytes with the
26 file it maps. Filesystem operations on a file being mapped are
27 unpredictable before this is done. */
30 msync (void *addr
, size_t length
, int flags
)
32 boolean_t should_flush
= flags
& MS_INVALIDATE
? 1 : 0;
33 boolean_t should_iosync
= flags
& MS_ASYNC
? 0 : 1;
35 vm_address_t cur
= (vm_address_t
) addr
;
36 vm_address_t target
= cur
+ length
;
43 memory_object_name_t obj
;
48 if (flags
& (MS_SYNC
| MS_ASYNC
) == (MS_SYNC
| MS_ASYNC
))
49 return __hurd_fail (EINVAL
);
53 vm_address_t begin
= cur
;
55 err
= __vm_region (__mach_task_self (),
56 &begin
, &len
, &prot
, &max_prot
, &inherit
,
57 &shared
, &obj
, &offset
);
59 if (err
!= KERN_SUCCESS
)
60 return __hurd_fail (err
);
63 /* We were given an address before the first region,
64 or we found a hole. */
68 /* We were given an ending address within a hole. */
71 if (MACH_PORT_VALID (obj
))
75 if (begin
+ len
> target
)
76 sync_len
= target
- begin
;
80 err
= __vm_object_sync (obj
, cur
- begin
+ offset
, sync_len
,
81 should_flush
, 1, should_iosync
);
82 __mach_port_deallocate (__mach_task_self (), obj
);
85 return __hurd_fail (err
);