Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use libc::getauxval #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = "Resolve Linux vDSO symbols"
readme = "README.md"
keywords = ["linux", "vdso"]
categories = ["development-tools", "os::linux-apis"]
exclude = [ ".gitignore", ".github/*" ]
exclude = [".gitignore", ".github/*"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -23,9 +23,6 @@ maintenance = { status = "actively-developed" }
is-it-maintained-issue-resolution = { repository = "enarx/vdso" }
is-it-maintained-open-issues = { repository = "enarx/vdso" }

[dev-dependencies]
libc = "0.2.67"

[dependencies]
crt0stack = "0.1"
goblin = "0.8.0"
libc = "0.2.153"
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![deny(missing_docs)]
#![deny(clippy::all)]

use crt0stack::{Entry, Reader};
use std::ffi::CStr;
use std::os::raw::c_char;
use std::slice::from_raw_parts;
Expand All @@ -20,6 +19,7 @@ mod elf {
pub use goblin::elf64::sym::Sym;

pub const CLASS: u8 = ELFCLASS64;

pub type Word = u64;
}

Expand All @@ -33,6 +33,7 @@ mod elf {
pub use goblin::elf32::sym::Sym;

pub const CLASS: u8 = ELFCLASS32;

pub type Word = u32;
}

Expand Down Expand Up @@ -114,14 +115,13 @@ pub struct Vdso<'a>(&'a Header);
impl Vdso<'static> {
/// Locates the vDSO by parsing the auxiliary vectors
pub fn locate() -> Option<Self> {
for aux in Reader::from_environ().done() {
if let Entry::SysInfoEHdr(addr) = aux {
let hdr = unsafe { Header::from_ptr(&*(addr as *const _))? };
return Some(Self(hdr));
}
let val = unsafe { libc::getauxval(libc::AT_SYSINFO_EHDR) };
if val == 0 {
return None;
}

None
let hdr = unsafe { Header::from_ptr(&*(val as *const _))? };
Some(Self(hdr))
}
}

Expand Down
Loading