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    fn dzmmap(
13        start: Address,
14        size: usize,
15        strategy: MmapStrategy,
16        annotation: &MmapAnnotation<'_>,
17    ) -> MmapResult<Address> {
18        linux_common::dzmmap(start, size, strategy, annotation)
19    }
20
21    fn dzmmap_anywhere(
22        size: usize,
23        align: usize,
24        strategy: MmapStrategy,
25        annotation: &MmapAnnotation<'_>,
26    ) -> Result<Address> {
27        linux_common::dzmmap_anywhere(size, align, strategy, annotation)
28    }
29
30    fn munmap(start: Address, size: usize) -> Result<()> {
31        unix_common::munmap(start, size)
32    }
33
34    fn set_memory_access(start: Address, size: usize, prot: MmapProtection) -> Result<()> {
35        unix_common::mprotect(start, size, prot)
36    }
37
38    fn is_mmap_oom(os_errno: i32) -> bool {
39        unix_common::is_mmap_oom(os_errno)
40    }
41
42    fn panic_if_unmapped(start: Address, size: usize) {
43        linux_common::panic_if_unmapped(start, size)
44    }
45}
46
47impl OSProcess for Linux {
48    type ProcessIDType = unix_common::ProcessIDType;
49    type ThreadIDType = unix_common::ThreadIDType;
50
51    fn get_process_memory_maps() -> Result<String> {
52        linux_common::get_process_memory_maps()
53    }
54
55    fn get_process_id() -> Result<Self::ProcessIDType> {
56        unix_common::get_process_id()
57    }
58
59    fn get_thread_id() -> Result<Self::ThreadIDType> {
60        unix_common::get_thread_id()
61    }
62
63    fn get_total_num_cpus() -> CoreNum {
64        linux_common::get_total_num_cpus()
65    }
66
67    fn bind_current_thread_to_core(core_id: CoreId) {
68        linux_common::bind_current_thread_to_core(core_id)
69    }
70
71    fn bind_current_thread_to_cpuset(core_ids: &[CoreId]) {
72        linux_common::bind_current_thread_to_cpuset(core_ids)
73    }
74}