Skip to content

Commit

Permalink
Get rid of tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaAtulTewari committed Dec 2, 2024
1 parent aea6f44 commit 171ed00
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions module/test/register_func.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include <cerrno>
#include <cstdint>
#include <cstdio>
#include <cerrno>
#include <fnctl.h>
#include <linux/bpf.h>
#include <optional>
#include <sys/ioctl.h>
#include <linux/bpf.h>
#include <fnctl.h>

enum fstore_cmd {
REGISTER_MAP = 0x0,
UNREGISTER_MAP = 0x1,
REGISTER_MAP = 0x0,
UNREGISTER_MAP = 0x1,
};

std::optional<uint64_t> convert8byteStringHash(char* string) {
uint64_t hash = 0;
uint8_t i = 0;
for(; string[i] != '\0' && i < 8; i++) {
hash |= ((uint64_t) string[i]) << (i * 8);
for (; string[i] != '\0' && i < 8; i++) {
hash |= ((uint64_t)string[i]) << (i * 8);
}
if(string[i] != '\0') {
if (string[i] != '\0') {
return std::nullopt;
}
return hash;
Expand All @@ -26,41 +26,42 @@ std::optional<uint64_t> convert8byteStringHash(char* string) {
consteval uint64_t unsafeHashConvert(const char* string) {
uint64_t hash = 0;
uint8_t i = 0;
for(; string[i] != '\0' && i < 8; i++) {
hash |= ((uint64_t) string[i]) << (i * 8);
for (; string[i] != '\0' && i < 8; i++) {
hash |= ((uint64_t)string[i]) << (i * 8);
}
return hash;
}

typedef struct register_input {
uint64_t map_name;
uint32_t fd;
uint64_t map_name;
uint32_t fd;
} register_t;

int main()
{
int main() {
union bpf_attr attr = {
.map_type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = 32,
.value_size = 32,
.max_entries = 100,
.map_type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = 32,
.value_size = 32,
.max_entries = 100,
};
int ebpf_fd = bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
if(ebpf_fd < 0) return ebpf_fd;
if (ebpf_fd < 0)
return ebpf_fd;

register_t reg = {
.map_name = unsafeHashConvert("hello"),
.fd = 0,
.map_name = unsafeHashConvert("hello"),
.fd = 0,
};
int fd = open("/dev/fstore", O_RDWR);
if(fd < 0) return -EBADF;
if (fd < 0)
return -EBADF;

int err = ioctl(fd, REGISTER_MAP, reg);
assert(err != 0);
assert(errno == EBADF);

reg.fd = ebpf_fd;
err = ioctl(fd, REGISTER_MAP, (unsigned long) &reg);
err = ioctl(fd, REGISTER_MAP, (unsigned long)&reg);
assert(err == 0);

err = ioctl(fd, UNREGISTER_MAP, (unsigned long)reg.map_name);
Expand Down

0 comments on commit 171ed00

Please sign in to comment.