Coverage Report

Created: 2024-11-21 12:31

/root/doris/be/src/vec/common/mremap.h
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/base/base/mremap.h
19
// and modified by Doris
20
21
#pragma once
22
23
#if !defined(_MSC_VER)
24
#include <sys/mman.h>
25
#endif
26
27
#ifdef MREMAP_MAYMOVE
28
#define HAS_MREMAP 1
29
#else
30
#define HAS_MREMAP 0
31
#endif
32
33
/// You can forcely disable mremap by defining DISABLE_MREMAP to 1 before including this file.
34
#ifndef DISABLE_MREMAP
35
#if HAS_MREMAP
36
#define DISABLE_MREMAP 0
37
#else
38
#define DISABLE_MREMAP 1
39
#endif
40
#endif
41
42
/// Implement mremap with mmap/memcpy/munmap.
43
void* mremap_fallback(void* old_address, size_t old_size, size_t new_size, int flags, int mmap_prot,
44
                      int mmap_flags, int mmap_fd, off_t mmap_offset);
45
46
#if !HAS_MREMAP
47
#define MREMAP_MAYMOVE 1
48
49
inline void* mremap(void* old_address, size_t old_size, size_t new_size, int flags = 0,
50
                    int mmap_prot = 0, int mmap_flags = 0, int mmap_fd = -1,
51
                    off_t mmap_offset = 0) {
52
    return mremap_fallback(old_address, old_size, new_size, flags, mmap_prot, mmap_flags, mmap_fd,
53
                           mmap_offset);
54
}
55
#endif
56
57
inline void* clickhouse_mremap(void* old_address, size_t old_size, size_t new_size, int flags = 0,
58
                               [[maybe_unused]] int mmap_prot = 0,
59
                               [[maybe_unused]] int mmap_flags = 0,
60
                               [[maybe_unused]] int mmap_fd = -1,
61
0
                               [[maybe_unused]] off_t mmap_offset = 0) {
62
#if DISABLE_MREMAP
63
    return mremap_fallback(old_address, old_size, new_size, flags, mmap_prot, mmap_flags, mmap_fd,
64
                           mmap_offset);
65
#else
66
67
0
    return mremap(old_address, old_size, new_size, flags
68
#if !defined(MREMAP_FIXED)
69
                  ,
70
                  mmap_prot, mmap_flags, mmap_fd, mmap_offset
71
#endif
72
0
    );
73
0
#endif
74
0
}