Skip to content

Commit

Permalink
cleanup(majority of u64/s64 integer types)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecbadeaux committed Nov 1, 2023
1 parent 5927dbe commit 97bb407
Show file tree
Hide file tree
Showing 115 changed files with 292 additions and 292 deletions.
4 changes: 2 additions & 2 deletions driver/bpf/bpf_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static unsigned long long (*bpf_get_prandom_u32)(void) =
(void *)BPF_FUNC_get_prandom_u32;
static int (*bpf_xdp_adjust_head)(void *ctx, int offset) =
(void *)BPF_FUNC_xdp_adjust_head;
static int (*bpf_probe_read_str)(void *dst, u64 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_str)(void *dst, uint64_tt64_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read_str;

#if defined(USE_BPF_PROBE_KERNEL_USER_VARIANTS)
Expand All @@ -93,7 +93,7 @@ static int (*bpf_probe_read_kernel_str)(void *dst, u32 size, const void *unsafe_
(void *)BPF_FUNC_probe_read_str;
#endif

static u64 (*bpf_get_current_task)(void) =
static uint64_tt64_t (*bpf_get_current_task)(void) =
(void *)BPF_FUNC_get_current_task;
static int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) =
(void *)BPF_FUNC_skb_load_bytes;
Expand Down
2 changes: 1 addition & 1 deletion driver/bpf/maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct bpf_map_def __bpf_section("maps") ia32_64_map = {
#ifndef BPF_SUPPORTS_RAW_TRACEPOINTS
struct bpf_map_def __bpf_section("maps") stash_map = {
.type = BPF_MAP_TYPE_HASH,
.key_size = sizeof(u64),
.key_size = sizeof(uint64_t),
.value_size = sizeof(struct sys_stash_args),
.max_entries = 65535,
};
Expand Down
4 changes: 2 additions & 2 deletions driver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (cmd == PPM_IOCTL_GET_PROCLIST) {
struct ppm_proclist_info *proclist_info = NULL;
struct task_struct *p, *t;
u64 nentries = 0;
uint64_t nentries = 0;
struct ppm_proclist_info pli;
u32 memsize;

Expand Down Expand Up @@ -839,7 +839,7 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0))
cputime_t utime, stime;
#else
u64 utime, stime;
uint64_t utime, stime;
#endif

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
Expand Down
2 changes: 1 addition & 1 deletion driver/modern_bpf/definitions/struct_flavors.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct mm_struct___v6_2

typedef struct
{
u64 val;
uint64_t val;
} kernel_cap_t___v6_3;

/* COS kernels handle audit field differently, see [1]. To support both
Expand Down
32 changes: 16 additions & 16 deletions driver/modern_bpf/helpers/base/push_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,55 +135,55 @@ static __always_inline void push__param_len(u8 *data, u8 *lengths_pos, u16 len)
// PUSH FIXED DIMENSIONS
///////////////////////////

static __always_inline void push__u8(u8 *data, u64 *payload_pos, u8 param)
static __always_inline void push__u8(u8 *data, uint64_t *payload_pos, u8 param)
{
*((u8 *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(u8);
}

static __always_inline void push__u16(u8 *data, u64 *payload_pos, u16 param)
static __always_inline void push__u16(u8 *data, uint64_t *payload_pos, u16 param)
{
*((u16 *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(u16);
}

static __always_inline void push__u32(u8 *data, u64 *payload_pos, u32 param)
static __always_inline void push__u32(u8 *data, uint64_t *payload_pos, u32 param)
{
*((u32 *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(u32);
}

static __always_inline void push__u64(u8 *data, u64 *payload_pos, u64 param)
static __always_inline void push__u64(u8 *data, uint64_t *payload_pos, uint64_t param)
{
*((u64 *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(u64);
*((uint64_t *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(uint64_t);
}

static __always_inline void push__s16(u8 *data, u64 *payload_pos, s16 param)
static __always_inline void push__s16(u8 *data, uint64_t *payload_pos, s16 param)
{
*((s16 *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(s16);
}

static __always_inline void push__s32(u8 *data, u64 *payload_pos, s32 param)
static __always_inline void push__s32(u8 *data, uint64_t *payload_pos, s32 param)
{
*((s32 *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(s32);
}

static __always_inline void push__s64(u8 *data, u64 *payload_pos, s64 param)
static __always_inline void push__s64(u8 *data, uint64_t *payload_pos, int64_t param)
{
*((s64 *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(s64);
*((int64_t *)&data[SAFE_ACCESS(*payload_pos)]) = param;
*payload_pos += sizeof(int64_t);
}

static __always_inline void push__ipv6(u8 *data, u64 *payload_pos, u32 ipv6[4])
static __always_inline void push__ipv6(u8 *data, uint64_t *payload_pos, u32 ipv6[4])
{
__builtin_memcpy(&data[SAFE_ACCESS(*payload_pos)], ipv6, 16);
*payload_pos += 16;
}

static __always_inline void push__new_character(u8 *data, u64 *payload_pos, char character)
static __always_inline void push__new_character(u8 *data, uint64_t *payload_pos, char character)
{
*((char *)&data[SAFE_ACCESS(*payload_pos)]) = character;
*payload_pos += sizeof(char);
Expand All @@ -193,7 +193,7 @@ static __always_inline void push__new_character(u8 *data, u64 *payload_pos, char
* a previous character. Since we overwrite it we don't need to update
* `payload_pos`.
*/
static __always_inline void push__previous_character(u8 *data, u64 *payload_pos, char character)
static __always_inline void push__previous_character(u8 *data, uint64_t *payload_pos, char character)
{
*((char *)&data[SAFE_ACCESS(*payload_pos - 1)]) = character;
}
Expand All @@ -216,7 +216,7 @@ static __always_inline void push__previous_character(u8 *data, u64 *payload_pos,
* @param mem tell where it must read: user-space or kernel-space.
* @return (u16) the number of bytes written in the buffer. Could be '0' if the passed pointer is not valid.
*/
static __always_inline u16 push__charbuf(u8 *data, u64 *payload_pos, unsigned long charbuf_pointer, u16 limit, enum read_memory mem)
static __always_inline u16 push__charbuf(u8 *data, uint64_t *payload_pos, unsigned long charbuf_pointer, u16 limit, enum read_memory mem)
{
int written_bytes = 0;

Expand Down Expand Up @@ -258,7 +258,7 @@ static __always_inline u16 push__charbuf(u8 *data, u64 *payload_pos, unsigned lo
* @param mem from which memory we need to read: user-space or kernel-space.
* @return (u16) the number of bytes written in the buffer. Could be '0' if the passed pointer is not valid.
*/
static __always_inline u16 push__bytebuf(u8 *data, u64 *payload_pos, unsigned long bytebuf_pointer, u16 len_to_read, enum read_memory mem)
static __always_inline u16 push__bytebuf(u8 *data, uint64_t *payload_pos, unsigned long bytebuf_pointer, u16 len_to_read, enum read_memory mem)
{
if(mem == KERNEL)
{
Expand Down
24 changes: 12 additions & 12 deletions driver/modern_bpf/helpers/extract/extract_from_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static __always_inline struct file *extract__file_struct_from_fd(s32 file_descri
* @param fd generic file descriptor.
* @param ino pointer to the inode number we have to fill.
*/
static __always_inline void extract__ino_from_fd(s32 fd, u64 *ino)
static __always_inline void extract__ino_from_fd(s32 fd, uint64_t *ino)
{
struct file *f = extract__file_struct_from_fd(fd);
if(!f)
Expand Down Expand Up @@ -282,7 +282,7 @@ static __always_inline struct file *extract__exe_file_from_task(struct task_stru
* @param ino pointer to the inode number we have to fill.
* @return `i_ino` from f_inode.
*/
static __always_inline void extract__ino_from_inode(struct inode *f_inode, u64 *ino)
static __always_inline void extract__ino_from_inode(struct inode *f_inode, uint64_t *ino)
{
BPF_CORE_READ_INTO(ino, f_inode, i_ino);
}
Expand All @@ -293,7 +293,7 @@ static __always_inline void extract__ino_from_inode(struct inode *f_inode, u64 *
* @param time timespec64 struct.
* @return epoch in ns.
*/
static __always_inline u64 extract__epoch_ns_from_time(struct timespec64 time)
static __always_inline uint64_t extract__epoch_ns_from_time(struct timespec64 time)
{
time64_t tv_sec = time.tv_sec;
if (tv_sec < 0)
Expand All @@ -310,7 +310,7 @@ static __always_inline u64 extract__epoch_ns_from_time(struct timespec64 time)
* @param dev pointer to the device number we have to fill.
* @param ino pointer to the inode number we have to fill.
*/
static __always_inline void extract__dev_and_ino_from_fd(s32 fd, dev_t *dev, u64 *ino)
static __always_inline void extract__dev_and_ino_from_fd(s32 fd, dev_t *dev, uint64_t *ino)
{
struct file *f = extract__file_struct_from_fd(fd);
if(!f)
Expand Down Expand Up @@ -383,7 +383,7 @@ static __always_inline void extract__fdlimit(struct task_struct *task, unsigned
* @param capability_type type of capability to extract defined by us.
* @return PPM encoded capability value
*/
static __always_inline u64 extract__capability(struct task_struct *task, enum capability_type capability_type)
static __always_inline uint64_t extract__capability(struct task_struct *task, enum capability_type capability_type)
{
kernel_cap_t cap_struct;
unsigned long capability;
Expand All @@ -407,7 +407,7 @@ static __always_inline u64 extract__capability(struct task_struct *task, enum ca
break;
}

// Kernel 6.3 changed the kernel_cap_struct type from u32[2] to u64.
// Kernel 6.3 changed the kernel_cap_struct type from u32[2] to uint64_t.
// Luckily enough, it also changed field name from cap to val.
if(bpf_core_field_exists(((struct kernel_cap_struct *)0)->cap))
{
Expand Down Expand Up @@ -550,7 +550,7 @@ static __always_inline pid_t extract__task_xid_vnr(struct task_struct *task, enu
* @param type pid type.
* @return `start_time` of init task struct from pid namespace seen from current task pid namespace.
*/
static __always_inline u64 extract__task_pidns_start_time(struct task_struct *task, enum pid_type type, long in_childtid)
static __always_inline uint64_t extract__task_pidns_start_time(struct task_struct *task, enum pid_type type, long in_childtid)
{
// only perform lookup when clone/vfork/fork returns 0 (child process / childtid)
if (in_childtid == 0)
Expand Down Expand Up @@ -609,9 +609,9 @@ static __always_inline unsigned long extract__vm_size(struct mm_struct *mm)
*/
static __always_inline unsigned long extract__vm_rss(struct mm_struct *mm)
{
s64 file_pages = 0;
s64 anon_pages = 0;
s64 shmem_pages = 0;
int64_t file_pages = 0;
int64_t anon_pages = 0;
int64_t shmem_pages = 0;

/* In recent kernel versions (https://github.com/torvalds/linux/commit/f1a7941243c102a44e8847e3b94ff4ff3ec56f25)
* `struct mm_rss_stat` doesn't exist anymore.
Expand Down Expand Up @@ -640,7 +640,7 @@ static __always_inline unsigned long extract__vm_rss(struct mm_struct *mm)
*/
static __always_inline unsigned long extract__vm_swap(struct mm_struct *mm)
{
s64 swap_entries = 0;
int64_t swap_entries = 0;
if(bpf_core_type_exists(struct mm_rss_stat))
{
BPF_CORE_READ_INTO(&swap_entries, mm, rss_stat.count[MM_SWAPENTS].counter);
Expand Down Expand Up @@ -1079,7 +1079,7 @@ static __always_inline bool extract__exe_writable(struct task_struct *task, stru

kernel_cap_t cap_struct = {0};
READ_TASK_FIELD_INTO(&cap_struct, task, cred, cap_effective);
// Kernel 6.3 changed the kernel_cap_struct type from u32[2] to u64.
// Kernel 6.3 changed the kernel_cap_struct type from u32[2] to uint64_t.
// Luckily enough, it also changed field name from cap to val.
if(bpf_core_field_exists(((struct kernel_cap_struct *)0)->cap))
{
Expand Down
Loading

0 comments on commit 97bb407

Please sign in to comment.