1*0f4c859eSApple OSS Distributions /*
2*0f4c859eSApple OSS Distributions * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3*0f4c859eSApple OSS Distributions *
4*0f4c859eSApple OSS Distributions * @APPLE_LICENSE_HEADER_START@
5*0f4c859eSApple OSS Distributions *
6*0f4c859eSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*0f4c859eSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*0f4c859eSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*0f4c859eSApple OSS Distributions * compliance with the License. Please obtain a copy of the License at
10*0f4c859eSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this
11*0f4c859eSApple OSS Distributions * file.
12*0f4c859eSApple OSS Distributions *
13*0f4c859eSApple OSS Distributions * The Original Code and all software distributed under the License are
14*0f4c859eSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15*0f4c859eSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16*0f4c859eSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17*0f4c859eSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18*0f4c859eSApple OSS Distributions * Please see the License for the specific language governing rights and
19*0f4c859eSApple OSS Distributions * limitations under the License.
20*0f4c859eSApple OSS Distributions *
21*0f4c859eSApple OSS Distributions * @APPLE_LICENSE_HEADER_END@
22*0f4c859eSApple OSS Distributions */
23*0f4c859eSApple OSS Distributions
24*0f4c859eSApple OSS Distributions #ifndef NO_SYSCALL_LEGACY
25*0f4c859eSApple OSS Distributions
26*0f4c859eSApple OSS Distributions #define _NONSTD_SOURCE
27*0f4c859eSApple OSS Distributions #include <sys/cdefs.h>
28*0f4c859eSApple OSS Distributions
29*0f4c859eSApple OSS Distributions #include <sys/types.h>
30*0f4c859eSApple OSS Distributions #include <sys/mman.h>
31*0f4c859eSApple OSS Distributions #include <mach/vm_param.h>
32*0f4c859eSApple OSS Distributions #include <mach/mach_init.h>
33*0f4c859eSApple OSS Distributions #include "stack_logging_internal.h"
34*0f4c859eSApple OSS Distributions
35*0f4c859eSApple OSS Distributions /*
36*0f4c859eSApple OSS Distributions * Stub function to account for the differences in standard compliance
37*0f4c859eSApple OSS Distributions * while maintaining binary backward compatibility.
38*0f4c859eSApple OSS Distributions *
39*0f4c859eSApple OSS Distributions * This is only the legacy behavior.
40*0f4c859eSApple OSS Distributions */
41*0f4c859eSApple OSS Distributions extern int __munmap(void *, size_t);
42*0f4c859eSApple OSS Distributions
43*0f4c859eSApple OSS Distributions int
munmap(void * addr,size_t len)44*0f4c859eSApple OSS Distributions munmap(void *addr, size_t len)
45*0f4c859eSApple OSS Distributions {
46*0f4c859eSApple OSS Distributions size_t offset;
47*0f4c859eSApple OSS Distributions
48*0f4c859eSApple OSS Distributions if (len == 0) {
49*0f4c859eSApple OSS Distributions /*
50*0f4c859eSApple OSS Distributions * Standard compliance now requires the system to return EINVAL
51*0f4c859eSApple OSS Distributions * for munmap(addr, 0). Return success now to maintain
52*0f4c859eSApple OSS Distributions * backwards compatibility.
53*0f4c859eSApple OSS Distributions */
54*0f4c859eSApple OSS Distributions return 0;
55*0f4c859eSApple OSS Distributions }
56*0f4c859eSApple OSS Distributions /*
57*0f4c859eSApple OSS Distributions * Page-align "addr" since the system now requires it
58*0f4c859eSApple OSS Distributions * for standards compliance.
59*0f4c859eSApple OSS Distributions * Update "len" to reflect the adjustment and still cover the same area.
60*0f4c859eSApple OSS Distributions */
61*0f4c859eSApple OSS Distributions offset = ((uintptr_t) addr) & PAGE_MASK;
62*0f4c859eSApple OSS Distributions addr = (void *) (((uintptr_t) addr) & ~PAGE_MASK);
63*0f4c859eSApple OSS Distributions len += offset;
64*0f4c859eSApple OSS Distributions
65*0f4c859eSApple OSS Distributions if (__syscall_logger) {
66*0f4c859eSApple OSS Distributions __syscall_logger(stack_logging_type_vm_deallocate, (uintptr_t)mach_task_self(), (uintptr_t)addr, len, 0, 0);
67*0f4c859eSApple OSS Distributions }
68*0f4c859eSApple OSS Distributions
69*0f4c859eSApple OSS Distributions int result = __munmap(addr, len);
70*0f4c859eSApple OSS Distributions
71*0f4c859eSApple OSS Distributions return result;
72*0f4c859eSApple OSS Distributions }
73*0f4c859eSApple OSS Distributions #endif /* NO_SYSCALL_LEGACY */
74