Skip to content

Commit

Permalink
cleanup(integer consistencies): use only int_t types
Browse files Browse the repository at this point in the history
Signed-off-by: Everett Badeaux <[email protected]>
  • Loading branch information
ecbadeaux authored and poiana committed Nov 14, 2023
1 parent 99f764d commit 4dd9c8a
Show file tree
Hide file tree
Showing 145 changed files with 759 additions and 759 deletions.
16 changes: 8 additions & 8 deletions driver/bpf/bpf_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@ static int (*bpf_probe_read_str)(void *dst, uint64_t size, const void *unsafe_pt
(void *)BPF_FUNC_probe_read_str;

#if defined(USE_BPF_PROBE_KERNEL_USER_VARIANTS)
static int (*bpf_probe_read_user)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_user)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read_user;
static int (*bpf_probe_read_kernel)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_kernel)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read_kernel;
static int (*bpf_probe_read_user_str)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_user_str)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read_user_str;
static int (*bpf_probe_read_kernel_str)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_kernel_str)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read_kernel_str;
#else
static int (*bpf_probe_read_user)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_user)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read;
static int (*bpf_probe_read_kernel)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_kernel)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read;
static int (*bpf_probe_read_user_str)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_user_str)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read_str;
static int (*bpf_probe_read_kernel_str)(void *dst, u32 size, const void *unsafe_ptr) =
static int (*bpf_probe_read_kernel_str)(void *dst, uint32_t size, const void *unsafe_ptr) =
(void *)BPF_FUNC_probe_read_str;
#endif

Expand Down
28 changes: 14 additions & 14 deletions driver/bpf/maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,79 +23,79 @@ struct bpf_map_def {
#ifdef __KERNEL__
struct bpf_map_def __bpf_section("maps") perf_map = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(uint32_t),
.max_entries = 0,
};

struct bpf_map_def __bpf_section("maps") tail_map = {
.type = BPF_MAP_TYPE_PROG_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(uint32_t),
.max_entries = PPM_FILLER_MAX,
};

struct bpf_map_def __bpf_section("maps") syscall_table = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(struct syscall_evt_pair),
.max_entries = SYSCALL_TABLE_SIZE,
};

struct bpf_map_def __bpf_section("maps") event_info_table = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(struct ppm_event_info),
.max_entries = PPM_EVENT_MAX,
};

struct bpf_map_def __bpf_section("maps") fillers_table = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(struct ppm_event_entry),
.max_entries = PPM_EVENT_MAX,
};

struct bpf_map_def __bpf_section("maps") frame_scratch_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = SCRATCH_SIZE,
.max_entries = 0,
};

struct bpf_map_def __bpf_section("maps") tmp_scratch_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = SCRATCH_SIZE,
.max_entries = 0,
};

struct bpf_map_def __bpf_section("maps") settings_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(struct scap_bpf_settings),
.max_entries = 1,
};

struct bpf_map_def __bpf_section("maps") local_state_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(struct scap_bpf_per_cpu_state),
.max_entries = 0,
};

struct bpf_map_def __bpf_section("maps") interesting_syscalls_table = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(bool),
.max_entries = SYSCALL_TABLE_SIZE,
};

// The key is the 32-bit syscall code while the value is 64-bit one
struct bpf_map_def __bpf_section("maps") ia32_64_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u32),
.key_size = sizeof(uint32_t),
.value_size = sizeof(uint32_t),
.max_entries = SYSCALL_TABLE_SIZE,
};

