mmtk/util/os/imp/unix_like/linux_like/
linux.rs

1use crate::util::address::Address;
2use crate::util::os::imp::unix_like::linux_like::linux_common;
3use crate::util::os::imp::unix_like::unix_common;
4use crate::util::os::*;
5
6use std::io::Result;
7
8/// Linux implementation of the `OS` trait.
9pub struct Linux;
10
11impl OSMemory for Linux {
12    const LOG_BYTES_IN_PAGE: u8 = 12;
13
14    fn dzmmap(
15        start: Address,
16        size: usize,
17        strategy: MmapStrategy,
18        annotation: &MmapAnnotation<'_>,
19    ) -> MmapResult<Address> {
20        linux_common::dzmmap(start, size, strategy, annotation)
21    }
22
23    fn dzmmap_anywhere(
24        size: usize,
25        align: usize,
26        strategy: MmapStrategy,
27        annotation: &MmapAnnotation<'_>,
28    ) -> MmapResult<Address> {
29        linux_common::dzmmap_anywhere(size, align, strategy, annotation)
30    }
31
32    fn dzmmap_preferred(
33        start: Address,
34        size: usize,
35        align: usize,
36        strategy: MmapStrategy,
37        annotation: &MmapAnnotation<'_>,
38    ) -> MmapResult<Address> {
39        linux_common::dzmmap_preferred(start, size, align, strategy, annotation)
40    }
41
42    fn munmap(start: Address, size: usize) -> Result<()> {
43        unix_common::munmap(start, size)
44    }
45
46    fn set_memory_access(start: Address, size: usize, prot: MmapProtection) -> Result<()> {
47        unix_common::mprotect(start, size, prot)
48    }
49
50    fn is_mmap_oom(os_errno: i32) -> bool {
51        unix_common::is_mmap_oom(os_errno)
52    }
53
54    fn panic_if_unmapped(start: Address, size: usize) {
55        linux_common::panic_if_unmapped(start, size)
56    }
57}
58
59impl OSProcess for Linux {
60    type ProcessIDType = unix_common::ProcessIDType;
61    type ThreadIDType = unix_common::ThreadIDType;
62
63    fn get_process_memory_maps() -> Result<String> {
64        linux_common::get_process_memory_maps()
65    }
66
67    fn get_process_id() -> Result<Self::ProcessIDType> {
68        unix_common::get_process_id()
69    }
70
71    fn get_thread_id() -> Result<Self::ThreadIDType> {
72        unix_common::get_thread_id()
73    }
74
75    fn get_total_num_cpus() -> CoreNum {
76        linux_common::get_total_num_cpus()
77    }
78
79    fn bind_current_thread_to_core(core_id: CoreId) {
80        linux_common::bind_current_thread_to_core(core_id)
81    }
82
83    fn bind_current_thread_to_cpuset(core_ids: &[CoreId]) {
84        linux_common::bind_current_thread_to_cpuset(core_ids)
85    }
86}