Skip to content

Commit

Permalink
Reformat repository to our C formatting rules (final iteration)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkow committed Sep 15, 2020
1 parent 56b329d commit e2e7e8a
Show file tree
Hide file tree
Showing 284 changed files with 5,320 additions and 5,759 deletions.
6 changes: 3 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ AlignConsecutiveAssignments: true
AlignConsecutiveMacros: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
ColumnLimit: 100
ColumnLimit: 100
DerivePointerAlignment: false
IndentWidth: 4
IndentWidth: 4
ObjCBlockIndentWidth: 4
PointerAlignment: Left
TabWidth: 4
TabWidth: 4
18 changes: 16 additions & 2 deletions Documentation/devel/coding-style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Coding style guidelines
This document describes coding conventions and formatting styles we use in
Graphene. All newly commited code must conform to them to pass a |~| review.

.. note:: Old code is temporarily excluded from these rules until reformatted.

Automatic reformatting
----------------------

Expand All @@ -31,6 +29,13 @@ recommend you first commit them (or add to `git index
:command:`git diff` (or :command:`git diff --cached` if you used :command:`git
add`).

.. warning::

Because of bugs in clang-format and its questionable reformats in many places
(seems it deals with C++ much better than with C) it's intended only as a |~|
helper tool. Adding it to git pre-commit hooks is definitely a |~| bad idea,
at least currently.

C
-

Expand Down Expand Up @@ -101,6 +106,15 @@ Code formatting
external dependencies, like :file:`curl.h`).
#. Graphene's headers.

#. Assignments may be aligned when assigning some structurized data (e.g. struct
members). Example::

int some_int = 0;
bool asdf = true;
file->size = 123;
file->full_path = "/asdf/ghjkl";
file->perms = 0644;

Conventions and high-level style
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#. Variable and function names should be sane and easy to understand (example:
Expand Down
6 changes: 2 additions & 4 deletions LibOS/shim/include/arch/x86_64/shim_dl-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
/* Copyright (C) 2014 Stony Brook University */

/*
* dl-machine-x86_64.c
*
* This file contains x64-specific codes for relocating ELF binaries.
* Most of the source codes are imported from GNU C library.
* This file contains x64-specific code for relocating ELF binaries. Most of the source code was
* imported from GNU C library.
*/

#ifndef __DL_MACHINE_H__
Expand Down
36 changes: 18 additions & 18 deletions LibOS/shim/include/arch/x86_64/shim_tcb-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
#include "pal.h"

struct shim_regs {
uint64_t orig_rax;
uint64_t rsp;
uint64_t r15;
uint64_t r14;
uint64_t r13;
uint64_t r12;
uint64_t r11;
uint64_t r10;
uint64_t r9;
uint64_t r8;
uint64_t rcx;
uint64_t rdx;
uint64_t rsi;
uint64_t rdi;
uint64_t rbx;
uint64_t rbp;
uint64_t rflags;
uint64_t rip;
uint64_t orig_rax;
uint64_t rsp;
uint64_t r15;
uint64_t r14;
uint64_t r13;
uint64_t r12;
uint64_t r11;
uint64_t r10;
uint64_t r9;
uint64_t r8;
uint64_t rcx;
uint64_t rdx;
uint64_t rsi;
uint64_t rdi;
uint64_t rbx;
uint64_t rbp;
uint64_t rflags;
uint64_t rip;
};

static inline uint64_t shim_regs_get_sp(struct shim_regs* sr) {
Expand Down
6 changes: 3 additions & 3 deletions LibOS/shim/include/arch/x86_64/shim_types-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include "shim_tcb-arch.h"

/* asm/signal.h */
#define NUM_SIGS 64
#define SIGRTMIN 32
#define NUM_SIGS 64
#define SIGRTMIN 32

typedef struct {
unsigned long __val[NUM_SIGS / (8 * sizeof(unsigned long))];
} __sigset_t;

#define RED_ZONE_SIZE 128
#define RED_ZONE_SIZE 128

#endif /* _SHIM_TYPES_ARCH_H_ */
48 changes: 24 additions & 24 deletions LibOS/shim/include/arch/x86_64/shim_ucontext-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
#ifndef _SHIM_UCONTEXT_ARCH_H_
#define _SHIM_UCONTEXT_ARCH_H_

#include <shim_types.h>
#include <ucontext.h>
#include "shim_types.h"
#include "ucontext.h"

static inline void shim_regs_to_ucontext(ucontext_t* context, struct shim_regs* regs) {
context->uc_mcontext.gregs[REG_R8] = regs->r8;
context->uc_mcontext.gregs[REG_R9] = regs->r9;
context->uc_mcontext.gregs[REG_R10] = regs->r10;
context->uc_mcontext.gregs[REG_R11] = regs->r11;
context->uc_mcontext.gregs[REG_R12] = regs->r12;
context->uc_mcontext.gregs[REG_R13] = regs->r13;
context->uc_mcontext.gregs[REG_R14] = regs->r14;
context->uc_mcontext.gregs[REG_R15] = regs->r15;
context->uc_mcontext.gregs[REG_RDI] = regs->rdi;
context->uc_mcontext.gregs[REG_RSI] = regs->rsi;
context->uc_mcontext.gregs[REG_RBP] = regs->rbp;
context->uc_mcontext.gregs[REG_RBX] = regs->rbx;
context->uc_mcontext.gregs[REG_RDX] = regs->rdx;
context->uc_mcontext.gregs[REG_RAX] = regs->orig_rax;
context->uc_mcontext.gregs[REG_RCX] = regs->rcx;
context->uc_mcontext.gregs[REG_RSP] = regs->rsp;
context->uc_mcontext.gregs[REG_RIP] = regs->rip;
context->uc_mcontext.gregs[REG_EFL] = regs->rflags;
context->uc_mcontext.gregs[REG_CSGSFS] = 0;
context->uc_mcontext.gregs[REG_ERR] = 0;
context->uc_mcontext.gregs[REG_TRAPNO] = 0;
context->uc_mcontext.gregs[REG_R8] = regs->r8;
context->uc_mcontext.gregs[REG_R9] = regs->r9;
context->uc_mcontext.gregs[REG_R10] = regs->r10;
context->uc_mcontext.gregs[REG_R11] = regs->r11;
context->uc_mcontext.gregs[REG_R12] = regs->r12;
context->uc_mcontext.gregs[REG_R13] = regs->r13;
context->uc_mcontext.gregs[REG_R14] = regs->r14;
context->uc_mcontext.gregs[REG_R15] = regs->r15;
context->uc_mcontext.gregs[REG_RDI] = regs->rdi;
context->uc_mcontext.gregs[REG_RSI] = regs->rsi;
context->uc_mcontext.gregs[REG_RBP] = regs->rbp;
context->uc_mcontext.gregs[REG_RBX] = regs->rbx;
context->uc_mcontext.gregs[REG_RDX] = regs->rdx;
context->uc_mcontext.gregs[REG_RAX] = regs->orig_rax;
context->uc_mcontext.gregs[REG_RCX] = regs->rcx;
context->uc_mcontext.gregs[REG_RSP] = regs->rsp;
context->uc_mcontext.gregs[REG_RIP] = regs->rip;
context->uc_mcontext.gregs[REG_EFL] = regs->rflags;
context->uc_mcontext.gregs[REG_CSGSFS] = 0;
context->uc_mcontext.gregs[REG_ERR] = 0;
context->uc_mcontext.gregs[REG_TRAPNO] = 0;
context->uc_mcontext.gregs[REG_OLDMASK] = 0;
context->uc_mcontext.gregs[REG_CR2] = 0;
context->uc_mcontext.gregs[REG_CR2] = 0;
}

#endif /* _SHIM_UCONTEXT_ARCH_H_ */
5 changes: 2 additions & 3 deletions LibOS/shim/include/shim_checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <stdint.h>

#include "pal.h"

#include "shim_defs.h"
#include "shim_ipc.h"

Expand Down Expand Up @@ -58,7 +57,7 @@ struct shim_mem_entry {
struct shim_mem_entry* next;
void* addr;
size_t size;
int prot; /* combination of PAL_PROT_* flags */
int prot; /* combination of PAL_PROT_* flags */
};

struct shim_palhdl_entry {
Expand Down Expand Up @@ -278,7 +277,7 @@ struct shim_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create);

#define BEGIN_MIGRATION_DEF(name, ...) \
int migrate_cp_##name(struct shim_cp_store* store, ##__VA_ARGS__) { \
int ret = 0; \
int ret = 0; \
size_t base = store->base;

#define END_MIGRATION_DEF(name) \
Expand Down
2 changes: 1 addition & 1 deletion LibOS/shim/include/shim_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef _SHIM_CONTEXT_H_
#define _SHIM_CONTEXT_H_

#include <shim_tcb.h>
#include "shim_tcb.h"

void restore_context(struct shim_context* context);
void fixup_child_context(struct shim_regs* regs);
Expand Down
22 changes: 11 additions & 11 deletions LibOS/shim/include/shim_defs.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#ifndef _SHIM_DEFS_H_
#define _SHIM_DEFS_H_

#define DEFAULT_HEAP_MIN_SIZE (256 * 1024 * 1024) /* 256MB */
#define DEFAULT_MEM_MAX_NPAGES (1024 * 1024) /* 4GB */
#define DEFAULT_BRK_MAX_SIZE (256 * 1024) /* 256KB */
#define DEFAULT_SYS_STACK_SIZE (256 * 1024) /* 256KB */
#define DEFAULT_HEAP_MIN_SIZE (256 * 1024 * 1024) /* 256MB */
#define DEFAULT_MEM_MAX_NPAGES (1024 * 1024) /* 4GB */
#define DEFAULT_BRK_MAX_SIZE (256 * 1024) /* 256KB */
#define DEFAULT_SYS_STACK_SIZE (256 * 1024) /* 256KB */

#define CP_INIT_VMA_SIZE (64 * 1024 * 1024) /* 64MB */
#define CP_INIT_VMA_SIZE (64 * 1024 * 1024) /* 64MB */

/* debug message printout */
#define DEBUGBUF_SIZE 256
#define DEBUGBUF_BREAK 0
#define DEBUGBUF_SIZE 256
#define DEBUGBUF_BREAK 0

#define DEFAULT_VMA_COUNT 64
#define DEFAULT_VMA_COUNT 64

/* ELF aux vectors */
#define REQUIRED_ELF_AUXV 8 /* number of LibOS-supported vectors */
#define REQUIRED_ELF_AUXV_SPACE 16 /* extra memory space (in bytes) */
#define REQUIRED_ELF_AUXV 8 /* number of LibOS-supported vectors */
#define REQUIRED_ELF_AUXV_SPACE 16 /* extra memory space (in bytes) */

#if defined(__i386__) || defined(__x86_64__)
#define LIBOS_SYSCALL_BOUND (340 + 1)
#define LIBOS_SYSCALL_BOUND (340 + 1)
#endif

#endif /* _SHIM_DEFS_H_ */
2 changes: 1 addition & 1 deletion LibOS/shim/include/shim_flags_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#define SHIM_FLAGS_CONV_H

#include <asm/fcntl.h>
#include <linux/mman.h>
#include <linux/fcntl.h>
#include <linux/mman.h>

#include "assert.h"
#include "pal.h"
Expand Down
6 changes: 2 additions & 4 deletions LibOS/shim/include/shim_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#define _SHIM_FS_H_

#define __KERNEL__
#include <stdbool.h>
#include <linux/stat.h>
#include <stdbool.h>

#include "list.h"
#include "pal.h"
Expand Down Expand Up @@ -295,8 +295,6 @@ void put_mount(struct shim_mount* mount);

struct shim_mount* find_mount_from_uri(const char* uri);

#include <shim_utils.h>

static inline void set_handle_fs(struct shim_handle* hdl, struct shim_mount* fs) {
get_mount(fs);
hdl->fs = fs;
Expand Down Expand Up @@ -512,7 +510,7 @@ struct pseudo_ent {
const char* name;
const struct pseudo_name_ops* name_ops;
const struct pseudo_fs_ops* fs_ops;
const struct pseudo_dir* dir; /* NULL if pseudo-FS entry is a file */
const struct pseudo_dir* dir; /* NULL if pseudo-FS entry is a file */
int type; /* LINUX_DT_REG, LINUX_DT_CHR, etc (if dir != NULL, then always LINUX_DT_DIR) */
};

Expand Down
13 changes: 7 additions & 6 deletions LibOS/shim/include/shim_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@

#include <asm/fcntl.h>
#include <asm/resource.h>
#include <atomic.h> // TODO: migrate to stdatomic.h
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/shm.h>
#include <linux/un.h>
#include <list.h>
#include <pal.h>
#include <shim_defs.h>
#include <shim_sysv.h>
#include <shim_types.h>
#include <stdalign.h>

#include "atomic.h" // TODO: migrate to stdatomic.h
#include "list.h"
#include "pal.h"
#include "shim_defs.h"
#include "shim_sysv.h"
#include "shim_types.h"

/* start definition of shim handle */
enum shim_handle_type {
TYPE_FILE,
Expand Down
Loading

0 comments on commit e2e7e8a

Please sign in to comment.