mmtk/util/os/imp/unix_like/linux_like/
linux.rs1use 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
8pub 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 ) -> MmapResult<Address> {
27 linux_common::dzmmap_anywhere(size, align, strategy, annotation)
28 }
29
30 fn dzmmap_preferred(
31 start: Address,
32 size: usize,
33 align: usize,
34 strategy: MmapStrategy,
35 annotation: &MmapAnnotation<'_>,
36 ) -> MmapResult<Address> {
37 linux_common::dzmmap_preferred(start, size, align, strategy, annotation)
38 }
39
40 fn munmap(start: Address, size: usize) -> Result<()> {
41 unix_common::munmap(start, size)
42 }
43
44 fn set_memory_access(start: Address, size: usize, prot: MmapProtection) -> Result<()> {
45 unix_common::mprotect(start, size, prot)
46 }
47
48 fn is_mmap_oom(os_errno: i32) -> bool {
49 unix_common::is_mmap_oom(os_errno)
50 }
51
52 fn panic_if_unmapped(start: Address, size: usize) {
53 linux_common::panic_if_unmapped(start, size)
54 }
55}
56
57impl OSProcess for Linux {
58 type ProcessIDType = unix_common::ProcessIDType;
59 type ThreadIDType = unix_common::ThreadIDType;
60
61 fn get_process_memory_maps() -> Result<String> {
62 linux_common::get_process_memory_maps()
63 }
64
65 fn get_process_id() -> Result<Self::ProcessIDType> {
66 unix_common::get_process_id()
67 }
68
69 fn get_thread_id() -> Result<Self::ThreadIDType> {
70 unix_common::get_thread_id()
71 }
72
73 fn get_total_num_cpus() -> CoreNum {
74 linux_common::get_total_num_cpus()
75 }
76
77 fn bind_current_thread_to_core(core_id: CoreId) {
78 linux_common::bind_current_thread_to_core(core_id)
79 }
80
81 fn bind_current_thread_to_cpuset(core_ids: &[CoreId]) {
82 linux_common::bind_current_thread_to_cpuset(core_ids)
83 }
84}