1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
// Copyright © 2020, Oracle and/or its affiliates.
//
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

/*
 * automatically generated by rust-bindgen using:
 *
 * # bindgen --with-derive-default elf.h > elf.rs
 *
 * From upstream linux include/uapi/linux/elf.h at commit:
 * 3cc6e2c599cdca573a8f347aea5da4c855ff5a78
 * and then edited to eliminate unnecessary definitions, add comments,
 * and relocate definitions and tests for clarity.
 */

pub const PT_LOAD: u32 = 1;
pub const PT_NOTE: u32 = 4;

pub const EI_MAG0: u32 = 0;
pub const EI_MAG1: u32 = 1;
pub const EI_MAG2: u32 = 2;
pub const EI_MAG3: u32 = 3;
pub const EI_DATA: u32 = 5;

pub const ELFMAG0: u32 = 127;

// The values for the following definitions have been edited
// to use their equivalent byte literal representations.
pub const ELFMAG1: u8 = b'E';
pub const ELFMAG2: u8 = b'L';
pub const ELFMAG3: u8 = b'F';

pub const ELFDATA2LSB: u32 = 1;

pub type __s8 = ::std::os::raw::c_schar;
pub type __u8 = ::std::os::raw::c_uchar;
pub type __s16 = ::std::os::raw::c_short;
pub type __u16 = ::std::os::raw::c_ushort;
pub type __s32 = ::std::os::raw::c_int;
pub type __u32 = ::std::os::raw::c_uint;
pub type __s64 = ::std::os::raw::c_longlong;
pub type __u64 = ::std::os::raw::c_ulonglong;

pub type Elf64_Addr = __u64;
pub type Elf64_Half = __u16;
pub type Elf64_Off = __u64;
pub type Elf64_Sword = __s32;
pub type Elf64_Word = __u32;
pub type Elf64_Xword = __u64;

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct elf64_hdr {
    pub e_ident: [::std::os::raw::c_uchar; 16usize],
    pub e_type: Elf64_Half,
    pub e_machine: Elf64_Half,
    pub e_version: Elf64_Word,
    pub e_entry: Elf64_Addr,
    pub e_phoff: Elf64_Off,
    pub e_shoff: Elf64_Off,
    pub e_flags: Elf64_Word,
    pub e_ehsize: Elf64_Half,
    pub e_phentsize: Elf64_Half,
    pub e_phnum: Elf64_Half,
    pub e_shentsize: Elf64_Half,
    pub e_shnum: Elf64_Half,
    pub e_shstrndx: Elf64_Half,
}
pub type Elf64_Ehdr = elf64_hdr;

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct elf64_phdr {
    pub p_type: Elf64_Word,
    pub p_flags: Elf64_Word,
    pub p_offset: Elf64_Off,
    pub p_vaddr: Elf64_Addr,
    pub p_paddr: Elf64_Addr,
    pub p_filesz: Elf64_Xword,
    pub p_memsz: Elf64_Xword,
    pub p_align: Elf64_Xword,
}
pub type Elf64_Phdr = elf64_phdr;

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct elf64_note {
    pub n_namesz: Elf64_Word,
    pub n_descsz: Elf64_Word,
    pub n_type: Elf64_Word,
}
pub type Elf64_Nhdr = elf64_note;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn bindgen_test_layout_elf64_hdr() {
        assert_eq!(
            ::std::mem::size_of::<elf64_hdr>(),
            64usize,
            concat!("Size of: ", stringify!(elf64_hdr))
        );
        assert_eq!(
            ::std::mem::align_of::<elf64_hdr>(),
            8usize,
            concat!("Alignment of ", stringify!(elf64_hdr))
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_ident as *const _ as usize },
            0usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_ident)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_type as *const _ as usize },
            16usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_type)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_machine as *const _ as usize },
            18usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_machine)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_version as *const _ as usize },
            20usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_version)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_entry as *const _ as usize },
            24usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_entry)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_phoff as *const _ as usize },
            32usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_phoff)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_shoff as *const _ as usize },
            40usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_shoff)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_flags as *const _ as usize },
            48usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_flags)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_ehsize as *const _ as usize },
            52usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_ehsize)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_phentsize as *const _ as usize },
            54usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_phentsize)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_phnum as *const _ as usize },
            56usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_phnum)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_shentsize as *const _ as usize },
            58usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_shentsize)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_shnum as *const _ as usize },
            60usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_shnum)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_hdr>())).e_shstrndx as *const _ as usize },
            62usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_hdr),
                "::",
                stringify!(e_shstrndx)
            )
        );
    }

    #[test]
    fn bindgen_test_layout_elf64_phdr() {
        assert_eq!(
            ::std::mem::size_of::<elf64_phdr>(),
            56usize,
            concat!("Size of: ", stringify!(elf64_phdr))
        );
        assert_eq!(
            ::std::mem::align_of::<elf64_phdr>(),
            8usize,
            concat!("Alignment of ", stringify!(elf64_phdr))
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_type as *const _ as usize },
            0usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_type)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_flags as *const _ as usize },
            4usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_flags)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_offset as *const _ as usize },
            8usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_offset)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_vaddr as *const _ as usize },
            16usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_vaddr)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_paddr as *const _ as usize },
            24usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_paddr)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_filesz as *const _ as usize },
            32usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_filesz)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_memsz as *const _ as usize },
            40usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_memsz)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_phdr>())).p_align as *const _ as usize },
            48usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_phdr),
                "::",
                stringify!(p_align)
            )
        );
    }

    #[test]
    fn bindgen_test_layout_elf64_note() {
        assert_eq!(
            ::std::mem::size_of::<elf64_note>(),
            12usize,
            concat!("Size of: ", stringify!(elf64_note))
        );
        assert_eq!(
            ::std::mem::align_of::<elf64_note>(),
            4usize,
            concat!("Alignment of ", stringify!(elf64_note))
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_note>())).n_namesz as *const _ as usize },
            0usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_note),
                "::",
                stringify!(n_namesz)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_note>())).n_descsz as *const _ as usize },
            4usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_note),
                "::",
                stringify!(n_descsz)
            )
        );
        assert_eq!(
            unsafe { &(*(::std::ptr::null::<elf64_note>())).n_type as *const _ as usize },
            8usize,
            concat!(
                "Offset of field: ",
                stringify!(elf64_note),
                "::",
                stringify!(n_type)
            )
        );
    }
}