Integrate cargo fmt into make format

This commit is contained in:
Hui, Chunyang 2020-09-17 07:16:46 +00:00 committed by Tate, Hongliang Tian
parent 8fbd6295bf
commit e82b3dab92
12 changed files with 88 additions and 58 deletions

@ -1,7 +1,13 @@
#!/bin/bash
if ! hash astyle; then
echo "You do not have astyle installed so your code style is not being checked!"
echo "Warning: \`astyle\` is not available."
exit 1
fi
cargo fmt --version >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo "Warning: \`cargo fmt\` is not available."
exit 1
fi
@ -15,23 +21,3 @@ if [ -n "$info" ]; then
echo
exit 1
fi
cd src/libos
output=$(cargo fmt -- --check 2>&1)
retval=$?
if [[ $retval -eq 0 ]]
then
exit 0
elif [[ $retval -eq 1 ]]
then
echo "Rust format suggestsions (generated by \`cd src/libos && cargo fmt -- --check\`):"
echo
echo "$output"
echo
echo "To get rid of the format warnings above, run \`cargo fmt\` before the next commit."
exit 1
else
echo "Warning: \`cargo fmt\` is not available."
exit 1
fi

@ -24,31 +24,21 @@ if ! hash astyle; then
exit 0
fi
cargo fmt --version >/dev/null 2>&1
if [[ $? != 0 ]]; then
echo "Warning: \`cargo fmt\` is not available."
exit 0
fi
info=$(make format-check)
if [ -n "$info" ]; then
echo "Format Error detected:"
echo
echo "$info"
echo
echo "Please run \`make format\` before next commit."
echo "To get rid of the format warnings above, please run \`make format\` before next commit."
echo
exit 1
fi
cd src/libos
output=$(cargo fmt -- --check 2>&1)
retval=$?
# cargo fmt finds any format issues
if [[ $retval -eq 1 ]]
then
echo "Rust format suggestsions (generated by \`cd src/libos && cargo fmt -- --check\`):"
echo
echo "$output"
echo
echo "To get rid of the format warnings above, run \`cargo fmt\` before the next commit."
exit 1
fi
# If cargo fmt finds no format issues or carg fmt is not available on the # platform
exit 0

@ -7,12 +7,16 @@ all:
@$(MAKE) --no-print-directory -C exec
format:
@$(MAKE) --no-print-directory -C libos format
@$(MAKE) --no-print-directory -C pal format
@$(MAKE) --no-print-directory -C run format
@$(MAKE) --no-print-directory -C exec format
format-check:
@$(MAKE) --no-print-directory -C libos format-check
@$(MAKE) --no-print-directory -C pal format-check
@$(MAKE) --no-print-directory -C run format-check
@$(MAKE) --no-print-directory -C exec format-check
clean:
@$(MAKE) --no-print-directory -C libos clean

@ -17,6 +17,12 @@ else
@echo "CARGO (debug) => exec"
endif
format: $(SRC_FILES)
@$(call format-rust)
format-check: $(SRC_FILES)
@$(call format-check-rust)
clean:
@cargo clean --target-dir=$(RUST_TARGET_DIR)
@-$(RM) -f $(EXEC_TARGET)