Expand Down
4 changes: 2 additions & 2 deletions driver/bpf/plumbing_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static __always_inline long bpf_syscall_get_retval(void *ctx)
static __always_inline bool bpf_in_ia32_syscall()
{
struct task_struct *task = (struct task_struct *)bpf_get_current_task();
u32 status = 0;
uint32_t status = 0;

#ifdef CONFIG_X86_64

Expand Down Expand Up @@ -327,7 +327,7 @@ static __always_inline unsigned long bpf_syscall_get_socketcall_arg(void *ctx, i
args_pointer = bpf_syscall_get_argument_from_ctx(ctx, 1);
if (bpf_in_ia32_syscall())
{
bpf_probe_read_user(&arg, sizeof(u32), (void*)(args_pointer + (idx * sizeof(u32))));
bpf_probe_read_user(&arg, sizeof(uint32_t), (void*)(args_pointer + (idx * sizeof(uint32_t))));
}
else
{
Expand Down
60 changes: 30 additions & 30 deletions driver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct event_data_t {
*/
static int ppm_open(struct inode *inode, struct file *filp);
static int ppm_release(struct inode *inode, struct file *filp);
static int force_tp_set(struct ppm_consumer_t *consumer, u32 new_tp_set);
static int force_tp_set(struct ppm_consumer_t *consumer, uint32_t new_tp_set);
static long ppm_ioctl(struct file *f, unsigned int cmd, unsigned long arg);
static int ppm_mmap(struct file *filp, struct vm_area_struct *vma);
static int record_event_consumer(struct ppm_consumer_t *consumer,
Expand Down Expand Up @@ -217,8 +217,8 @@ static const struct file_operations g_ppm_fops = {

LIST_HEAD(g_consumer_list);
static DEFINE_MUTEX(g_consumer_mutex);
static u32 g_tracepoints_attached; // list of attached tracepoints; bitmask using ppm_tp.h enum
static u32 g_tracepoints_refs[KMOD_PROG_ATTACHED_MAX];
static uint32_t g_tracepoints_attached; // list of attached tracepoints; bitmask using ppm_tp.h enum
static uint32_t g_tracepoints_refs[KMOD_PROG_ATTACHED_MAX];
static unsigned long g_buffer_bytes_dim = DEFAULT_BUFFER_BYTES_DIM; // dimension of a single per-CPU buffer in bytes.
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20)
static struct tracepoint *tp_sys_enter;
Expand Down Expand Up @@ -307,7 +307,7 @@ static void compat_unregister_trace(void *func, const char *probename, struct tr
#endif
}

static void set_consumer_tracepoints(struct ppm_consumer_t *consumer, u32 tp_set)
static void set_consumer_tracepoints(struct ppm_consumer_t *consumer, uint32_t tp_set)
{
int i;
int bits_processed;
Expand Down Expand Up @@ -630,11 +630,11 @@ static int compat_set_tracepoint(void *func, const char *probename, struct trace
return ret;
}

static int force_tp_set(struct ppm_consumer_t *consumer, u32 new_tp_set)
static int force_tp_set(struct ppm_consumer_t *consumer, uint32_t new_tp_set)
{
u32 idx;
u32 new_val;
u32 curr_val;
uint32_t idx;
uint32_t new_val;
uint32_t curr_val;
int cpu;
int ret;

Expand Down Expand Up @@ -796,7 +796,7 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
struct task_struct *p, *t;
uint64_t nentries = 0;
struct ppm_proclist_info pli;
u32 memsize;
uint32_t memsize;

if (copy_from_user(&pli, (void *)arg, sizeof(pli))) {
ret = -EINVAL;
Expand Down Expand Up @@ -957,12 +957,12 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case PPM_IOCTL_ENABLE_DROPPING_MODE:
{
u32 new_sampling_ratio;
uint32_t new_sampling_ratio;

consumer->dropping_mode = 1;
vpr_info("PPM_IOCTL_ENABLE_DROPPING_MODE, consumer %p\n", consumer_id);

new_sampling_ratio = (u32)arg;
new_sampling_ratio = (uint32_t)arg;

if (new_sampling_ratio != 1 &&
new_sampling_ratio != 2 &&
Expand All @@ -987,10 +987,10 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case PPM_IOCTL_SET_SNAPLEN:
{
u32 new_snaplen;
uint32_t new_snaplen;

vpr_info("PPM_IOCTL_SET_SNAPLEN, consumer %p\n", consumer_id);
new_snaplen = (u32)arg;
new_snaplen = (uint32_t)arg;

if (new_snaplen > SNAPLEN_MAX) {
pr_err("invalid snaplen %u\n", new_snaplen);
Expand All @@ -1007,10 +1007,10 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case PPM_IOCTL_SET_FULLCAPTURE_PORT_RANGE:
{
u32 encoded_port_range;
uint32_t encoded_port_range;

vpr_info("PPM_IOCTL_SET_FULLCAPTURE_PORT_RANGE, consumer %p\n", consumer_id);
encoded_port_range = (u32)arg;
encoded_port_range = (uint32_t)arg;

consumer->fullcapture_port_range_start = encoded_port_range & 0xFFFF;
consumer->fullcapture_port_range_end = encoded_port_range >> 16;
Expand All @@ -1032,7 +1032,7 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case PPM_IOCTL_ENABLE_SYSCALL:
{
u32 syscall_to_set = (u32)arg - SYSCALL_TABLE_ID0;
uint32_t syscall_to_set = (uint32_t)arg - SYSCALL_TABLE_ID0;

vpr_info("PPM_IOCTL_ENABLE_SYSCALL (%u), consumer %p\n", syscall_to_set, consumer_id);

Expand All @@ -1049,7 +1049,7 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case PPM_IOCTL_DISABLE_SYSCALL:
{
u32 syscall_to_unset = (u32)arg - SYSCALL_TABLE_ID0;
uint32_t syscall_to_unset = (uint32_t)arg - SYSCALL_TABLE_ID0;

vpr_info("PPM_IOCTL_DISABLE_SYSCALL (%u), consumer %p\n", syscall_to_unset, consumer_id);

Expand Down Expand Up @@ -1136,28 +1136,28 @@ static long ppm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case PPM_IOCTL_ENABLE_TP:
{
u32 new_tp_set;
if ((u32)arg >= KMOD_PROG_ATTACHED_MAX) {
pr_err("invalid tp %u\n", (u32)arg);
uint32_t new_tp_set;
if ((uint32_t)arg >= KMOD_PROG_ATTACHED_MAX) {
pr_err("invalid tp %u\n", (uint32_t)arg);
ret = -EINVAL;
goto cleanup_ioctl;
}
new_tp_set = consumer->tracepoints_attached;
new_tp_set |= 1 << (u32)arg;
new_tp_set |= 1 << (uint32_t)arg;
set_consumer_tracepoints(consumer, new_tp_set);
ret = 0;
goto cleanup_ioctl;
}
case PPM_IOCTL_DISABLE_TP:
{
u32 new_tp_set;
if ((u32)arg >= KMOD_PROG_ATTACHED_MAX) {
pr_err("invalid tp %u\n", (u32)arg);
uint32_t new_tp_set;
if ((uint32_t)arg >= KMOD_PROG_ATTACHED_MAX) {
pr_err("invalid tp %u\n", (uint32_t)arg);
ret = -EINVAL;
goto cleanup_ioctl;
}
new_tp_set = consumer->tracepoints_attached;
new_tp_set &= ~(1 << (u32)arg);
new_tp_set &= ~(1 << (uint32_t)arg);
set_consumer_tracepoints(consumer, new_tp_set);
ret = 0;
goto cleanup_ioctl;
Expand Down Expand Up @@ -1761,12 +1761,12 @@ static int record_event_consumer(struct ppm_consumer_t *consumer,
int res = 0;
size_t event_size = 0;
int next;
u32 freespace;
u32 usedspace;
u32 delta_from_end;
uint32_t freespace;
uint32_t usedspace;
uint32_t delta_from_end;
struct event_filler_arguments args = {};
u32 ttail;
u32 head;
uint32_t ttail;
uint32_t head;
struct ppm_ring_buffer_context *ring;
struct ppm_ring_buffer_info *ring_info;
int drop = 1;
Expand Down
16 changes: 8 additions & 8 deletions driver/modern_bpf/helpers/base/maps_getters.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ static __always_inline void maps__set_is_dropping(bool value)

/*=============================== SAMPLING TABLES ===========================*/

static __always_inline uint8_t maps__64bit_sampling_syscall_table(u32 syscall_id)
static __always_inline uint8_t maps__64bit_sampling_syscall_table(uint32_t syscall_id)
{
return g_64bit_sampling_syscall_table[syscall_id & (SYSCALL_TABLE_SIZE - 1)];
}

static __always_inline uint8_t maps__64bit_sampling_tracepoint_table(u32 event_id)
static __always_inline uint8_t maps__64bit_sampling_tracepoint_table(uint32_t event_id)
{
return g_64bit_sampling_tracepoint_table[event_id < PPM_EVENT_MAX ? event_id : PPM_EVENT_MAX-1];
}
Expand All @@ -94,7 +94,7 @@ static __always_inline uint8_t maps__64bit_sampling_tracepoint_table(u32 event_i

/*=============================== SYSCALL-64 INTERESTING TABLE ===========================*/

static __always_inline bool maps__64bit_interesting_syscall(u32 syscall_id)
static __always_inline bool maps__64bit_interesting_syscall(uint32_t syscall_id)
{
return g_64bit_interesting_syscalls_table[syscall_id & (SYSCALL_TABLE_SIZE - 1)];
}
Expand All @@ -103,7 +103,7 @@ static __always_inline bool maps__64bit_interesting_syscall(u32 syscall_id)

/*=============================== IA32 to 64 TABLE ===========================*/

static __always_inline u32 maps__ia32_to_64(u32 syscall_id)
static __always_inline uint32_t maps__ia32_to_64(uint32_t syscall_id)
{
return g_ia32_to_64_table[syscall_id & (SYSCALL_TABLE_SIZE - 1)];
}
Expand All @@ -112,7 +112,7 @@ static __always_inline u32 maps__ia32_to_64(u32 syscall_id)

/*=============================== EVENT NUM PARAMS TABLE ===========================*/

static __always_inline u8 maps__get_event_num_params(u32 event_id)
static __always_inline uint8_t maps__get_event_num_params(uint32_t event_id)
{
if(event_id < 0 || event_id >= PPM_EVENT_MAX)
{
Expand All @@ -136,7 +136,7 @@ static __always_inline uint16_t maps__get_ppm_sc(uint16_t syscall_id)

static __always_inline struct auxiliary_map *maps__get_auxiliary_map()
{
u32 cpu_id = (u32)bpf_get_smp_processor_id();
uint32_t cpu_id = (uint32_t)bpf_get_smp_processor_id();
return (struct auxiliary_map *)bpf_map_lookup_elem(&auxiliary_maps, &cpu_id);
}

Expand All @@ -146,7 +146,7 @@ static __always_inline struct auxiliary_map *maps__get_auxiliary_map()

static __always_inline struct counter_map *maps__get_counter_map()
{
u32 cpu_id = (u32)bpf_get_smp_processor_id();
uint32_t cpu_id = (uint32_t)bpf_get_smp_processor_id();
return (struct counter_map *)bpf_map_lookup_elem(&counter_maps, &cpu_id);
}

Expand All @@ -156,7 +156,7 @@ static __always_inline struct counter_map *maps__get_counter_map()

static __always_inline struct ringbuf_map *maps__get_ringbuf_map()
{
u32 cpu_id = (u32)bpf_get_smp_processor_id();
uint32_t cpu_id = (uint32_t)bpf_get_smp_processor_id();
return (struct ringbuf_map *)bpf_map_lookup_elem(&ringbuf_maps, &cpu_id);
}

Expand Down
Loading

0 comments on commit 4dd9c8a

Please sign in to comment.