1#![allow(clippy::single_match)]
2#[doc = " vDSO for `x86_64`"]
3#[derive(Debug, Copy, Clone)]
4pub struct Vdso {
5 pub clock_gettime: *const ::core::ffi::c_void,
6 pub getcpu: *const ::core::ffi::c_void,
7 pub gettimeofday: *const ::core::ffi::c_void,
8 pub time: *const ::core::ffi::c_void,
9}
10impl Vdso {
11 fn from_reader(reader: crate::VdsoReader) -> ::core::option::Option<Self> {
12 unsafe {
13 let mut version_mandatory_0 = 0u16;
14 let mut vdso_inst = Self {
15 clock_gettime: ::core::ptr::null(),
16 getcpu: ::core::ptr::null(),
17 gettimeofday: ::core::ptr::null(),
18 time: ::core::ptr::null(),
19 };
20 {
21 let mut mandatory_count = 0usize;
22 for version in reader.versions() {
23 match version.hash() {
24 61765110 => {
25 if crate::util::streq(
26 version.name(),
27 [76, 73, 78, 85, 88, 95, 50, 46, 54, 0u8][..].as_ptr(),
28 ) {
29 if version_mandatory_0 == 0 {
30 mandatory_count += 1;
31 version_mandatory_0 = version.id();
32 } else {
33 return ::core::option::Option::None;
34 }
35 }
36 }
37 _ => (),
38 }
39 if mandatory_count == 1 {
40 break;
41 }
42 }
43 if mandatory_count != 1 {
44 return ::core::option::Option::None;
45 }
46 }
47 {
48 let mut mandatory_count = 0usize;
49 for symbol in reader.symbols() {
50 match crate::util::elf_hash(symbol.name()) {
51 11538501 => {
52 if crate::util::streq(
53 symbol.name(),
54 [
55 95, 95, 118, 100, 115, 111, 95, 103, 101, 116, 99, 112, 117,
56 0u8,
57 ][..]
58 .as_ptr(),
59 ) && Some(version_mandatory_0) == symbol.version_id()
60 {
61 if vdso_inst.getcpu.is_null() {
62 mandatory_count += 1;
63 vdso_inst.getcpu = symbol.ptr();
64 } else {
65 return ::core::option::Option::None;
66 }
67 }
68 }
69 51759705 => {
70 if crate::util::streq(
71 symbol.name(),
72 [
73 95, 95, 118, 100, 115, 111, 95, 103, 101, 116, 116, 105, 109,
74 101, 111, 102, 100, 97, 121, 0u8,
75 ][..]
76 .as_ptr(),
77 ) && Some(version_mandatory_0) == symbol.version_id()
78 {
79 if vdso_inst.gettimeofday.is_null() {
80 mandatory_count += 1;
81 vdso_inst.gettimeofday = symbol.ptr();
82 } else {
83 return ::core::option::Option::None;
84 }
85 }
86 }
87 171164805 => {
88 if crate::util::streq(
89 symbol.name(),
90 [95, 95, 118, 100, 115, 111, 95, 116, 105, 109, 101, 0u8][..]
91 .as_ptr(),
92 ) && Some(version_mandatory_0) == symbol.version_id()
93 {
94 if vdso_inst.time.is_null() {
95 mandatory_count += 1;
96 vdso_inst.time = symbol.ptr();
97 } else {
98 return ::core::option::Option::None;
99 }
100 }
101 }
102 221637749 => {
103 if crate::util::streq(
104 symbol.name(),
105 [
106 95, 95, 118, 100, 115, 111, 95, 99, 108, 111, 99, 107, 95, 103,
107 101, 116, 116, 105, 109, 101, 0u8,
108 ][..]
109 .as_ptr(),
110 ) && Some(version_mandatory_0) == symbol.version_id()
111 {
112 if vdso_inst.clock_gettime.is_null() {
113 mandatory_count += 1;
114 vdso_inst.clock_gettime = symbol.ptr();
115 } else {
116 return ::core::option::Option::None;
117 }
118 }
119 }
120 _ => (),
121 }
122 if mandatory_count == 4 {
123 break;
124 }
125 }
126 if mandatory_count != 4 {
127 return ::core::option::Option::None;
128 }
129 }
130 Some(vdso_inst)
131 }
132 }
133 #[doc = r" Parse vDSO from memory"]
134 #[doc = r" # Safety"]
135 #[doc = r" This is unsafe because we can't validate the given pointer so"]
136 #[doc = r" use it carefully"]
137 pub unsafe fn from_ptr(ptr: *const ::core::ffi::c_void) -> ::core::option::Option<Self> {
138 Self::from_reader(crate::VdsoReader::from_ptr(ptr)?)
139 }
140}