@ -27,8 +27,8 @@ use signal_hook::iterator::Signals;
use signal_hook::{SIGINT, SIGKILL, SIGQUIT, SIGTERM, SIGUSR1};
use std::cmp;
use std::env;
use std::path::Path;
use std::os::unix::net::UnixListener;
use std::path::Path;
use std::process;
use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex};
@ -309,7 +309,11 @@ fn main() -> Result<(), i32> {
let cmd = cmd_args[0];
// Change cmd_args[0] from path name to program name
cmd_args[0] = Path::new(cmd_args[0]).file_name().unwrap().to_str().unwrap();
cmd_args[0] = Path::new(cmd_args[0])
.file_name()
.unwrap()
.to_str()
.unwrap();
let env: Vec<&str> = env.iter().map(|string| string.as_str()).collect();
// Create the signal handler

@ -120,7 +120,7 @@ extern "C" {
pub struct occlum_pal_attr_t {
/// Occlum instance directory.
///
/// Specifies the path of an Occlum instance directory, which is usually created with the
/// Specifies the path of an Occlum instance directory, which is usually created with the
/// `occlum new` command. The default value is "."; that is, the current working directory
/// is the Occlum instance directory.
pub instance_dir: *const libc::c_char,

@ -214,7 +214,8 @@ impl OcclumExec for OcclumExecImpl {
"process:{} finished, send signal to {}",
process_id, client_process_id
);
signal::kill(Pid::from_raw(client_process_id as i32), Signal::SIGUSR1).unwrap_or_default();
signal::kill(Pid::from_raw(client_process_id as i32), Signal::SIGUSR1)
.unwrap_or_default();
});
resp.finish(ExecCommResponse {

@ -88,7 +88,7 @@ _Other_Link_Flags := -L$(RUST_SGX_SDK_DIR)/compiler-rt/ -L$(BUILD_DIR)/lib -L$(R
_Other_Enclave_Libs := -l$(LIBOS_CORE_LIB_NAME) -lsgx_tprotected_fs
LINK_FLAGS := $(SGX_LFLAGS_T)
.PHONY: all clean
.PHONY: all clean format format-c format-rust format-check format-check-c format-check-rust
all: $(ALL_BUILD_SUBDIRS) $(LIBOS_SO_REAL)
@ -136,6 +136,22 @@ $(S_OBJS):$(OBJ_DIR)/libos/$(SRC_OBJ)/%.o: src/%.S
@$(CC) $(C_FLAGS) -c $< -o $@
@echo "AS <= $@"
format: format-c format-rust
format-c: $(C_SRCS) $(CXX_SRCS)
@$(C_FORMATTER) $^
format-rust: $(RUST_SRCS)
@$(call format-rust)
format-check: format-check-c format-check-rust
format-check-c: $(C_SRCS) $(CXX_SRCS)
@$(C_FORMATTER) --check $^
format-check-rust: $(RUST_SRCS)
@$(call format-check-rust)
clean:
@-$(RM) -rf $(OBJ_DIR)/libos
@-$(RM) -f $(LIBOS_SO_REAL)

@ -16,6 +16,6 @@
*/
void __attribute__((optimize("O0"))) occlum_gdb_hook_load_elf(
uint64_t elf_base,
const char* elf_path,
const char *elf_path,
uint64_t elf_path_len) {
}

@ -2,8 +2,7 @@
#include "task.h"
/* See /<path-to-linux-sgx>/common/inc/internal/thread_data.h */
typedef struct _thread_data_t
{
typedef struct _thread_data_t {
uint64_t reserved1[2];
uint64_t stack_base_addr;
uint64_t stack_limit_addr;
@ -14,7 +13,7 @@ typedef struct _thread_data_t
extern thread_data_t *get_thread_data(void);
extern void __exec_task(struct Task* task);
extern void __exec_task(struct Task *task);
extern uint64_t __get_stack_guard(void);
extern void __set_stack_guard(uint64_t new_val);
@ -25,7 +24,7 @@ void sgx_disable_user_stack(void);
#define OCCLUM_PAGE_SIZE 4096
static uint64_t get_syscall_stack(struct Task* this_task) {
static uint64_t get_syscall_stack(struct Task *this_task) {
#define LARGE_ENOUGH_GAP (8192)
char libos_stack_var = 0;
uint64_t libos_stack = ((uint64_t) &libos_stack_var) - LARGE_ENOUGH_GAP;
@ -40,9 +39,9 @@ static uint64_t get_syscall_stack(struct Task* this_task) {
#define RESET_CURRENT_TASK() \
__set_stack_guard(stack_guard);
int do_exec_task(struct Task* task) {
int do_exec_task(struct Task *task) {
jmp_buf libos_state = {0};
thread_data_t* td = get_thread_data();
thread_data_t *td = get_thread_data();
task->saved_state = &libos_state;
task->kernel_rsp = get_syscall_stack(task);
task->kernel_stack_base = td->stack_base_addr;
@ -50,8 +49,8 @@ int do_exec_task(struct Task* task) {
//Reserve two pages stack for exception handler
//The SGX SDK exception handler depends on the two pages as stack to handle exceptions in user's code
//TODO:Add a check in the sysreturn logic to confirm the stack is not corrupted
assert(task->kernel_stack_limit+OCCLUM_PAGE_SIZE*2 <= task->kernel_rsp);
//TODO:Add a check in the sysreturn logic to confirm the stack is not corrupted
assert(task->kernel_stack_limit + OCCLUM_PAGE_SIZE * 2 <= task->kernel_rsp);
SET_CURRENT_TASK(task);
@ -66,7 +65,7 @@ int do_exec_task(struct Task* task) {
}
void do_exit_task(void) {
struct Task* task = __get_current_task();
jmp_buf* jb = task->saved_state;
struct Task *task = __get_current_task();
jmp_buf *jb = task->saved_state;
longjmp(*jb, 1);
}

@ -45,15 +45,15 @@ typedef struct {
* rfbm is the requested-feature bitmap, whose bits specifies which state
* components are to restored by this instruction.
*/
static void xrstor(xsave_area_t* xsave_area, uint64_t rfbm) {
static void xrstor(xsave_area_t *xsave_area, uint64_t rfbm) {
#define REX_PREFIX "0x48, "
#define XRSTOR64 REX_PREFIX "0x0f,0xae,0x2f "
__asm__ __volatile__ (
".byte " XRSTOR64 "\n\t"
:
: "D" (xsave_area), "m" (*xsave_area), "a" (rfbm), "d" (rfbm)
: "memory");
:
: "D" (xsave_area), "m" (*xsave_area), "a" (rfbm), "d" (rfbm)
: "memory");
}
/* The state component bitmaps for MPX

@ -13,6 +13,15 @@ PATCH_VER_NUM = $(shell grep '\#define OCCLUM_PATCH_VERSION' $(PROJECT_DIR)/src/
VERSION_NUM = $(MAJOR_VER_NUM).$(MINOR_VER_NUM).$(PATCH_VER_NUM)
C_FORMATTER := $(PROJECT_DIR)/tools/c_formatter
# Use echo program instead of built-in echo command in shell. This ensures
# that echo can recognize escaped sequences (with -e argument) regardless of
# the specific shell (e.g., bash, zash, etc.)
ECHO := /bin/echo -e
# Shell escaped sequences for colorful output
CYAN := \033[1;36m
GREEN := \033[1;32m
RED := \033[1;31m
NO_COLOR := \033[0m
# Save code and object file generated during building src
OBJ_DIR := $(PROJECT_DIR)/build/internal/src
@ -127,3 +136,18 @@ SGX_LFLAGS_T = $(SGX_COMMON_CFLAGS) -nostdlib -L$(SGX_LIBRARY_PATH) $(_Other_Lin
-Wl,--defsym,__ImageBase=0 \
-Wl,--gc-sections \
-Wl,--version-script=Enclave.lds
define format-rust
output=$$(cargo fmt -- --check 2>&1); retval=$$?; \
if [[ $$retval -eq 1 ]]; then \
$(ECHO) "$$output"; cargo fmt; $(ECHO) "$(GREEN)\nRust code format corrected.$(NO_COLOR)"; \
fi
endef
define format-check-rust
output=$$(cargo fmt -- --check 2>&1); retval=$$?; \
if [[ $$retval -eq 1 ]]; then \
$(ECHO) "$(RED)\nSome format issues of Rust code are detected:$(NO_COLOR)"; $(ECHO) "\n$$output"; \
$(ECHO) "\nTo get rid of the format warnings above, run $(CYAN)"make format"$(NO_COLOR) to correct"; \
fi
endef