Skip to content

Commit

Permalink
Add linux headers for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
hp77-creator committed Aug 25, 2024
1 parent 9d82754 commit a571be3
Show file tree
Hide file tree
Showing 29 changed files with 5,412 additions and 13 deletions.
18 changes: 12 additions & 6 deletions example/map-op/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
CXX = clang

CXXFLAGS = -I../../runtime/include \
-I../../vm/compat/include \
-I../../third_party/spdlog/include \
-I../../vm/vm-core/include
CFLAGS = -nostdinc \
-I../../third_party/macos \
-I../../runtime/include \
-I../../vm/compat/include \
-I../../third_party/spdlog/include \
-I../../vm/vm-core/include \
-D__KERNEL__ \
-D__BPF_TRACING__ \
-D__TARGET_ARCH_bpf \
-DCONFIG_64BIT

SRC = mapop.bpf.c
TGT = main

main: $(SRC)
$(CXX) $(SRC) -g --target=bpf -o $(TGT) $(CXXFLAGS)
$(CXX) -g $(CFLAGS) -target bpf -Wall -O2 -c $(SRC) -o $(TGT)

.PHONY: clean

clean:
rm -rf $(TGT)
9 changes: 2 additions & 7 deletions example/map-op/mapop.bpf.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#include <stdint.h>

#ifdef __linux__
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#elif defined(__APPLE__)
#include "bpftime_epoll.h"
#else
#error "Unsupported platform"
#endif
#include <linux/types.h>


struct bpf_map_def {
unsigned int type;
Expand Down
7 changes: 7 additions & 0 deletions third_party/macos/asm/byteorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <libkern/OSByteOrder.h>

#if defined(__LITTLE_ENDIAN__)
#define __LITTLE_ENDIAN_BITFIELD
#else
#define __BIG_ENDIAN_BITFIELD
#endif
3 changes: 3 additions & 0 deletions third_party/macos/asm/errno.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <errno.h>

#define EUCLEAN 117 /* Structure needs cleaning */
Empty file.
11 changes: 11 additions & 0 deletions third_party/macos/asm/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
typedef __signed__ char __s8;
typedef unsigned char __u8;

typedef __signed__ short __s16;
typedef unsigned short __u16;

typedef __signed__ int __s32;
typedef unsigned int __u32;

__extension__ typedef __signed__ long long __s64;
__extension__ typedef unsigned long long __u64;
2 changes: 2 additions & 0 deletions third_party/macos/asm/unistd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define __NR_perf_event_open -1
#define __NR_bpf -1
Empty file.
11 changes: 11 additions & 0 deletions third_party/macos/byteswap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#define bswap_16(value) \
((((value) & 0xff) << 8) | ((value) >> 8))

#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))

#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
Loading

0 comments on commit a571be3

Please sign in to comment.