Coder Social home page Coder Social logo

Invalid ELF header size or alignment about aya HOT 3 CLOSED

aya-rs avatar aya-rs commented on May 18, 2024
Invalid ELF header size or alignment

from aya.

Comments (3)

ecarrara avatar ecarrara commented on May 18, 2024

@tw4452852 i think you should align you array of bytes.

Zero-copy buffer mode
bpf devices may also operate in the BPF_BUFMODE_ZEROCOPY mode, in which
packet data is written directly into two user memory buffers by the ker-
nel, avoiding both system call and copying overhead. Buffers are of
fixed (and equal) size, page-aligned, and an even multiple of the page
size. The maximum zero-copy buffer size is returned by the BIOCGETZMAX
ioctl. Note that an individual packet larger than the buffer size is
necessarily truncated.
https://www.freebsd.org/cgi/man.cgi?bpf(4)

What works for me:

macro_rules! include_bytes_align_as {
    ($align_ty:ty, $path:literal) => {{
        #[repr(C)]
        pub struct AlignedAs<Align, Bytes: ?Sized> {
            pub _align: [Align; 0],
            pub bytes: Bytes,
        }

        static ALIGNED: &AlignedAs<$align_ty, [u8]> = &AlignedAs {
            _align: [],
            bytes: *include_bytes!($path),
        };

        &ALIGNED.bytes
    }};
}

static PROGRAM_DATA: &'static [u8] = include_bytes_align_as!(
    u32,
    "../../target/bpfel-unknown-none/release/libpq-tracer-bpf"
);

    // ..
    let mut bpf = Bpf::load(PROGRAM_DATA.into(), None)?;

I copied the include_bytes_align_as macro from here.

from aya.

tw4452852 avatar tw4452852 commented on May 18, 2024

Wow, thanks @ecarrara , Now it's clear now.

from aya.

willfindlay avatar willfindlay commented on May 18, 2024

Just an FYI for folks coming here from their favourite search engine: As of #76 we will have aya::include_bytes_aligned which can be used instead.

from aya.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.