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

Move to 22 #9

Merged
merged 11 commits into from
Apr 7, 2024
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Java 21
- name: Setup Java 22
uses: actions/setup-java@v4
with:
java-version: '21'
java-version: '22'
distribution: 'adopt'

- name: Cache Maven
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '21'
java-version: '22'
distribution: 'adopt'

- run: sudo pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/early-access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ main ]

env:
JAVA_VERSION: '21'
JAVA_VERSION: '22'
JAVA_DISTRO: 'adopt'

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
required: true

env:
JAVA_VERSION: '21'
JAVA_VERSION: '22'
JAVA_DISTRO: 'adopt'

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,5 @@ hello-ebpf.iml
*.zst
*.c
kprobe*
vmlinux*
vmlinux*
**/jextract-*
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ These might change in the future, but for now, you need the following:
Either a Linux machine with the following:

- Linux 64-bit (or a VM)
- Java 21 (exactly this version, as we need [Project Panama](https://openjdk.org/projects/panama/) with is a preview
feature), we'll switch to Java 22 as soon as it is released
- Java 22 or later
- libbcc (see [bcc installation instructions](https://github.com/iovisor/bcc/blob/master/INSTALL.md), be sure to install the libbpfcc-dev package)
- e.g. `apt install bpfcc-tools libbpfcc-dev linux-tools-common linux-tools-$(uname -r)` on Ubuntu
- root privileges (for eBPF programs)
On Mac OS, you can use the [Lima VM](https://lima-vm.io/) (or use the `hello-ebpf.yaml` file as a guide to install the prerequisites):

```sh
limactl start hello-ebpf.yaml
limactl start hello-ebpf.yaml --mount-writable
limactl shell hello-ebpf sudo bin/install.sh
limactl shell hello-ebpf

# You'll need to be root for most of the examples
sudo -s
sudo -s PATH=$PATH
```

Build
Expand All @@ -81,10 +81,10 @@ To build the project, make sure you have all prerequisites installed, then just

Running the examples
--------------------
Be sure to run the following in a shell with root privileges that uses JDK 21:
Be sure to run the following in a shell with root privileges that uses JDK 22:

```shell
java --enable-preview -cp bcc/target/bcc.jar --enable-native-access=ALL-UNNAMED me.bechberger.ebpf.samples.EXAMPLE_NAME
java -cp bcc/target/bcc.jar --enable-native-access=ALL-UNNAMED me.bechberger.ebpf.samples.EXAMPLE_NAME
# or in the project directory
./run.sh EXAMPLE_NAME

Expand Down Expand Up @@ -225,6 +225,7 @@ You can run them using the `./run_bpf.sh` script. All examples have accompanying
| Ansil H | [RingSample](bpf/src/main/java/me/bechberger/ebpf/samples/RingSample.java) | Record openat calls in a ring buffer |
| | [TypeProcessingSample](bpf/src/main/java/me/bechberger/ebpf/samples/TypeProcessingSample.java) | RingSample using the @Type annotation |
| | [HashMapSample](bpf/src/main/java/me/bechberger/ebpf/samples/HashMapSample.java) | Record openat calls in a hash map |
| | [TypeProcessingSample](bpf/src/main/java/me/bechberger/ebpf/samples/TypeProcessingSample.java) | RingSample using more code generation |

Classes and Methods
-------
Expand Down
4 changes: 2 additions & 2 deletions annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<artifactId>ebpf-annotations</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
*/
@Target(ElementType.TYPE)
public @interface BPF {
/**
* License of the eBPF program, the EBPF_PROGRAM contains a <code>SEC("license")</code> variable
* only iff this license is not present. Typically, the license is GPL.
*/
String license() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package me.bechberger.ebpf.annotations.bpf;

import java.io.FileDescriptor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specify that a class is a BPF map class
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
public @interface BPFMapClass {
/**
* Template for the generated C code
* <p>
* Available placeholders:
* <ul>
* <li>$field: The field name</li>
* <li>$maxEntries: max entries as specified in the {@link BPFMapDefinition} annotation</li>
* <li>$class: name of the class</li>
* <li>$c1, ...: C type names for every generic type parameter</li>
* <li>$b1, ...: BPFTypes</li>
* <li>$j1, ...: Java class names</li>
* </ul>
* <p>
* Example:
* {@snippet :
* struct {
* __uint (type, BPF_MAP_TYPE_RINGBUF);
* __uint (max_entries, $maxEntries);
* } $field SEC(".maps");
* }
*/
String cTemplate();

/**
* Code template for generating the Java generation code, see {@link BPFMapClass#cTemplate()} for available placeholders,
* here are the additions:
* <ul>
* <li>$fd: code that creates a FileDescriptor instance</li>
* </ul>
* <p>
* Example:
* {@snippet :
* new $class<>($fd, $b1)
* }
*/
String javaTemplate();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.bechberger.ebpf.annotations.bpf;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Declare maps for the eBPF program by annotating non-final, non-private instance fields of a type
* annotated with {@link BPFMapClass} with this annotation. The generic type parameters have to adhere
* to the same constraints as the members of {@link Type} annotated records.
* <p>
* Example:
* {@snippet :
* @BPFMapDefinition(maxEntries = 1024)
* private BPFHashMap<Integer, Integer> map;
* }
* this defines a hash map with 1024 entries.
*/
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.CLASS)
public @interface BPFMapDefinition {
/**
* Maximum number of entries in the map.
* <p>
* For ring buffers, this is the number of bytes in the buffer which should be a multiple of the kernel page size
* (usually 4096), has to be larger than zero
*/
int maxEntries();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* <li>integer types (int, long, ...), optionally annotated with {@link Unsigned} if unsigned</li>
* <li>String types, annotated with {@link Size} to specify the size</li>
* <li>Other {@link Type} annotated types</li>
* <li>{@link Type.Member} annotated member, to specify the BPFType directly</li>
* </ul>
*/
@Target(ElementType.TYPE)
Expand All @@ -32,11 +31,6 @@
/** Name of the generated BPFStructType, uses the type as default */
String name() default "";

@Target({ElementType.TYPE, ElementType.TYPE_USE})
@Retention(RetentionPolicy.CLASS)
public @interface Member {

/** Java statement directly copied into the result at the place of the BPFType */
String bpfType();
}
}
/** Don't generate C code and insert it into the ebpf program string */
boolean noCCodeGeneration() default false;
}
11 changes: 6 additions & 5 deletions bcc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
</properties>

<build>
Expand All @@ -50,7 +50,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -85,7 +86,7 @@
<dependency>
<groupId>me.bechberger</groupId>
<artifactId>rawbcc</artifactId>
<version>0.1.3</version>
<version>0.1.4</version>
</dependency>
<dependency>
<groupId>me.bechberger</groupId>
Expand All @@ -111,4 +112,4 @@
<artifactId>hello-ebpf</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
</project>
</project>
Loading
Loading