Merge "switch BpfBitmap key from U32 to S32"
This commit is contained in:
@@ -27,7 +27,7 @@ import androidx.annotation.NonNull;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BpfBitmap {
|
public class BpfBitmap {
|
||||||
private BpfMap<Struct.U32, Struct.S64> mBpfMap;
|
private BpfMap<Struct.S32, Struct.S64> mBpfMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a BpfBitmap map wrapper with "path" of filesystem.
|
* Create a BpfBitmap map wrapper with "path" of filesystem.
|
||||||
@@ -35,8 +35,8 @@ public class BpfBitmap {
|
|||||||
* @param path The path of the BPF map.
|
* @param path The path of the BPF map.
|
||||||
*/
|
*/
|
||||||
public BpfBitmap(@NonNull String path) throws ErrnoException {
|
public BpfBitmap(@NonNull String path) throws ErrnoException {
|
||||||
mBpfMap = new BpfMap<Struct.U32, Struct.S64>(path, BpfMap.BPF_F_RDWR,
|
mBpfMap = new BpfMap<Struct.S32, Struct.S64>(path, BpfMap.BPF_F_RDWR,
|
||||||
Struct.U32.class, Struct.S64.class);
|
Struct.S32.class, Struct.S64.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +44,7 @@ public class BpfBitmap {
|
|||||||
*
|
*
|
||||||
* @param key The key in the map corresponding to the value to return.
|
* @param key The key in the map corresponding to the value to return.
|
||||||
*/
|
*/
|
||||||
private long getBpfMapValue(Struct.U32 key) throws ErrnoException {
|
private long getBpfMapValue(Struct.S32 key) throws ErrnoException {
|
||||||
Struct.S64 curVal = mBpfMap.getValue(key);
|
Struct.S64 curVal = mBpfMap.getValue(key);
|
||||||
if (curVal != null) {
|
if (curVal != null) {
|
||||||
return curVal.val;
|
return curVal.val;
|
||||||
@@ -61,7 +61,7 @@ public class BpfBitmap {
|
|||||||
public boolean get(int index) throws ErrnoException {
|
public boolean get(int index) throws ErrnoException {
|
||||||
if (index < 0) return false;
|
if (index < 0) return false;
|
||||||
|
|
||||||
Struct.U32 key = new Struct.U32(index >> 6);
|
Struct.S32 key = new Struct.S32(index >> 6);
|
||||||
return ((getBpfMapValue(key) >>> (index & 63)) & 1L) != 0;
|
return ((getBpfMapValue(key) >>> (index & 63)) & 1L) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class BpfBitmap {
|
|||||||
public void set(int index, boolean set) throws ErrnoException {
|
public void set(int index, boolean set) throws ErrnoException {
|
||||||
if (index < 0) throw new IllegalArgumentException("Index out of bounds.");
|
if (index < 0) throw new IllegalArgumentException("Index out of bounds.");
|
||||||
|
|
||||||
Struct.U32 key = new Struct.U32(index >> 6);
|
Struct.S32 key = new Struct.S32(index >> 6);
|
||||||
long mask = (1L << (index & 63));
|
long mask = (1L << (index & 63));
|
||||||
long val = getBpfMapValue(key);
|
long val = getBpfMapValue(key);
|
||||||
if (set) val |= mask; else val &= ~mask;
|
if (set) val |= mask; else val &= ~mask;
|
||||||
@@ -114,7 +114,7 @@ public class BpfBitmap {
|
|||||||
* Checks if all bitmap values are 0.
|
* Checks if all bitmap values are 0.
|
||||||
*/
|
*/
|
||||||
public boolean isEmpty() throws ErrnoException {
|
public boolean isEmpty() throws ErrnoException {
|
||||||
Struct.U32 key = mBpfMap.getFirstKey();
|
Struct.S32 key = mBpfMap.getFirstKey();
|
||||||
while (key != null) {
|
while (key != null) {
|
||||||
if (getBpfMapValue(key) != 0) {
|
if (getBpfMapValue(key) != 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user