From 98bf6a84012b8dadc194776ad023cf07b18c0d11 Mon Sep 17 00:00:00 2001 From: Martin Teichmann <martin.teichmann@xfel.eu> Date: Mon, 18 Jan 2021 18:52:36 +0000 Subject: [PATCH] try platform independency --- .gitlab-ci.yml | 3 +-- bpf.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4e13e66..19eb304 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,5 +2,4 @@ test: image: python:3.8-slim script: - cd .. - - python3 -m ebpfcat.ebpf_test -v Tests - - sudo python3 -m ebpfcat.ebpf_test -v KernelTests + - python3 -m ebpfcat.ebpf_test -v diff --git a/bpf.py b/bpf.py index a545eb9..26dca12 100644 --- a/bpf.py +++ b/bpf.py @@ -1,9 +1,19 @@ from ctypes import CDLL, c_int, get_errno, cast, c_void_p, create_string_buffer, c_char_p from enum import Enum from struct import pack, unpack +from platform import machine from os import strerror +try: + SYS_BPF = { + "armv7l": 386, + "x86_64": 321, + }[machine()] +except KeyError: + print("Unknown platform:", machine()) + + class BPFError(OSError): pass @@ -61,7 +71,7 @@ def addrof(ptr): def bpf(cmd, fmt, *args): attr = pack(fmt, *args) attr = create_string_buffer(attr, len(attr)) - ret = libc.syscall(386, c_int(cmd), attr, len(attr)) + ret = libc.syscall(SYS_BPF, c_int(cmd), attr, len(attr)) if ret == -1: raise OSError(get_errno(), strerror(get_errno())) return ret, unpack(fmt, attr.raw) -- GitLab