• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "berberis/base/mmap.h"
18 
19 #include <stdint.h>
20 #include <sys/mman.h>
21 
22 #include "berberis/base/checks.h"
23 
24 namespace berberis {
25 
MmapImpl(MmapImplArgs args)26 void* MmapImpl(MmapImplArgs args) {
27   return mmap(args.addr, args.size, args.prot, args.flags, args.fd, args.offset);
28 }
29 
MmapImplOrDie(MmapImplArgs args)30 void* MmapImplOrDie(MmapImplArgs args) {
31   void* ptr = MmapImpl(args);
32   CHECK_NE(ptr, MAP_FAILED);
33   return ptr;
34 }
35 
MunmapOrDie(void * ptr,size_t size)36 void MunmapOrDie(void* ptr, size_t size) {
37   int res = munmap(ptr, size);
38   CHECK_EQ(res, 0);
39 }
40 
MprotectOrDie(void * ptr,size_t size,int prot)41 void MprotectOrDie(void* ptr, size_t size, int prot) {
42   int res = mprotect(ptr, size, prot);
43   CHECK_EQ(res, 0);
44 }
45 
46 }  // namespace berberis
47