Skip to content

Commit dcd1af3

Browse files
committed
style: fix code formatting
1 parent 0379621 commit dcd1af3

File tree

6 files changed

+17
-27
lines changed

6 files changed

+17
-27
lines changed

cpu_stealer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef struct {
2929
* @param priority: The priority to set for the current process.
3030
* @return 0 on success, -1 on failure.
3131
*/
32-
static int set_priority(const int priority){
32+
static int set_priority(const int priority) {
3333
const struct sched_param sparam = {
3434
.sched_priority = priority
3535
};

dump.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ static int dump_region(const uintptr_t region_start, const uintptr_t region_end,
3030
unsigned char *read_data = NULL;
3131

3232
chunk_start = region_start;
33-
while (chunk_start <= region_end)
34-
{
33+
while (chunk_start <= region_end) {
3534
/* Read memory region in chunks of maximum granule bytes */
3635
chunk_end = (region_end - chunk_start + 1 > granule) ? chunk_start + granule - 1 : region_end;
3736
chunk_size = chunk_end - chunk_start + 1;

lemon.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ static int check_kernel_version() {
119119
return (major > MIN_MAJOR_LINUX) || ((major == MIN_MAJOR_LINUX) && (minor >= MIN_MINOR_LINUX));
120120
}
121121

122-
int main(int argc, char **argv)
123-
{
122+
int main(int argc, char **argv) {
124123
struct ram_regions ram_regions;
125124
struct options opts = {0};
126125
struct argp argp = {options, parse_opt, "", doc};

lemon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <stdbool.h>
55
#include <errno.h>
66

7-
#define MIN_MAJOR_LINUX 5 /* Minimium kernel version supported */
7+
#define MIN_MAJOR_LINUX 5 /* Minimium kernel version supported */
88
#define MIN_MINOR_LINUX 5
99

1010
#define HUGE_PAGE_SIZE 2 * 1024 * 1024 /* Same for huge pages */

mem.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ int load_ebpf_mem_progs() {
200200
mem_ebpf_skel = mem_ebpf__open();
201201
if(!mem_ebpf_skel) {
202202
perror("Failed to open BPF skeleton");
203-
return errno;
203+
return -errno;
204204
}
205205

206206
/* ARM64 phys to virt translation requires two values, one of the two (CONFIG_ARM64_VA_BITS)
@@ -219,7 +219,7 @@ int load_ebpf_mem_progs() {
219219
/* Load the BPF objectes */
220220
if (mem_ebpf__load(mem_ebpf_skel)) {
221221
perror("Failed to load BPF object");
222-
return errno;
222+
return -errno;
223223
}
224224

225225
/* Attach the uprobe to the 'read_kernel_memory' function in the current executable */
@@ -288,7 +288,6 @@ void cleanup_mem_ebpf() {
288288
* Performs architecture-specific translation using kernel direct mapping.
289289
* Currently supports x86_64 and ARM64 only.
290290
*/
291-
292291
uintptr_t phys_to_virt(const uintptr_t phy_addr) {
293292
#ifdef __TARGET_ARCH_x86
294293
return phy_addr + v2p_offset;
@@ -388,12 +387,11 @@ int __attribute__((noinline, optnone)) read_kernel_memory(const uintptr_t addr,
388387
* Scans the line for the symbol name and extracts its address using sscanf.
389388
* Returns 1 on success, 0 on not looked for element or a negative error code from read_kernel_memory().
390389
*/
391-
392390
static int inline parse_kallsyms_line(const char *restrict line, const char *restrict symbol, uintptr_t *restrict current_symb_addr) {
393391
char current_symb_name[256];
394392

395393
/* Read the address and check if the it is the symbol that we look for */
396-
if ((sscanf(line, "%lx %*c %255s\n",current_symb_addr, current_symb_name) != 2) || strncmp(current_symb_name, symbol, strlen(symbol)))
394+
if ((sscanf(line, "%lx %*c %255s\n", current_symb_addr, current_symb_name) != 2) || strncmp(current_symb_name, symbol, strlen(symbol)))
397395
return 0;
398396

399397
/* Check that address is not 0 */
@@ -405,10 +403,10 @@ static int inline parse_kallsyms_line(const char *restrict line, const char *res
405403
*
406404
* Opens /proc/kallsyms, searches for the appropriate symbol (e.g., "page_offset_base" or
407405
* "memstart_addr" and "iomem_resource") based on architecture, and retrieves the physical-to-virtual address
408-
* translation offset and the pointer to the tree of physical memory regions. Returns 0 on success, or an error code on failure.
406+
* translation offset and the pointer to the tree of physical memory regions.
407+
* Returns 0 on success, or an error code on failure.
409408
*/
410-
static int parse_kallsyms()
411-
{
409+
static int parse_kallsyms() {
412410
FILE *fp;
413411
char line[256];
414412
__u8 *data = NULL;
@@ -488,11 +486,10 @@ static int parse_kallsyms()
488486
*
489487
* Opens /proc/iomem, searches for "System RAM" regions, and populates the provided
490488
* ram_regions struct with the start and end addresses of each region. The function
491-
* reallocates memory as needed to accommodate additional regions. Returns 0 on success,
492-
* or an error code on failure.
489+
* reallocates memory as needed to accommodate additional regions.
490+
* Returns 0 on success, or an error code on failure.
493491
*/
494-
static int get_iomem_regions_user(struct ram_regions *restrict ram_regions)
495-
{
492+
static int get_iomem_regions_user(struct ram_regions *restrict ram_regions) {
496493
FILE *fp;
497494
char line[256];
498495
int slot_availables;
@@ -565,11 +562,10 @@ static int get_iomem_regions_user(struct ram_regions *restrict ram_regions)
565562
*
566563
* Read struct resources from kernel, and populates the provided
567564
* ram_regions struct with the start and end addresses of each region. The function
568-
* reallocates memory as needed to accommodate additional regions. Returns 0 on success,
569-
* or an error code on failure.
565+
* reallocates memory as needed to accommodate additional regions.
566+
* Returns 0 on success, or an error code on failure.
570567
*/
571-
static int get_iomem_regions_kernel(struct ram_regions *restrict ram_regions)
572-
{
568+
static int get_iomem_regions_kernel(struct ram_regions *restrict ram_regions) {
573569
int slot_availables;
574570
__u8 *data = NULL;
575571
struct resource *res, *next_res;
@@ -590,7 +586,7 @@ static int get_iomem_regions_kernel(struct ram_regions *restrict ram_regions)
590586
* Is it possible to have "System RAM" regions inside non System RAM regions? I don't think so.
591587
*/
592588

593-
/* Obrain the address child of the root struct */
589+
/* Obtain the address child of the root struct */
594590
if((err = read_kernel_memory(iomem_resource, sizeof(struct resource), &data))) {
595591
fprintf(stderr, "Error reading root struct resource");
596592
return err;

net.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct net_args {
2020
*
2121
* Returns 0 on success.
2222
*/
23-
2423
int write_on_socket(void *restrict args, const void *restrict data, const unsigned long size) {
2524
unsigned long r;
2625
unsigned long total;
@@ -48,7 +47,6 @@ int write_on_socket(void *restrict args, const void *restrict data, const unsign
4847
*
4948
* On success, it returns 0. On failure, a negative value or errno is returned.
5049
*/
51-
5250
int dump_on_net(const struct options *restrict opts, const struct ram_regions *restrict ram_regions) {
5351
int sockfd;
5452
struct sockaddr_in dest_addr;
@@ -86,5 +84,3 @@ int dump_on_net(const struct options *restrict opts, const struct ram_regions *r
8684

8785
return ret;
8886
}
89-
90-

0 commit comments

Comments
 (0)