diff --git a/LibOS/shim/include/shim_checkpoint.h b/LibOS/shim/include/shim_checkpoint.h index 81687a0086..06efe2debf 100644 --- a/LibOS/shim/include/shim_checkpoint.h +++ b/LibOS/shim/include/shim_checkpoint.h @@ -296,7 +296,7 @@ struct shim_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create); #if DEBUG_RESUME == 1 #define DEBUG_RS(fmt, ...) \ - log_debug("GET %s(0x%08lx): " fmt "\n", CP_FUNC_NAME, entry->cp_val, ##__VA_ARGS__) + log_debug("GET %s(0x%08lx): " fmt, CP_FUNC_NAME, entry->cp_val, ##__VA_ARGS__) #else #define DEBUG_RS(...) do {} while (0) #endif @@ -313,7 +313,7 @@ struct shim_cp_map_entry* get_cp_map_entry(void* map, void* addr, bool create); if (ret < 0) \ goto out; \ \ - log_debug("complete checkpointing data\n"); \ + log_debug("complete checkpointing data"); \ out: \ destroy_cp_map((store)->cp_map); \ } while (0); \ diff --git a/LibOS/shim/include/shim_internal.h b/LibOS/shim/include/shim_internal.h index b2f9a1c079..89e2d62a5c 100644 --- a/LibOS/shim/include/shim_internal.h +++ b/LibOS/shim/include/shim_internal.h @@ -39,14 +39,14 @@ void shim_log(int level, const char* fmt, ...) __attribute__((format(printf, 2, #define BUG() \ do { \ - log_error("BUG() " __FILE__ ":%d\n", __LINE__); \ + log_error("BUG() " __FILE__ ":%d", __LINE__); \ DEBUG_BREAK_ON_FAILURE(); \ die_or_inf_loop(); \ } while (0) #define DEBUG_HERE() \ do { \ - log_debug("%s (" __FILE__ ":%d)\n", __func__, __LINE__); \ + log_debug("%s (" __FILE__ ":%d)", __func__, __LINE__); \ } while (0) /*! @@ -301,7 +301,7 @@ static inline int64_t __ref_dec(REFTYPE* ref) { do { _c = __atomic_load_n(&ref->counter, __ATOMIC_SEQ_CST); if (!_c) { - log_error("Fail: Trying to drop reference count below 0\n"); + log_error("Fail: Trying to drop reference count below 0"); BUG(); return 0; } diff --git a/LibOS/shim/include/shim_lock.h b/LibOS/shim/include/shim_lock.h index 5c412884ff..f94e296b28 100644 --- a/LibOS/shim/include/shim_lock.h +++ b/LibOS/shim/include/shim_lock.h @@ -81,11 +81,11 @@ extern struct shim_lock __master_lock; #define MASTER_LOCK() \ do { \ lock(&__master_lock); \ - log_debug("master lock " __FILE__ ":%d\n", __LINE__); \ + log_debug("master lock " __FILE__ ":%d", __LINE__); \ } while (0) #define MASTER_UNLOCK() \ do { \ - log_debug("master unlock " __FILE__ ":%d\n", __LINE__); \ + log_debug("master unlock " __FILE__ ":%d", __LINE__); \ unlock(&__master_lock); \ } while (0) #else diff --git a/LibOS/shim/include/shim_sync.h b/LibOS/shim/include/shim_sync.h index bc195ca452..15ffe79032 100644 --- a/LibOS/shim/include/shim_sync.h +++ b/LibOS/shim/include/shim_sync.h @@ -147,7 +147,7 @@ #define uthash_fatal(msg) \ do { \ - log_error("uthash error: %s\n", msg); \ + log_error("uthash error: %s", msg); \ DkProcessExit(PAL_ERROR_NOMEM); \ } while (0) #include "uthash.h" diff --git a/LibOS/shim/src/arch/x86_64/shim_arch_prctl.c b/LibOS/shim/src/arch/x86_64/shim_arch_prctl.c index 97a72007e9..12f5c45398 100644 --- a/LibOS/shim/src/arch/x86_64/shim_arch_prctl.c +++ b/LibOS/shim/src/arch/x86_64/shim_arch_prctl.c @@ -22,7 +22,7 @@ long shim_do_arch_prctl(int code, void* addr) { return pal_to_unix_errno(DkSegmentRegisterGet(PAL_SEGMENT_FS, addr)); default: - log_warning("Not supported flag (0x%x) passed to arch_prctl\n", code); + log_warning("Not supported flag (0x%x) passed to arch_prctl", code); return -ENOSYS; } } diff --git a/LibOS/shim/src/arch/x86_64/shim_context.c b/LibOS/shim/src/arch/x86_64/shim_context.c index f0e03043b2..426605c4ac 100644 --- a/LibOS/shim/src/arch/x86_64/shim_context.c +++ b/LibOS/shim/src/arch/x86_64/shim_context.c @@ -68,7 +68,7 @@ void shim_xstate_init(void) { g_shim_xsave_size = xsavesize; out: - log_debug("LibOS xsave_enabled %d, xsave_size 0x%x(%u), xsave_features 0x%lx\n", + log_debug("LibOS xsave_enabled %d, xsave_size 0x%x(%u), xsave_features 0x%lx", g_shim_xsave_enabled, g_shim_xsave_size, g_shim_xsave_size, g_shim_xsave_features); } @@ -274,7 +274,7 @@ void prepare_sigframe(PAL_CONTEXT* context, siginfo_t* siginfo, void* handler, v * register arguments in `rax`. */ context->rax = 0; - log_debug("Created sigframe for sig: %d at %p (handler: %p, restorer: %p)\n", + log_debug("Created sigframe for sig: %d at %p (handler: %p, restorer: %p)", siginfo->si_signo, sigframe, handler, restorer); } diff --git a/LibOS/shim/src/bookkeep/shim_handle.c b/LibOS/shim/src/bookkeep/shim_handle.c index f72b438021..13ea910f71 100644 --- a/LibOS/shim/src/bookkeep/shim_handle.c +++ b/LibOS/shim/src/bookkeep/shim_handle.c @@ -102,12 +102,12 @@ static int init_exec_handle(void) { assert(g_manifest_root); ret = toml_string_in(g_manifest_root, "libos.entrypoint", &entrypoint); if (ret < 0) { - log_error("Cannot parse 'libos.entrypoint'\n"); + log_error("Cannot parse 'libos.entrypoint'"); ret = -EINVAL; goto out; } if (!entrypoint) { - log_error("'libos.entrypoint' must be specified in the manifest\n"); + log_error("'libos.entrypoint' must be specified in the manifest"); ret = -EINVAL; goto out; } @@ -117,7 +117,7 @@ static int init_exec_handle(void) { if (strstartswith(exec_path, URI_PREFIX_FILE)) { /* TODO: change to error after some deprecation period */ log_error("'libos.entrypoint' is now a Graphene path, not URI. " - "Ignoring the 'file:' prefix.\n"); + "Ignoring the 'file:' prefix."); exec_path += strlen(URI_PREFIX_FILE); } @@ -129,7 +129,7 @@ static int init_exec_handle(void) { ret = open_executable(hdl, exec_path); if (ret < 0) { - log_error("init_exec_handle: error opening executable: %d\n", ret); + log_error("init_exec_handle: error opening executable: %d", ret); goto out; } @@ -442,7 +442,7 @@ void get_handle(struct shim_handle* hdl) { #ifdef DEBUG_REF int ref_count = REF_INC(hdl->ref_count); - log_debug("get handle %p(%s) (ref_count = %d)\n", hdl, __handle_name(hdl), ref_count); + log_debug("get handle %p(%s) (ref_count = %d)", hdl, __handle_name(hdl), ref_count); #else REF_INC(hdl->ref_count); #endif @@ -458,7 +458,7 @@ void put_handle(struct shim_handle* hdl) { int ref_count = REF_DEC(hdl->ref_count); #ifdef DEBUG_REF - log_debug("put handle %p(%s) (ref_count = %d)\n", hdl, __handle_name(hdl), ref_count); + log_debug("put handle %p(%s) (ref_count = %d)", hdl, __handle_name(hdl), ref_count); #endif if (!ref_count) { @@ -483,7 +483,7 @@ void put_handle(struct shim_handle* hdl) { if (hdl->pal_handle) { #ifdef DEBUG_REF - log_debug("handle %p closes PAL handle %p\n", hdl, hdl->pal_handle); + log_debug("handle %p closes PAL handle %p", hdl, hdl->pal_handle); #endif DkObjectClose(hdl->pal_handle); // TODO: handle errors hdl->pal_handle = NULL; diff --git a/LibOS/shim/src/bookkeep/shim_pid.c b/LibOS/shim/src/bookkeep/shim_pid.c index f7bcb73111..03e26eb3be 100644 --- a/LibOS/shim/src/bookkeep/shim_pid.c +++ b/LibOS/shim/src/bookkeep/shim_pid.c @@ -72,14 +72,14 @@ IDTYPE get_new_id(bool remove_from_owned) { if (!g_last_range) { g_last_range = malloc(sizeof(*g_last_range)); if (!g_last_range) { - log_debug("OOM in %s:%d\n", __FILE__, __LINE__); + log_debug("OOM in %s:%d", __FILE__, __LINE__); goto out; } IDTYPE start; IDTYPE end; int ret = ipc_alloc_id_range(&start, &end); if (ret < 0) { - log_debug("Failed to allocate new id range: %d\n", ret); + log_debug("Failed to allocate new id range: %d", ret); free(g_last_range); g_last_range = NULL; goto out; @@ -115,7 +115,7 @@ IDTYPE get_new_id(bool remove_from_owned) { } else { struct id_range* range = malloc(sizeof(*range)); if (!range) { - log_debug("OOM in %s:%d\n", __FILE__, __LINE__); + log_debug("OOM in %s:%d", __FILE__, __LINE__); g_last_used_id--; ret_id = 0; goto out; @@ -152,12 +152,12 @@ void release_id(IDTYPE id) { }; struct avl_tree_node* node = avl_tree_lower_bound(&g_used_ranges_tree, &dummy.node); if (!node) { - log_error("Trying to release unknown ID!\n"); + log_error("Trying to release unknown ID!"); BUG(); } struct id_range* range = container_of(node, struct id_range, node); if (id < range->start || range->end < id) { - log_error("Trying to release unknown ID!\n"); + log_error("Trying to release unknown ID!"); BUG(); } assert(range->taken_count > 0); @@ -168,7 +168,7 @@ void release_id(IDTYPE id) { int ret = ipc_release_id_range(range->start, range->end); if (ret < 0) { - log_error("IPC pid release failed\n"); + log_error("IPC pid release failed"); die_or_inf_loop(); } free(range); diff --git a/LibOS/shim/src/bookkeep/shim_process.c b/LibOS/shim/src/bookkeep/shim_process.c index df10360d3f..b1912be11b 100644 --- a/LibOS/shim/src/bookkeep/shim_process.c +++ b/LibOS/shim/src/bookkeep/shim_process.c @@ -48,7 +48,7 @@ int init_process(int argc, const char** argv) { struct shim_dentry* dent = NULL; int ret = path_lookupat(/*start=*/NULL, "/", LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &dent); if (ret < 0) { - log_error("Could not set up dentry for \"/\", something is seriously broken.\n"); + log_error("Could not set up dentry for \"/\", something is seriously broken."); return ret; } g_process.root = dent; @@ -162,7 +162,7 @@ static bool mark_child_exited(child_cmp_t child_cmp, unsigned long arg, IDTYPE c fill_siginfo_code_and_status(&info, signal, exit_code); int x = kill_current_proc(&info); if (x < 0) { - log_error("Sending child death signal failed: %d!\n", x); + log_error("Sending child death signal failed: %d!", x); } } diff --git a/LibOS/shim/src/bookkeep/shim_signal.c b/LibOS/shim/src/bookkeep/shim_signal.c index bf613ea75a..fef94ad25e 100644 --- a/LibOS/shim/src/bookkeep/shim_signal.c +++ b/LibOS/shim/src/bookkeep/shim_signal.c @@ -59,7 +59,7 @@ void thread_sigaction_reset_on_execve(void) { } static noreturn void sighandler_kill(int sig) { - log_debug("killed by signal %d\n", sig & ~__WCOREDUMP_BIT); + log_debug("killed by signal %d", sig & ~__WCOREDUMP_BIT); process_exit(0, sig); } @@ -310,10 +310,10 @@ static noreturn void internal_fault(const char* errstr, PAL_NUM addr, PAL_CONTEX PAL_NUM ip = pal_context_get_ip(context); if (context_is_libos(context)) - log_error("%s at 0x%08lx (IP = +0x%lx, VMID = %u, TID = %u)\n", errstr, addr, + log_error("%s at 0x%08lx (IP = +0x%lx, VMID = %u, TID = %u)", errstr, addr, (void*)ip - (void*)&__load_address, g_self_vmid, tid); else - log_error("%s at 0x%08lx (IP = 0x%08lx, VMID = %u, TID = %u)\n", errstr, addr, + log_error("%s at 0x%08lx (IP = 0x%08lx, VMID = %u, TID = %u)", errstr, addr, context ? ip : 0, g_self_vmid, tid); DEBUG_BREAK_ON_FAILURE(); @@ -328,7 +328,7 @@ static void arithmetic_error_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* c if (is_internal(get_cur_thread()) || context_is_libos(context)) { internal_fault("Internal arithmetic fault", addr, context); } else { - log_debug("arithmetic fault at 0x%08lx\n", pal_context_get_ip(context)); + log_debug("arithmetic fault at 0x%08lx", pal_context_get_ip(context)); siginfo_t info = { .si_signo = SIGFPE, .si_code = FPE_INTDIV, @@ -348,7 +348,7 @@ static void memfault_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) internal_fault("Internal memory fault", addr, context); } - log_debug("memory fault at 0x%08lx (IP = 0x%08lx)\n", addr, pal_context_get_ip(context)); + log_debug("memory fault at 0x%08lx (IP = 0x%08lx)", addr, pal_context_get_ip(context)); siginfo_t info = { .si_addr = (void*)addr, @@ -470,7 +470,7 @@ static void illegal_upcall(bool is_in_pal, PAL_NUM addr, PAL_CONTEXT* context) { /* Emulate syscall instruction, which is prohibited in Linux-SGX PAL and raises a SIGILL. */ if (!maybe_emulate_syscall(context)) { void* rip = (void*)pal_context_get_ip(context); - log_debug("Illegal instruction during app execution at %p; delivering to app\n", rip); + log_debug("Illegal instruction during app execution at %p; delivering to app", rip); siginfo_t info = { .si_signo = SIGILL, .si_code = ILL_ILLOPC, @@ -521,7 +521,7 @@ int init_signal_handling(void) { &g_inject_host_signal_enabled); if (ret < 0) { log_error("Cannot parse 'sys.enable_sigterm_injection' (the value must be `true` or " - "`false`)\n"); + "`false`)"); return -EINVAL; } @@ -529,7 +529,7 @@ int init_signal_handling(void) { &g_check_invalid_ptrs); if (ret < 0) { log_error("Cannot parse 'libos.check_invalid_pointers' (the value must be `true` or " - "`false`)\n"); + "`false`)"); return -EINVAL; } @@ -797,10 +797,10 @@ int append_signal(struct shim_thread* thread, siginfo_t* info) { } if (thread) { - log_debug("Signal %d queue of thread %u is full, dropping incoming signal\n", + log_debug("Signal %d queue of thread %u is full, dropping incoming signal", info->si_signo, thread->tid); } else { - log_debug("Signal %d queue of process is full, dropping incoming signal\n", info->si_signo); + log_debug("Signal %d queue of process is full, dropping incoming signal", info->si_signo); } /* This is counter-intuitive, but we report success here: after all signal was successfully * delivered, just the queue was full. */ diff --git a/LibOS/shim/src/bookkeep/shim_thread.c b/LibOS/shim/src/bookkeep/shim_thread.c index 0179d36dcf..eda8fd6843 100644 --- a/LibOS/shim/src/bookkeep/shim_thread.c +++ b/LibOS/shim/src/bookkeep/shim_thread.c @@ -32,7 +32,7 @@ struct shim_lock g_thread_list_lock; //#define DEBUG_REF #ifdef DEBUG_REF -#define DEBUG_PRINT_REF_COUNT(rc) log_debug("%s %p ref_count = %d\n", __func__, dispositions, rc) +#define DEBUG_PRINT_REF_COUNT(rc) log_debug("%s %p ref_count = %d", __func__, dispositions, rc) #else #define DEBUG_PRINT_REF_COUNT(rc) __UNUSED(rc) #endif @@ -109,7 +109,7 @@ unmap:; void* tmp_vma = NULL; if (bkeep_munmap(addr, SHIM_THREAD_LIBOS_STACK_SIZE, /*is_internal=*/true, &tmp_vma) < 0) { log_error("[alloc_thread_libos_stack]" - " Failed to remove bookkeeped memory that was not allocated at %p-%p!\n", + " Failed to remove bookkeeped memory that was not allocated at %p-%p!", addr, (char*)addr + SHIM_THREAD_LIBOS_STACK_SIZE); BUG(); } @@ -143,7 +143,7 @@ static int init_main_thread(void) { cur_thread->tid = get_new_id(/*remove_from_owned=*/false); if (!cur_thread->tid) { - log_error("Cannot allocate pid for the initial thread!\n"); + log_error("Cannot allocate pid for the initial thread!"); put_thread(cur_thread); return -ESRCH; } @@ -307,7 +307,7 @@ void put_thread(struct shim_thread* thread) { void* tmp_vma = NULL; char* addr = (char*)thread->libos_stack_bottom - SHIM_THREAD_LIBOS_STACK_SIZE; if (bkeep_munmap(addr, SHIM_THREAD_LIBOS_STACK_SIZE, /*is_internal=*/true, &tmp_vma) < 0) { - log_error("[put_thread] Failed to remove bookkeeped memory at %p-%p!\n", + log_error("[put_thread] Failed to remove bookkeeped memory at %p-%p!", addr, (char*)addr + SHIM_THREAD_LIBOS_STACK_SIZE); BUG(); } diff --git a/LibOS/shim/src/bookkeep/shim_vma.c b/LibOS/shim/src/bookkeep/shim_vma.c index cd1f6fdfa9..e033ab07cb 100644 --- a/LibOS/shim/src/bookkeep/shim_vma.c +++ b/LibOS/shim/src/bookkeep/shim_vma.c @@ -219,9 +219,9 @@ static int _vma_bkeep_remove(uintptr_t begin, uintptr_t end, bool is_internal, while (vma && vma->begin < end) { if (!!(vma->flags & VMA_INTERNAL) != is_internal) { if (is_internal) { - log_warning("LibOS tried to free a user vma!\n"); + log_warning("LibOS tried to free a user vma!"); } else { - log_warning("user app tried to free an internal vma!\n"); + log_warning("user app tried to free an internal vma!"); } return -EACCES; } @@ -234,7 +234,7 @@ static int _vma_bkeep_remove(uintptr_t begin, uintptr_t end, bool is_internal, if (vma->begin < begin) { if (end < vma->end) { if (!new_vma_ptr) { - log_warning("need an additional vma to free this range!\n"); + log_warning("need an additional vma to free this range!"); return -ENOMEM; } struct shim_vma* new_vma = *new_vma_ptr; @@ -303,7 +303,7 @@ static void* _vma_malloc(size_t size) { &vmas_to_free); spinlock_unlock(&vma_tree_lock); if (ret < 0) { - log_error("Removing a vma we just created failed with %d!\n", ret); + log_error("Removing a vma we just created failed with %d!", ret); BUG(); } @@ -441,7 +441,7 @@ static struct shim_vma* alloc_vma(void) { struct shim_vma tmp_vma = {0}; /* vma cache is empty, as we checked it before. */ if (!add_to_thread_vma_cache(&tmp_vma)) { - log_error("Failed to add tmp vma to cache!\n"); + log_error("Failed to add tmp vma to cache!"); BUG(); } if (!enlarge_mem_mgr(vma_mgr, size_align_up(DEFAULT_VMA_COUNT))) { @@ -451,7 +451,7 @@ static struct shim_vma* alloc_vma(void) { struct shim_vma* vma_migrate = get_mem_obj_from_mgr(vma_mgr); if (!vma_migrate) { - log_error("Failed to allocate a vma right after enlarge_mem_mgr!\n"); + log_error("Failed to allocate a vma right after enlarge_mem_mgr!"); BUG(); } @@ -553,23 +553,23 @@ int init_vma(void) { assert(init_vmas[i].begin <= init_vmas[i].end); /* Skip empty areas. */ if (init_vmas[i].begin == init_vmas[i].end) { - log_debug("Skipping bookkeeping of empty region at 0x%lx (comment: \"%s\")\n", + log_debug("Skipping bookkeeping of empty region at 0x%lx (comment: \"%s\")", init_vmas[i].begin, init_vmas[i].comment); continue; } if (!IS_ALLOC_ALIGNED(init_vmas[i].begin) || !IS_ALLOC_ALIGNED(init_vmas[i].end)) { - log_error("Unaligned VMA region: 0x%lx-0x%lx (%s)\n", init_vmas[i].begin, + log_error("Unaligned VMA region: 0x%lx-0x%lx (%s)", init_vmas[i].begin, init_vmas[i].end, init_vmas[i].comment); ret = -EINVAL; break; } ret = _bkeep_initial_vma(&init_vmas[i]); if (ret < 0) { - log_error("Failed to bookkeep initial VMA region 0x%lx-0x%lx (%s)\n", + log_error("Failed to bookkeep initial VMA region 0x%lx-0x%lx (%s)", init_vmas[i].begin, init_vmas[i].end, init_vmas[i].comment); break; } - log_debug("Initial VMA region 0x%lx-0x%lx (%s) bookkeeped\n", init_vmas[i].begin, + log_debug("Initial VMA region 0x%lx-0x%lx (%s) bookkeeped", init_vmas[i].begin, init_vmas[i].end, init_vmas[i].comment); } spinlock_unlock(&vma_tree_lock); @@ -600,20 +600,20 @@ int init_vma(void) { gap = ALLOC_ALIGN_DOWN(gap % gap_max_size); g_aslr_addr_top = (char*)g_aslr_addr_top - gap; - log_debug("ASLR top address adjusted to %p\n", g_aslr_addr_top); + log_debug("ASLR top address adjusted to %p", g_aslr_addr_top); } else { - log_warning("Not enough space to make meaningful address space randomization.\n"); + log_warning("Not enough space to make meaningful address space randomization."); } } /* We need 1 vma to create the memmgr. */ if (!add_to_thread_vma_cache(&init_vmas[0])) { - log_error("Failed to add tmp vma to cache!\n"); + log_error("Failed to add tmp vma to cache!"); BUG(); } vma_mgr = create_mem_mgr(DEFAULT_VMA_COUNT); if (!vma_mgr) { - log_error("Failed to create VMA memory manager!\n"); + log_error("Failed to create VMA memory manager!"); return -ENOMEM; } @@ -1284,7 +1284,7 @@ BEGIN_RS_FUNC(vma) { void* need_mapped = (void*)GET_CP_ENTRY(ADDR); CP_REBASE(vma->file); - DEBUG_RS("vma: %p-%p flags 0x%x prot 0x%08x comment \"%s\"\n", vma->addr, + DEBUG_RS("vma: %p-%p flags 0x%x prot 0x%08x comment \"%s\"", vma->addr, vma->addr + vma->length, vma->flags, vma->prot, vma->comment); int ret = bkeep_mmap_fixed(vma->addr, vma->length, vma->prot, vma->flags | MAP_FIXED, vma->file, @@ -1329,7 +1329,7 @@ BEGIN_RS_FUNC(vma) { } if (need_mapped < vma->addr + vma->length) { - log_error("vma %p-%p cannot be allocated!\n", need_mapped, vma->addr + vma->length); + log_error("vma %p-%p cannot be allocated!", need_mapped, vma->addr + vma->length); return -ENOMEM; } } @@ -1359,7 +1359,7 @@ END_CP_FUNC_NO_RS(all_vmas) static void debug_print_vma(struct shim_vma* vma) { - log_debug("[0x%lx-0x%lx] prot=0x%x flags=0x%x%s%s file=%p (offset=%ld)%s%s\n", + log_debug("[0x%lx-0x%lx] prot=0x%x flags=0x%x%s%s file=%p (offset=%ld)%s%s", vma->begin, vma->end, vma->prot, vma->flags & ~(VMA_INTERNAL | VMA_UNMAPPED), diff --git a/LibOS/shim/src/fs/chroot/fs.c b/LibOS/shim/src/fs/chroot/fs.c index 25c56ac019..e439cbb7b3 100644 --- a/LibOS/shim/src/fs/chroot/fs.c +++ b/LibOS/shim/src/fs/chroot/fs.c @@ -255,7 +255,7 @@ static int __query_attr(struct shim_dentry* dent, struct shim_file_data* data, type = S_IFCHR; break; default: - log_error("unknown PAL handle type: %d\n", pal_attr.handle_type); + log_error("unknown PAL handle type: %d", pal_attr.handle_type); BUG(); } @@ -844,7 +844,7 @@ static int chroot_readdir(struct shim_dentry* dent, readdir_callback_t callback, end++; if (end == start) { - log_error("chroot_readdir: empty name returned from PAL\n"); + log_error("chroot_readdir: empty name returned from PAL"); die_or_inf_loop(); } diff --git a/LibOS/shim/src/fs/dev/attestation.c b/LibOS/shim/src/fs/dev/attestation.c index bf1e2dbe11..fb2f80760c 100644 --- a/LibOS/shim/src/fs/dev/attestation.c +++ b/LibOS/shim/src/fs/dev/attestation.c @@ -267,7 +267,7 @@ static int pfkey_save(struct shim_dentry* dent, const char* data, size_t size) { __UNUSED(dent); if (size != sizeof(g_pf_key_hex)) { - log_debug("/dev/attestation/protected_files_key: invalid length\n"); + log_debug("/dev/attestation/protected_files_key: invalid length"); return -EACCES; } @@ -285,7 +285,7 @@ static int pfkey_save(struct shim_dentry* dent, const char* data, size_t size) { int init_attestation(struct pseudo_node* dev) { if (strcmp(g_pal_control->host_type, "Linux-SGX")) { - log_debug("host is not Linux-SGX, skipping /dev/attestation setup\n"); + log_debug("host is not Linux-SGX, skipping /dev/attestation setup"); return 0; } diff --git a/LibOS/shim/src/fs/pipe/fs.c b/LibOS/shim/src/fs/pipe/fs.c index 5cbaea2886..1e1a6f34de 100644 --- a/LibOS/shim/src/fs/pipe/fs.c +++ b/LibOS/shim/src/fs/pipe/fs.c @@ -56,7 +56,7 @@ static ssize_t pipe_write(struct shim_handle* hdl, const void* buf, size_t count .si_code = SI_USER, }; if (kill_current_proc(&info) < 0) { - log_error("pipe_write: failed to deliver a signal\n"); + log_error("pipe_write: failed to deliver a signal"); } } return ret; @@ -178,7 +178,7 @@ static int fifo_open(struct shim_handle* hdl, struct shim_dentry* dent, int flag * one end (read or write) in our emulation, so we treat such FIFOs as read-only. This * covers most apps seen in the wild (in particular, LTP apps). */ log_warning("FIFO (named pipe) '%s' cannot be opened in read-write mode in Graphene. " - "Treating it as read-only.\n", qstrgetstr(&dent->mount->path)); + "Treating it as read-only.", qstrgetstr(&dent->mount->path)); flags = O_RDONLY; } diff --git a/LibOS/shim/src/fs/shim_dcache.c b/LibOS/shim/src/fs/shim_dcache.c index 8840acc76f..f5ed6552eb 100644 --- a/LibOS/shim/src/fs/shim_dcache.c +++ b/LibOS/shim/src/fs/shim_dcache.c @@ -92,7 +92,7 @@ void get_dentry(struct shim_dentry* dent) { const char* path = NULL; dentry_abs_path(dent, &path, /*size=*/NULL); - log_debug("get dentry %p(%s) (ref_count = %lld)\n", dent, path, count); + log_debug("get dentry %p(%s) (ref_count = %lld)", dent, path, count); free(path); #else REF_INC(dent->ref_count); @@ -131,7 +131,7 @@ void put_dentry(struct shim_dentry* dent) { #ifdef DEBUG_REF const char* path = NULL; dentry_abs_path(dent, &path, /*size=*/NULL); - log_debug("put dentry %p(%s) (ref_count = %lld)\n", dent, path, count); + log_debug("put dentry %p(%s) (ref_count = %lld)", dent, path, count); free(path); #endif assert(count >= 0); @@ -175,7 +175,7 @@ struct shim_dentry* get_new_dentry(struct shim_mount* mount, struct shim_dentry* } if (parent && parent->nchildren >= DENTRY_MAX_CHILDREN) { - log_warning("get_new_dentry: nchildren limit reached\n"); + log_warning("get_new_dentry: nchildren limit reached"); free_dentry(dent); return NULL; } @@ -341,7 +341,7 @@ int dentry_rel_path(struct shim_dentry* dent, char** path, size_t* size) { static int dump_dentry_write_all(const char* str, size_t size, void* arg) { __UNUSED(arg); - log_always("%.*s\n", (int)size, str); + log_always("%.*s", (int)size, str); return 0; } diff --git a/LibOS/shim/src/fs/shim_fs.c b/LibOS/shim/src/fs/shim_fs.c index 5172fd01c7..7612534879 100644 --- a/LibOS/shim/src/fs/shim_fs.c +++ b/LibOS/shim/src/fs/shim_fs.c @@ -96,28 +96,28 @@ static int __mount_root(void) { ret = toml_string_in(g_manifest_root, "fs.root.type", &fs_root_type); if (ret < 0) { - log_error("Cannot parse 'fs.root.type' (the value must be put in double quotes!)\n"); + log_error("Cannot parse 'fs.root.type' (the value must be put in double quotes!)"); ret = -EINVAL; goto out; } ret = toml_string_in(g_manifest_root, "fs.root.uri", &fs_root_uri); if (ret < 0) { - log_error("Cannot parse 'fs.root.uri' (the value must be put in double quotes!)\n"); + log_error("Cannot parse 'fs.root.uri' (the value must be put in double quotes!)"); ret = -EINVAL; goto out; } if (fs_root_type && fs_root_uri) { - log_debug("Mounting root as %s filesystem: from %s to /\n", fs_root_type, fs_root_uri); + log_debug("Mounting root as %s filesystem: from %s to /", fs_root_type, fs_root_uri); if ((ret = mount_fs(fs_root_type, fs_root_uri, "/")) < 0) { - log_error("Mounting root filesystem failed (%d)\n", ret); + log_error("Mounting root filesystem failed (%d)", ret); goto out; } } else { - log_debug("Mounting root as chroot filesystem: from file:. to /\n"); + log_debug("Mounting root as chroot filesystem: from file:. to /"); if ((ret = mount_fs("chroot", URI_PREFIX_FILE, "/")) < 0) { - log_error("Mounting root filesystem failed (%d)\n", ret); + log_error("Mounting root filesystem failed (%d)", ret); goto out; } } @@ -132,27 +132,27 @@ static int __mount_root(void) { static int __mount_sys(void) { int ret; - log_debug("Mounting special proc filesystem: /proc\n"); + log_debug("Mounting special proc filesystem: /proc"); if ((ret = mount_fs("pseudo", "proc", "/proc")) < 0) { - log_error("Mounting proc filesystem failed (%d)\n", ret); + log_error("Mounting proc filesystem failed (%d)", ret); return ret; } - log_debug("Mounting special dev filesystem: /dev\n"); + log_debug("Mounting special dev filesystem: /dev"); if ((ret = mount_fs("pseudo", "dev", "/dev")) < 0) { - log_error("Mounting dev filesystem failed (%d)\n", ret); + log_error("Mounting dev filesystem failed (%d)", ret); return ret; } - log_debug("Mounting terminal device /dev/tty under /dev\n"); + log_debug("Mounting terminal device /dev/tty under /dev"); if ((ret = mount_fs("chroot", URI_PREFIX_DEV "tty", "/dev/tty")) < 0) { - log_error("Mounting terminal device /dev/tty failed (%d)\n", ret); + log_error("Mounting terminal device /dev/tty failed (%d)", ret); return ret; } - log_debug("Mounting special sys filesystem: /sys\n"); + log_debug("Mounting special sys filesystem: /sys"); if ((ret = mount_fs("pseudo", "sys", "/sys")) < 0) { - log_error("Mounting sys filesystem failed (%d)\n", ret); + log_error("Mounting sys filesystem failed (%d)", ret); return ret; } @@ -167,19 +167,19 @@ static int __mount_one_other(toml_table_t* mount) { toml_raw_t mount_type_raw = toml_raw_in(mount, "type"); if (!mount_type_raw) { - log_error("Cannot find 'fs.mount.%s.type'\n", key); + log_error("Cannot find 'fs.mount.%s.type'", key); return -EINVAL; } toml_raw_t mount_path_raw = toml_raw_in(mount, "path"); if (!mount_path_raw) { - log_error("Cannot find 'fs.mount.%s.path'\n", key); + log_error("Cannot find 'fs.mount.%s.path'", key); return -EINVAL; } toml_raw_t mount_uri_raw = toml_raw_in(mount, "uri"); if (!mount_uri_raw) { - log_error("Cannot find 'fs.mount.%s.uri'\n", key); + log_error("Cannot find 'fs.mount.%s.uri'", key); return -EINVAL; } @@ -189,29 +189,26 @@ static int __mount_one_other(toml_table_t* mount) { ret = toml_rtos(mount_type_raw, &mount_type); if (ret < 0) { - log_error("Cannot parse 'fs.mount.%s.type' (the value must be put in double quotes!)\n", - key); + log_error("Cannot parse 'fs.mount.%s.type' (the value must be put in double quotes!)", key); ret = -EINVAL; goto out; } ret = toml_rtos(mount_path_raw, &mount_path); if (ret < 0) { - log_error("Cannot parse 'fs.mount.%s.path' (the value must be put in double quotes!)\n", - key); + log_error("Cannot parse 'fs.mount.%s.path' (the value must be put in double quotes!)", key); ret = -EINVAL; goto out; } ret = toml_rtos(mount_uri_raw, &mount_uri); if (ret < 0) { - log_error("Cannot parse 'fs.mount.%s.uri' (the value must be put in double quotes!)\n", - key); + log_error("Cannot parse 'fs.mount.%s.uri' (the value must be put in double quotes!)", key); ret = -EINVAL; goto out; } - log_debug("Mounting as %s filesystem: from %s to %s\n", mount_type, mount_uri, mount_path); + log_debug("Mounting as %s filesystem: from %s to %s", mount_type, mount_uri, mount_path); if (!strcmp(mount_path, "/")) { log_error( @@ -223,13 +220,13 @@ static int __mount_one_other(toml_table_t* mount) { } if (!strcmp(mount_path, ".") || !strcmp(mount_path, "..")) { - log_error("Mount points '.' and '..' are not allowed, remove them from manifest.\n"); + log_error("Mount points '.' and '..' are not allowed, remove them from manifest."); ret = -EINVAL; goto out; } if ((ret = mount_fs(mount_type, mount_uri, mount_path)) < 0) { - log_error("Mounting %s on %s (type=%s) failed (%d)\n", mount_uri, mount_path, mount_type, + log_error("Mounting %s on %s (type=%s) failed (%d)", mount_uri, mount_path, mount_type, -ret); goto out; } @@ -342,8 +339,7 @@ int init_mount(void) { char* fs_start_dir = NULL; ret = toml_string_in(g_manifest_root, "fs.start_dir", &fs_start_dir); if (ret < 0) { - log_error("Can't parse 'fs.start_dir' (note that the value must be put in double quotes)!" - "\n"); + log_error("Can't parse 'fs.start_dir' (note that the value must be put in double quotes)!"); return ret; } @@ -352,7 +348,7 @@ int init_mount(void) { ret = path_lookupat(/*start=*/NULL, fs_start_dir, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &dent); free(fs_start_dir); if (ret < 0) { - log_error("Invalid 'fs.start_dir' in manifest.\n"); + log_error("Invalid 'fs.start_dir' in manifest."); return ret; } lock(&g_process.fs_lock); @@ -437,7 +433,7 @@ static int mount_fs_at_dentry(const char* type, const char* uri, const char* mou struct shim_dentry* root; if ((ret = _path_lookupat(g_dentry_root, mount_path, LOOKUP_NO_FOLLOW, &root))) { - log_warning("error looking up mount root %s: %d\n", mount_path, ret); + log_warning("error looking up mount root %s: %d", mount_path, ret); goto err; } assert(root == mount->root); @@ -469,7 +465,7 @@ static int mount_fs_at_dentry(const char* type, const char* uri, const char* mou if (fs->fs_ops->unmount) { int ret_unmount = fs->fs_ops->unmount(mount_data); if (ret_unmount < 0) { - log_warning("error unmounting %s: %d\n", mount_path, ret_unmount); + log_warning("error unmounting %s: %d", mount_path, ret_unmount); } } @@ -484,7 +480,7 @@ int mount_fs(const char* type, const char* uri, const char* mount_path) { int lookup_flags = LOOKUP_NO_FOLLOW | LOOKUP_MAKE_SYNTHETIC; if ((ret = _path_lookupat(g_dentry_root, mount_path, lookup_flags, &mount_point)) < 0) { - log_warning("error looking up mountpoint %s: %d\n", mount_path, ret); + log_warning("error looking up mountpoint %s: %d", mount_path, ret); goto out; } diff --git a/LibOS/shim/src/fs/shim_fs_pseudo.c b/LibOS/shim/src/fs/shim_fs_pseudo.c index c619d1a2a5..8d194145ca 100644 --- a/LibOS/shim/src/fs/shim_fs_pseudo.c +++ b/LibOS/shim/src/fs/shim_fs_pseudo.c @@ -24,7 +24,7 @@ static struct pseudo_node* pseudo_find_root(const char* name) { } } - log_debug("Cannot find pseudofs node: %s\n", name); + log_debug("Cannot find pseudofs node: %s", name); return NULL; } @@ -420,7 +420,7 @@ static int pseudo_close(struct shim_handle* hdl) { if (hdl->flags & (O_WRONLY | O_RDWR)) { int ret = str_flush(hdl); if (ret < 0) { - log_debug("str_flush() failed, proceeding with close\n"); + log_debug("str_flush() failed, proceeding with close"); } } diff --git a/LibOS/shim/src/fs/shim_namei.c b/LibOS/shim/src/fs/shim_namei.c index 5c143481d3..256485e7a9 100644 --- a/LibOS/shim/src/fs/shim_namei.c +++ b/LibOS/shim/src/fs/shim_namei.c @@ -667,7 +667,7 @@ static int populate_directory(struct shim_dentry* dent) { LISTP_TYPE(temp_dirent) ents = LISTP_INIT; int ret = dent->fs->d_ops->readdir(dent, &add_name, &ents); if (ret < 0) - log_error("readdir error: %d\n", ret); + log_error("readdir error: %d", ret); struct temp_dirent* ent; struct temp_dirent* tmp; diff --git a/LibOS/shim/src/fs/socket/fs.c b/LibOS/shim/src/fs/socket/fs.c index 4bfce0c59e..d73d58c113 100644 --- a/LibOS/shim/src/fs/socket/fs.c +++ b/LibOS/shim/src/fs/socket/fs.c @@ -96,7 +96,7 @@ static ssize_t socket_write(struct shim_handle* hdl, const void* buf, size_t cou .si_code = SI_USER, }; if (kill_current_proc(&info) < 0) { - log_error("socket_write: failed to deliver a signal\n"); + log_error("socket_write: failed to deliver a signal"); } } @@ -193,7 +193,7 @@ static off_t socket_poll(struct shim_handle* hdl, int poll_type) { out: if (ret < 0) { - log_error("socket_poll failed (%ld)\n", ret); + log_error("socket_poll failed (%ld)", ret); sock->error = -ret; } diff --git a/LibOS/shim/src/fs/str/fs.c b/LibOS/shim/src/fs/str/fs.c index 3ee3c29693..941cfe4900 100644 --- a/LibOS/shim/src/fs/str/fs.c +++ b/LibOS/shim/src/fs/str/fs.c @@ -98,7 +98,7 @@ ssize_t str_read(struct shim_handle* hdl, void* buf, size_t count) { struct shim_str_data* data = strhdl->data; if (!data->str) { - log_warning("str_read: str_data has no str\n"); + log_warning("str_read: str_data has no str"); ret = 0; goto out; } diff --git a/LibOS/shim/src/fs/sys/cache_info.c b/LibOS/shim/src/fs/sys/cache_info.c index b41d864f9d..e201829de0 100644 --- a/LibOS/shim/src/fs/sys/cache_info.c +++ b/LibOS/shim/src/fs/sys/cache_info.c @@ -43,7 +43,7 @@ int sys_cache_load(struct shim_dentry* dent, char** out_data, size_t* out_size) } else if (strcmp(name, "physical_line_partition") == 0) { str = cache->physical_line_partition; } else { - log_debug("unrecognized file: %s\n", name); + log_debug("unrecognized file: %s", name); return -ENOENT; } diff --git a/LibOS/shim/src/fs/sys/cpu_info.c b/LibOS/shim/src/fs/sys/cpu_info.c index 627fe04bab..7937df157d 100644 --- a/LibOS/shim/src/fs/sys/cpu_info.c +++ b/LibOS/shim/src/fs/sys/cpu_info.c @@ -21,7 +21,7 @@ int sys_cpu_general_load(struct shim_dentry* dent, char** out_data, size_t* out_ } else if (strcmp(name, "possible") == 0) { str = g_pal_control->topo_info.possible_logical_cores; } else { - log_debug("unrecognized file: %s\n", name); + log_debug("unrecognized file: %s", name); return -ENOENT; } @@ -54,7 +54,7 @@ int sys_cpu_load(struct shim_dentry* dent, char** out_data, size_t* out_size) { } else if (strcmp(name, "thread_siblings") == 0) { str = core_topology->thread_siblings; } else { - log_debug("unrecognized file: %s\n", name); + log_debug("unrecognized file: %s", name); return -ENOENT; } diff --git a/LibOS/shim/src/fs/sys/fs.c b/LibOS/shim/src/fs/sys/fs.c index 39aa5fb957..6b616f9419 100644 --- a/LibOS/shim/src/fs/sys/fs.c +++ b/LibOS/shim/src/fs/sys/fs.c @@ -31,7 +31,7 @@ static int sys_resource(struct shim_dentry* parent, const char* name, unsigned i pal_total = g_pal_control->topo_info.num_cache_index; prefix = "index"; } else { - log_debug("unrecognized resource: %s\n", parent_name); + log_debug("unrecognized resource: %s", parent_name); return -ENOENT; } diff --git a/LibOS/shim/src/fs/sys/node_info.c b/LibOS/shim/src/fs/sys/node_info.c index 9d72536070..1c7dc12406 100644 --- a/LibOS/shim/src/fs/sys/node_info.c +++ b/LibOS/shim/src/fs/sys/node_info.c @@ -17,7 +17,7 @@ int sys_node_general_load(struct shim_dentry* dent, char** out_data, size_t* out if (strcmp(name, "online") == 0) { str = g_pal_control->topo_info.online_nodes; } else { - log_debug("unrecognized file: %s\n", name); + log_debug("unrecognized file: %s", name); return -ENOENT; } @@ -47,7 +47,7 @@ int sys_node_load(struct shim_dentry* dent, char** out_data, size_t* out_size) { } } if (!str) { - log_debug("unrecognized file: %s\n", name); + log_debug("unrecognized file: %s", name); return -ENOENT; } diff --git a/LibOS/shim/src/fs/tmpfs/fs.c b/LibOS/shim/src/fs/tmpfs/fs.c index 83c2cae6db..8c449d7de2 100644 --- a/LibOS/shim/src/fs/tmpfs/fs.c +++ b/LibOS/shim/src/fs/tmpfs/fs.c @@ -256,7 +256,7 @@ static int tmpfs_mmap(struct shim_handle* hdl, void** addr, size_t size, int pro __UNUSED(flags); __UNUSED(offset); - log_error("tmpfs_mmap(): mmap() function for tmpfs mount type is not implemented.\n"); + log_error("tmpfs_mmap(): mmap() function for tmpfs mount type is not implemented."); return -ENOSYS; } diff --git a/LibOS/shim/src/ipc/shim_ipc.c b/LibOS/shim/src/ipc/shim_ipc.c index 3257c12d46..6fbd67ce74 100644 --- a/LibOS/shim/src/ipc/shim_ipc.c +++ b/LibOS/shim/src/ipc/shim_ipc.c @@ -114,7 +114,7 @@ static int ipc_connect(IDTYPE dest, struct shim_ipc_connection** conn_ptr) { char uri[PIPE_URI_SIZE]; if (vmid_to_uri(dest, uri, sizeof(uri)) < 0) { - log_error("buffer for IPC pipe URI too small\n"); + log_error("buffer for IPC pipe URI too small"); BUG(); } ret = DkStreamOpen(uri, 0, 0, 0, 0, &conn->handle); @@ -191,7 +191,7 @@ void remove_outgoing_ipc_connection(IDTYPE dest) { if (waiter->dest == dest) { waiter->response_data = NULL; DkEventSet(waiter->event); - log_debug("Woke up a thread waiting for a message from a disconnected process\n"); + log_debug("Woke up a thread waiting for a message from a disconnected process"); } node = avl_tree_next(node); } @@ -210,13 +210,13 @@ void init_ipc_response(struct shim_ipc_msg* msg, uint64_t seq, size_t size) { } static int ipc_send_message_to_conn(struct shim_ipc_connection* conn, struct shim_ipc_msg* msg) { - log_debug("Sending ipc message to %u\n", conn->vmid); + log_debug("Sending ipc message to %u", conn->vmid); lock(&conn->lock); int ret = write_exact(conn->handle, msg, GET_UNALIGNED(msg->header.size)); if (ret < 0) { - log_error("Failed to send IPC msg to %u: %d\n", conn->vmid, ret); + log_error("Failed to send IPC msg to %u: %d", conn->vmid, ret); unlock(&conn->lock); remove_ipc_connection(conn); return ret; @@ -239,14 +239,14 @@ int ipc_send_message(IDTYPE dest, struct shim_ipc_msg* msg) { } static int wait_for_response(struct ipc_msg_waiter* waiter) { - log_debug("Waiting for a response to %lu\n", waiter->seq); + log_debug("Waiting for a response to %lu", waiter->seq); int ret = 0; do { ret = pal_to_unix_errno(DkEventWait(waiter->event, /*timeout=*/NULL)); } while (ret == -EINTR); - log_debug("Waiting finished: %d\n", ret); + log_debug("Waiting finished: %d", ret); return ret; } @@ -280,7 +280,7 @@ int ipc_send_msg_and_get_response(IDTYPE dest, struct shim_ipc_msg* msg, void** } if (!waiter.response_data) { - log_warning("IPC recipient %u died while we were waiting for a message response\n", dest); + log_warning("IPC recipient %u died while we were waiting for a message response", dest); ret = -ESRCH; } else { if (resp) { @@ -302,7 +302,7 @@ int ipc_send_msg_and_get_response(IDTYPE dest, struct shim_ipc_msg* msg, void** int ipc_response_callback(IDTYPE src, void* data, uint64_t seq) { int ret = 0; if (!seq) { - log_error("Got an IPC response without a sequence number\n"); + log_error("Got an IPC response without a sequence number"); ret = -EINVAL; goto out; } @@ -313,7 +313,7 @@ int ipc_response_callback(IDTYPE src, void* data, uint64_t seq) { }; struct avl_tree_node* node = avl_tree_find(&g_msg_waiters_tree, &dummy.node); if (!node) { - log_error("No thread is waiting for a response with seq: %lu\n", seq); + log_error("No thread is waiting for a response with seq: %lu", seq); ret = -EINVAL; goto out_unlock; } @@ -322,7 +322,7 @@ int ipc_response_callback(IDTYPE src, void* data, uint64_t seq) { waiter->response_data = data; DkEventSet(waiter->event); ret = 0; - log_debug("Got an IPC response from %u, seq: %lu\n", src, seq); + log_debug("Got an IPC response from %u, seq: %lu", src, seq); out_unlock: unlock(&g_msg_waiters_tree_lock); diff --git a/LibOS/shim/src/ipc/shim_ipc_child.c b/LibOS/shim/src/ipc/shim_ipc_child.c index bb130deec2..32dfb6eb12 100644 --- a/LibOS/shim/src/ipc/shim_ipc_child.c +++ b/LibOS/shim/src/ipc/shim_ipc_child.c @@ -19,9 +19,9 @@ void ipc_child_disconnect_callback(IDTYPE vmid) { * is not distinguishable from a genuine signal). */ if (mark_child_exited_by_vmid(vmid, /*uid=*/0, /*exit_code=*/0, SIGPWR)) { - log_error("Child process (vmid: 0x%x) got disconnected\n", vmid); + log_error("Child process (vmid: 0x%x) got disconnected", vmid); } else { - log_debug("Unknown process (vmid: 0x%x) disconnected\n", vmid); + log_debug("Unknown process (vmid: 0x%x) disconnected", vmid); } } @@ -57,13 +57,13 @@ int ipc_cld_exit_callback(IDTYPE src, void* data, uint64_t seq) { __UNUSED(seq); struct shim_ipc_cld_exit* msgin = (struct shim_ipc_cld_exit*)data; - log_debug("IPC callback from %u: IPC_MSG_CHILDEXIT(%u, %u, %d, %u)\n", src, - msgin->ppid, msgin->pid, msgin->exitcode, msgin->term_signal); + log_debug("IPC callback from %u: IPC_MSG_CHILDEXIT(%u, %u, %d, %u)", src, msgin->ppid, + msgin->pid, msgin->exitcode, msgin->term_signal); if (mark_child_exited_by_pid(msgin->pid, msgin->uid, msgin->exitcode, msgin->term_signal)) { - log_debug("Child process (pid: %u) died\n", msgin->pid); + log_debug("Child process (pid: %u) died", msgin->pid); } else { - log_error("Unknown process sent a child-death notification: pid: %d, vmid: %u\n", + log_error("Unknown process sent a child-death notification: pid: %d, vmid: %u", msgin->pid, src); return -EINVAL; } diff --git a/LibOS/shim/src/ipc/shim_ipc_pid.c b/LibOS/shim/src/ipc/shim_ipc_pid.c index 1c99a50b35..b4338c6345 100644 --- a/LibOS/shim/src/ipc/shim_ipc_pid.c +++ b/LibOS/shim/src/ipc/shim_ipc_pid.c @@ -149,12 +149,12 @@ static int change_id_owner(IDTYPE id, IDTYPE new_owner) { }; struct avl_tree_node* node = avl_tree_lower_bound(&g_id_owners_tree, &dummy.node); if (!node) { - log_debug("ID %u unknown!\n", id); + log_debug("ID %u unknown!", id); BUG(); } struct id_range* range = container_of(node, struct id_range, node); if (id < range->start || range->end < id) { - log_debug("ID %u unknown!\n", id); + log_debug("ID %u unknown!", id); BUG(); } @@ -198,7 +198,7 @@ static void release_id_range(IDTYPE start, IDTYPE end) { }; struct avl_tree_node* node = avl_tree_find(&g_id_owners_tree, &dummy.node); if (!node) { - log_debug("Releasing invalid ID range!\n"); + log_debug("Releasing invalid ID range!"); BUG(); } struct id_range* range = container_of(node, struct id_range, node); @@ -244,7 +244,7 @@ int ipc_alloc_id_range(IDTYPE* out_start, IDTYPE* out_end) { } init_ipc_msg(msg, IPC_MSG_ALLOC_ID_RANGE, msg_size); - log_debug("%s: sending a request\n", __func__); + log_debug("%s: sending a request", __func__); void* resp = NULL; int ret = ipc_send_msg_and_get_response(g_process_ipc_ids.leader_vmid, msg, &resp); @@ -261,7 +261,7 @@ int ipc_alloc_id_range(IDTYPE* out_start, IDTYPE* out_end) { ret = -EAGAIN; } - log_debug("%s: got a response: [%u..%u]\n", __func__, range->start, range->end); + log_debug("%s: got a response: [%u..%u]", __func__, range->start, range->end); out: free(resp); @@ -279,7 +279,7 @@ int ipc_alloc_id_range_callback(IDTYPE src, void* data, uint64_t seq) { end = 0; } - log_debug("%s: %d\n", __func__, ret); + log_debug("%s: %d", __func__, ret); struct ipc_id_range_msg range = { .start = start, @@ -311,10 +311,10 @@ int ipc_release_id_range(IDTYPE start, IDTYPE end) { init_ipc_msg(msg, IPC_MSG_RELEASE_ID_RANGE, msg_size); memcpy(&msg->data, &range, sizeof(range)); - log_debug("%s: sending a request: [%u..%u]\n", __func__, start, end); + log_debug("%s: sending a request: [%u..%u]", __func__, start, end); int ret = ipc_send_message(g_process_ipc_ids.leader_vmid, msg); - log_debug("%s: ipc_send_message: %d\n", __func__, ret); + log_debug("%s: ipc_send_message: %d", __func__, ret); free(msg); return ret; } @@ -324,7 +324,7 @@ int ipc_release_id_range_callback(IDTYPE src, void* data, uint64_t seq) { __UNUSED(seq); struct ipc_id_range_msg* range = data; release_id_range(range->start, range->end); - log_debug("%s: release_id_range(%u..%u)\n", __func__, range->start, range->end); + log_debug("%s: release_id_range(%u..%u)", __func__, range->start, range->end); return 0; } @@ -345,10 +345,10 @@ int ipc_change_id_owner(IDTYPE id, IDTYPE new_owner) { init_ipc_msg(msg, IPC_MSG_CHANGE_ID_OWNER, msg_size); memcpy(&msg->data, &owner_msg, sizeof(owner_msg)); - log_debug("%s: sending a request (%u..%u)\n", __func__, id, new_owner); + log_debug("%s: sending a request (%u..%u)", __func__, id, new_owner); int ret = ipc_send_msg_and_get_response(g_process_ipc_ids.leader_vmid, msg, /*resp=*/NULL); - log_debug("%s: ipc_send_msg_and_get_response: %d\n", __func__, ret); + log_debug("%s: ipc_send_msg_and_get_response: %d", __func__, ret); free(msg); return ret; } @@ -356,7 +356,7 @@ int ipc_change_id_owner(IDTYPE id, IDTYPE new_owner) { int ipc_change_id_owner_callback(IDTYPE src, void* data, uint64_t seq) { struct ipc_id_owner_msg* owner_msg = data; int ret = change_id_owner(owner_msg->id, owner_msg->owner); - log_debug("%s: change_id_owner(%u..%u): %d\n", __func__, owner_msg->id, owner_msg->owner, ret); + log_debug("%s: change_id_owner(%u..%u): %d", __func__, owner_msg->id, owner_msg->owner, ret); if (ret < 0) { return ret; } @@ -382,7 +382,7 @@ int ipc_get_id_owner(IDTYPE id, IDTYPE* out_owner) { init_ipc_msg(msg, IPC_MSG_GET_ID_OWNER, msg_size); memcpy(&msg->data, &id, sizeof(id)); - log_debug("%s: sending a request: %u\n", __func__, id); + log_debug("%s: sending a request: %u", __func__, id); void* resp = NULL; int ret = ipc_send_msg_and_get_response(g_process_ipc_ids.leader_vmid, msg, &resp); @@ -393,7 +393,7 @@ int ipc_get_id_owner(IDTYPE id, IDTYPE* out_owner) { *out_owner = *(IDTYPE*)resp; ret = 0; - log_debug("%s: got a response: %u\n", __func__, *out_owner); + log_debug("%s: got a response: %u", __func__, *out_owner); out: free(resp); @@ -404,7 +404,7 @@ int ipc_get_id_owner(IDTYPE id, IDTYPE* out_owner) { int ipc_get_id_owner_callback(IDTYPE src, void* data, uint64_t seq) { IDTYPE* id = data; IDTYPE owner = find_id_owner(*id); - log_debug("%s: find_id_owner(%u): %u\n", __func__, *id, owner); + log_debug("%s: find_id_owner(%u): %u", __func__, *id, owner); size_t msg_size = get_ipc_msg_size(sizeof(owner)); struct shim_ipc_msg* msg = __alloca(msg_size); diff --git a/LibOS/shim/src/ipc/shim_ipc_process_info.c b/LibOS/shim/src/ipc/shim_ipc_process_info.c index ba8c62e1d1..9a1cf01f45 100644 --- a/LibOS/shim/src/ipc/shim_ipc_process_info.c +++ b/LibOS/shim/src/ipc/shim_ipc_process_info.c @@ -44,7 +44,7 @@ int ipc_pid_getmeta(IDTYPE pid, enum pid_meta_code code, struct shim_ipc_pid_ret memcpy(&msg->data, &msgin, sizeof(msgin)); - log_debug("ipc send to %u: IPC_MSG_PID_GETMETA(%u, %s)\n", dest, pid, pid_meta_code_str[code]); + log_debug("ipc send to %u: IPC_MSG_PID_GETMETA(%u, %s)", dest, pid, pid_meta_code_str[code]); struct shim_ipc_pid_retmeta* resp = NULL; ret = ipc_send_msg_and_get_response(dest, msg, (void**)&resp); @@ -65,7 +65,7 @@ int ipc_pid_getmeta_callback(IDTYPE src, void* msg_data, uint64_t seq) { struct shim_ipc_pid_getmeta* msgin = (struct shim_ipc_pid_getmeta*)msg_data; int ret = 0; - log_debug("ipc callback from %u: IPC_MSG_PID_GETMETA(%u, %s)\n", src, msgin->pid, + log_debug("ipc callback from %u: IPC_MSG_PID_GETMETA(%u, %s)", src, msgin->pid, pid_meta_code_str[msgin->code]); struct shim_thread* thread = lookup_thread(msgin->pid); @@ -143,7 +143,7 @@ out_send:; memcpy(&msg->data, &retmeta, sizeof(retmeta)); memcpy(&((struct shim_ipc_pid_retmeta*)&msg->data)->data, data, datasize); - log_debug("IPC send to %u: shim_ipc_pid_retmeta{%lu, ...}\n", src, datasize); + log_debug("IPC send to %u: shim_ipc_pid_retmeta{%lu, ...}", src, datasize); ret = ipc_send_message(src, msg); diff --git a/LibOS/shim/src/ipc/shim_ipc_signal.c b/LibOS/shim/src/ipc/shim_ipc_signal.c index 8e0e28c0bc..a3bec31e8d 100644 --- a/LibOS/shim/src/ipc/shim_ipc_signal.c +++ b/LibOS/shim/src/ipc/shim_ipc_signal.c @@ -52,10 +52,10 @@ static int ipc_pid_kill_send(enum kill_type type, IDTYPE sender, IDTYPE dest_pid memcpy(&msg->data, &msgin, sizeof(msgin)); if (type == KILL_ALL && !g_process_ipc_ids.leader_vmid) { - log_debug("IPC broadcast: IPC_MSG_PID_KILL(%u, %d, %u, %d)\n", sender, type, dest_pid, sig); + log_debug("IPC broadcast: IPC_MSG_PID_KILL(%u, %d, %u, %d)", sender, type, dest_pid, sig); ret = ipc_broadcast(msg, /*exclude_id=*/0); } else { - log_debug("IPC send to %u: IPC_MSG_PID_KILL(%u, %d, %u, %d)\n", dest, sender, type, + log_debug("IPC send to %u: IPC_MSG_PID_KILL(%u, %d, %u, %d)", dest, sender, type, dest_pid, sig); void* resp = NULL; @@ -69,7 +69,7 @@ static int ipc_pid_kill_send(enum kill_type type, IDTYPE sender, IDTYPE dest_pid int wait_iter = 3; while (wait_iter--) { if (is_zombie_process(dest_pid)) { - log_debug("IPC send to terminated child process %u is dropped\n", dest_pid); + log_debug("IPC send to terminated child process %u is dropped", dest_pid); ret = 0; break; } else { @@ -108,7 +108,7 @@ int ipc_kill_all(IDTYPE sender, int sig) { int ipc_pid_kill_callback(IDTYPE src, void* data, uint64_t seq) { struct shim_ipc_pid_kill* msgin = (struct shim_ipc_pid_kill*)data; - log_debug("IPC callback from %u: IPC_MSG_PID_KILL(%u, %d, %u, %d)\n", src, msgin->sender, + log_debug("IPC callback from %u: IPC_MSG_PID_KILL(%u, %d, %u, %d)", src, msgin->sender, msgin->type, msgin->id, msgin->signum); int ret = 0; diff --git a/LibOS/shim/src/ipc/shim_ipc_sync.c b/LibOS/shim/src/ipc/shim_ipc_sync.c index 634ed027ac..79cb4e32d7 100644 --- a/LibOS/shim/src/ipc/shim_ipc_sync.c +++ b/LibOS/shim/src/ipc/shim_ipc_sync.c @@ -28,7 +28,7 @@ static const char* sync_message_names[IPC_MSG_CODE_BOUND] = { }; static inline void sync_log(const char* prefix, int code, uint64_t id, int state) { - log_trace("%s: %s(0x%lx, %s)\n", prefix, sync_message_names[code], id, sync_state_names[state]); + log_trace("%s: %s(0x%lx, %s)", prefix, sync_message_names[code], id, sync_state_names[state]); } static int sync_msg_send(IDTYPE dest, int code, uint64_t id, int state, size_t data_size, diff --git a/LibOS/shim/src/ipc/shim_ipc_worker.c b/LibOS/shim/src/ipc/shim_ipc_worker.c index 99a7b66e2f..0b24e8f8ef 100644 --- a/LibOS/shim/src/ipc/shim_ipc_worker.c +++ b/LibOS/shim/src/ipc/shim_ipc_worker.c @@ -66,7 +66,7 @@ static void ipc_leader_died_callback(void) { /* This might happen legitimately e.g. if IPC leader is also our parent and does `wait` + `exit` * If this is an erroneous disconnect it will be noticed when trying to communicate with * the leader. */ - log_debug("IPC leader disconnected\n"); + log_debug("IPC leader disconnected"); } static void disconnect_callbacks(struct shim_ipc_connection* conn) { @@ -139,7 +139,7 @@ static int receive_ipc_messages(struct shim_ipc_connection* conn) { continue; } ret = pal_to_unix_errno(ret); - log_error(LOG_PREFIX "receiving message header from %u failed: %d\n", conn->vmid, + log_error(LOG_PREFIX "receiving message header from %u failed: %d", conn->vmid, ret); return ret; } @@ -148,7 +148,7 @@ static int receive_ipc_messages(struct shim_ipc_connection* conn) { /* EOF on the handle, but exactly on the message boundary. */ return 1; } - log_error(LOG_PREFIX "receiving message from %u failed: remote closed early\n", + log_error(LOG_PREFIX "receiving message from %u failed: remote closed early", conn->vmid); return -ENODATA; } @@ -181,13 +181,13 @@ static int receive_ipc_messages(struct shim_ipc_connection* conn) { data_size - current_size); if (ret < 0) { free(msg_data); - log_error(LOG_PREFIX "receiving message from %u failed: %d\n", conn->vmid, ret); + log_error(LOG_PREFIX "receiving message from %u failed: %d", conn->vmid, ret); return ret; } size = 0; } - log_debug(LOG_PREFIX "received IPC message from %u: code=%d size=%lu seq=%lu\n", conn->vmid, + log_debug(LOG_PREFIX "received IPC message from %u: code=%d size=%lu seq=%lu", conn->vmid, msg_code, msg_size, msg_seq); int ret = 0; @@ -198,7 +198,7 @@ static int receive_ipc_messages(struct shim_ipc_connection* conn) { DkProcessExit(1); } } else { - log_error(LOG_PREFIX "received unknown IPC msg type: %u\n", msg_code); + log_error(LOG_PREFIX "received unknown IPC msg type: %u", msg_code); } if (msg_code != IPC_MSG_RESP) { @@ -234,7 +234,7 @@ static noreturn void ipc_worker_main(void) { events = malloc(items_cnt * sizeof(*events)); ret_events = malloc(items_cnt * sizeof(*ret_events)); if (!connections || !handles || !events || !ret_events) { - log_error(LOG_PREFIX "arrays allocation failed\n"); + log_error(LOG_PREFIX "arrays allocation failed"); goto out_die; } @@ -268,17 +268,17 @@ static noreturn void ipc_worker_main(void) { continue; } ret = pal_to_unix_errno(ret); - log_error(LOG_PREFIX "DkStreamsWaitEvents failed: %d\n", ret); + log_error(LOG_PREFIX "DkStreamsWaitEvents failed: %d", ret); goto out_die; } if (ret_events[0]) { /* `exit_notification_event`. */ if (ret_events[0] & ~PAL_WAIT_READ) { - log_error(LOG_PREFIX "unexpected event (%d) on exit handle\n", ret_events[0]); + log_error(LOG_PREFIX "unexpected event (%d) on exit handle", ret_events[0]); goto out_die; } - log_debug(LOG_PREFIX "exiting worker thread\n"); + log_debug(LOG_PREFIX "exiting worker thread"); free(connections); free(handles); @@ -298,25 +298,25 @@ static noreturn void ipc_worker_main(void) { if (ret_events[1]) { /* New connection incoming. */ if (ret_events[1] & ~PAL_WAIT_READ) { - log_error(LOG_PREFIX "unexpected event (%d) on listening handle\n", ret_events[1]); + log_error(LOG_PREFIX "unexpected event (%d) on listening handle", ret_events[1]); goto out_die; } PAL_HANDLE new_handle = NULL; ret = DkStreamWaitForClient(g_self_ipc_handle, &new_handle); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error(LOG_PREFIX "DkStreamWaitForClient failed: %d\n", ret); + log_error(LOG_PREFIX "DkStreamWaitForClient failed: %d", ret); goto out_die; } IDTYPE new_id = 0; ret = read_exact(new_handle, &new_id, sizeof(new_id)); if (ret < 0) { - log_error(LOG_PREFIX "receiving id failed: %d\n", ret); + log_error(LOG_PREFIX "receiving id failed: %d", ret); DkObjectClose(new_handle); } else { ret = add_ipc_connection(new_handle, new_id); if (ret < 0) { - log_error(LOG_PREFIX "add_ipc_connection failed: %d\n", ret); + log_error(LOG_PREFIX "add_ipc_connection failed: %d", ret); goto out_die; } } @@ -333,7 +333,7 @@ static noreturn void ipc_worker_main(void) { continue; } if (ret < 0) { - log_error(LOG_PREFIX "failed to receive an IPC message from %u: %d\n", + log_error(LOG_PREFIX "failed to receive an IPC message from %u: %d", conn->vmid, ret); /* Let the code below handle this error. */ ret_events[i] = PAL_WAIT_ERROR; @@ -361,7 +361,7 @@ static void ipc_worker_wrapper(void* arg) { log_setprefix(shim_get_tcb()); - log_debug("IPC worker started\n"); + log_debug("IPC worker started"); ipc_worker_main(); /* Unreachable. */ } diff --git a/LibOS/shim/src/shim_async.c b/LibOS/shim/src/shim_async.c index 40ff422602..b8056e65d0 100644 --- a/LibOS/shim/src/shim_async.c +++ b/LibOS/shim/src/shim_async.c @@ -117,7 +117,7 @@ int64_t install_async_event(PAL_HANDLE object, uint64_t time, unlock(&async_worker_lock); - log_debug("Installed async event at %lu\n", now); + log_debug("Installed async event at %lu", now); set_event(&install_new_event, 1); return max_prev_expire_time - now; } @@ -161,7 +161,7 @@ static void shim_async_worker(void* arg) { /* Assume async worker thread will not drain the stack that PAL provides, * so for efficiency we don't swap the stack. */ - log_debug("Async worker thread started\n"); + log_debug("Async worker thread started"); /* Simple heuristic to not burn cycles when no async events are installed: * async worker thread sleeps IDLE_SLEEP_TIME for MAX_IDLE_CYCLES and @@ -173,14 +173,14 @@ static void shim_async_worker(void* arg) { size_t pals_max_cnt = 32; PAL_HANDLE* pals = malloc(sizeof(*pals) * (1 + pals_max_cnt)); if (!pals) { - log_error("Allocation of pals failed\n"); + log_error("Allocation of pals failed"); goto out_err; } /* allocate one memory region to hold two PAL_FLG arrays: events and revents */ PAL_FLG* pal_events = malloc(sizeof(*pal_events) * (1 + pals_max_cnt) * 2); if (!pal_events) { - log_error("Allocation of pal_events failed\n"); + log_error("Allocation of pal_events failed"); goto out_err; } PAL_FLG* ret_events = pal_events + 1 + pals_max_cnt; @@ -195,7 +195,7 @@ static void shim_async_worker(void* arg) { int ret = DkSystemTimeQuery(&now); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("DkSystemTimeQuery failed with: %d\n", ret); + log_error("DkSystemTimeQuery failed with: %d", ret); goto out_err; } @@ -219,13 +219,13 @@ static void shim_async_worker(void* arg) { /* grow `pals` to accommodate more objects */ PAL_HANDLE* tmp_pals = malloc(sizeof(*tmp_pals) * (1 + pals_max_cnt * 2)); if (!tmp_pals) { - log_error("tmp_pals allocation failed\n"); + log_error("tmp_pals allocation failed"); goto out_err_unlock; } PAL_FLG* tmp_pal_events = malloc(sizeof(*tmp_pal_events) * (2 + pals_max_cnt * 4)); if (!tmp_pal_events) { - log_error("tmp_pal_events allocation failed\n"); + log_error("tmp_pal_events allocation failed"); goto out_err_unlock; } PAL_FLG* tmp_ret_events = tmp_pal_events + 1 + pals_max_cnt * 2; @@ -278,7 +278,7 @@ static void shim_async_worker(void* arg) { async_worker_state = WORKER_NOTALIVE; async_worker_thread = NULL; unlock(&async_worker_lock); - log_debug("Async worker thread has been idle for some time; stopping it\n"); + log_debug("Async worker thread has been idle for some time; stopping it"); break; } unlock(&async_worker_lock); @@ -287,7 +287,7 @@ static void shim_async_worker(void* arg) { ret = DkStreamsWaitEvents(pals_cnt + 1, pals, pal_events, ret_events, sleep_time); if (ret < 0 && ret != -PAL_ERROR_INTERRUPTED && ret != -PAL_ERROR_TRYAGAIN) { ret = pal_to_unix_errno(ret); - log_error("DkStreamsWaitEvents failed with: %d\n", ret); + log_error("DkStreamsWaitEvents failed with: %d", ret); goto out_err; } PAL_BOL polled = ret == 0; @@ -295,7 +295,7 @@ static void shim_async_worker(void* arg) { ret = DkSystemTimeQuery(&now); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("DkSystemTimeQuery failed with: %d\n", ret); + log_error("DkSystemTimeQuery failed with: %d", ret); goto out_err; } @@ -317,7 +317,7 @@ static void shim_async_worker(void* arg) { /* check if this event is an IO event found in async_list */ LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &async_list, list) { if (tmp->object == pals[i]) { - log_debug("Async IO event triggered at %lu\n", now); + log_debug("Async IO event triggered at %lu", now); LISTP_ADD_TAIL(tmp, &triggered, triggered_list); break; } @@ -328,11 +328,11 @@ static void shim_async_worker(void* arg) { /* check if exit-child or alarm/timer events were triggered */ LISTP_FOR_EACH_ENTRY_SAFE(tmp, n, &async_list, list) { if (tmp->callback == &cleanup_thread) { - log_debug("Thread exited, cleaning up\n"); + log_debug("Thread exited, cleaning up"); LISTP_DEL(tmp, &async_list, list); LISTP_ADD_TAIL(tmp, &triggered, triggered_list); } else if (tmp->expire_time && tmp->expire_time <= now) { - log_debug("Alarm/timer triggered at %lu (expired at %lu)\n", now, tmp->expire_time); + log_debug("Alarm/timer triggered at %lu (expired at %lu)", now, tmp->expire_time); LISTP_DEL(tmp, &async_list, list); LISTP_ADD_TAIL(tmp, &triggered, triggered_list); } @@ -354,7 +354,7 @@ static void shim_async_worker(void* arg) { } put_thread(self); - log_debug("Async worker thread terminated\n"); + log_debug("Async worker thread terminated"); free(pals); free(pal_events); @@ -365,7 +365,7 @@ static void shim_async_worker(void* arg) { out_err_unlock: unlock(&async_worker_lock); out_err: - log_error("Terminating the process due to a fatal error in async worker\n"); + log_error("Terminating the process due to a fatal error in async worker"); put_thread(self); DkProcessExit(1); } diff --git a/LibOS/shim/src/shim_checkpoint.c b/LibOS/shim/src/shim_checkpoint.c index 5ff9253328..b9c902ebde 100644 --- a/LibOS/shim/src/shim_checkpoint.c +++ b/LibOS/shim/src/shim_checkpoint.c @@ -305,7 +305,7 @@ static int receive_memory_on_stream(PAL_HANDLE handle, struct checkpoint_hdr* hd for (; entry; entry = entry->next) { CP_REBASE(entry->next); - log_debug("memory entry [%p]: %p-%p\n", entry, entry->addr, entry->addr + entry->size); + log_debug("memory entry [%p]: %p-%p", entry, entry->addr, entry->addr + entry->size); PAL_PTR addr = ALLOC_ALIGN_DOWN_PTR(entry->addr); PAL_NUM size = (char*)ALLOC_ALIGN_UP_PTR(entry->addr + entry->size) - (char*)addr; @@ -313,7 +313,7 @@ static int receive_memory_on_stream(PAL_HANDLE handle, struct checkpoint_hdr* hd int ret = DkVirtualMemoryAlloc(&addr, size, 0, prot | PAL_PROT_WRITE); if (ret < 0) { - log_error("failed allocating %p-%p\n", addr, addr + size); + log_error("failed allocating %p-%p", addr, addr + size); return pal_to_unix_errno(ret); } @@ -325,7 +325,7 @@ static int receive_memory_on_stream(PAL_HANDLE handle, struct checkpoint_hdr* hd if (!(prot & PAL_PROT_WRITE)) { ret = DkVirtualMemoryProtect(addr, size, prot); if (ret < 0) { - log_error("failed protecting %p-%p\n", addr, addr + size); + log_error("failed protecting %p-%p", addr, addr + size); return pal_to_unix_errno(ret); } } @@ -339,7 +339,7 @@ static int restore_checkpoint(struct checkpoint_hdr* hdr, uintptr_t base) { size_t cpoffset = hdr->offset; size_t* offset = &cpoffset; - log_debug("restoring checkpoint at 0x%08lx rebased from %p\n", base, hdr->addr); + log_debug("restoring checkpoint at 0x%08lx rebased from %p", base, hdr->addr); struct shim_cp_entry* cpent = NEXT_CP_ENTRY(); ssize_t rebase = base - (uintptr_t)hdr->addr; @@ -353,14 +353,14 @@ static int restore_checkpoint(struct checkpoint_hdr* hdr, uintptr_t base) { rs_func rs = __rs_func[cpent->cp_type - CP_FUNC_BASE]; int ret = (*rs)(cpent, base, offset, rebase); if (ret < 0) { - log_error("failed restoring checkpoint at %s (%d)\n", CP_FUNC_NAME(cpent->cp_type), + log_error("failed restoring checkpoint at %s (%d)", CP_FUNC_NAME(cpent->cp_type), ret); return ret; } cpent = NEXT_CP_ENTRY(); } - log_debug("successfully restored checkpoint at 0x%08lx - 0x%08lx\n", base, base + hdr->size); + log_debug("successfully restored checkpoint at 0x%08lx - 0x%08lx", base, base + hdr->size); return 0; } @@ -374,7 +374,7 @@ static int receive_handles_on_stream(struct checkpoint_hdr* hdr, void* base, ssi if (!entries_cnt) return 0; - log_debug("receiving %lu PAL handles\n", entries_cnt); + log_debug("receiving %lu PAL handles", entries_cnt); struct shim_palhdl_entry** entries = malloc(sizeof(*entries) * entries_cnt); @@ -413,7 +413,7 @@ static int receive_handles_on_stream(struct checkpoint_hdr* hdr, void* base, ssi static void* cp_alloc(void* addr, size_t size) { if (addr) { - log_debug("extending checkpoint store: %p-%p (size = %lu)\n", addr, addr + size, size); + log_debug("extending checkpoint store: %p-%p (size = %lu)", addr, addr + size, size); if (bkeep_mmap_fixed(addr, size, PROT_READ | PROT_WRITE, CP_MMAP_FLAGS | MAP_FIXED_NOREPLACE, NULL, 0, "cpstore") < 0) @@ -428,7 +428,7 @@ static void* cp_alloc(void* addr, size_t size) { * reserved space is half of the size of the checkpoint space. */ size_t reserve_size = ALLOC_ALIGN_UP(size >> 1); - log_debug("allocating checkpoint store (size = %ld, reserve = %ld)\n", size, reserve_size); + log_debug("allocating checkpoint store (size = %ld, reserve = %ld)", size, reserve_size); int ret = bkeep_mmap_any(size + reserve_size, PROT_READ | PROT_WRITE, CP_MMAP_FLAGS, NULL, 0, "cpstore", &addr); @@ -494,7 +494,7 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, if (!cpstore.base) { ret = -ENOMEM; - log_error("failed allocating enough memory for checkpoint\n"); + log_error("failed allocating enough memory for checkpoint"); goto out; } @@ -507,11 +507,11 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, ret = (*migrate_func)(&cpstore, process_description, thread_description, &process_ipc_ids, ap); va_end(ap); if (ret < 0) { - log_error("failed creating checkpoint (ret = %d)\n", ret); + log_error("failed creating checkpoint (ret = %d)", ret); goto out; } - log_debug("checkpoint of %lu bytes created\n", cpstore.offset); + log_debug("checkpoint of %lu bytes created", cpstore.offset); struct checkpoint_hdr hdr; memset(&hdr, 0, sizeof(hdr)); @@ -532,26 +532,26 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, /* send a checkpoint header to child process to notify it to start receiving checkpoint */ ret = write_exact(pal_process, &hdr, sizeof(hdr)); if (ret < 0) { - log_error("failed writing checkpoint header to child process (ret = %d)\n", ret); + log_error("failed writing checkpoint header to child process (ret = %d)", ret); goto out; } ret = send_checkpoint_on_stream(pal_process, &cpstore); if (ret < 0) { - log_error("failed sending checkpoint (ret = %d)\n", ret); + log_error("failed sending checkpoint (ret = %d)", ret); goto out; } ret = send_handles_on_stream(pal_process, &cpstore); if (ret < 0) { - log_error("failed sending PAL handles as part of checkpoint (ret = %d)\n", ret); + log_error("failed sending PAL handles as part of checkpoint (ret = %d)", ret); goto out; } void* tmp_vma = NULL; ret = bkeep_munmap((void*)cpstore.base, cpstore.bound, /*is_internal=*/true, &tmp_vma); if (ret < 0) { - log_error("failed unmaping checkpoint (ret = %d)\n", ret); + log_error("failed unmaping checkpoint (ret = %d)", ret); goto out; } if (DkVirtualMemoryFree((PAL_PTR)cpstore.base, cpstore.bound) < 0) { @@ -581,7 +581,7 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, * here and it should be indistinguishable form host OS killing the child process right * after we return from this function. */ - log_error("failed to send process creation ack to the child: %d\n", ret); + log_error("failed to send process creation ack to the child: %d", ret); (void)mark_child_exited_by_vmid(child_vmid, /*uid=*/0, /*exit_code=*/0, SIGPWR); } @@ -591,7 +591,7 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func, DkObjectClose(pal_process); if (ret < 0) { - log_error("process creation failed\n"); + log_error("process creation failed"); } return ret; @@ -639,19 +639,19 @@ int receive_checkpoint_and_restore(struct checkpoint_hdr* hdr) { return pal_to_unix_errno(ret); } - log_debug("checkpoint mapped at %p-%p\n", base, base + hdr->size); + log_debug("checkpoint mapped at %p-%p", base, base + hdr->size); ret = read_exact(g_pal_control->parent_process, base, hdr->size); if (ret < 0) { goto out_fail; } - log_debug("read checkpoint of %lu bytes from parent\n", hdr->size); + log_debug("read checkpoint of %lu bytes from parent", hdr->size); ret = receive_memory_on_stream(g_pal_control->parent_process, hdr, (uintptr_t)base); if (ret < 0) { goto out_fail; } - log_debug("restored memory from checkpoint\n"); + log_debug("restored memory from checkpoint"); /* if checkpoint is loaded at a different address in child from where it was created in parent, * need to rebase the pointers in the checkpoint */ diff --git a/LibOS/shim/src/shim_debug.c b/LibOS/shim/src/shim_debug.c index fe46e6fc6e..c336744f5d 100644 --- a/LibOS/shim/src/shim_debug.c +++ b/LibOS/shim/src/shim_debug.c @@ -71,7 +71,7 @@ void remove_r_debug(void* addr) { if (!m) return; - log_debug("removing a library for gdb: %s\n", m->l_name); + log_debug("removing a library for gdb: %s", m->l_name); if (m->l_prev) { m->l_prev->l_next = m->l_next; @@ -109,7 +109,7 @@ void append_r_debug(const char* uri, void* addr) { tail = &(*tail)->l_next; } - log_debug("adding a library for gdb: %s\n", uri); + log_debug("adding a library for gdb: %s", uri); new->l_prev = prev; new->l_next = NULL; diff --git a/LibOS/shim/src/shim_init.c b/LibOS/shim/src/shim_init.c index a528203e95..536e7b5a51 100644 --- a/LibOS/shim/src/shim_init.c +++ b/LibOS/shim/src/shim_init.c @@ -104,7 +104,7 @@ void* allocate_stack(size_t size, size_t protect_size, bool user) { size = ALLOC_ALIGN_UP(size); protect_size = ALLOC_ALIGN_UP(protect_size); - log_debug("Allocating stack at %p (size = %ld)\n", stack, size); + log_debug("Allocating stack at %p (size = %ld)", stack, size); if (!user) { stack = system_malloc(size + protect_size); @@ -292,7 +292,7 @@ int init_stack(const char** argv, const char** envp, const char*** out_argp, ret = toml_sizestring_in(g_manifest_root, "sys.stack.size", get_rlimit_cur(RLIMIT_STACK), &stack_size); if (ret < 0) { - log_error("Cannot parse \'sys.stack.size\' (the value must be put in double quotes!)\n"); + log_error("Cannot parse \'sys.stack.size\' (the value must be put in double quotes!)"); return -EINVAL; } @@ -366,7 +366,7 @@ static int read_environs(const char** envp) { do { \ int _err = CALL_INIT(func, ##__VA_ARGS__); \ if (_err < 0) { \ - log_error("Error during shim_init() in " #func " (%d)\n", _err); \ + log_error("Error during shim_init() in " #func " (%d)", _err); \ DkProcessExit(-_err); \ } \ } while (0) @@ -383,10 +383,10 @@ noreturn void* shim_init(int argc, void* args) { log_setprefix(shim_get_tcb()); - log_debug("Host: %s\n", g_pal_control->host_type); + log_debug("Host: %s", g_pal_control->host_type); if (!IS_POWER_OF_2(ALLOC_ALIGNMENT)) { - log_error("Error during shim_init(): PAL allocation alignment not a power of 2\n"); + log_error("Error during shim_init(): PAL allocation alignment not a power of 2"); DkProcessExit(EINVAL); } @@ -395,7 +395,7 @@ noreturn void* shim_init(int argc, void* args) { shim_xstate_init(); if (!create_lock(&__master_lock)) { - log_error("Error during shim_init(): failed to allocate __master_lock\n"); + log_error("Error during shim_init(): failed to allocate __master_lock"); DkProcessExit(ENOMEM); } @@ -411,14 +411,14 @@ noreturn void* shim_init(int argc, void* args) { RUN_INIT(init_dcache); RUN_INIT(init_handle); - log_debug("Shim loaded at %p, ready to initialize\n", &__load_address); + log_debug("Shim loaded at %p, ready to initialize", &__load_address); if (g_pal_control->parent_process) { struct checkpoint_hdr hdr; int ret = read_exact(g_pal_control->parent_process, &hdr, sizeof(hdr)); if (ret < 0) { - log_error("shim_init: failed to read the whole checkpoint header: %d\n", ret); + log_error("shim_init: failed to read the whole checkpoint header: %d", ret); DkProcessExit(1); } @@ -449,7 +449,7 @@ noreturn void* shim_init(int argc, void* args) { if (g_pal_control->parent_process) { int ret = connect_to_process(g_process_ipc_ids.parent_vmid); if (ret < 0) { - log_error("shim_init: failed to establish IPC connection to parent: %d\n", ret); + log_error("shim_init: failed to establish IPC connection to parent: %d", ret); DkProcessExit(1); } @@ -457,7 +457,7 @@ noreturn void* shim_init(int argc, void* args) { * this process, so that it's included in all broadcast messages. */ ret = ipc_change_id_owner(g_process.pid, g_self_vmid); if (ret < 0) { - log_debug("shim_init: failed to change child process PID ownership: %d\n", ret); + log_debug("shim_init: failed to change child process PID ownership: %d", ret); DkProcessExit(1); } @@ -465,7 +465,7 @@ noreturn void* shim_init(int argc, void* args) { IDTYPE child_vmid = g_self_vmid; ret = write_exact(g_pal_control->parent_process, &child_vmid, sizeof(child_vmid)); if (ret < 0) { - log_error("shim_init: failed to write child_vmid: %d\n", ret); + log_error("shim_init: failed to write child_vmid: %d", ret); DkProcessExit(1); } @@ -473,7 +473,7 @@ noreturn void* shim_init(int argc, void* args) { char dummy_c = 0; ret = read_exact(g_pal_control->parent_process, &dummy_c, sizeof(dummy_c)); if (ret < 0) { - log_error("shim_init: failed to read parent's confirmation: %d\n", ret); + log_error("shim_init: failed to read parent's confirmation: %d", ret); DkProcessExit(1); } } else { /* !g_pal_control->parent_process */ @@ -484,7 +484,7 @@ noreturn void* shim_init(int argc, void* args) { * communicates with server over a "loopback" IPC connection. */ RUN_INIT(init_sync_client); - log_debug("Shim process initialized\n"); + log_debug("Shim process initialized"); shim_tcb_t* cur_tcb = shim_get_tcb(); @@ -551,7 +551,7 @@ int create_pipe(char* name, char* uri, size_t size, PAL_HANDLE* hdl, struct shim return ret; } - log_debug("Creating pipe: " URI_PREFIX_PIPE_SRV "%s\n", pipename); + log_debug("Creating pipe: " URI_PREFIX_PIPE_SRV "%s", pipename); len = snprintf(uri, size, URI_PREFIX_PIPE_SRV "%s", pipename); if (len >= size) return -ERANGE; diff --git a/LibOS/shim/src/shim_malloc.c b/LibOS/shim/src/shim_malloc.c index d7000f42d0..92b1832a6e 100644 --- a/LibOS/shim/src/shim_malloc.c +++ b/LibOS/shim/src/shim_malloc.c @@ -44,7 +44,7 @@ void* __system_malloc(size_t size) { ret = DkVirtualMemoryAlloc(&addr, alloc_size, 0, PAL_PROT_WRITE | PAL_PROT_READ); if (ret < 0) { - log_error("failed to allocate memory (%ld)\n", pal_to_unix_errno(ret)); + log_error("failed to allocate memory (%ld)", pal_to_unix_errno(ret)); void* tmp_vma = NULL; if (bkeep_munmap(addr, alloc_size, /*is_internal=*/true, &tmp_vma) < 0) { BUG(); @@ -87,7 +87,7 @@ void* malloc(size_t size) { * If malloc() failed internally, we cannot handle the * condition and must terminate the current process. */ - log_error("Out-of-memory in library OS\n"); + log_error("Out-of-memory in library OS"); DkProcessExit(1); } diff --git a/LibOS/shim/src/shim_object.c b/LibOS/shim/src/shim_object.c index 90a6738362..6fd4f8c99f 100644 --- a/LibOS/shim/src/shim_object.c +++ b/LibOS/shim/src/shim_object.c @@ -9,7 +9,7 @@ int object_wait_with_retry(PAL_HANDLE handle) { if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("waiting on an object with retry failed (%d)\n", ret); + log_error("waiting on an object with retry failed (%d)", ret); return ret; } return 0; diff --git a/LibOS/shim/src/shim_parser.c b/LibOS/shim/src/shim_parser.c index 5424cc7cbf..750ad1b88b 100644 --- a/LibOS/shim/src/shim_parser.c +++ b/LibOS/shim/src/shim_parser.c @@ -1543,9 +1543,9 @@ static void print_syscall_name(struct print_buf* buf, const char* name, unsigned void warn_unsupported_syscall(unsigned long sysno) { if (sysno < ARRAY_SIZE(syscall_parser_table) && syscall_parser_table[sysno].name) - log_warning("Unsupported system call %s\n", syscall_parser_table[sysno].name); + log_warning("Unsupported system call %s", syscall_parser_table[sysno].name); else - log_warning("Unsupported system call %lu\n", sysno); + log_warning("Unsupported system call %lu", sysno); } static int buf_write_all(const char* str, size_t size, void* arg) { @@ -1554,7 +1554,7 @@ static int buf_write_all(const char* str, size_t size, void* arg) { /* Pass the buffer contents to log_trace(). Usually, that will be the whole message. However, if * the message is longer than the buffer, we will be called multiple times and the message will * be split across multiple log lines. */ - log_trace("%.*s\n", (int)size, str); + log_trace("%.*s", (int)size, str); return 0; } diff --git a/LibOS/shim/src/shim_rtld.c b/LibOS/shim/src/shim_rtld.c index 44a17d96fd..61fdbc25d2 100644 --- a/LibOS/shim/src/shim_rtld.c +++ b/LibOS/shim/src/shim_rtld.c @@ -131,22 +131,22 @@ static int read_loadcmd(const ElfW(Phdr)* ph, struct loadcmd* c) { if (ph->p_align > 1) { if (!IS_POWER_OF_2(ph->p_align)) { - log_debug("%s: ELF load command alignment value is not a power of 2\n", __func__); + log_debug("%s: ELF load command alignment value is not a power of 2", __func__); return -EINVAL; } if (!IS_ALIGNED_POW2(ph->p_vaddr - ph->p_offset, ph->p_align)) { - log_debug("%s: ELF load command address/offset not properly aligned\n", __func__); + log_debug("%s: ELF load command address/offset not properly aligned", __func__); return -EINVAL; } } if (!IS_ALLOC_ALIGNED(ph->p_vaddr - ph->p_offset)) { - log_debug("%s: ELF load command address/offset not page-aligned\n", __func__); + log_debug("%s: ELF load command address/offset not page-aligned", __func__); return -EINVAL; } if (ph->p_filesz > ph->p_memsz) { - log_debug("%s: file size larger than memory size\n", __func__); + log_debug("%s: file size larger than memory size", __func__); return -EINVAL; } @@ -183,7 +183,7 @@ static int read_all_loadcmds(const ElfW(Phdr)* phdr, size_t phnum, size_t* n_loa } if ((*loadcmds = malloc(n * sizeof(**loadcmds))) == NULL) { - log_debug("%s: failed to allocate memory\n", __func__); + log_debug("%s: failed to allocate memory", __func__); return -ENOMEM; } @@ -192,7 +192,7 @@ static int read_all_loadcmds(const ElfW(Phdr)* phdr, size_t phnum, size_t* n_loa for (ph = phdr; ph < &phdr[phnum]; ph++) { if (ph->p_type == PT_LOAD) { if (ph_prev && !(ph_prev->p_vaddr < ph->p_vaddr)) { - log_debug("%s: PT_LOAD segments are not in ascending order\n", __func__); + log_debug("%s: PT_LOAD segments are not in ascending order", __func__); ret = -EINVAL; goto err; } @@ -225,7 +225,7 @@ static int reserve_dyn(size_t total_size, void** addr) { if ((ret = bkeep_mmap_any_aslr(ALLOC_ALIGN_UP(total_size), PROT_NONE, VMA_UNMAPPED, /*file=*/NULL, /*offset=*/0, /*comment=*/NULL, addr) < 0)) { - log_debug("reserve_dyn: failed to find an address for shared object\n"); + log_debug("reserve_dyn: failed to find an address for shared object"); return ret; } @@ -252,13 +252,13 @@ static int execute_loadcmd(const struct loadcmd* c, ElfW(Addr) load_addr, if ((ret = bkeep_mmap_fixed(map_start, map_size, c->prot, map_flags, file, c->map_off, /*comment=*/NULL)) < 0) { - log_debug("%s: failed to bookkeep address of segment\n", __func__); + log_debug("%s: failed to bookkeep address of segment", __func__); return ret; } if ((ret = file->fs->fs_ops->mmap(file, &map_start, map_size, c->prot, map_flags, c->map_off) < 0)) { - log_debug("%s: failed to map segment\n", __func__); + log_debug("%s: failed to map segment", __func__); return ret; } } @@ -273,7 +273,7 @@ static int execute_loadcmd(const struct loadcmd* c, ElfW(Addr) load_addr, if ((c->prot & PROT_WRITE) == 0) { if ((ret = DkVirtualMemoryProtect(last_page_start, ALLOC_ALIGNMENT, pal_prot | PAL_PROT_WRITE) < 0)) { - log_debug("%s: cannot change memory protections\n", __func__); + log_debug("%s: cannot change memory protections", __func__); return pal_to_unix_errno(ret); } } @@ -282,7 +282,7 @@ static int execute_loadcmd(const struct loadcmd* c, ElfW(Addr) load_addr, if ((c->prot & PROT_WRITE) == 0) { if ((ret = DkVirtualMemoryProtect(last_page_start, ALLOC_ALIGNMENT, pal_prot) < 0)) { - log_debug("%s: cannot change memory protections\n", __func__); + log_debug("%s: cannot change memory protections", __func__); return pal_to_unix_errno(ret); } } @@ -297,13 +297,13 @@ static int execute_loadcmd(const struct loadcmd* c, ElfW(Addr) load_addr, if ((ret = bkeep_mmap_fixed(zero_page_start, zero_page_size, c->prot, zero_map_flags, /*file=*/NULL, /*offset=*/0, /*comment=*/NULL)) < 0) { - log_debug("%s: cannot bookkeep address of zero-fill pages\n", __func__); + log_debug("%s: cannot bookkeep address of zero-fill pages", __func__); return ret; } if ((ret = DkVirtualMemoryAlloc(&zero_page_start, zero_page_size, /*alloc_type=*/0, zero_pal_prot)) < 0) { - log_debug("%s: cannot map zero-fill pages\n", __func__); + log_debug("%s: cannot map zero-fill pages", __func__); return pal_to_unix_errno(ret); } } @@ -467,7 +467,7 @@ static struct link_map* __map_elf_object(struct shim_handle* file, ElfW(Ehdr)* e return l; err: - log_debug("loading %s: %s (%d)\n", l->l_name, errstring, ret); + log_debug("loading %s: %s (%d)", l->l_name, errstring, ret); free(phdr); free(loadcmds); free(l); @@ -569,7 +569,7 @@ static int __check_elf_header(ElfW(Ehdr)* ehdr) { /* check if the type of ELF header is either DYN or EXEC */ if (ehdr->e_type != ET_DYN && ehdr->e_type != ET_EXEC) { - errstring = "only ET_DYN and ET_EXEC can be loaded\n"; + errstring = "only ET_DYN and ET_EXEC can be loaded"; goto verify_failed; } @@ -582,7 +582,7 @@ static int __check_elf_header(ElfW(Ehdr)* ehdr) { return 0; verify_failed: - log_debug("load runtime object: %s\n", errstring); + log_debug("load runtime object: %s", errstring); return -EINVAL; } @@ -639,7 +639,7 @@ int load_elf_object(struct shim_handle* file) { if (!file) return -EINVAL; - log_debug("loading \"%s\"\n", file ? qstrgetstr(&file->uri) : "(unknown)"); + log_debug("loading \"%s\"", file ? qstrgetstr(&file->uri) : "(unknown)"); return __load_elf_object(file); } @@ -731,7 +731,7 @@ static int __load_interp_object(struct link_map* exec_map) { interp_path[plen] = '/'; memcpy(interp_path + plen + 1, filename, len + 1); - log_debug("searching for interpreter: %s\n", interp_path); + log_debug("searching for interpreter: %s", interp_path); struct shim_dentry* dent = NULL; int ret = 0; @@ -869,7 +869,7 @@ int init_loader(void) { dentry_abs_path(exec->dentry, &path, /*size=*/NULL); log_error("Failed to load %s. This may be caused by the binary being non-PIE, in which " "case Graphene requires a specially-crafted memory layout. You can enable it " - "by adding 'sgx.nonpie_binary = true' to the manifest.\n", + "by adding 'sgx.nonpie_binary = true' to the manifest.", path ? path : "(unknown)"); free(path); goto out; @@ -901,7 +901,7 @@ int init_brk_from_executable(struct shim_handle* exec) { } int register_library(const char* name, unsigned long load_address) { - log_debug("glibc register library %s loaded at 0x%08lx\n", name, load_address); + log_debug("glibc register library %s loaded at 0x%08lx", name, load_address); struct shim_handle* hdl = get_new_handle(); @@ -922,7 +922,7 @@ int register_library(const char* name, unsigned long load_address) { noreturn void execute_elf_object(struct shim_handle* exec, void* argp, ElfW(auxv_t)* auxp) { int ret = vdso_map_init(); if (ret < 0) { - log_error("Could not initialize vDSO (error code = %d)\n", ret); + log_error("Could not initialize vDSO (error code = %d)", ret); process_exit(/*error_code=*/0, /*term_signal=*/SIGKILL); } @@ -978,7 +978,7 @@ noreturn void execute_elf_object(struct shim_handle* exec, void* argp, ElfW(auxv ElfW(Addr) random = auxp_extra; /* random 16B for AT_RANDOM */ ret = DkRandomBitsRead((PAL_PTR)random, 16); if (ret < 0) { - log_error("execute_elf_object: DkRandomBitsRead failed: %d\n", ret); + log_error("execute_elf_object: DkRandomBitsRead failed: %d", ret); DkProcessExit(1); /* UNREACHABLE */ } diff --git a/LibOS/shim/src/sync/shim_sync_client.c b/LibOS/shim/src/sync/shim_sync_client.c index e1296433b3..60f274ae0d 100644 --- a/LibOS/shim/src/sync/shim_sync_client.c +++ b/LibOS/shim/src/sync/shim_sync_client.c @@ -47,7 +47,7 @@ static void get_sync_handle(struct sync_handle* handle) { static void put_sync_handle(struct sync_handle* handle) { if (!REF_DEC(handle->ref_count)) { - log_trace("sync client: destroying handle: 0x%lx\n", handle->id); + log_trace("sync client: destroying handle: 0x%lx", handle->id); free(handle->data); destroy_lock(&handle->use_lock); destroy_lock(&handle->prop_lock); @@ -64,7 +64,7 @@ static uint64_t sync_new_id(void) { lock_client(); uint64_t id = ((uint64_t)pid << 32) + g_client_counter++; if (g_client_counter == 0) - FATAL("g_client_counter wrapped around\n"); + FATAL("g_client_counter wrapped around"); unlock_client(); return id; } @@ -77,7 +77,7 @@ static void sync_wait_without_lock(struct sync_handle* handle) { handle->n_waiters++; unlock(&handle->prop_lock); if (object_wait_with_retry(handle->event) < 0) - FATAL("waiting for event\n"); + FATAL("waiting for event"); lock(&handle->prop_lock); if (--handle->n_waiters == 0) DkEventClear(handle->event); @@ -104,7 +104,7 @@ static void sync_downgrade(struct sync_handle* handle) { } if (ipc_sync_client_send(IPC_MSG_SYNC_CONFIRM_DOWNGRADE, handle->id, handle->server_req_state, data_size, handle->data) < 0) - FATAL("sending CONFIRM_DOWNGRADE\n"); + FATAL("sending CONFIRM_DOWNGRADE"); handle->cur_state = handle->server_req_state; handle->server_req_state = SYNC_STATE_NONE; } @@ -117,7 +117,7 @@ static void update_handle_data(struct sync_handle* handle, size_t data_size, voi free(handle->data); handle->data_size = data_size; if (!(handle->data = malloc(handle->data_size))) - FATAL("Cannot allocate data for handle\n"); + FATAL("Cannot allocate data for handle"); } memcpy(handle->data, data, data_size); } @@ -131,11 +131,11 @@ int init_sync_client(void) { int ret = toml_bool_in(g_manifest_root, "libos.sync.enable", /*defaultval=*/false, &sync_enable); if (ret < 0) { - log_error("Cannot parse 'libos.sync.enable' (the value must be `true` or `false`)\n"); + log_error("Cannot parse 'libos.sync.enable' (the value must be `true` or `false`)"); return -EINVAL; } if (sync_enable) { - log_debug("Enabling sync client\n"); + log_debug("Enabling sync client"); g_sync_enabled = true; } return 0; @@ -242,7 +242,7 @@ void sync_destroy(struct sync_handle* handle) { if (g_sync_enabled && handle->phase == SYNC_PHASE_OPEN) { if (send_request_close(handle) < 0) - FATAL("sending REQUEST_CLOSE\n"); + FATAL("sending REQUEST_CLOSE"); handle->phase = SYNC_PHASE_CLOSING; handle->cur_state = SYNC_STATE_INVALID; do { @@ -277,12 +277,12 @@ bool sync_lock(struct sync_handle* handle, int state, void* data, size_t data_si if (handle->cur_state < state) { do { if (handle->phase == SYNC_PHASE_CLOSING || handle->phase == SYNC_PHASE_CLOSED) - FATAL("sync_lock() on a closed handle\n"); + FATAL("sync_lock() on a closed handle"); if (handle->client_req_state < state) { if (ipc_sync_client_send(IPC_MSG_SYNC_REQUEST_UPGRADE, handle->id, state, /*data_size=*/0, /*data=*/NULL) < 0) - FATAL("sending REQUEST_UPGRADE\n"); + FATAL("sending REQUEST_UPGRADE"); handle->client_req_state = state; handle->phase = SYNC_PHASE_OPEN; } @@ -291,7 +291,7 @@ bool sync_lock(struct sync_handle* handle, int state, void* data, size_t data_si if (data_size > 0 && handle->data_size > 0) { if (data_size != handle->data_size) - FATAL("handle data size mismatch\n"); + FATAL("handle data size mismatch"); memcpy(data, handle->data, data_size); updated = true; @@ -327,14 +327,14 @@ int shutdown_sync_client(void) { /* Send REQUEST_CLOSE for all open handles. At this point, no threads using the sync engine * should be running (except for the IPC helper), so no handles will be created or upgraded. */ - log_debug("sync client shutdown: closing handles\n"); + log_debug("sync client shutdown: closing handles"); struct sync_handle* handle; struct sync_handle* tmp; HASH_ITER(hh, g_client_handles, handle, tmp) { lock(&handle->prop_lock); if (g_sync_enabled && handle->phase == SYNC_PHASE_OPEN) { if (send_request_close(handle) < 0) - FATAL("sending REQUEST_CLOSE\n"); + FATAL("sending REQUEST_CLOSE"); handle->phase = SYNC_PHASE_CLOSING; handle->cur_state = SYNC_STATE_INVALID; } @@ -342,7 +342,7 @@ int shutdown_sync_client(void) { } /* Wait for server to confirm the handles are closed. */ - log_debug("sync client shutdown: waiting for confirmation\n"); + log_debug("sync client shutdown: waiting for confirmation"); HASH_ITER(hh, g_client_handles, handle, tmp) { unlock_client(); lock(&handle->prop_lock); @@ -355,7 +355,7 @@ int shutdown_sync_client(void) { } unlock_client(); - log_debug("sync client shutdown: finished\n"); + log_debug("sync client shutdown: finished"); return 0; } @@ -367,7 +367,7 @@ static struct sync_handle* find_handle(uint64_t id) { HASH_FIND(hh, g_client_handles, &id, sizeof(id), handle); if (!handle) - FATAL("message for unknown handle\n"); + FATAL("message for unknown handle"); get_sync_handle(handle); unlock_client(); @@ -435,7 +435,7 @@ void sync_client_message_callback(int code, uint64_t id, int state, size_t data_ do_confirm_close(id); break; default: - FATAL("unknown message: %d\n", code); + FATAL("unknown message: %d", code); } } diff --git a/LibOS/shim/src/sync/shim_sync_server.c b/LibOS/shim/src/sync/shim_sync_server.c index 46732d08a2..e2ca7859a5 100644 --- a/LibOS/shim/src/sync/shim_sync_server.c +++ b/LibOS/shim/src/sync/shim_sync_server.c @@ -364,13 +364,13 @@ static void do_request_close(IDTYPE vmid, uint64_t id, int cur_state, size_t dat free(lease); if (LISTP_EMPTY(&client->leases)) { - log_trace("sync server: deleting unused client: %d\n", client->vmid); + log_trace("sync server: deleting unused client: %d", client->vmid); HASH_DELETE(hh, g_server_clients, client); free(client); } if (LISTP_EMPTY(&handle->leases)) { - log_trace("sync server: deleting unused handle: 0x%lx\n", handle->id); + log_trace("sync server: deleting unused handle: 0x%lx", handle->id); HASH_DELETE(hh, g_server_handles, handle); free(handle->data); free(handle); diff --git a/LibOS/shim/src/sys/shim_alarm.c b/LibOS/shim/src/sys/shim_alarm.c index 4d7a43cc01..d78e294cfb 100644 --- a/LibOS/shim/src/sys/shim_alarm.c +++ b/LibOS/shim/src/sys/shim_alarm.c @@ -23,7 +23,7 @@ static void signal_alarm(IDTYPE caller, void* arg) { .si_code = SI_USER, }; if (kill_current_proc(&info) < 0) { - log_warning("signal_alarm: failed to deliver a signal\n"); + log_warning("signal_alarm: failed to deliver a signal"); } } diff --git a/LibOS/shim/src/sys/shim_brk.c b/LibOS/shim/src/sys/shim_brk.c index 60995d7383..fe0731c7e3 100644 --- a/LibOS/shim/src/sys/shim_brk.c +++ b/LibOS/shim/src/sys/shim_brk.c @@ -31,7 +31,7 @@ int init_brk_region(void* brk_start, size_t data_segment_size) { int ret; if (!create_lock(&brk_lock)) { - log_error("Creating brk_lock failed!\n"); + log_error("Creating brk_lock failed!"); return -ENOMEM; } @@ -48,16 +48,16 @@ int init_brk_region(void* brk_start, size_t data_segment_size) { ret = toml_sizestring_in(g_manifest_root, "sys.brk.max_size", DEFAULT_BRK_MAX_SIZE, &brk_max_size); if (ret < 0) { - log_error("Cannot parse \'sys.brk.max_size\' (the value must be put in double quotes!)\n"); + log_error("Cannot parse \'sys.brk.max_size\' (the value must be put in double quotes!)"); return -EINVAL; } if (brk_start && !IS_ALLOC_ALIGNED_PTR(brk_start)) { - log_error("Starting brk address is not aligned!\n"); + log_error("Starting brk address is not aligned!"); return -EINVAL; } if (!IS_ALLOC_ALIGNED(brk_max_size)) { - log_error("Max brk size is not aligned!\n"); + log_error("Max brk size is not aligned!"); return -EINVAL; } diff --git a/LibOS/shim/src/sys/shim_clone.c b/LibOS/shim/src/sys/shim_clone.c index a5028c07d5..ea411ebf07 100644 --- a/LibOS/shim/src/sys/shim_clone.c +++ b/LibOS/shim/src/sys/shim_clone.c @@ -248,7 +248,7 @@ long shim_do_clone(unsigned long flags, unsigned long user_stack_addr, int* pare CSIGNAL; if (flags & ~supported_flags) { - log_warning("clone called with unsupported flags argument.\n"); + log_warning("clone called with unsupported flags argument."); return -EINVAL; } @@ -268,7 +268,7 @@ long shim_do_clone(unsigned long flags, unsigned long user_stack_addr, int* pare * explicitly disallowed for now. */ if (flags & CLONE_VM) { if (!((flags & CLONE_THREAD) || (flags & CLONE_VFORK))) { - log_warning("CLONE_VM without either CLONE_THREAD or CLONE_VFORK is unsupported\n"); + log_warning("CLONE_VM without either CLONE_THREAD or CLONE_VFORK is unsupported"); return -EINVAL; } } @@ -279,7 +279,7 @@ long shim_do_clone(unsigned long flags, unsigned long user_stack_addr, int* pare * assume that performance hit is negligible (Graphene has to migrate internal state anyway * which is slow) and apps do not rely on insane Linux-specific semantics of vfork(). */ log_warning("vfork was called by the application, implemented as an alias to fork in " - "Graphene\n"); + "Graphene"); flags &= ~(CLONE_VFORK | CLONE_VM); } @@ -335,7 +335,7 @@ long shim_do_clone(unsigned long flags, unsigned long user_stack_addr, int* pare IDTYPE tid = get_new_id(/*remove_from_owned=*/clone_new_process); if (!tid) { - log_error("Could not allocate a tid!\n"); + log_error("Could not allocate a tid!"); ret = -EAGAIN; goto failed; } @@ -359,14 +359,14 @@ long shim_do_clone(unsigned long flags, unsigned long user_stack_addr, int* pare * a part of one)... */ int tmp_ret = ipc_change_id_owner(tid, g_self_vmid); if (tmp_ret < 0) { - log_debug("Failed to change back ID %u owner: %d\n", tid, tmp_ret); + log_debug("Failed to change back ID %u owner: %d", tid, tmp_ret); /* No way to recover gracefully. */ DkProcessExit(1); } /* ... and release it. */ tmp_ret = ipc_release_id_range(tid, tid); if (tmp_ret < 0) { - log_debug("Failed to release ID %u: %d\n", tid, tmp_ret); + log_debug("Failed to release ID %u: %d", tid, tmp_ret); /* No way to recover gracefully. */ DkProcessExit(1); } diff --git a/LibOS/shim/src/sys/shim_epoll.c b/LibOS/shim/src/sys/shim_epoll.c index ebc74274b7..666e973f9a 100644 --- a/LibOS/shim/src/sys/shim_epoll.c +++ b/LibOS/shim/src/sys/shim_epoll.c @@ -197,7 +197,7 @@ long shim_do_epoll_ctl(int epfd, int op, int fd, struct __kernel_epoll_event* ev goto out; } - log_debug("add fd %d (handle %p) to epoll handle %p\n", fd, hdl, epoll); + log_debug("add fd %d (handle %p) to epoll handle %p", fd, hdl, epoll); epoll_item->fd = fd; epoll_item->events = event->events; epoll_item->data = event->data; @@ -240,7 +240,7 @@ long shim_do_epoll_ctl(int epfd, int op, int fd, struct __kernel_epoll_event* ev __atomic_store_n(&handle->needs_et_poll_out, true, __ATOMIC_RELEASE); } - log_debug("modified fd %d at epoll handle %p\n", fd, epoll); + log_debug("modified fd %d at epoll handle %p", fd, epoll); notify_epoll_waiters(epoll); goto out; } @@ -254,7 +254,7 @@ long shim_do_epoll_ctl(int epfd, int op, int fd, struct __kernel_epoll_event* ev LISTP_FOR_EACH_ENTRY(epoll_item, &epoll->fds, list) { if (epoll_item->fd == fd) { struct shim_handle* hdl = epoll_item->handle; - log_debug("delete fd %d (handle %p) from epoll handle %p\n", fd, hdl, epoll); + log_debug("delete fd %d (handle %p) from epoll handle %p", fd, hdl, epoll); /* unregister hdl (corresponding to FD) in epoll (corresponding to EPFD): * - unbind hdl from epoll-item via the `back` list @@ -512,7 +512,7 @@ BEGIN_CP_FUNC(epoll_item) { LISTP_TYPE(shim_epoll_item)* new_list = (LISTP_TYPE(shim_epoll_item)*)objp; struct shim_epoll_item* epoll_item; - log_debug("checkpoint epoll: %p -> %p (base = 0x%08lx)\n", old_list, new_list, base); + log_debug("checkpoint epoll: %p -> %p (base = 0x%08lx)", old_list, new_list, base); INIT_LISTP(new_list); diff --git a/LibOS/shim/src/sys/shim_eventfd.c b/LibOS/shim/src/sys/shim_eventfd.c index 898c9adca4..47ebf7244f 100644 --- a/LibOS/shim/src/sys/shim_eventfd.c +++ b/LibOS/shim/src/sys/shim_eventfd.c @@ -28,7 +28,7 @@ static int create_eventfd(PAL_HANDLE* efd, unsigned count, int flags) { &allow_eventfd); if (ret < 0) { log_error("Cannot parse \'sys.insecure__allow_eventfd\' (the value must be `true` or " - "`false`)\n"); + "`false`)"); return -ENOSYS; } @@ -48,7 +48,7 @@ static int create_eventfd(PAL_HANDLE* efd, unsigned count, int flags) { * argument. Using create arg as a work-around (note: initval is uint32 but create is int32). */ ret = DkStreamOpen(URI_PREFIX_EVENTFD, 0, 0, count, pal_flags, &hdl); if (ret < 0) { - log_error("eventfd open failure\n"); + log_error("eventfd open failure"); return pal_to_unix_errno(ret); } diff --git a/LibOS/shim/src/sys/shim_exec.c b/LibOS/shim/src/sys/shim_exec.c index 45122cdabd..d1e9f99c28 100644 --- a/LibOS/shim/src/sys/shim_exec.c +++ b/LibOS/shim/src/sys/shim_exec.c @@ -94,13 +94,13 @@ noreturn static void __shim_do_execve_rtld(struct execve_rtld_arg* __arg) { cur_thread->robust_list = NULL; - log_debug("execve: start execution\n"); + log_debug("execve: start execution"); /* Passing ownership of `exec` to `execute_elf_object`. */ execute_elf_object(exec, arg.new_argp, arg.new_auxv); /* NOTREACHED */ error: - log_error("execve failed with errno=%d\n", ret); + log_error("execve failed with errno=%d", ret); process_exit(/*error_code=*/0, /*term_signal=*/SIGKILL); } @@ -183,7 +183,7 @@ long shim_do_execve(const char* file, const char** argv, const char** envp) { /* TODO: consider handling shebangs, if necessary */ if ((ret = check_elf_object(exec)) < 0) { - log_warning("file not recognized as ELF\n"); + log_warning("file not recognized as ELF"); put_handle(exec); return ret; } diff --git a/LibOS/shim/src/sys/shim_exit.c b/LibOS/shim/src/sys/shim_exit.c index 9a648bcbfe..1e9db3c7a2 100644 --- a/LibOS/shim/src/sys/shim_exit.c +++ b/LibOS/shim/src/sys/shim_exit.c @@ -55,7 +55,7 @@ static noreturn void libos_clean_and_exit(int exit_code) { terminate_ipc_worker(); - log_debug("process %u exited with status %d\n", g_self_vmid, exit_code); + log_debug("process %u exited with status %d", g_self_vmid, exit_code); /* TODO: We exit whole libos, but there are some objects that might need cleanup, e.g. we should * release this (last) thread pid. We should do a proper cleanup of everything. */ @@ -82,7 +82,7 @@ noreturn void thread_exit(int error_code, int term_signal) { if (ret < 0) { log_error("failed to set up async cleanup_thread (exiting without clear child tid)," - " return code: %ld\n", ret); + " return code: %ld", ret); /* `cleanup_thread` did not get this reference, clean it. We have to be careful, as * this is most likely the last reference and will free this `cur_thread`. */ put_thread(cur_thread); @@ -97,7 +97,7 @@ noreturn void thread_exit(int error_code, int term_signal) { /* This is the last thread of the process. Let parent know we exited. */ int ret = ipc_cld_exit_send(error_code, term_signal); if (ret < 0) { - log_error("Sending IPC process-exit notification failed: %d\n", ret); + log_error("Sending IPC process-exit notification failed: %d", ret); } /* At this point other threads might be still in the middle of an exit routine, but we don't @@ -165,7 +165,7 @@ long shim_do_exit_group(int error_code) { error_code &= 0xFF; - log_debug("---- shim_exit_group (returning %d)\n", error_code); + log_debug("---- shim_exit_group (returning %d)", error_code); process_exit(error_code, 0); } @@ -175,7 +175,7 @@ long shim_do_exit(int error_code) { error_code &= 0xFF; - log_debug("---- shim_exit (returning %d)\n", error_code); + log_debug("---- shim_exit (returning %d)", error_code); thread_exit(error_code, 0); } diff --git a/LibOS/shim/src/sys/shim_file.c b/LibOS/shim/src/sys/shim_file.c index 87dff29e12..6a89c717eb 100644 --- a/LibOS/shim/src/sys/shim_file.c +++ b/LibOS/shim/src/sys/shim_file.c @@ -338,7 +338,7 @@ static ssize_t handle_copy(struct shim_handle* hdli, off_t* offseti, struct shim if (!do_mapi && (hdli->flags & O_NONBLOCK) && fsi->fs_ops->setflags) { int ret = fsi->fs_ops->setflags(hdli, 0); if (!ret) { - log_debug("mark handle %s as blocking\n", qstrgetstr(&hdli->uri)); + log_debug("mark handle %s as blocking", qstrgetstr(&hdli->uri)); do_marki = true; } } @@ -346,7 +346,7 @@ static ssize_t handle_copy(struct shim_handle* hdli, off_t* offseti, struct shim if (!do_mapo && (hdlo->flags & O_NONBLOCK) && fso->fs_ops->setflags) { int ret = fso->fs_ops->setflags(hdlo, 0); if (!ret) { - log_debug("mark handle %s as blocking\n", qstrgetstr(&hdlo->uri)); + log_debug("mark handle %s as blocking", qstrgetstr(&hdlo->uri)); do_marko = true; } } @@ -371,7 +371,7 @@ static ssize_t handle_copy(struct shim_handle* hdli, off_t* offseti, struct shim if ((hdli->flags & O_NONBLOCK) && fsi->fs_ops->setflags) { int ret = fsi->fs_ops->setflags(hdli, 0); if (!ret) { - log_debug("mark handle %s as blocking\n", qstrgetstr(&hdli->uri)); + log_debug("mark handle %s as blocking", qstrgetstr(&hdli->uri)); do_marki = true; } } @@ -392,7 +392,7 @@ static ssize_t handle_copy(struct shim_handle* hdli, off_t* offseti, struct shim if ((hdlo->flags & O_NONBLOCK) && fso->fs_ops->setflags) { int ret = fso->fs_ops->setflags(hdlo, 0); if (!ret) { - log_debug("mark handle %s as blocking\n", qstrgetstr(&hdlo->uri)); + log_debug("mark handle %s as blocking", qstrgetstr(&hdlo->uri)); do_marko = true; } } @@ -449,7 +449,7 @@ static ssize_t handle_copy(struct shim_handle* hdli, off_t* offseti, struct shim break; } - log_debug("copy %d bytes\n", copysize); + log_debug("copy %d bytes", copysize); bytes += copysize; offi += copysize; offo += copysize; @@ -471,12 +471,12 @@ static ssize_t handle_copy(struct shim_handle* hdli, off_t* offseti, struct shim } if (do_marki && (hdli->flags & O_NONBLOCK)) { - log_debug("mark handle %s as nonblocking\n", qstrgetstr(&hdli->uri)); + log_debug("mark handle %s as nonblocking", qstrgetstr(&hdli->uri)); fsi->fs_ops->setflags(hdli, O_NONBLOCK); } if (do_marko && (hdlo->flags & O_NONBLOCK)) { - log_debug("mark handle %s as nonblocking\n", qstrgetstr(&hdlo->uri)); + log_debug("mark handle %s as nonblocking", qstrgetstr(&hdlo->uri)); fso->fs_ops->setflags(hdlo, O_NONBLOCK); } diff --git a/LibOS/shim/src/sys/shim_futex.c b/LibOS/shim/src/sys/shim_futex.c index 31da06d2be..129a5d4eff 100644 --- a/LibOS/shim/src/sys/shim_futex.c +++ b/LibOS/shim/src/sys/shim_futex.c @@ -748,12 +748,11 @@ static int _shim_do_futex(uint32_t* uaddr, int op, uint32_t val, void* utime, ui return -ENOSYS; } /* Graphene has only one clock for now. */ - log_warning("Ignoring FUTEX_CLOCK_REALTIME flag\n"); + log_warning("Ignoring FUTEX_CLOCK_REALTIME flag"); } if (!(op & FUTEX_PRIVATE_FLAG)) { - log_warning("Non-private futexes are not supported, assuming implicit " - "FUTEX_PRIVATE_FLAG\n"); + log_warning("Non-private futexes are not supported, assuming implicit FUTEX_PRIVATE_FLAG"); } int ret = 0; @@ -798,10 +797,10 @@ static int _shim_do_futex(uint32_t* uaddr, int op, uint32_t val, void* utime, ui case FUTEX_UNLOCK_PI: case FUTEX_CMP_REQUEUE_PI: case FUTEX_WAIT_REQUEUE_PI: - log_warning("PI futexes are not yet supported!\n"); + log_warning("PI futexes are not yet supported!"); return -ENOSYS; default: - log_warning("Invalid futex op: %d\n", cmd); + log_warning("Invalid futex op: %d", cmd); return -ENOSYS; } } diff --git a/LibOS/shim/src/sys/shim_getcwd.c b/LibOS/shim/src/sys/shim_getcwd.c index 1ce0f9eddb..62ae970a1a 100644 --- a/LibOS/shim/src/sys/shim_getcwd.c +++ b/LibOS/shim/src/sys/shim_getcwd.c @@ -90,7 +90,7 @@ long shim_do_fchdir(int fd) { if (!(dent->state & DENTRY_ISDIRECTORY)) { char* path = NULL; dentry_abs_path(dent, &path, /*size=*/NULL); - log_debug("%s is not a directory\n", path); + log_debug("%s is not a directory", path); free(path); put_handle(hdl); return -ENOTDIR; diff --git a/LibOS/shim/src/sys/shim_ioctl.c b/LibOS/shim/src/sys/shim_ioctl.c index afab997605..4d1f2b175e 100644 --- a/LibOS/shim/src/sys/shim_ioctl.c +++ b/LibOS/shim/src/sys/shim_ioctl.c @@ -25,7 +25,7 @@ static void signal_io(IDTYPE caller, void* arg) { .si_fd = 0, }; if (kill_current_proc(&info) < 0) { - log_warning("signal_io: failed to deliver a signal\n"); + log_warning("signal_io: failed to deliver a signal"); } } diff --git a/LibOS/shim/src/sys/shim_mmap.c b/LibOS/shim/src/sys/shim_mmap.c index 59c744eee9..f3dc99e40e 100644 --- a/LibOS/shim/src/sys/shim_mmap.c +++ b/LibOS/shim/src/sys/shim_mmap.c @@ -177,7 +177,7 @@ void* shim_do_mmap(void* addr, size_t length, int prot, int flags, int fd, unsig void* ret_addr = addr; ret = hdl->fs->fs_ops->mmap(hdl, &ret_addr, length, prot, flags, offset); if (ret_addr != addr) { - log_error("Requested address (%p) differs from allocated (%p)!\n", addr, ret_addr); + log_error("Requested address (%p) differs from allocated (%p)!", addr, ret_addr); BUG(); } } @@ -185,9 +185,8 @@ void* shim_do_mmap(void* addr, size_t length, int prot, int flags, int fd, unsig if (ret < 0) { void* tmp_vma = NULL; if (bkeep_munmap(addr, length, /*is_internal=*/false, &tmp_vma) < 0) { - log_error( - "[mmap] Failed to remove bookkeeped memory that was not allocated at %p-%p!\n", - addr, (char*)addr + length); + log_error("[mmap] Failed to remove bookkeeped memory that was not allocated at %p-%p!", + addr, (char*)addr + length); BUG(); } bkeep_remove_tmp_vma(tmp_vma); @@ -254,7 +253,7 @@ long shim_do_mprotect(void* addr, size_t length, int prot) { } } else { log_warning("Memory that was about to be mprotected was unmapped, your program is " - "buggy!\n"); + "buggy!"); return -ENOTRECOVERABLE; } } @@ -320,7 +319,7 @@ long shim_do_mincore(void* addr, size_t len, unsigned char* vec) { if (!warned) { warned = true; log_warning( - "mincore emulation always tells pages are _NOT_ in RAM. This may cause issues.\n"); + "mincore emulation always tells pages are _NOT_ in RAM. This may cause issues."); } /* There is no good way to know if the page is in RAM. @@ -441,7 +440,7 @@ long shim_do_msync(unsigned long start, size_t len_orig, int flags) { } if (flags != MS_ASYNC) { - log_warning("Graphene does not support flags to msync other than MS_ASYNC\n"); + log_warning("Graphene does not support flags to msync other than MS_ASYNC"); return -ENOSYS; } diff --git a/LibOS/shim/src/sys/shim_pipe.c b/LibOS/shim/src/sys/shim_pipe.c index 9419848970..ff86f209aa 100644 --- a/LibOS/shim/src/sys/shim_pipe.c +++ b/LibOS/shim/src/sys/shim_pipe.c @@ -31,21 +31,21 @@ static int create_pipes(struct shim_handle* srv, struct shim_handle* cli, int fl if ((ret = create_pipe(name, uri, PIPE_URI_SIZE, &hdl0, qstr, /*use_vmid_for_name=*/false)) < 0) { - log_error("pipe creation failure\n"); + log_error("pipe creation failure"); return ret; } ret = DkStreamOpen(uri, 0, 0, 0, LINUX_OPEN_FLAGS_TO_PAL_OPTIONS(flags), &hdl2); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("pipe connection failure\n"); + log_error("pipe connection failure"); goto out; } ret = DkStreamWaitForClient(hdl0, &hdl1); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("pipe acceptance failure\n"); + log_error("pipe acceptance failure"); goto out; } @@ -89,7 +89,7 @@ long shim_do_pipe2(int* filedes, int flags) { int ret = 0; if (flags & O_DIRECT) { - log_warning("shim_do_pipe2(): ignoring not supported O_DIRECT flag\n"); + log_warning("shim_do_pipe2(): ignoring not supported O_DIRECT flag"); flags &= ~O_DIRECT; } diff --git a/LibOS/shim/src/sys/shim_sched.c b/LibOS/shim/src/sys/shim_sched.c index cdf24c69ef..8f7338747b 100644 --- a/LibOS/shim/src/sys/shim_sched.c +++ b/LibOS/shim/src/sys/shim_sched.c @@ -185,7 +185,7 @@ long shim_do_sched_getaffinity(pid_t pid, unsigned int cpumask_size, unsigned lo * to sizeof(long) */ size_t bitmask_size_in_bytes = BITS_TO_LONGS(cpu_cnt) * sizeof(long); if (cpumask_size < bitmask_size_in_bytes) { - log_warning("size of cpumask must be at least %lu but supplied cpumask is %u\n", + log_warning("size of cpumask must be at least %lu but supplied cpumask is %u", bitmask_size_in_bytes, cpumask_size); return -EINVAL; } diff --git a/LibOS/shim/src/sys/shim_sigaction.c b/LibOS/shim/src/sys/shim_sigaction.c index d7f4a78e93..cd22dc82aa 100644 --- a/LibOS/shim/src/sys/shim_sigaction.c +++ b/LibOS/shim/src/sys/shim_sigaction.c @@ -43,7 +43,7 @@ long shim_do_rt_sigaction(int signum, const struct __kernel_sigaction* act, if (act && !(act->sa_flags & SA_RESTORER)) { /* XXX: This might not be true for all architectures (but is for x86_64)... * Check `shim_signal.c` if you update this! */ - log_warning("rt_sigaction: SA_RESTORER flag is required!\n"); + log_warning("rt_sigaction: SA_RESTORER flag is required!"); return -EINVAL; } diff --git a/LibOS/shim/src/sys/shim_sleep.c b/LibOS/shim/src/sys/shim_sleep.c index effc2b79c5..591be3e471 100644 --- a/LibOS/shim/src/sys/shim_sleep.c +++ b/LibOS/shim/src/sys/shim_sleep.c @@ -89,7 +89,7 @@ long shim_do_clock_nanosleep(clockid_t clock_id, int flags, struct __kernel_time ret = DkSystemTimeQuery(¤t_time); if (ret < 0) { ret = pal_to_unix_errno(ret); - log_error("clock_nanosleep: DkSystemTimeQuery failed with: %d\n", ret); + log_error("clock_nanosleep: DkSystemTimeQuery failed with: %d", ret); die_or_inf_loop(); } if (timeout_us <= current_time) { diff --git a/LibOS/shim/src/sys/shim_socket.c b/LibOS/shim/src/sys/shim_socket.c index cb2f3b4f40..6ff93b1027 100644 --- a/LibOS/shim/src/sys/shim_socket.c +++ b/LibOS/shim/src/sys/shim_socket.c @@ -88,7 +88,7 @@ long shim_do_socket(int family, int type, int protocol) { break; default: - log_warning("shim_socket: unknown socket domain %d\n", sock->domain); + log_warning("shim_socket: unknown socket domain %d", sock->domain); goto err; } @@ -100,7 +100,7 @@ long shim_do_socket(int family, int type, int protocol) { break; default: - log_warning("shim_socket: unknown socket type %d\n", sock->sock_type); + log_warning("shim_socket: unknown socket type %d", sock->sock_type); goto err; } @@ -291,7 +291,7 @@ static int unix_copy_addr(struct sockaddr* saddr, struct shim_dentry* dent) { return ret; if (size > ARRAY_SIZE(un->sun_path)) { - log_warning("unix_copy_addr(): path too long, truncating: %s\n", path); + log_warning("unix_copy_addr(): path too long, truncating: %s", path); memcpy(un->sun_path, path, ARRAY_SIZE(un->sun_path) - 1); un->sun_path[ARRAY_SIZE(un->sun_path) - 1] = 0; } else { @@ -460,7 +460,7 @@ long shim_do_bind(int sockfd, struct sockaddr* addr, int _addrlen) { enum shim_sock_state state = sock->sock_state; if (state != SOCK_CREATED) { - log_debug("shim_bind: bind on a bound socket\n"); + log_debug("shim_bind: bind on a bound socket"); goto out; } @@ -510,7 +510,7 @@ long shim_do_bind(int sockfd, struct sockaddr* addr, int _addrlen) { if (ret < 0) { ret = (ret == -PAL_ERROR_STREAMEXIST) ? -EADDRINUSE : pal_to_unix_errno(ret); - log_error("bind: invalid handle returned\n"); + log_error("bind: invalid handle returned"); goto out; } @@ -648,7 +648,7 @@ long shim_do_listen(int sockfd, int backlog) { struct shim_sock_handle* sock = &hdl->info.sock; if (sock->sock_type != SOCK_STREAM) { - log_warning("shim_listen: not a stream socket\n"); + log_warning("shim_listen: not a stream socket"); put_handle(hdl); return -EINVAL; } @@ -659,7 +659,7 @@ long shim_do_listen(int sockfd, int backlog) { int ret = -EINVAL; if (state != SOCK_BOUND && state != SOCK_LISTENED) { - log_warning("shim_listen: listen on unbound socket\n"); + log_warning("shim_listen: listen on unbound socket"); goto out; } @@ -717,18 +717,18 @@ long shim_do_connect(int sockfd, struct sockaddr* addr, int _addrlen) { hdl->pal_handle = NULL; pal_handle_updated = true; } - log_debug("shim_connect: reconnect on a stream socket\n"); + log_debug("shim_connect: reconnect on a stream socket"); ret = 0; goto out; } - log_debug("shim_connect: reconnect on a stream socket\n"); + log_debug("shim_connect: reconnect on a stream socket"); ret = -EISCONN; goto out; } if (state != SOCK_BOUND && state != SOCK_CREATED) { - log_warning("shim_connect: connect on invalid socket\n"); + log_warning("shim_connect: connect on invalid socket"); goto out; } @@ -857,7 +857,7 @@ static int __do_accept(struct shim_handle* hdl, int flags, struct sockaddr* addr PAL_HANDLE accepted = NULL; if (sock->sock_type != SOCK_STREAM) { - log_warning("shim_accept: not a stream socket\n"); + log_warning("shim_accept: not a stream socket"); return -EOPNOTSUPP; } @@ -876,7 +876,7 @@ static int __do_accept(struct shim_handle* hdl, int flags, struct sockaddr* addr PAL_HANDLE handle = hdl->pal_handle; if (sock->sock_state != SOCK_LISTENED) { - log_warning("shim_accept: invalid socket\n"); + log_warning("shim_accept: invalid socket"); ret = -EINVAL; goto out; } @@ -895,7 +895,7 @@ static int __do_accept(struct shim_handle* hdl, int flags, struct sockaddr* addr assert(hdl->pal_handle == handle); if (sock->sock_state != SOCK_LISTENED) { - log_debug("shim_accept: socket changed while waiting for a client connection\n"); + log_debug("shim_accept: socket changed while waiting for a client connection"); ret = -ECONNABORTED; goto out; } @@ -1031,7 +1031,7 @@ static ssize_t do_sendmsg(int fd, struct iovec* bufs, int nbufs, int flags, if (flags & ~(MSG_NOSIGNAL | MSG_DONTWAIT)) { log_warning("sendmsg()/sendmmsg()/sendto(): unknown flag (only MSG_NOSIGNAL and " - "MSG_DONTWAIT are supported).\n"); + "MSG_DONTWAIT are supported)."); ret = -EOPNOTSUPP; goto out; } @@ -1050,7 +1050,7 @@ static ssize_t do_sendmsg(int fd, struct iovec* bufs, int nbufs, int flags, if (flags & MSG_DONTWAIT) { if (!(hdl->flags & O_NONBLOCK)) { log_warning("MSG_DONTWAIT on blocking socket is ignored, may lead to a write that " - "unexpectedly blocks.\n"); + "unexpectedly blocks."); } flags &= ~MSG_DONTWAIT; } @@ -1116,7 +1116,7 @@ static ssize_t do_sendmsg(int fd, struct iovec* bufs, int nbufs, int flags, goto out_locked; } - log_debug("next packet send to %s\n", uri); + log_debug("next packet send to %s", uri); } int bytes = 0; @@ -1135,7 +1135,7 @@ static ssize_t do_sendmsg(int fd, struct iovec* bufs, int nbufs, int flags, .si_code = SI_USER, }; if (kill_current_proc(&info) < 0) { - log_error("do_sendmsg: failed to deliver a signal\n"); + log_error("do_sendmsg: failed to deliver a signal"); } } break; @@ -1287,7 +1287,7 @@ static ssize_t do_recvmsg(int fd, struct iovec* bufs, size_t nbufs, int flags, if (flags & ~(MSG_PEEK | MSG_DONTWAIT | MSG_WAITALL)) { log_warning("recvmsg()/recvmmsg()/recvfrom(): unknown flag (only MSG_PEEK, MSG_DONTWAIT and" - " MSG_WAITALL are supported).\n"); + " MSG_WAITALL are supported)."); ret = -EOPNOTSUPP; goto out; } @@ -1296,14 +1296,14 @@ static ssize_t do_recvmsg(int fd, struct iovec* bufs, size_t nbufs, int flags, if (flags & MSG_WAITALL) { log_warning("recvmsg()/recvmmsg()/recvfrom(): MSG_WAITALL is ignored, may lead to a read" - " that returns less data.\n"); + " that returns less data."); flags &= ~MSG_WAITALL; } if (flags & MSG_DONTWAIT) { if (!(hdl->flags & O_NONBLOCK)) { log_warning("MSG_DONTWAIT on blocking socket is ignored, may lead to a read that " - "unexpectedly blocks.\n"); + "unexpectedly blocks."); } flags &= ~MSG_DONTWAIT; } @@ -1434,7 +1434,7 @@ static ssize_t do_recvmsg(int fd, struct iovec* bufs, size_t nbufs, int flags, goto out_locked; } - log_debug("last packet received from %s\n", uri); + log_debug("last packet received from %s", uri); inet_rebase_port(true, sock->domain, &conn, false); *addrlen = inet_copy_addr(sock->domain, addr, *addrlen, &conn); @@ -1562,7 +1562,7 @@ long shim_do_recvmmsg(int sockfd, struct mmsghdr* msg, unsigned int vlen, int fl // Issue # 753 - https://github.com/oscarlab/graphene/issues/753 /* TODO(donporter): timeout properly. For now, explicitly return an error. */ if (timeout) { - log_warning("recvmmsg(): timeout parameter unsupported.\n"); + log_warning("recvmmsg(): timeout parameter unsupported."); return -EOPNOTSUPP; } diff --git a/LibOS/shim/src/sys/shim_stat.c b/LibOS/shim/src/sys/shim_stat.c index eb030f523e..683a2c9b87 100644 --- a/LibOS/shim/src/sys/shim_stat.c +++ b/LibOS/shim/src/sys/shim_stat.c @@ -160,7 +160,7 @@ static int __do_statfs(struct shim_mount* mount, struct statfs* buf) { buf->f_bfree = 10000000; buf->f_bavail = 10000000; - log_debug("statfs: %ld %ld %ld\n", buf->f_blocks, buf->f_bfree, buf->f_bavail); + log_debug("statfs: %ld %ld %ld", buf->f_blocks, buf->f_bfree, buf->f_bavail); return 0; } diff --git a/LibOS/shim/src/sys/shim_wait.c b/LibOS/shim/src/sys/shim_wait.c index de90eba8fa..c070004128 100644 --- a/LibOS/shim/src/sys/shim_wait.c +++ b/LibOS/shim/src/sys/shim_wait.c @@ -90,7 +90,7 @@ static void remove_qnode_from_wait_queue(struct shim_thread_queue* qnode) { int ret = thread_wait(/*timeout_us=*/NULL, /*ignore_pending_signals=*/true); if (ret < 0 && ret != -EINTR) { /* We cannot handle any errors here. */ - log_error("remove_qnode_from_wait_queue: thread_wait failed with: %d\n", ret); + log_error("remove_qnode_from_wait_queue: thread_wait failed with: %d", ret); } } } else { @@ -104,17 +104,17 @@ static long do_waitid(int which, pid_t id, siginfo_t* infop, int options) { } if (options & WSTOPPED) { - log_warning("Ignoring unsupported WSTOPPED flag to wait4\n"); + log_warning("Ignoring unsupported WSTOPPED flag to wait4"); options &= ~WSTOPPED; } if (options & WCONTINUED) { - log_warning("Ignoring unsupported WCONTINUED flag to wait4\n"); + log_warning("Ignoring unsupported WCONTINUED flag to wait4"); options &= ~WCONTINUED; } assert(options & WEXITED); if (options & __WNOTHREAD) { - log_warning("Ignoring unsupported __WNOTHREAD flag to wait4\n"); + log_warning("Ignoring unsupported __WNOTHREAD flag to wait4"); options &= ~__WNOTHREAD; } @@ -195,7 +195,7 @@ static long do_waitid(int which, pid_t id, siginfo_t* infop, int options) { } ret = thread_wait(/*timeout_us=*/NULL, /*ignore_pending_signals=*/false); if (ret < 0 && ret != -EINTR) { - log_warning("thread_wait failed in waitid\n"); + log_warning("thread_wait failed in waitid"); remove_qnode_from_wait_queue(&qnode); /* `ret` is already set. */ goto out; diff --git a/LibOS/shim/src/utils/log.c b/LibOS/shim/src/utils/log.c index 98e8f3d4e8..64b421b5b8 100644 --- a/LibOS/shim/src/utils/log.c +++ b/LibOS/shim/src/utils/log.c @@ -93,6 +93,7 @@ void shim_log(int level, const char* fmt, ...) { va_start(ap, fmt); buf_vprintf(&buf, fmt, ap); va_end(ap); + buf_printf(&buf, "\n"); buf_flush(&buf); } diff --git a/Pal/include/arch/x86_64/dl-machine.h b/Pal/include/arch/x86_64/dl-machine.h index 1646f7443c..70536d671f 100644 --- a/Pal/include/arch/x86_64/dl-machine.h +++ b/Pal/include/arch/x86_64/dl-machine.h @@ -34,11 +34,11 @@ static void elf_machine_rela(struct link_map* l, Elf64_Rela* reloc, Elf64_Sym* s #define debug_reloc(r_type) \ do { \ if (strtab && sym && sym->st_name) \ - log_debug("%p " #r_type ": %s %p\n", reloc_addr, strtab + sym->st_name, value); \ + log_debug("%p " #r_type ": %s %p", reloc_addr, strtab + sym->st_name, value); \ else if (value) \ - log_debug("%p " #r_type ": %p\n", reloc_addr, value); \ + log_debug("%p " #r_type ": %p", reloc_addr, value); \ else \ - log_debug("%p " #r_type "\n", reloc_addr, value); \ + log_debug("%p " #r_type, reloc_addr, value); \ } while (0) #else #define debug_reloc(...) \ diff --git a/Pal/include/pal_internal.h b/Pal/include/pal_internal.h index 87f7380aee..5ea01095ba 100644 --- a/Pal/include/pal_internal.h +++ b/Pal/include/pal_internal.h @@ -234,7 +234,7 @@ int _DkSetProtectedFilesKey(PAL_PTR pf_key_hex); #define INIT_FAIL(exitcode, reason) \ do { \ - log_error("PAL failed at " __FILE__ ":%s:%u (exitcode = %u, reason=%s)\n", __FUNCTION__, \ + log_error("PAL failed at " __FILE__ ":%s:%u (exitcode = %u, reason=%s)", __FUNCTION__, \ (unsigned int)__LINE__, (unsigned int)(exitcode), reason); \ _DkProcessExit(exitcode); \ } while (0) @@ -243,7 +243,7 @@ int _DkSetProtectedFilesKey(PAL_PTR pf_key_hex); do { \ log_error("PAL failed at parsing the manifest: %s\n" \ " Graphene switched to the TOML format recently, please update the manifest\n"\ - " (in particular, string values must be put in double quotes)\n", reason); \ + " (in particular, string values must be put in double quotes)", reason); \ _DkProcessExit(exitcode); \ } while (0) @@ -282,7 +282,7 @@ void pal_log(int level, const char* fmt, ...) __attribute__((format(printf, 2, 3 #define uthash_fatal(msg) \ do { \ - log_error("uthash error: %s\n", msg); \ + log_error("uthash error: %s", msg); \ _DkProcessExit(PAL_ERROR_NOMEM); \ } while (0) #include "uthash.h" diff --git a/Pal/regression/utils.c b/Pal/regression/utils.c index 0b13e1e2a5..5b621ac5da 100644 --- a/Pal/regression/utils.c +++ b/Pal/regression/utils.c @@ -9,16 +9,18 @@ static int buf_write_all(const char* str, size_t size, void* arg) { return 0; } -static void log_vprintf(const char* fmt, va_list ap) { +static void log_vprintf(const char* fmt, va_list ap, bool append_newline) { struct print_buf buf = INIT_PRINT_BUF(buf_write_all); buf_vprintf(&buf, fmt, ap); + if (append_newline) + buf_printf(&buf, "\n"); buf_flush(&buf); } void pal_printf(const char* fmt, ...) { va_list ap; va_start(ap, fmt); - log_vprintf(fmt, ap); + log_vprintf(fmt, ap, /*append_newline=*/false); va_end(ap); } @@ -29,7 +31,7 @@ void _log(int level, const char* fmt, ...) { (void)level; /* PAL regression always prints log messages */ va_list ap; va_start(ap, fmt); - log_vprintf(fmt, ap); + log_vprintf(fmt, ap, /*append_newline=*/true); va_end(ap); } diff --git a/Pal/src/db_main.c b/Pal/src/db_main.c index ead04c8eb5..d11f226231 100644 --- a/Pal/src/db_main.c +++ b/Pal/src/db_main.c @@ -295,7 +295,7 @@ noreturn void pal_main(PAL_NUM instance_id, /* current instance id */ /*defaultval=*/false, &disable_aslr); if (ret < 0) { INIT_FAIL_MANIFEST(PAL_ERROR_DENIED, "Cannot parse 'loader.insecure__disable_aslr' " - "(the value must be `true` or `false`)\n"); + "(the value must be `true` or `false`)"); } /* Load argv */ @@ -326,14 +326,14 @@ noreturn void pal_main(PAL_NUM instance_id, /* current instance id */ /*defaultval=*/false, &use_cmdline_argv); if (ret < 0) { INIT_FAIL_MANIFEST(PAL_ERROR_DENIED, "Cannot parse 'loader.insecure__use_cmdline_argv' " - "(the value must be `true` or `false`)\n"); + "(the value must be `true` or `false`)"); } if (use_cmdline_argv) { /* Warn only in the first process. */ if (!parent_process) { log_error("Using insecure argv source. Graphene will continue application execution, " - "but this configuration must not be used in production!\n"); + "but this configuration must not be used in production!"); } } else { char* argv_src_file = NULL; @@ -347,7 +347,7 @@ noreturn void pal_main(PAL_NUM instance_id, /* current instance id */ * be achieved using protected or trusted files). */ if (arguments[0] && arguments[1]) log_error("Discarding cmdline arguments (%s %s [...]) because loader.argv_src_file " - "was specified in the manifest.\n", arguments[0], arguments[1]); + "was specified in the manifest.", arguments[0], arguments[1]); ret = load_cstring_array(argv_src_file, &arguments); if (ret < 0) @@ -365,7 +365,7 @@ noreturn void pal_main(PAL_NUM instance_id, /* current instance id */ /*defaultval=*/false, &use_host_env); if (ret < 0) { INIT_FAIL_MANIFEST(PAL_ERROR_DENIED, "Cannot parse 'loader.insecure__use_host_env' " - "(the value must be `true` or `false`)\n"); + "(the value must be `true` or `false`)"); } if (use_host_env) { @@ -373,7 +373,7 @@ noreturn void pal_main(PAL_NUM instance_id, /* current instance id */ if (!parent_process) { log_error("Forwarding host environment variables to the app is enabled. Graphene will " "continue application execution, but this configuration must not be used in " - "production!\n"); + "production!"); } } else { environments = malloc(sizeof(*environments)); @@ -417,7 +417,7 @@ noreturn void pal_main(PAL_NUM instance_id, /* current instance id */ INIT_FAIL_MANIFEST(PAL_ERROR_INVAL, "Cannot parse 'pal.entrypoint'"); if (entrypoint) { if (!strstartswith(entrypoint, URI_PREFIX_FILE)) - INIT_FAIL(PAL_ERROR_INVAL, "'pal.entrypoint' is missing 'file:' prefix\n"); + INIT_FAIL(PAL_ERROR_INVAL, "'pal.entrypoint' is missing 'file:' prefix"); } g_pal_control.host_type = XSTRINGIFY(HOST_TYPE); diff --git a/Pal/src/db_rtld.c b/Pal/src/db_rtld.c index a0c037ce1b..f3ae0e239d 100644 --- a/Pal/src/db_rtld.c +++ b/Pal/src/db_rtld.c @@ -24,7 +24,7 @@ struct link_map* lookup_symbol(const char* undef_name, ElfW(Sym)** ref); /* err - positive or negative value of error code */ static inline void print_error(const char* msg, int err) { - log_error("%s (%s)\n", msg, pal_strerror(err)); + log_error("%s (%s)", msg, pal_strerror(err)); } /* This macro is used as a callback from the ELF_DYNAMIC_RELOCATE code. */ @@ -539,7 +539,7 @@ int load_elf_object_by_handle(PAL_HANDLE handle, enum object_type type, void** o if (phdr && phdr_malloced) free(phdr); - log_error("%s\n", errstring); + log_error("%s", errstring); return ret; } diff --git a/Pal/src/host/Linux-SGX/db_exception.c b/Pal/src/host/Linux-SGX/db_exception.c index 7d7065a97a..412b9cd146 100644 --- a/Pal/src/host/Linux-SGX/db_exception.c +++ b/Pal/src/host/Linux-SGX/db_exception.c @@ -115,13 +115,13 @@ static void emulate_rdtsc_and_print_warning(sgx_cpu_context_t* uc) { extern uint64_t g_tsc_hz; g_tsc_hz = 0; log_warning("all RDTSC/RDTSCP instructions are emulated (imprecisely) via gettime() " - "syscall.\n"); + "syscall."); } uint64_t usec; int res = _DkSystemTimeQuery(&usec); if (res < 0) { - log_error("_DkSystemTimeQuery() failed in unrecoverable context, exiting.\n"); + log_error("_DkSystemTimeQuery() failed in unrecoverable context, exiting."); _DkProcessExit(1); } /* FIXME: Ideally, we would like to scale microseconds back to RDTSC clock cycles */ @@ -160,13 +160,13 @@ static bool handle_ud(sgx_cpu_context_t* uc) { /* A disabled {RD,WR}{FS,GS}BASE instruction generated a #UD */ log_error( "{RD,WR}{FS,GS}BASE instructions are not permitted on this platform. Please check the " - "instructions under \"Building with SGX support\" from Graphene documentation.\n"); + "instructions under \"Building with SGX support\" from Graphene documentation."); return false; } else if (instr[0] == 0x0f && instr[1] == 0x05) { /* syscall: LibOS may know how to handle this */ return false; } - log_error("Unknown or illegal instruction at RIP 0x%016lx\n", uc->rip); + log_error("Unknown or illegal instruction at RIP 0x%016lx", uc->rip); return false; } @@ -185,13 +185,13 @@ void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, if (!ei.info.valid) { event_num = exit_info; if (event_num <= 0 || event_num >= PAL_EVENT_NUM_BOUND) { - log_error("Illegal exception reported by untrusted PAL: %d\n", event_num); + log_error("Illegal exception reported by untrusted PAL: %d", event_num); _DkProcessExit(1); } } else { switch (ei.info.vector) { case SGX_EXCEPTION_VECTOR_BR: - log_error("Handling #BR exceptions is currently unsupported by Graphene\n"); + log_error("Handling #BR exceptions is currently unsupported by Graphene"); _DkProcessExit(1); break; case SGX_EXCEPTION_VECTOR_UD: @@ -221,22 +221,22 @@ void _DkExceptionHandler(unsigned int exit_info, sgx_cpu_context_t* uc, /* event isn't asynchronous (i.e., synchronous exception) */ event_num != PAL_EVENT_QUIT && event_num != PAL_EVENT_INTERRUPTED) { - log_error("*** Unexpected exception occurred inside PAL at RIP = +0x%08lx! ***\n", + log_error("*** Unexpected exception occurred inside PAL at RIP = +0x%08lx! ***", uc->rip - (uintptr_t)TEXT_START); if (ei.info.valid) { /* EXITINFO field: vector = exception number, exit_type = 0x3 for HW / 0x6 for SW */ - log_error("(SGX HW reported AEX vector 0x%x with exit_type = 0x%x)\n", ei.info.vector, + log_error("(SGX HW reported AEX vector 0x%x with exit_type = 0x%x)", ei.info.vector, ei.info.exit_type); } else { - log_error("(untrusted PAL sent PAL event 0x%x)\n", ei.intval); + log_error("(untrusted PAL sent PAL event 0x%x)", ei.intval); } log_error("rax: 0x%08lx rcx: 0x%08lx rdx: 0x%08lx rbx: 0x%08lx\n" "rsp: 0x%08lx rbp: 0x%08lx rsi: 0x%08lx rdi: 0x%08lx\n" "r8 : 0x%08lx r9 : 0x%08lx r10: 0x%08lx r11: 0x%08lx\n" "r12: 0x%08lx r13: 0x%08lx r14: 0x%08lx r15: 0x%08lx\n" - "rflags: 0x%08lx rip: 0x%08lx\n", + "rflags: 0x%08lx rip: 0x%08lx", uc->rax, uc->rcx, uc->rdx, uc->rbx, uc->rsp, uc->rbp, uc->rsi, uc->rdi, uc->r8, uc->r9, uc->r10, uc->r11, @@ -283,7 +283,7 @@ noreturn void _DkHandleExternalEvent(PAL_NUM event, sgx_cpu_context_t* uc, assert(IS_ALIGNED_PTR(xregs_state, PAL_XSTATE_ALIGN)); if (event != PAL_EVENT_QUIT && event != PAL_EVENT_INTERRUPTED) { - log_error("Illegal exception reported by untrusted PAL: %lu\n", event); + log_error("Illegal exception reported by untrusted PAL: %lu", event); _DkProcessExit(1); } diff --git a/Pal/src/host/Linux-SGX/db_files.c b/Pal/src/host/Linux-SGX/db_files.c index db03a195a6..03bc023821 100644 --- a/Pal/src/host/Linux-SGX/db_files.c +++ b/Pal/src/host/Linux-SGX/db_files.c @@ -45,7 +45,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int char* path = (void*)hdl + HANDLE_SIZE(file); int ret; if ((ret = get_norm_path(uri, path, &uri_size)) < 0) { - log_error("Could not normalize path (%s): %s\n", uri, pal_strerror(ret)); + log_error("Could not normalize path (%s): %s", uri, pal_strerror(ret)); free(hdl); return ret; } @@ -71,7 +71,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int /* check if the file is seekable and get real file size */ ret = ocall_fstat(fd, &st); if (ret < 0) { - log_error("file_open(%s): fstat failed: %d\n", path, ret); + log_error("file_open(%s): fstat failed: %d", path, ret); ret = unix_to_pal_error(ret); goto out; } @@ -90,7 +90,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int /* disallow opening more than one writable handle to a PF */ if (pf_mode & PF_FILE_MODE_WRITE) { if (pf->writable_fd >= 0) { - log_error("file_open(%s): disallowing concurrent writable handle\n", path); + log_error("file_open(%s): disallowing concurrent writable handle", path); ret = -PAL_ERROR_DENIED; goto out; } @@ -100,7 +100,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int /* the protected files should be regular files (seekable) */ if (!hdl->file.seekable) { - log_error("file_open(%s): disallowing non-seekable file handle\n", path); + log_error("file_open(%s): disallowing non-seekable file handle", path); goto out; } @@ -111,7 +111,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int pf->writable_fd = fd; } } else { - log_error("load_protected_file(%s, %d) failed\n", path, hdl->file.fd); + log_error("load_protected_file(%s, %d) failed", path, hdl->file.fd); goto out; } } else { @@ -121,7 +121,7 @@ static int file_open(PAL_HANDLE* handle, const char* type, const char* uri, int ret = load_trusted_file(hdl, &chunk_hashes, &total, create, &umem); if (ret < 0) { log_error("Accessing file:%s is denied (%s). This file is not trusted or allowed." - " Trusted files should be regular files (seekable).\n", hdl->file.realpath, + " Trusted files should be regular files (seekable).", hdl->file.realpath, pal_strerror(ret)); goto out; } @@ -155,7 +155,7 @@ static int64_t pf_file_read(struct protected_file* pf, PAL_HANDLE handle, uint64 int fd = handle->file.fd; if (!pf->context) { - log_error("pf_file_read(PF fd %d): PF not initialized\n", fd); + log_error("pf_file_read(PF fd %d): PF not initialized", fd); return -PAL_ERROR_BADHANDLE; } @@ -163,7 +163,7 @@ static int64_t pf_file_read(struct protected_file* pf, PAL_HANDLE handle, uint64 pf_status_t pfs = pf_read(pf->context, offset, count, buffer, &bytes_read); if (PF_FAILURE(pfs)) { - log_error("pf_file_read(PF fd %d): pf_read failed: %s\n", fd, pf_strerror(pfs)); + log_error("pf_file_read(PF fd %d): pf_read failed: %s", fd, pf_strerror(pfs)); return -PAL_ERROR_DENIED; } @@ -216,14 +216,14 @@ static int64_t pf_file_write(struct protected_file* pf, PAL_HANDLE handle, uint6 int fd = handle->file.fd; if (!pf->context) { - log_error("pf_file_write(PF fd %d): PF not initialized\n", fd); + log_error("pf_file_write(PF fd %d): PF not initialized", fd); return -PAL_ERROR_BADHANDLE; } pf_status_t pf_ret = pf_write(pf->context, offset, count, buffer); if (PF_FAILURE(pf_ret)) { - log_error("pf_file_write(PF fd %d): pf_write failed: %s\n", fd, pf_strerror(pf_ret)); + log_error("pf_file_write(PF fd %d): pf_write failed: %s", fd, pf_strerror(pf_ret)); return -PAL_ERROR_DENIED; } @@ -254,7 +254,7 @@ static int64_t file_write(PAL_HANDLE handle, uint64_t offset, uint64_t count, co } /* case of trusted file: disallow writing completely */ - log_error("Writing to a trusted file (%s) is disallowed!\n", handle->file.realpath); + log_error("Writing to a trusted file (%s) is disallowed!", handle->file.realpath); return -PAL_ERROR_DENIED; } @@ -262,7 +262,7 @@ static int pf_file_close(struct protected_file* pf, PAL_HANDLE handle) { int fd = handle->file.fd; if (pf->refcount == 0) { - log_error("pf_file_close(PF fd %d): refcount == 0\n", fd); + log_error("pf_file_close(PF fd %d): refcount == 0", fd); return -PAL_ERROR_INVAL; } @@ -324,12 +324,12 @@ static int pf_file_map(struct protected_file* pf, PAL_HANDLE handle, void** addr assert(WITHIN_MASK(prot, PAL_PROT_MASK)); if ((prot & PAL_PROT_READ) && (prot & PAL_PROT_WRITE)) { - log_error("pf_file_map(PF fd %d): trying to map with R+W access\n", fd); + log_error("pf_file_map(PF fd %d): trying to map with R+W access", fd); return -PAL_ERROR_NOTSUPPORT; } if (!pf->context) { - log_error("pf_file_map(PF fd %d): PF not initialized\n", fd); + log_error("pf_file_map(PF fd %d): PF not initialized", fd); return -PAL_ERROR_BADHANDLE; } @@ -338,7 +338,7 @@ static int pf_file_map(struct protected_file* pf, PAL_HANDLE handle, void** addr __UNUSED(pfs); assert(PF_SUCCESS(pfs)); - log_debug("pf_file_map(PF fd %d): pf %p, addr %p, prot %d, offset %lu, size %lu\n", fd, pf, + log_debug("pf_file_map(PF fd %d): pf %p, addr %p, prot %d, offset %lu, size %lu", fd, pf, *addr, prot, offset, size); if (*addr == NULL) { @@ -370,7 +370,7 @@ static int pf_file_map(struct protected_file* pf, PAL_HANDLE handle, void** addr if (prot & PAL_PROT_READ) { /* we don't check this on writes since file size may be extended then */ if (offset >= pf_size) { - log_error("pf_file_map(PF fd %d): offset (%lu) >= file size (%lu)\n", fd, offset, + log_error("pf_file_map(PF fd %d): offset (%lu) >= file size (%lu)", fd, offset, pf_size); ret = -PAL_ERROR_INVAL; goto out; @@ -385,7 +385,7 @@ static int pf_file_map(struct protected_file* pf, PAL_HANDLE handle, void** addr pf_ret = PF_STATUS_CORRUPTED; } if (PF_FAILURE(pf_ret)) { - log_error("pf_file_map(PF fd %d): pf_read failed: %s\n", fd, pf_strerror(pf_ret)); + log_error("pf_file_map(PF fd %d): pf_read failed: %s", fd, pf_strerror(pf_ret)); ret = -PAL_ERROR_DENIED; goto out; } @@ -436,10 +436,10 @@ static int file_map(PAL_HANDLE handle, void** addr, int prot, uint64_t offset, u if (!(prot & PAL_PROT_WRITECOPY) && (prot & PAL_PROT_WRITE)) { log_error( - "file_map does not currently support writable pass-through mappings on SGX. You " + "file_map does not currently support writable pass-through mappings on SGX. You " "may add the PAL_PROT_WRITECOPY (MAP_PRIVATE) flag to your file mapping to keep " "the writes inside the enclave but they won't be reflected outside of the " - "enclave.\n"); + "enclave."); return -PAL_ERROR_DENIED; } @@ -465,7 +465,7 @@ static int file_map(PAL_HANDLE handle, void** addr, int prot, uint64_t offset, u aligned_offset, aligned_end, offset, end, chunk_hashes, handle->file.total); if (ret < 0) { - log_error("file_map - copy & verify on trusted file returned %d\n", ret); + log_error("file_map - copy & verify on trusted file returned %d", ret); goto out; } } else { @@ -482,7 +482,7 @@ static int file_map(PAL_HANDLE handle, void** addr, int prot, uint64_t offset, u } else if (bytes == -EINTR || bytes == -EAGAIN) { continue; } else { - log_error("file_map - ocall_pread on allowed file returned %ld\n", bytes); + log_error("file_map - ocall_pread on allowed file returned %ld", bytes); ret = unix_to_pal_error(bytes); goto out; } @@ -510,7 +510,7 @@ static int64_t pf_file_setlength(struct protected_file* pf, PAL_HANDLE handle, u pf_status_t pfs = pf_set_size(pf->context, length); if (PF_FAILURE(pfs)) { - log_error("pf_file_setlength(PF fd %d, %lu): pf_set_size returned %s\n", fd, length, + log_error("pf_file_setlength(PF fd %d, %lu): pf_set_size returned %s", fd, length, pf_strerror(pfs)); return -PAL_ERROR_DENIED; } @@ -538,12 +538,12 @@ static int file_flush(PAL_HANDLE handle) { if (pf) { int ret = flush_pf_maps(pf, /*buffer=*/NULL, /*remove=*/false); if (ret < 0) { - log_error("file_flush(PF fd %d): flush_pf_maps returned %s\n", fd, pal_strerror(ret)); + log_error("file_flush(PF fd %d): flush_pf_maps returned %s", fd, pal_strerror(ret)); return ret; } pf_status_t pfs = pf_flush(pf->context); if (PF_FAILURE(pfs)) { - log_error("file_flush(PF fd %d): pf_flush returned %s\n", fd, pf_strerror(pfs)); + log_error("file_flush(PF fd %d): pf_flush returned %s", fd, pf_strerror(pfs)); return -PAL_ERROR_DENIED; } } else { @@ -584,7 +584,7 @@ static int pf_file_attrquery(struct protected_file* pf, int fd_from_attrquery, c pf = load_protected_file(path, &fd_from_attrquery, real_size, PF_FILE_MODE_READ, /*create=*/false, pf); if (!pf) { - log_error("pf_file_attrquery: load_protected_file(%s, %d) failed\n", path, + log_error("pf_file_attrquery: load_protected_file(%s, %d) failed", path, fd_from_attrquery); /* The call above will fail for PFs that were tampered with or have a wrong path. * glibc kills the process if this fails during directory enumeration, but that @@ -643,7 +643,7 @@ static int file_attrquery(const char* type, const char* uri, PAL_STREAM_ATTR* at } ret = get_norm_path(uri, path, &len); if (ret < 0) { - log_error("Could not normalize path (%s): %s\n", uri, pal_strerror(ret)); + log_error("Could not normalize path (%s): %s", uri, pal_strerror(ret)); goto out; } diff --git a/Pal/src/host/Linux-SGX/db_main.c b/Pal/src/host/Linux-SGX/db_main.c index 94384836d7..15b5facc11 100644 --- a/Pal/src/host/Linux-SGX/db_main.c +++ b/Pal/src/host/Linux-SGX/db_main.c @@ -56,7 +56,7 @@ void _DkGetAvailableUserAddressRange(PAL_PTR* start, PAL_PTR* end) { *end = SATURATED_P_SUB(*end, g_pal_internal_mem_size, *start); if (*end <= *start) { - log_error("Not enough enclave memory, please increase enclave size!\n"); + log_error("Not enough enclave memory, please increase enclave size!"); ocall_exit(1, /*is_exitgroup=*/true); } } @@ -363,14 +363,14 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { return -1; int64_t online_logical_cores = (int64_t)sec_info->online_logical_cores; if (!IS_IN_RANGE_INCL(online_logical_cores, 1, 1 << 16)) { - log_error("Invalid sec_info.online_logical_cores: %ld\n", online_logical_cores); + log_error("Invalid sec_info.online_logical_cores: %ld", online_logical_cores); return -1; } g_pal_sec.online_logical_cores = online_logical_cores; if (online_logical_cores != sanitize_hw_resource_count(sec_info->topo_info.online_logical_cores, /*ordered=*/true)) { - log_error("Invalid sec_info.topo_info.online_logical_cores\n"); + log_error("Invalid sec_info.topo_info.online_logical_cores"); return -1; } COPY_ARRAY(g_pal_sec.topo_info.online_logical_cores, sec_info->topo_info.online_logical_cores); @@ -379,22 +379,22 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { return -1; int64_t possible_logical_cores = (int64_t)sec_info->possible_logical_cores; if (!IS_IN_RANGE_INCL(possible_logical_cores, 1, 1 << 16)) { - log_error("Invalid sec_info.possible_logical_cores: %ld\n", possible_logical_cores); + log_error("Invalid sec_info.possible_logical_cores: %ld", possible_logical_cores); return -1; } g_pal_sec.possible_logical_cores = possible_logical_cores; if (possible_logical_cores != sanitize_hw_resource_count(sec_info->topo_info.possible_logical_cores, /*ordered=*/true)) { - log_error("Invalid sec_info.topo_info.possible_logical_cores\n"); + log_error("Invalid sec_info.topo_info.possible_logical_cores"); return -1; } COPY_ARRAY(g_pal_sec.topo_info.possible_logical_cores, sec_info->topo_info.possible_logical_cores); if (!IS_IN_RANGE_INCL(sec_info->physical_cores_per_socket, 1, 1 << 13)) { - log_error("Invalid sec_info.physical_cores_per_socket: %ld\n", - sec_info->physical_cores_per_socket); + log_error("Invalid sec_info.physical_cores_per_socket: %ld", + sec_info->physical_cores_per_socket); return -1; } g_pal_sec.physical_cores_per_socket = sec_info->physical_cores_per_socket; @@ -403,14 +403,14 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { return -1; int64_t num_online_nodes = (int64_t)sec_info->topo_info.num_online_nodes; if (!IS_IN_RANGE_INCL(num_online_nodes, 1, 1 << 8)) { - log_error("Invalid sec_info.topo_info.num_online_nodes: %ld\n", num_online_nodes); + log_error("Invalid sec_info.topo_info.num_online_nodes: %ld", num_online_nodes); return -1; } g_pal_sec.topo_info.num_online_nodes = num_online_nodes; if (num_online_nodes != sanitize_hw_resource_count(sec_info->topo_info.online_nodes, /*ordered=*/true)) { - log_error("Invalid sec_info.topo_info.online_nodes\n"); + log_error("Invalid sec_info.topo_info.online_nodes"); return -1; } COPY_ARRAY(g_pal_sec.topo_info.online_nodes, sec_info->topo_info.online_nodes); @@ -419,7 +419,7 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { return -1; int64_t num_cache_index = (int64_t)sec_info->topo_info.num_cache_index; if (!IS_IN_RANGE_INCL(num_cache_index, 1, 1 << 4)) { - log_error("Invalid sec_info.topo_info.num_cache_index: %ld\n", num_cache_index); + log_error("Invalid sec_info.topo_info.num_cache_index: %ld", num_cache_index); return -1; } g_pal_sec.topo_info.num_cache_index = num_cache_index; @@ -427,20 +427,20 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { /* Sanitize logical core -> socket mappings */ int ret = sanitize_socket_info(sec_info->cpu_socket, online_logical_cores); if (ret < 0) { - log_error("Sanitization of logical core -> socket mappings failed\n"); + log_error("Sanitization of logical core -> socket mappings failed"); return -1; } /* Allocate enclave memory to store "logical core -> socket" mappings */ int* cpu_socket = (int*)malloc(online_logical_cores * sizeof(int)); if (!cpu_socket) { - log_error("Allocation for logical core -> socket mappings failed\n"); + log_error("Allocation for logical core -> socket mappings failed"); return -1; } if (!sgx_copy_to_enclave(cpu_socket, online_logical_cores * sizeof(int), sec_info->cpu_socket, online_logical_cores * sizeof(int))) { - log_error("Copying cpu_socket into the enclave failed\n"); + log_error("Copying cpu_socket into the enclave failed"); return -1; } g_pal_sec.cpu_socket = cpu_socket; @@ -449,7 +449,7 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { ret = sanitize_core_topology_info(sec_info->topo_info.core_topology, online_logical_cores, num_cache_index); if (ret < 0) { - log_error("Sanitization of core_topology failed\n"); + log_error("Sanitization of core_topology failed"); return -1; } @@ -457,14 +457,14 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { PAL_CORE_TOPO_INFO* core_topology = (PAL_CORE_TOPO_INFO*)malloc(online_logical_cores * sizeof(PAL_CORE_TOPO_INFO)); if (!core_topology) { - log_error("Allocation for core topology failed\n"); + log_error("Allocation for core topology failed"); return -1; } if (!sgx_copy_to_enclave(core_topology, online_logical_cores * sizeof(PAL_CORE_TOPO_INFO), sec_info->topo_info.core_topology, online_logical_cores * sizeof(PAL_CORE_TOPO_INFO))) { - log_error("Copying core_topology into the enclave failed\n"); + log_error("Copying core_topology into the enclave failed"); return -1; } @@ -472,14 +472,14 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { PAL_CORE_CACHE_INFO* cache_info = (PAL_CORE_CACHE_INFO*)malloc(num_cache_index * sizeof(PAL_CORE_CACHE_INFO)); if (!cache_info) { - log_error("Allocation for cache_info failed\n"); + log_error("Allocation for cache_info failed"); return -1; } if (!sgx_copy_to_enclave(cache_info, num_cache_index * sizeof(PAL_CORE_CACHE_INFO), sec_info->topo_info.core_topology->cache, num_cache_index * sizeof(PAL_CORE_CACHE_INFO))) { - log_error("Copying cache_info into the enclave failed\n"); + log_error("Copying cache_info into the enclave failed"); return -1; } core_topology->cache = cache_info; @@ -489,7 +489,7 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { ret = sanitize_numa_topology_info(sec_info->topo_info.numa_topology, num_online_nodes, online_logical_cores); if (ret < 0) { - log_error("Sanitization of numa_topology failed\n"); + log_error("Sanitization of numa_topology failed"); return -1; } @@ -497,14 +497,14 @@ static int parse_host_topo_info(struct pal_sec* sec_info) { PAL_NUMA_TOPO_INFO* numa_topology = (PAL_NUMA_TOPO_INFO*)malloc(num_online_nodes * sizeof(PAL_NUMA_TOPO_INFO)); if (!numa_topology) { - log_error("Allocation for numa topology failed\n"); + log_error("Allocation for numa topology failed"); return -1; } if (!sgx_copy_to_enclave(numa_topology, num_online_nodes * sizeof(PAL_NUMA_TOPO_INFO), sec_info->topo_info.numa_topology, num_online_nodes * sizeof(PAL_NUMA_TOPO_INFO))) { - log_error("Copying numa_topology into the enclave failed\n"); + log_error("Copying numa_topology into the enclave failed"); return -1; } g_pal_sec.topo_info.numa_topology = numa_topology; @@ -527,7 +527,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* uint64_t start_time; ret = _DkSystemTimeQuery(&start_time); if (ret < 0) { - log_error("_DkSystemTimeQuery() failed: %d\n", ret); + log_error("_DkSystemTimeQuery() failed: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } @@ -537,7 +537,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* struct pal_sec sec_info; if (!sgx_copy_to_enclave(&sec_info, sizeof(sec_info), uptr_sec_info, sizeof(*uptr_sec_info))) { - log_error("Copying sec_info into the enclave failed\n"); + log_error("Copying sec_info into the enclave failed"); ocall_exit(1, /*is_exitgroup=*/true); } @@ -546,7 +546,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* /* Skip URI_PREFIX_FILE. */ if (libpal_uri_len < URI_PREFIX_FILE_LEN) { - log_error("Invalid libpal_uri length (missing \"%s\" prefix?)\n", URI_PREFIX_FILE); + log_error("Invalid libpal_uri length (missing \"%s\" prefix?)", URI_PREFIX_FILE); ocall_exit(1, /*is_exitgroup=*/true); } libpal_uri_len -= URI_PREFIX_FILE_LEN; @@ -557,7 +557,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* if (libpal_uri_len >= sizeof(libpal_path) || !sgx_copy_to_enclave(libpal_path, sizeof(libpal_path) - 1, uptr_libpal_uri, libpal_uri_len)) { - log_error("Copying libpal_path into the enclave failed\n"); + log_error("Copying libpal_path into the enclave failed"); ocall_exit(1, /*is_exitgroup=*/true); } libpal_path[libpal_uri_len] = '\0'; @@ -590,21 +590,21 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* /* ppid should be positive when interpreted as signed. It's 0 if we don't * have a graphene parent process. */ if (sec_info.ppid > INT32_MAX) { - log_error("Invalid sec_info.ppid: %u\n", sec_info.ppid); + log_error("Invalid sec_info.ppid: %u", sec_info.ppid); ocall_exit(1, /*is_exitgroup=*/true); } g_pal_sec.ppid = sec_info.ppid; /* As ppid but we always have a pid, so 0 is invalid. */ if (sec_info.pid > INT32_MAX || sec_info.pid == 0) { - log_error("Invalid sec_info.pid: %u\n", sec_info.pid); + log_error("Invalid sec_info.pid: %u", sec_info.pid); ocall_exit(1, /*is_exitgroup=*/true); } g_pal_sec.pid = sec_info.pid; /* -1 is treated as special value for example by chown. */ if (sec_info.uid == (PAL_IDX)-1 || sec_info.gid == (PAL_IDX)-1) { - log_error("Invalid sec_info.gid: %u\n", sec_info.gid); + log_error("Invalid sec_info.gid: %u", sec_info.gid); ocall_exit(1, /*is_exitgroup=*/true); } g_pal_sec.uid = sec_info.uid; @@ -622,22 +622,22 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* /* initialize enclave properties */ ret = init_enclave(); if (ret) { - log_error("Failed to initialize enclave properties: %d\n", ret); + log_error("Failed to initialize enclave properties: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } if (args_size > MAX_ARGS_SIZE || env_size > MAX_ENV_SIZE) { - log_error("Invalid args_size (%lu) or env_size (%lu)\n", args_size, env_size); + log_error("Invalid args_size (%lu) or env_size (%lu)", args_size, env_size); ocall_exit(1, /*is_exitgroup=*/true); } const char** arguments = make_argv_list(uptr_args, args_size); if (!arguments) { - log_error("Creating arguments failed\n"); + log_error("Creating arguments failed"); ocall_exit(1, /*is_exitgroup=*/true); } const char** environments = make_argv_list(uptr_env, env_size); if (!environments) { - log_error("Creating environments failed\n"); + log_error("Creating environments failed"); ocall_exit(1, /*is_exitgroup=*/true); } @@ -666,7 +666,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* * this enclave is child */ ret = _DkRandomBitsRead(&g_master_key, sizeof(g_master_key)); if (ret < 0) { - log_error("_DkRandomBitsRead failed: %d\n", ret); + log_error("_DkRandomBitsRead failed: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } @@ -674,7 +674,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* PAL_HANDLE parent = NULL; if (g_pal_sec.ppid) { if ((ret = init_child_process(&parent)) < 0) { - log_error("Failed to initialize child process: %d\n", ret); + log_error("Failed to initialize child process: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } } @@ -685,7 +685,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* ret = add_preloaded_range((uintptr_t)manifest_addr, (uintptr_t)manifest_addr + manifest_size, "manifest"); if (ret < 0) { - log_error("Failed to initialize manifest preload range: %d\n", ret); + log_error("Failed to initialize manifest preload range: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } @@ -695,7 +695,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* if (!manifest_root) { log_error("PAL failed at parsing the manifest: %s\n" " Graphene switched to the TOML format recently, please update the manifest\n" - " (in particular, string values must be put in double quotes)\n", errbuf); + " (in particular, string values must be put in double quotes)", errbuf); ocall_exit(1, /*is_exitgroup=*/true); } g_pal_state.raw_manifest_data = manifest_addr; @@ -705,7 +705,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* ret = toml_bool_in(g_pal_state.manifest_root, "sgx.preheat_enclave", /*defaultval=*/false, &preheat_enclave); if (ret < 0) { - log_error("Cannot parse \'sgx.preheat_enclave\' (the value must be `true` or `false`)\n"); + log_error("Cannot parse \'sgx.preheat_enclave\' (the value must be `true` or `false`)"); ocall_exit(1, true); } if (preheat_enclave) { @@ -717,29 +717,29 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* /*defaultval=*/0, &g_pal_internal_mem_size); if (ret < 0) { log_error("Cannot parse \'loader.pal_internal_mem_size\' " - "(the value must be put in double quotes!)\n"); + "(the value must be put in double quotes!)"); ocall_exit(1, true); } if ((ret = init_trusted_files()) < 0) { - log_error("Failed to load the checksums of trusted files: %d\n", ret); + log_error("Failed to load the checksums of trusted files: %d", ret); ocall_exit(1, true); } if ((ret = init_file_check_policy()) < 0) { - log_error("Failed to load the file check policy: %d\n", ret); + log_error("Failed to load the file check policy: %d", ret); ocall_exit(1, true); } if ((ret = init_protected_files()) < 0) { - log_error("Failed to initialize protected files: %d\n", ret); + log_error("Failed to initialize protected files: %d", ret); ocall_exit(1, true); } /* set up thread handle */ PAL_HANDLE first_thread = malloc(HANDLE_SIZE(thread)); if (!first_thread) { - log_error("Out of memory\n"); + log_error("Out of memory"); ocall_exit(1, true); } SET_HANDLE_TYPE(first_thread, thread); @@ -752,7 +752,7 @@ noreturn void pal_linux_main(char* uptr_libpal_uri, size_t libpal_uri_len, char* uint64_t stack_protector_canary; ret = _DkRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); if (ret < 0) { - log_error("_DkRandomBitsRead failed: %d\n", ret); + log_error("_DkRandomBitsRead failed: %d", ret); ocall_exit(1, /*is_exitgroup=*/true); } pal_set_tcb_stack_canary(stack_protector_canary); diff --git a/Pal/src/host/Linux-SGX/db_memory.c b/Pal/src/host/Linux-SGX/db_memory.c index 5dd2a3dfe3..27cda28102 100644 --- a/Pal/src/host/Linux-SGX/db_memory.c +++ b/Pal/src/host/Linux-SGX/db_memory.c @@ -20,7 +20,7 @@ extern struct atomic_int g_allocated_pages; bool _DkCheckMemoryMappable(const void* addr, size_t size) { if (addr < DATA_END && addr + size > TEXT_START) { - log_error("Address %p-%p is not mappable\n", addr, addr + size); + log_error("Address %p-%p is not mappable", addr, addr + size); return true; } @@ -76,7 +76,7 @@ int _DkVirtualMemoryProtect(void* addr, uint64_t size, int prot) { int64_t t = 0; if (__atomic_compare_exchange_n(&at_cnt.counter, &t, 1, /*weak=*/false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED)) - log_warning("DkVirtualMemoryProtect is unimplemented in Linux-SGX PAL\n"); + log_warning("DkVirtualMemoryProtect is unimplemented in Linux-SGX PAL"); return 0; } diff --git a/Pal/src/host/Linux-SGX/db_misc.c b/Pal/src/host/Linux-SGX/db_misc.c index 427429c9ed..33567a4fb6 100644 --- a/Pal/src/host/Linux-SGX/db_misc.c +++ b/Pal/src/host/Linux-SGX/db_misc.c @@ -273,7 +273,7 @@ static void sanity_check_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t values[ if (extension_enabled(xfrm, subleaf)) { if (values[EAX] != extension_sizes_bytes[subleaf] || values[EBX] != extension_offset_bytes[subleaf]) { - log_error("Unexpected value in host CPUID. Exiting...\n"); + log_error("Unexpected value in host CPUID. Exiting..."); _DkProcessExit(1); } } else { @@ -385,7 +385,7 @@ int _DkCpuIdRetrieve(unsigned int leaf, unsigned int subleaf, unsigned int value return 0; fail: - log_error("Unrecognized leaf/subleaf in CPUID (EAX=%u, ECX=%u). Exiting...\n", leaf, + log_error("Unrecognized leaf/subleaf in CPUID (EAX=%u, ECX=%u). Exiting...", leaf, subleaf); _DkProcessExit(1); } @@ -461,8 +461,7 @@ int _DkAttestationQuote(const PAL_PTR user_report_data, PAL_NUM user_report_data char* ra_client_spid_str = NULL; ret = toml_string_in(g_pal_state.manifest_root, "sgx.ra_client_spid", &ra_client_spid_str); if (ret < 0) { - log_error("Cannot parse \'sgx.ra_client_spid\' " - "(the value must be put in double quotes!)\n"); + log_error("Cannot parse \'sgx.ra_client_spid\' (the value must be put in double quotes!)"); return -PAL_ERROR_INVAL; } @@ -476,7 +475,7 @@ int _DkAttestationQuote(const PAL_PTR user_report_data, PAL_NUM user_report_data is_epid = true; if (strlen(ra_client_spid_str) != sizeof(sgx_spid_t) * 2) { - log_error("Malformed \'sgx.ra_client_spid\' value in the manifest: %s\n", + log_error("Malformed \'sgx.ra_client_spid\' value in the manifest: %s", ra_client_spid_str); free(ra_client_spid_str); return -PAL_ERROR_INVAL; @@ -485,7 +484,7 @@ int _DkAttestationQuote(const PAL_PTR user_report_data, PAL_NUM user_report_data for (size_t i = 0; i < strlen(ra_client_spid_str); i++) { int8_t val = hex2dec(ra_client_spid_str[i]); if (val < 0) { - log_error("Malformed \'sgx.ra_client_spid\' value in the manifest: %s\n", + log_error("Malformed \'sgx.ra_client_spid\' value in the manifest: %s", ra_client_spid_str); free(ra_client_spid_str); return -PAL_ERROR_INVAL; @@ -498,7 +497,7 @@ int _DkAttestationQuote(const PAL_PTR user_report_data, PAL_NUM user_report_data /*defaultval=*/false, &linkable); if (ret < 0) { log_error("Cannot parse \'sgx.ra_client_linkable\' (the value must be `true` or " - "`false`)\n"); + "`false`)"); free(ra_client_spid_str); return -PAL_ERROR_INVAL; } @@ -743,7 +742,7 @@ int _DkGetCPUInfo(PAL_CPU_INFO* ci) { ci->cpu_bogomips = get_bogomips(); if (ci->cpu_bogomips == 0.0) { - log_warning("bogomips could not be retrieved, passing 0.0 to the application\n"); + log_warning("bogomips could not be retrieved, passing 0.0 to the application"); } return rv; diff --git a/Pal/src/host/Linux-SGX/db_pipes.c b/Pal/src/host/Linux-SGX/db_pipes.c index 7a20ed4311..a425e3a0ec 100644 --- a/Pal/src/host/Linux-SGX/db_pipes.c +++ b/Pal/src/host/Linux-SGX/db_pipes.c @@ -53,7 +53,7 @@ static int thread_handshake_func(void* param) { int ret = _DkStreamSecureInit(handle, handle->pipe.is_server, &handle->pipe.session_key, (LIB_SSL_CONTEXT**)&handle->pipe.ssl_ctx, NULL, 0); if (ret < 0) { - log_error("Failed to initialize secure pipe %s: %d\n", handle->pipe.name.str, ret); + log_error("Failed to initialize secure pipe %s: %d", handle->pipe.name.str, ret); _DkProcessExit(1); } diff --git a/Pal/src/host/Linux-SGX/db_process.c b/Pal/src/host/Linux-SGX/db_process.c index 1268f81c2c..8ce4760409 100644 --- a/Pal/src/host/Linux-SGX/db_process.c +++ b/Pal/src/host/Linux-SGX/db_process.c @@ -266,7 +266,7 @@ int init_child_process(PAL_HANDLE* parent_handle) { noreturn void _DkProcessExit(int exitcode) { if (exitcode) - log_debug("DkProcessExit: Returning exit code %d\n", exitcode); + log_debug("DkProcessExit: Returning exit code %d", exitcode); ocall_exit(exitcode, /*is_exitgroup=*/true); /* Unreachable. */ } diff --git a/Pal/src/host/Linux-SGX/db_threading.c b/Pal/src/host/Linux-SGX/db_threading.c index 56b94d1090..6c429fa215 100644 --- a/Pal/src/host/Linux-SGX/db_threading.c +++ b/Pal/src/host/Linux-SGX/db_threading.c @@ -81,7 +81,7 @@ __attribute__((__optimize__("-fno-stack-protector"))) void pal_start_thread(void uint64_t stack_protector_canary; int ret = _DkRandomBitsRead(&stack_protector_canary, sizeof(stack_protector_canary)); if (ret < 0) { - log_error("_DkRandomBitsRead() failed (%d)\n", ret); + log_error("_DkRandomBitsRead() failed (%d)", ret); _DkProcessExit(1); } pal_set_tcb_stack_canary(stack_protector_canary); diff --git a/Pal/src/host/Linux-SGX/enclave_framework.c b/Pal/src/host/Linux-SGX/enclave_framework.c index 4a186ba778..0628bfe5ab 100644 --- a/Pal/src/host/Linux-SGX/enclave_framework.c +++ b/Pal/src/host/Linux-SGX/enclave_framework.c @@ -120,23 +120,23 @@ bool sgx_copy_to_enclave(void* ptr, size_t maxsize, const void* uptr, size_t usi } static void print_report(sgx_report_t* r) { - log_debug(" cpu_svn: %s\n", ALLOCA_BYTES2HEXSTR(r->body.cpu_svn.svn)); - log_debug(" mr_enclave: %s\n", ALLOCA_BYTES2HEXSTR(r->body.mr_enclave.m)); - log_debug(" mr_signer: %s\n", ALLOCA_BYTES2HEXSTR(r->body.mr_signer.m)); - log_debug(" attr.flags: %016lx\n", r->body.attributes.flags); - log_debug(" attr.xfrm: %016lx\n", r->body.attributes.xfrm); - log_debug(" isv_prod_id: %02x\n", r->body.isv_prod_id); - log_debug(" isv_svn: %02x\n", r->body.isv_svn); - log_debug(" report_data: %s\n", ALLOCA_BYTES2HEXSTR(r->body.report_data.d)); - log_debug(" key_id: %s\n", ALLOCA_BYTES2HEXSTR(r->key_id.id)); - log_debug(" mac: %s\n", ALLOCA_BYTES2HEXSTR(r->mac)); + log_debug(" cpu_svn: %s", ALLOCA_BYTES2HEXSTR(r->body.cpu_svn.svn)); + log_debug(" mr_enclave: %s", ALLOCA_BYTES2HEXSTR(r->body.mr_enclave.m)); + log_debug(" mr_signer: %s", ALLOCA_BYTES2HEXSTR(r->body.mr_signer.m)); + log_debug(" attr.flags: %016lx", r->body.attributes.flags); + log_debug(" attr.xfrm: %016lx", r->body.attributes.xfrm); + log_debug(" isv_prod_id: %02x", r->body.isv_prod_id); + log_debug(" isv_svn: %02x", r->body.isv_svn); + log_debug(" report_data: %s", ALLOCA_BYTES2HEXSTR(r->body.report_data.d)); + log_debug(" key_id: %s", ALLOCA_BYTES2HEXSTR(r->key_id.id)); + log_debug(" mac: %s", ALLOCA_BYTES2HEXSTR(r->mac)); } int sgx_get_report(const sgx_target_info_t* target_info, const sgx_report_data_t* data, sgx_report_t* report) { int ret = sgx_report(target_info, data, report); if (ret) { - log_error("sgx_report failed: ret = %d\n", ret); + log_error("sgx_report failed: ret = %d", ret); return -PAL_ERROR_DENIED; } return 0; @@ -153,11 +153,11 @@ int sgx_verify_report(sgx_report_t* report) { int ret = sgx_getkey(&keyrequest, &report_key); if (ret) { - log_error("Can't get report key\n"); + log_error("Can't get report key"); return -PAL_ERROR_DENIED; } - log_debug("Get report key for verification: %s\n", ALLOCA_BYTES2HEXSTR(report_key)); + log_debug("Get report key for verification: %s", ALLOCA_BYTES2HEXSTR(report_key)); sgx_mac_t check_mac; memset(&check_mac, 0, sizeof(check_mac)); @@ -172,12 +172,12 @@ int sgx_verify_report(sgx_report_t* report) { // Clear the report key for security memset(&report_key, 0, sizeof(report_key)); - log_debug("Verify report:\n"); + log_debug("Verify report:"); print_report(report); - log_debug(" verify: %s\n", ALLOCA_BYTES2HEXSTR(check_mac)); + log_debug(" verify: %s", ALLOCA_BYTES2HEXSTR(check_mac)); if (memcmp(&check_mac, &report->mac, sizeof(check_mac))) { - log_error("Report verification failed\n"); + log_error("Report verification failed"); return -PAL_ERROR_DENIED; } @@ -264,7 +264,7 @@ int load_trusted_file(PAL_HANDLE file, sgx_chunk_hash_t** chunk_hashes_ptr, uint /* Normalize the uri */ if (!strstartswith(uri, URI_PREFIX_FILE)) { - log_error("Invalid URI [%s]: Trusted files must start with 'file:'\n", uri); + log_error("Invalid URI [%s]: Trusted files must start with 'file:'", uri); ret = -PAL_ERROR_INVAL; goto out_free; } @@ -273,7 +273,7 @@ int load_trusted_file(PAL_HANDLE file, sgx_chunk_hash_t** chunk_hashes_ptr, uint size_t len = normpath_size - URI_PREFIX_FILE_LEN; ret = get_norm_path(uri + URI_PREFIX_FILE_LEN, normpath + URI_PREFIX_FILE_LEN, &len); if (ret < 0) { - log_error("Path (%s) normalization failed: %s\n", uri + URI_PREFIX_FILE_LEN, + log_error("Path (%s) normalization failed: %s", uri + URI_PREFIX_FILE_LEN, pal_strerror(ret)); goto out_free; } @@ -305,8 +305,7 @@ int load_trusted_file(PAL_HANDLE file, sgx_chunk_hash_t** chunk_hashes_ptr, uint } if (!tf) { - log_always("Allowing access to an unknown file due to file_check_policy settings: %s\n", - uri); + log_always("Allowing access to an unknown file due to file_check_policy settings: %s", uri); PAL_STREAM_ATTR attr; ret = _DkStreamAttributesQuery(normpath, &attr); @@ -321,7 +320,7 @@ int load_trusted_file(PAL_HANDLE file, sgx_chunk_hash_t** chunk_hashes_ptr, uint assert(tf); if (create && !tf->allowed) { - log_error("Trying to create/write/append an already-created trusted file '%s'\n", uri); + log_error("Trying to create/write/append an already-created trusted file '%s'", uri); ret = -PAL_ERROR_DENIED; goto out_free; } @@ -539,7 +538,7 @@ int copy_and_verify_trusted_file(const char* path, uint8_t* buf, const void* ume goto failed; if (memcmp(chunk_hashes_item, &chunk_hash[0], sizeof(*chunk_hashes_item))) { - log_error("Accessing file '%s' is denied: incorrect hash of file chunk at %lu-%lu.\n", + log_error("Accessing file '%s' is denied: incorrect hash of file chunk at %lu-%lu.", path, chunk_offset, chunk_end); ret = -PAL_ERROR_DENIED; goto failed; @@ -560,7 +559,7 @@ static int register_trusted_file(const char* uri, const char* checksum_str, bool size_t uri_len = strlen(uri); if (uri_len >= URI_MAX) { - log_error("Size of file exceeds maximum %dB: %s\n", URI_MAX, uri); + log_error("Size of file exceeds maximum %dB: %s", URI_MAX, uri); return -PAL_ERROR_INVAL; } @@ -594,7 +593,7 @@ static int register_trusted_file(const char* uri, const char* checksum_str, bool PAL_STREAM_ATTR attr; ret = _DkStreamAttributesQuery(uri, &attr); if (ret < 0) { - log_error("Could not find size of file: %s\n", uri); + log_error("Could not find size of file: %s", uri); free(new); return ret; } @@ -606,7 +605,7 @@ static int register_trusted_file(const char* uri, const char* checksum_str, bool int8_t byte2 = hex2dec(checksum_str[i * 2 + 1]); if (byte1 < 0 || byte2 < 0) { - log_error("Could not parse checksum of file: %s\n", uri); + log_error("Could not parse checksum of file: %s", uri); free(new); return -PAL_ERROR_INVAL; } @@ -653,12 +652,12 @@ static int init_trusted_file(const char* key, const char* uri) { char* trusted_checksum_str = NULL; ret = toml_string_in(g_pal_state.manifest_root, fullkey, &trusted_checksum_str); if (ret < 0) { - log_error("Cannot parse '%s'\n", fullkey); + log_error("Cannot parse '%s'", fullkey); ret = -PAL_ERROR_INVAL; goto out; } if (!trusted_checksum_str) { - log_error("Missing '%s' entry\n", fullkey); + log_error("Missing '%s' entry", fullkey); ret = -PAL_ERROR_INVAL; goto out; } @@ -673,14 +672,14 @@ static int init_trusted_file(const char* key, const char* uri) { (void)strcpy_static(normpath, URI_PREFIX_FILE, normpath_size); if (!strstartswith(uri, URI_PREFIX_FILE)) { - log_error("Invalid URI [%s]: Trusted files must start with 'file:'\n", uri); + log_error("Invalid URI [%s]: Trusted files must start with 'file:'", uri); ret = -PAL_ERROR_INVAL; goto out; } size_t len = normpath_size - strlen(normpath); ret = get_norm_path(uri + URI_PREFIX_FILE_LEN, normpath + URI_PREFIX_FILE_LEN, &len); if (ret < 0) { - log_error("Path (%s) normalization failed: %s\n", uri + URI_PREFIX_FILE_LEN, + log_error("Path (%s) normalization failed: %s", uri + URI_PREFIX_FILE_LEN, pal_strerror(ret)); goto out; } @@ -701,7 +700,7 @@ int init_trusted_files(void) { ret = toml_string_in(g_pal_state.manifest_root, "loader.preload", &preload_str); if (ret < 0) { log_error("Cannot parse \'loader.preload\' " - "(the value must be put in double quotes!)\n"); + "(the value must be put in double quotes!)"); return -PAL_ERROR_INVAL; } @@ -754,7 +753,7 @@ int init_trusted_files(void) { char* toml_trusted_file_str = NULL; ret = toml_rtos(toml_trusted_file_raw, &toml_trusted_file_str); if (ret < 0) { - log_error("Invalid trusted file in manifest: \'%s\'\n", toml_trusted_file_key); + log_error("Invalid trusted file in manifest: \'%s\'", toml_trusted_file_key); continue; } @@ -799,12 +798,12 @@ int init_trusted_files(void) { char* toml_allowed_file_str = NULL; ret = toml_rtos(toml_allowed_file_raw, &toml_allowed_file_str); if (ret < 0) { - log_error("Invalid allowed file in manifest: \'%s\'\n", toml_allowed_file_key); + log_error("Invalid allowed file in manifest: \'%s\'", toml_allowed_file_key); continue; } if (!strstartswith(toml_allowed_file_str, URI_PREFIX_FILE)) { - log_error("Invalid URI [%s]: Allowed files must start with 'file:'\n", + log_error("Invalid URI [%s]: Allowed files must start with 'file:'", toml_allowed_file_str); free(toml_allowed_file_str); ret = -PAL_ERROR_INVAL; @@ -819,7 +818,7 @@ int init_trusted_files(void) { norm_path + URI_PREFIX_FILE_LEN, &norm_path_len); if (ret < 0) { - log_error("Path (%s) normalization failed: %s\n", + log_error("Path (%s) normalization failed: %s", toml_allowed_file_str + URI_PREFIX_FILE_LEN, pal_strerror(ret)); free(toml_allowed_file_str); goto no_allowed; @@ -844,7 +843,7 @@ int init_file_check_policy(void) { &file_check_policy_str); if (ret < 0) { log_error("Cannot parse \'sgx.file_check_policy\' " - "(the value must be put in double quotes!)\n"); + "(the value must be put in double quotes!)"); return -PAL_ERROR_INVAL; } @@ -857,12 +856,12 @@ int init_file_check_policy(void) { set_file_check_policy(FILE_CHECK_POLICY_ALLOW_ALL_BUT_LOG); } else { log_error("Unknown value for \'sgx.file_check_policy\' " - "(allowed: `strict`, `allow_all_but_log`)'\n"); + "(allowed: `strict`, `allow_all_but_log`)'"); free(file_check_policy_str); return -PAL_ERROR_INVAL; } - log_debug("File check policy: %s\n", file_check_policy_str); + log_debug("File check policy: %s", file_check_policy_str); free(file_check_policy_str); return 0; } @@ -879,7 +878,7 @@ int init_enclave(void) { int ret = sgx_report(&targetinfo, &reportdata, &report); if (ret) { - log_error("failed to get self report: %d\n", ret); + log_error("failed to get self report: %d", ret); return -PAL_ERROR_INVAL; } @@ -902,14 +901,14 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* key) { ret = lib_DhInit(&context); if (ret < 0) { - log_error("Key Exchange: DH Init failed: %ld\n", ret); + log_error("Key Exchange: DH Init failed: %ld", ret); goto out_no_final; } pubsz = sizeof(pub); ret = lib_DhCreatePublic(&context, pub, &pubsz); if (ret < 0) { - log_error("Key Exchange: DH CreatePublic failed: %ld\n", ret); + log_error("Key Exchange: DH CreatePublic failed: %ld", ret); goto out; } @@ -930,7 +929,7 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* key) { ret = 0; continue; } - log_error("Failed to exchange the secret key via RPC: %ld\n", ret); + log_error("Failed to exchange the secret key via RPC: %ld", ret); goto out; } } @@ -942,7 +941,7 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* key) { ret = 0; continue; } - log_error("Failed to exchange the secret key via RPC: %ld\n", ret); + log_error("Failed to exchange the secret key via RPC: %ld", ret); goto out; } } @@ -950,7 +949,7 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* key) { agreesz = sizeof(agree); ret = lib_DhCalcSecret(&context, pub, DH_SIZE, agree, &agreesz); if (ret < 0) { - log_error("Key Exchange: DH CalcSecret failed: %ld\n", ret); + log_error("Key Exchange: DH CalcSecret failed: %ld", ret); goto out; } @@ -959,11 +958,11 @@ int _DkStreamKeyExchange(PAL_HANDLE stream, PAL_SESSION_KEY* key) { ret = lib_HKDF_SHA256(agree, agreesz, /*salt=*/NULL, /*salt_size=*/0, /*info=*/NULL, /*info_size=*/0, (uint8_t*)key, sizeof(*key)); if (ret < 0) { - log_error("Failed to derive the session key: %ld\n", ret); + log_error("Failed to derive the session key: %ld", ret); goto out; } - log_debug("Key exchange succeeded: %s\n", ALLOCA_BYTES2HEXSTR(*key)); + log_debug("Key exchange succeeded: %s", ALLOCA_BYTES2HEXSTR(*key)); ret = 0; out: lib_DhFinal(&context); @@ -999,7 +998,7 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data ret = 0; continue; } - log_error("Failed to send target info via RPC: %ld\n", ret); + log_error("Failed to send target info via RPC: %ld", ret); goto out; } } @@ -1012,30 +1011,30 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data ret = 0; continue; } - log_error("Failed to receive local report via RPC: %ld\n", ret); + log_error("Failed to receive local report via RPC: %ld", ret); goto out; } } - log_debug("Received local report (mr_enclave = %s)\n", + log_debug("Received local report (mr_enclave = %s)", ALLOCA_BYTES2HEXSTR(report.body.mr_enclave.m)); /* Verify report[B -> A] */ ret = sgx_verify_report(&report); if (ret < 0) { - log_error("Failed to verify local report: %ld\n", ret); + log_error("Failed to verify local report: %ld", ret); goto out; } if (!is_remote_enclave_ok(&stream->process.session_key, &report.body.mr_enclave, &report.body.report_data)) { - log_error("Not an allowed enclave (mr_enclave = %s)\n", + log_error("Not an allowed enclave (mr_enclave = %s)", ALLOCA_BYTES2HEXSTR(report.body.mr_enclave.m)); ret = -PAL_ERROR_DENIED; goto out; } - log_debug("Local attestation succeeded!\n"); + log_debug("Local attestation succeeded!"); /* A -> B: report[A -> B] */ memcpy(&target_info.mr_enclave, &report.body.mr_enclave, sizeof(sgx_measurement_t)); @@ -1043,7 +1042,7 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data ret = sgx_get_report(&target_info, sgx_report_data, &report); if (ret < 0) { - log_error("Failed to get local report from CPU: %ld\n", ret); + log_error("Failed to get local report from CPU: %ld", ret); goto out; } @@ -1054,7 +1053,7 @@ int _DkStreamReportRequest(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data ret = 0; continue; } - log_error("Failed to send local report via RPC: %ld\n", ret); + log_error("Failed to send local report via RPC: %ld", ret); goto out; } } @@ -1092,7 +1091,7 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data ret = 0; continue; } - log_error("Failed to receive target info via RPC: %ld\n", ret); + log_error("Failed to receive target info via RPC: %ld", ret); goto out; } } @@ -1100,7 +1099,7 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data /* B -> A: report[B -> A] */ ret = sgx_get_report(&target_info, sgx_report_data, &report); if (ret < 0) { - log_error("Failed to get local report from CPU: %ld\n", ret); + log_error("Failed to get local report from CPU: %ld", ret); goto out; } @@ -1111,7 +1110,7 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data ret = 0; continue; } - log_error("Failed to send local report via PRC: %ld\n", ret); + log_error("Failed to send local report via PRC: %ld", ret); goto out; } } @@ -1124,30 +1123,30 @@ int _DkStreamReportRespond(PAL_HANDLE stream, sgx_report_data_t* sgx_report_data ret = 0; continue; } - log_error("Failed to receive local report via RPC: %ld\n", ret); + log_error("Failed to receive local report via RPC: %ld", ret); goto out; } } - log_debug("Received local report (mr_enclave = %s)\n", - ALLOCA_BYTES2HEXSTR(report.body.mr_enclave.m)); + log_debug("Received local report (mr_enclave = %s)", + ALLOCA_BYTES2HEXSTR(report.body.mr_enclave.m)); /* Verify report[A -> B] */ ret = sgx_verify_report(&report); if (ret < 0) { - log_error("Failed to verify local report: %ld\n", ret); + log_error("Failed to verify local report: %ld", ret); goto out; } if (!is_remote_enclave_ok(&stream->process.session_key, &report.body.mr_enclave, &report.body.report_data)) { - log_error("Not an allowed enclave (mr_enclave = %s)\n", + log_error("Not an allowed enclave (mr_enclave = %s)", ALLOCA_BYTES2HEXSTR(report.body.mr_enclave.m)); ret = -PAL_ERROR_DENIED; goto out; } - log_debug("Local attestation succeeded!\n"); + log_debug("Local attestation succeeded!"); return 0; out: diff --git a/Pal/src/host/Linux-SGX/enclave_pages.c b/Pal/src/host/Linux-SGX/enclave_pages.c index d5adbedd65..6868304783 100644 --- a/Pal/src/host/Linux-SGX/enclave_pages.c +++ b/Pal/src/host/Linux-SGX/enclave_pages.c @@ -164,7 +164,7 @@ static void* __create_vma_and_merge(void* addr, size_t size, bool is_pal_interna LISTP_ADD_AFTER(vma, vma_above, &g_heap_vma_list, list); if (vma->bottom >= vma->top) { - log_error("Bad memory bookkeeping: %p - %p\n", vma->bottom, vma->top); + log_error("Bad memory bookkeeping: %p - %p", vma->bottom, vma->top); ocall_exit(/*exitcode=*/1, /*is_exitgroup=*/true); } @@ -277,7 +277,7 @@ int free_enclave_pages(void* addr, size_t size) { if (is_pal_internal != vma->is_pal_internal) { log_error("Area to free (address %p, size %lu) overlaps with both normal and " - "pal-internal VMAs\n", + "pal-internal VMAs", addr, size); ret = -PAL_ERROR_INVAL; goto out; @@ -289,7 +289,7 @@ int free_enclave_pages(void* addr, size_t size) { /* create VMA [vma->bottom, addr); this may leave VMA [addr + size, vma->top), see below */ struct heap_vma* new = __alloc_vma(); if (!new) { - log_error("Cannot create split VMA during freeing of address %p\n", addr); + log_error("Cannot create split VMA during freeing of address %p", addr); ret = -PAL_ERROR_NOMEM; goto out; } diff --git a/Pal/src/host/Linux-SGX/enclave_pf.c b/Pal/src/host/Linux-SGX/enclave_pf.c index 85a4d37def..cf7f4e6bf4 100644 --- a/Pal/src/host/Linux-SGX/enclave_pf.c +++ b/Pal/src/host/Linux-SGX/enclave_pf.c @@ -42,14 +42,14 @@ static pf_status_t cb_read(pf_handle_t handle, void* buffer, uint64_t offset, si continue; if (read < 0) { - log_error("cb_read(%d, %p, %lu, %lu): read failed: %ld\n", fd, buffer, offset, + log_error("cb_read(%d, %p, %lu, %lu): read failed: %ld", fd, buffer, offset, size, read); return PF_STATUS_CALLBACK_FAILED; } /* EOF is an error condition, we want to read exactly `size` bytes */ if (read == 0) { - log_error("cb_read(%d, %p, %lu, %lu): EOF\n", fd, buffer, offset, size); + log_error("cb_read(%d, %p, %lu, %lu): EOF", fd, buffer, offset, size); return PF_STATUS_CALLBACK_FAILED; } @@ -70,14 +70,14 @@ static pf_status_t cb_write(pf_handle_t handle, const void* buffer, uint64_t off continue; if (written < 0) { - log_error("cb_write(%d, %p, %lu, %lu): write failed: %ld\n", fd, buffer, offset, + log_error("cb_write(%d, %p, %lu, %lu): write failed: %ld", fd, buffer, offset, size, written); return PF_STATUS_CALLBACK_FAILED; } /* EOF is an error condition, we want to write exactly `size` bytes */ if (written == 0) { - log_error("cb_write(%d, %p, %lu, %lu): EOF\n", fd, buffer, offset, size); + log_error("cb_write(%d, %p, %lu, %lu): EOF", fd, buffer, offset, size); return PF_STATUS_CALLBACK_FAILED; } @@ -91,7 +91,7 @@ static pf_status_t cb_truncate(pf_handle_t handle, uint64_t size) { int fd = *(int*)handle; int ret = ocall_ftruncate(fd, size); if (ret < 0) { - log_error("cb_truncate(%d, %lu): ocall failed: %d\n", fd, size, ret); + log_error("cb_truncate(%d, %lu): ocall failed: %d", fd, size, ret); return PF_STATUS_CALLBACK_FAILED; } return PF_STATUS_SUCCESS; @@ -108,7 +108,7 @@ static pf_status_t cb_aes_cmac(const pf_key_t* key, const void* input, size_t in int ret = lib_AESCMAC((const uint8_t*)key, sizeof(*key), input, input_size, (uint8_t*)mac, sizeof(*mac)); if (ret != 0) { - log_error("lib_AESCMAC failed: %d\n", ret); + log_error("lib_AESCMAC failed: %d", ret); return PF_STATUS_CALLBACK_FAILED; } return PF_STATUS_SUCCESS; @@ -120,7 +120,7 @@ static pf_status_t cb_aes_gcm_encrypt(const pf_key_t* key, const pf_iv_t* iv, co int ret = lib_AESGCMEncrypt((const uint8_t*)key, sizeof(*key), (const uint8_t*)iv, input, input_size, aad, aad_size, output, (uint8_t*)mac, sizeof(*mac)); if (ret != 0) { - log_error("lib_AESGCMEncrypt failed: %d\n", ret); + log_error("lib_AESGCMEncrypt failed: %d", ret); return PF_STATUS_CALLBACK_FAILED; } return PF_STATUS_SUCCESS; @@ -133,7 +133,7 @@ static pf_status_t cb_aes_gcm_decrypt(const pf_key_t* key, const pf_iv_t* iv, co input_size, aad, aad_size, output, (const uint8_t*)mac, sizeof(*mac)); if (ret != 0) { - log_error("lib_AESGCMDecrypt failed: %d\n", ret); + log_error("lib_AESGCMDecrypt failed: %d", ret); return PF_STATUS_CALLBACK_FAILED; } return PF_STATUS_SUCCESS; @@ -142,7 +142,7 @@ static pf_status_t cb_aes_gcm_decrypt(const pf_key_t* key, const pf_iv_t* iv, co static pf_status_t cb_random(uint8_t* buffer, size_t size) { int ret = _DkRandomBitsRead(buffer, size); if (ret < 0) { - log_error("_DkRandomBitsRead failed: %d\n", ret); + log_error("_DkRandomBitsRead failed: %d", ret); return PF_STATUS_CALLBACK_FAILED; } return PF_STATUS_SUCCESS; @@ -233,7 +233,7 @@ struct protected_file* get_protected_file(const char* path) { pf = find_protected_dir(path); if (pf) { /* path not registered but matches registered dir */ - log_debug("get_pf: registering new PF '%s' in dir '%s'\n", path, pf->path); + log_debug("get_pf: registering new PF '%s' in dir '%s'", path, pf->path); int ret = register_protected_path(path, &pf); __UNUSED(ret); assert(ret == 0); @@ -261,7 +261,7 @@ static int is_directory(const char* path, bool* is_dir) { fd = ret; ret = ocall_fstat(fd, &st); if (ret < 0) { - log_error("is_directory(%s): fstat failed: %d\n", path, ret); + log_error("is_directory(%s): fstat failed: %d", path, ret); goto out; } @@ -272,7 +272,7 @@ static int is_directory(const char* path, bool* is_dir) { if (fd >= 0) { int rv = ocall_close(fd); if (rv < 0) { - log_error("is_directory(%s): close failed: %d\n", path, rv); + log_error("is_directory(%s): close failed: %d", path, rv); } } @@ -291,7 +291,7 @@ static int register_protected_dir(const char* path) { ret = ocall_open(path, O_RDONLY | O_DIRECTORY, 0); if (ret < 0) { - log_error("register_protected_dir: opening %s failed: %d\n", path, ret); + log_error("register_protected_dir: opening %s failed: %d", path, ret); ret = unix_to_pal_error(ret); goto out; } @@ -303,7 +303,7 @@ static int register_protected_dir(const char* path) { returned = ocall_getdents(fd, buf, bufsize); if (returned < 0) { ret = unix_to_pal_error(returned); - log_error("register_protected_dir: reading %s failed: %d\n", path, ret); + log_error("register_protected_dir: reading %s failed: %d", path, ret); goto out; } @@ -355,7 +355,7 @@ static int register_protected_path(const char* path, struct protected_file** new size_t len = URI_MAX; ret = get_norm_path(path, normpath, &len); if (ret < 0) { - log_error("Couldn't normalize path (%s): %s\n", path, pal_strerror(ret)); + log_error("Couldn't normalize path (%s): %s", path, pal_strerror(ret)); goto out; } @@ -367,7 +367,7 @@ static int register_protected_path(const char* path, struct protected_file** new if (find_protected_file(path)) { ret = 0; - log_debug("register_protected_path: file %s already registered\n", path); + log_debug("register_protected_path: file %s already registered", path); goto out; } @@ -395,7 +395,7 @@ static int register_protected_path(const char* path, struct protected_file** new if (ret < 0) goto out; - log_debug("register_protected_path: [%s] %s = %p\n", is_dir ? "dir" : "file", path, new); + log_debug("register_protected_path: [%s] %s = %p", is_dir ? "dir" : "file", path, new); if (is_dir) register_protected_dir(path); @@ -450,7 +450,7 @@ static int register_protected_files(void) { char* toml_pf_value = NULL; ret = toml_rtos(toml_pf_value_raw, &toml_pf_value); if (ret < 0) { - log_error("Invalid PF entry in manifest: \'%s\'\n", toml_pf_key); + log_error("Invalid PF entry in manifest: \'%s\'", toml_pf_key); continue; } @@ -464,7 +464,7 @@ static int register_protected_files(void) { } pf_lock(); - log_debug("Registered %u protected directories and %u protected files\n", + log_debug("Registered %u protected directories and %u protected files", HASH_COUNT(g_protected_dirs), HASH_COUNT(g_protected_files)); pf_unlock(); return 0; @@ -489,13 +489,13 @@ int init_protected_files(void) { &protected_files_key_str); if (ret < 0) { log_error("Cannot parse \'sgx.protected_files_key\' " - "(the value must be put in double quotes!)\n"); + "(the value must be put in double quotes!)"); return -PAL_ERROR_INVAL; } if (protected_files_key_str) { if (strlen(protected_files_key_str) != PF_KEY_SIZE * 2) { - log_error("Malformed \'sgx.protected_files_key\' value in the manifest\n"); + log_error("Malformed \'sgx.protected_files_key\' value in the manifest"); free(protected_files_key_str); return -PAL_ERROR_INVAL; } @@ -504,7 +504,7 @@ int init_protected_files(void) { for (size_t i = 0; i < strlen(protected_files_key_str); i++) { int8_t val = hex2dec(protected_files_key_str[i]); if (val < 0) { - log_error("Malformed \'sgx.protected_files_key\' value in the manifest\n"); + log_error("Malformed \'sgx.protected_files_key\' value in the manifest"); free(protected_files_key_str); return -PAL_ERROR_INVAL; } @@ -516,7 +516,7 @@ int init_protected_files(void) { } if (register_protected_files() < 0) { - log_error("Malformed protected files found in manifest\n"); + log_error("Malformed protected files found in manifest"); } return 0; @@ -526,14 +526,14 @@ int init_protected_files(void) { static int open_protected_file(const char* path, struct protected_file* pf, pf_handle_t handle, uint64_t size, pf_file_mode_t mode, bool create) { if (!g_pf_wrap_key_set) { - log_error("pf_open(%d, %s) failed: wrap key was not provided\n", *(int*)handle, path); + log_error("pf_open(%d, %s) failed: wrap key was not provided", *(int*)handle, path); return -PAL_ERROR_DENIED; } pf_status_t pfs; pfs = pf_open(handle, path, size, mode, create, &g_pf_wrap_key, &pf->context); if (PF_FAILURE(pfs)) { - log_error("pf_open(%d, %s) failed: %s\n", *(int*)handle, path, pf_strerror(pfs)); + log_error("pf_open(%d, %s) failed: %s", *(int*)handle, path, pf_strerror(pfs)); return -PAL_ERROR_DENIED; } return 0; @@ -545,7 +545,7 @@ static int open_protected_file(const char* path, struct protected_file* pf, pf_h struct protected_file* load_protected_file(const char* path, int* fd, uint64_t size, pf_file_mode_t mode, bool create, struct protected_file* pf) { - log_debug("load_protected_file: %s, fd %d, size %lu, mode %d, create %d, pf %p\n", path, + log_debug("load_protected_file: %s, fd %d, size %lu, mode %d, create %d, pf %p", path, *fd, size, mode, create, pf); if (!pf) @@ -553,12 +553,12 @@ struct protected_file* load_protected_file(const char* path, int* fd, uint64_t s if (pf) { if (!pf->context) { - log_debug("load_protected_file: %s, fd %d: opening new PF %p\n", path, *fd, pf); + log_debug("load_protected_file: %s, fd %d: opening new PF %p", path, *fd, pf); int ret = open_protected_file(path, pf, (pf_handle_t)fd, size, mode, create); if (ret < 0) return NULL; } else { - log_debug("load_protected_file: %s, fd %d: returning old PF %p\n", path, *fd, pf); + log_debug("load_protected_file: %s, fd %d: returning old PF %p", path, *fd, pf); } } @@ -597,7 +597,7 @@ int flush_pf_maps(struct protected_file* pf, void* buffer, bool remove) { if (map_size > 0) { pfs = pf_write(map_pf->context, map->offset, map_size, map->buffer); if (PF_FAILURE(pfs)) { - log_error("flush_pf_maps: pf_write failed: %s\n", pf_strerror(pfs)); + log_error("flush_pf_maps: pf_write failed: %s", pf_strerror(pfs)); pf_unlock(); return -PAL_ERROR_INVAL; } @@ -621,7 +621,7 @@ int unload_protected_file(struct protected_file* pf) { return ret; pf_status_t pfs = pf_close(pf->context); if (PF_FAILURE(pfs)) { - log_error("unload_protected_file(%p) failed: %s\n", pf, pf_strerror(pfs)); + log_error("unload_protected_file(%p) failed: %s", pf, pf_strerror(pfs)); } pf->context = NULL; diff --git a/Pal/src/host/Linux-SGX/enclave_platform.c b/Pal/src/host/Linux-SGX/enclave_platform.c index bd6da113eb..ecfb5d8f6b 100644 --- a/Pal/src/host/Linux-SGX/enclave_platform.c +++ b/Pal/src/host/Linux-SGX/enclave_platform.c @@ -16,13 +16,13 @@ int sgx_get_quote(const sgx_spid_t* spid, const sgx_quote_nonce_t* nonce, int ret = sgx_report(&targetinfo, &_report_data, &report); if (ret) { - log_error("Failed to get enclave report\n"); + log_error("Failed to get enclave report"); return -PAL_ERROR_DENIED; } ret = ocall_get_quote(spid, linkable, &report, nonce, quote, quote_len); if (ret < 0) { - log_error("Failed to get quote\n"); + log_error("Failed to get quote"); return unix_to_pal_error(ret); } return 0; diff --git a/Pal/src/host/Linux-SGX/enclave_xstate.c b/Pal/src/host/Linux-SGX/enclave_xstate.c index 37eb5190e9..5a0c9d3e7f 100644 --- a/Pal/src/host/Linux-SGX/enclave_xstate.c +++ b/Pal/src/host/Linux-SGX/enclave_xstate.c @@ -84,7 +84,7 @@ void init_xsave_size(uint64_t xfrm) { g_xsave_features = PAL_XFEATURE_MASK_FPSSE; g_xsave_size = 512 + 64; if (!xfrm || (xfrm & SGX_XFRM_RESERVED)) { - log_debug("xsave is disabled, xfrm 0x%lx\n", xfrm); + log_debug("xsave is disabled, xfrm 0x%lx", xfrm); return; } @@ -95,5 +95,5 @@ void init_xsave_size(uint64_t xfrm) { g_xsave_size = xsave_size_table[i].size; } } - log_debug("xsave is enabled with g_xsave_size: %u\n", g_xsave_size); + log_debug("xsave is enabled with g_xsave_size: %u", g_xsave_size); } diff --git a/Pal/src/host/Linux-SGX/sgx_enclave.c b/Pal/src/host/Linux-SGX/sgx_enclave.c index c0cc71c42f..97ab9caead 100644 --- a/Pal/src/host/Linux-SGX/sgx_enclave.c +++ b/Pal/src/host/Linux-SGX/sgx_enclave.c @@ -37,7 +37,7 @@ static long sgx_ocall_exit(void* pms) { ODEBUG(OCALL_EXIT, NULL); if (ms->ms_exitcode != (int)((uint8_t)ms->ms_exitcode)) { - log_debug("Saturation error in exit code %d, getting rounded down to %u\n", + log_debug("Saturation error in exit code %d, getting rounded down to %u", ms->ms_exitcode, (uint8_t)ms->ms_exitcode); ms->ms_exitcode = 255; } @@ -339,7 +339,7 @@ static long sgx_ocall_socketpair(void* pms) { } static long sock_getopt(int fd, struct sockopt* opt) { - log_debug("sock_getopt (fd = %d, sockopt addr = %p) is not implemented and always returns 0\n", + log_debug("sock_getopt (fd = %d, sockopt addr = %p) is not implemented and always returns 0", fd, opt); /* initialize *opt with constant */ *opt = (struct sockopt){0}; @@ -661,7 +661,7 @@ static long sgx_ocall_debug_map_add(void* pms) { #ifdef DEBUG int ret = debug_map_add(ms->ms_name, ms->ms_addr); if (ret < 0) - log_error("debug_map_add(%s, %p): %d\n", ms->ms_name, ms->ms_addr, ret); + log_error("debug_map_add(%s, %p): %d", ms->ms_name, ms->ms_addr, ret); sgx_profile_report_elf(ms->ms_name, ms->ms_addr); #else @@ -676,7 +676,7 @@ static long sgx_ocall_debug_map_remove(void* pms) { #ifdef DEBUG int ret = debug_map_remove(ms->ms_addr); if (ret < 0) - log_error("debug_map_remove(%p): %d\n", ms->ms_addr, ret); + log_error("debug_map_remove(%p): %d", ms->ms_addr, ret); #else __UNUSED(ms); #endif @@ -795,7 +795,7 @@ static int rpc_thread_loop(void* arg) { int ret = INLINE_SYSCALL(futex, 6, &req->lock.lock, FUTEX_WAKE_PRIVATE, 1, NULL, NULL, 0); if (ret == -1) - log_error("RPC thread failed to wake up enclave thread\n"); + log_error("RPC thread failed to wake up enclave thread"); } } diff --git a/Pal/src/host/Linux-SGX/sgx_exception.c b/Pal/src/host/Linux-SGX/sgx_exception.c index f6a65fceda..4a20b922f8 100644 --- a/Pal/src/host/Linux-SGX/sgx_exception.c +++ b/Pal/src/host/Linux-SGX/sgx_exception.c @@ -142,16 +142,16 @@ static void handle_sync_signal(int signum, siginfo_t* info, struct ucontext* uc) unsigned long rip = ucontext_get_ip(uc); switch (signum) { case SIGSEGV: - log_error("Segmentation Fault in Untrusted Code (RIP = %08lx)\n", rip); + log_error("Segmentation Fault in Untrusted Code (RIP = %08lx)", rip); break; case SIGILL: - log_error("Illegal Instruction in Untrusted Code (RIP = %08lx)\n", rip); + log_error("Illegal Instruction in Untrusted Code (RIP = %08lx)", rip); break; case SIGFPE: - log_error("Arithmetic Exception in Untrusted Code (RIP = %08lx)\n", rip); + log_error("Arithmetic Exception in Untrusted Code (RIP = %08lx)", rip); break; case SIGBUS: - log_error("Memory Mapping Exception in Untrusted Code (RIP = %08lx)\n", rip); + log_error("Memory Mapping Exception in Untrusted Code (RIP = %08lx)", rip); break; } INLINE_SYSCALL(exit_group, 1, 1); diff --git a/Pal/src/host/Linux-SGX/sgx_framework.c b/Pal/src/host/Linux-SGX/sgx_framework.c index b28766c020..5b3601d93c 100644 --- a/Pal/src/host/Linux-SGX/sgx_framework.c +++ b/Pal/src/host/Linux-SGX/sgx_framework.c @@ -26,7 +26,7 @@ int open_sgx_driver(bool need_gsgx) { "\ta kernel with a back-ported patch to support FSGSBASE.\n" "\tOne may also load the Graphene SGX module, although this is insecure.\n" "\tIf the Graphene SGX module is loaded, check permissions on the device " - GSGX_FILE ",\n\tas we cannot open this file.\n\n"); + GSGX_FILE ",\n\tas we cannot open this file."); return g_gsgx_device; } } @@ -34,7 +34,7 @@ int open_sgx_driver(bool need_gsgx) { g_isgx_device = INLINE_SYSCALL(open, 3, ISGX_FILE, O_RDWR | O_CLOEXEC, 0); if (g_isgx_device < 0) { log_error("Cannot open device " ISGX_FILE ". " - "Please make sure the Intel SGX kernel module is loaded.\n"); + "Please make sure the Intel SGX kernel module is loaded."); if (need_gsgx) { INLINE_SYSCALL(close, 1, g_gsgx_device); g_gsgx_device = -1; @@ -53,7 +53,7 @@ int read_enclave_token(int token_file, sgx_arch_token_t* token) { return ret; if (stat.st_size != sizeof(sgx_arch_token_t)) { - log_error("size of token size does not match\n"); + log_error("size of token size does not match"); return -EINVAL; } @@ -62,20 +62,20 @@ int read_enclave_token(int token_file, sgx_arch_token_t* token) { return bytes; #ifdef SGX_DCAP - log_debug("Read dummy DCAP token\n"); + log_debug("Read dummy DCAP token"); #else - log_debug("Read token:\n"); - log_debug(" valid: 0x%08x\n", token->body.valid); - log_debug(" attr.flags: 0x%016lx\n", token->body.attributes.flags); - log_debug(" attr.xfrm: 0x%016lx\n", token->body.attributes.xfrm); - log_debug(" mr_enclave: %s\n", ALLOCA_BYTES2HEXSTR(token->body.mr_enclave.m)); - log_debug(" mr_signer: %s\n", ALLOCA_BYTES2HEXSTR(token->body.mr_signer.m)); - log_debug(" LE cpu_svn: %s\n", ALLOCA_BYTES2HEXSTR(token->cpu_svn_le.svn)); - log_debug(" LE isv_prod_id: %02x\n", token->isv_prod_id_le); - log_debug(" LE isv_svn: %02x\n", token->isv_svn_le); - log_debug(" LE masked_misc_select: 0x%08x\n", token->masked_misc_select_le); - log_debug(" LE attr.flags: 0x%016lx\n", token->attributes_le.flags); - log_debug(" LE attr.xfrm: 0x%016lx\n", token->attributes_le.xfrm); + log_debug("Read token:"); + log_debug(" valid: 0x%08x", token->body.valid); + log_debug(" attr.flags: 0x%016lx", token->body.attributes.flags); + log_debug(" attr.xfrm: 0x%016lx", token->body.attributes.xfrm); + log_debug(" mr_enclave: %s", ALLOCA_BYTES2HEXSTR(token->body.mr_enclave.m)); + log_debug(" mr_signer: %s", ALLOCA_BYTES2HEXSTR(token->body.mr_signer.m)); + log_debug(" LE cpu_svn: %s", ALLOCA_BYTES2HEXSTR(token->cpu_svn_le.svn)); + log_debug(" LE isv_prod_id: %02x", token->isv_prod_id_le); + log_debug(" LE isv_svn: %02x", token->isv_svn_le); + log_debug(" LE masked_misc_select: 0x%08x", token->masked_misc_select_le); + log_debug(" LE attr.flags: 0x%016lx", token->attributes_le.flags); + log_debug(" LE attr.xfrm: 0x%016lx", token->attributes_le.xfrm); #endif return 0; @@ -89,7 +89,7 @@ int read_enclave_sigstruct(int sigfile, sgx_arch_enclave_css_t* sig) { return ret; if ((size_t)stat.st_size != sizeof(sgx_arch_enclave_css_t)) { - log_error("size of sigstruct size does not match\n"); + log_error("size of sigstruct size does not match"); return -EINVAL; } @@ -107,7 +107,7 @@ bool is_wrfsbase_supported(void) { if (!(cpuinfo[1] & 0x1)) { log_error( "{RD,WR}{FS,GS}BASE instructions are not permitted on this platform. Please check the " - "instructions under \"Building with SGX support\" from Graphene documentation.\n"); + "instructions under \"Building with SGX support\" from Graphene documentation."); return false; } @@ -151,10 +151,10 @@ int create_enclave(sgx_arch_secs_t* secs, sgx_arch_token_t* token) { if (IS_ERR_P(addr)) { if (ERRNO_P(addr) == EPERM) { log_error("Permission denied on mapping enclave. " - "You may need to set sysctl vm.mmap_min_addr to zero\n"); + "You may need to set sysctl vm.mmap_min_addr to zero"); } - log_error("ECREATE failed in allocating EPC memory (errno = %ld)\n", -ERRNO_P(addr)); + log_error("ECREATE failed in allocating EPC memory (errno = %ld)", -ERRNO_P(addr)); return -ENOMEM; } @@ -166,26 +166,26 @@ int create_enclave(sgx_arch_secs_t* secs, sgx_arch_token_t* token) { int ret = INLINE_SYSCALL(ioctl, 3, g_isgx_device, SGX_IOC_ENCLAVE_CREATE, ¶m); if (ret < 0) { - log_error("ECREATE failed in enclave creation ioctl (errno = %d)\n", ret); + log_error("ECREATE failed in enclave creation ioctl (errno = %d)", ret); return ret; } if (ret) { - log_error("ECREATE failed (errno = %d)\n", ret); + log_error("ECREATE failed (errno = %d)", ret); return -EPERM; } secs->attributes.flags |= SGX_FLAGS_INITIALIZED; - log_debug("enclave created:\n"); - log_debug(" base: 0x%016lx\n", secs->base); - log_debug(" size: 0x%016lx\n", secs->size); - log_debug(" misc_select: 0x%08x\n", secs->misc_select); - log_debug(" attr.flags: 0x%016lx\n", secs->attributes.flags); - log_debug(" attr.xfrm: 0x%016lx\n", secs->attributes.xfrm); - log_debug(" ssa_frame_size: %d\n", secs->ssa_frame_size); - log_debug(" isv_prod_id: 0x%08x\n", secs->isv_prod_id); - log_debug(" isv_svn: 0x%08x\n", secs->isv_svn); + log_debug("enclave created:"); + log_debug(" base: 0x%016lx", secs->base); + log_debug(" size: 0x%016lx", secs->size); + log_debug(" misc_select: 0x%08x", secs->misc_select); + log_debug(" attr.flags: 0x%016lx", secs->attributes.flags); + log_debug(" attr.xfrm: 0x%016lx", secs->attributes.xfrm); + log_debug(" ssa_frame_size: %d", secs->ssa_frame_size); + log_debug(" isv_prod_id: 0x%08x", secs->isv_prod_id); + log_debug(" isv_svn: 0x%08x", secs->isv_svn); return 0; } @@ -202,7 +202,7 @@ int add_pages_to_enclave(sgx_arch_secs_t* secs, void* addr, void* user_addr, uns g_zero_pages = (void*)INLINE_SYSCALL(mmap, 6, NULL, g_page_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (IS_ERR_P(g_zero_pages)) { - log_error("Cannot mmap zero pages %ld\n", ERRNO_P(g_zero_pages)); + log_error("Cannot mmap zero pages %ld", ERRNO_P(g_zero_pages)); return -ENOMEM; } g_zero_pages_size = g_page_size; @@ -241,9 +241,9 @@ int add_pages_to_enclave(sgx_arch_secs_t* secs, void* addr, void* user_addr, uns } if (size == g_page_size) - log_debug("adding page to enclave: %p [%s:%s] (%s)%s\n", addr, t, p, comment, m); + log_debug("adding page to enclave: %p [%s:%s] (%s)%s", addr, t, p, comment, m); else - log_debug("adding pages to enclave: %p-%p [%s:%s] (%s)%s\n", addr, addr + size, t, p, + log_debug("adding pages to enclave: %p-%p [%s:%s] (%s)%s", addr, addr + size, t, p, comment, m); #ifdef SGX_DCAP @@ -252,14 +252,14 @@ int add_pages_to_enclave(sgx_arch_secs_t* secs, void* addr, void* user_addr, uns /* TODO: this logic can be removed if we introduce a size cap in ENCLAVE_ADD_PAGES ioctl */ ret = INLINE_SYSCALL(munmap, 2, g_zero_pages, g_zero_pages_size); if (ret < 0) { - log_error("Cannot unmap zero pages %d\n", ret); + log_error("Cannot unmap zero pages %d", ret); return ret; } g_zero_pages = (void*)INLINE_SYSCALL(mmap, 6, NULL, size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (IS_ERR_P(g_zero_pages)) { - log_error("Cannot map zero pages %ld\n", ERRNO_P(g_zero_pages)); + log_error("Cannot map zero pages %ld", ERRNO_P(g_zero_pages)); return -ENOMEM; } g_zero_pages_size = size; @@ -291,14 +291,14 @@ int add_pages_to_enclave(sgx_arch_secs_t* secs, void* addr, void* user_addr, uns if (ret < 0) { if (ret == -EINTR) continue; - log_error("Enclave EADD returned %d\n", ret); + log_error("Enclave EADD returned %d", ret); return ret; } uint64_t added_size = ret > 0 ? (uint64_t)ret : param.count; if (!added_size) { log_error("Intel SGX driver did not perform EADD. This may indicate a buggy " - "driver, please update to the most recent version.\n"); + "driver, please update to the most recent version."); return -EPERM; } @@ -312,7 +312,7 @@ int add_pages_to_enclave(sgx_arch_secs_t* secs, void* addr, void* user_addr, uns uint64_t mapped = INLINE_SYSCALL(mmap, 6, addr, size, prot, MAP_FIXED | MAP_SHARED, g_isgx_device, 0); if (IS_ERR_P(mapped)) { - log_error("Cannot map enclave pages %ld\n", ERRNO_P(mapped)); + log_error("Cannot map enclave pages %ld", ERRNO_P(mapped)); return -EACCES; } #else @@ -330,7 +330,7 @@ int add_pages_to_enclave(sgx_arch_secs_t* secs, void* addr, void* user_addr, uns if (ret < 0) { if (ret == -EINTR) continue; - log_error("Enclave EADD returned %d\n", ret); + log_error("Enclave EADD returned %d", ret); return ret; } @@ -343,7 +343,7 @@ int add_pages_to_enclave(sgx_arch_secs_t* secs, void* addr, void* user_addr, uns /* need to change permissions for EADDed pages since the initial mmap was with PROT_NONE */ ret = mprotect(addr, size, prot); if (ret < 0) { - log_error("Changing protections of EADDed pages returned %d\n", ret); + log_error("Changing protections of EADDed pages returned %d", ret); return ret; } #endif /* SGX_DCAP */ @@ -358,9 +358,9 @@ int init_enclave(sgx_arch_secs_t* secs, sgx_arch_enclave_css_t* sigstruct, #endif unsigned long enclave_valid_addr = secs->base + secs->size - g_page_size; - log_debug("enclave initializing:\n"); - log_debug(" enclave id: 0x%016lx\n", enclave_valid_addr); - log_debug(" mr_enclave: %s\n", ALLOCA_BYTES2HEXSTR(sigstruct->body.enclave_hash.m)); + log_debug("enclave initializing:"); + log_debug(" enclave id: 0x%016lx", enclave_valid_addr); + log_debug(" mr_enclave: %s", ALLOCA_BYTES2HEXSTR(sigstruct->body.enclave_hash.m)); struct sgx_enclave_init param = { #ifndef SGX_DCAP @@ -403,14 +403,14 @@ int init_enclave(sgx_arch_secs_t* secs, sgx_arch_enclave_css_t* sigstruct, error = "Unknown reason"; break; } - log_error("enclave EINIT failed - %s\n", error); + log_error("enclave EINIT failed - %s", error); return -EPERM; } /* all enclave pages were EADDed, don't need zero pages anymore */ ret = INLINE_SYSCALL(munmap, 2, g_zero_pages, g_zero_pages_size); if (ret < 0) { - log_error("Cannot unmap zero pages %d\n", ret); + log_error("Cannot unmap zero pages %d", ret); return ret; } @@ -418,12 +418,12 @@ int init_enclave(sgx_arch_secs_t* secs, sgx_arch_enclave_css_t* sigstruct, } int destroy_enclave(void* base_addr, size_t length) { - log_debug("destroying enclave...\n"); + log_debug("destroying enclave..."); int ret = INLINE_SYSCALL(munmap, 2, base_addr, length); if (ret < 0) { - log_error("enclave EDESTROY failed\n"); + log_error("enclave EDESTROY failed"); return ret; } diff --git a/Pal/src/host/Linux-SGX/sgx_log.c b/Pal/src/host/Linux-SGX/sgx_log.c index 622d47767d..7912b7bf39 100644 --- a/Pal/src/host/Linux-SGX/sgx_log.c +++ b/Pal/src/host/Linux-SGX/sgx_log.c @@ -53,8 +53,9 @@ static void print_to_fd(int fd, const char* prefix, const char* fmt, va_list ap) if (prefix) buf_puts(&buf, prefix); buf_vprintf(&buf, fmt, ap); + buf_printf(&buf, "\n"); buf_flush(&buf); - // No error handling, as `_urts_log` doesn't return errors anyways. + // No error handling, as `pal_log` doesn't return errors anyways. } void pal_log(int level, const char* fmt, ...) { diff --git a/Pal/src/host/Linux-SGX/sgx_main.c b/Pal/src/host/Linux-SGX/sgx_main.c index b9b4ea35f5..7bda1c3d9f 100644 --- a/Pal/src/host/Linux-SGX/sgx_main.c +++ b/Pal/src/host/Linux-SGX/sgx_main.c @@ -202,7 +202,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ enclave_image = INLINE_SYSCALL(open, 3, enclave->libpal_uri + URI_PREFIX_FILE_LEN, O_RDONLY, 0); if (enclave_image < 0) { - log_error("Cannot find enclave image: %s\n", enclave->libpal_uri); + log_error("Cannot find enclave image: %s", enclave->libpal_uri); ret = enclave_image; goto out; } @@ -222,7 +222,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ ret = read_enclave_token(enclave->token, &enclave_token); if (ret < 0) { - log_error("Reading enclave token failed: %d\n", ret); + log_error("Reading enclave token failed: %d", ret); goto out; } enclave->pal_sec.enclave_attributes = enclave_token.body.attributes; @@ -230,7 +230,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ #ifdef DEBUG if (enclave->profile_enable) { if (!(enclave->pal_sec.enclave_attributes.flags & SGX_FLAGS_DEBUG)) { - log_error("Cannot use 'sgx.profile' with a production enclave\n"); + log_error("Cannot use 'sgx.profile' with a production enclave"); ret = -EINVAL; goto out; } @@ -243,7 +243,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ ret = read_enclave_sigstruct(enclave->sigfile, &enclave_sigstruct); if (ret < 0) { - log_error("Reading enclave sigstruct failed: %d\n", ret); + log_error("Reading enclave sigstruct failed: %d", ret); goto out; } @@ -252,7 +252,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ enclave_secs.size = enclave->size; ret = create_enclave(&enclave_secs, &enclave_token); if (ret < 0) { - log_error("Creating enclave failed: %d\n", ret); + log_error("Creating enclave failed: %d", ret); goto out; } @@ -371,7 +371,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ ret = scan_enclave_binary(enclave_image, &pal_area->addr, &pal_area->size, &enclave_entry_addr); if (ret < 0) { - log_error("Scanning Pal binary (%s) failed: %d\n", enclave->libpal_uri, ret); + log_error("Scanning Pal binary (%s) failed: %d", enclave->libpal_uri, ret); goto out; } @@ -400,7 +400,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ if (areas[i].data_src == ELF_FD) { ret = load_enclave_binary(&enclave_secs, areas[i].fd, areas[i].addr, areas[i].prot); if (ret < 0) { - log_error("Loading enclave binary failed: %d\n", ret); + log_error("Loading enclave binary failed: %d", ret); goto out; } continue; @@ -412,7 +412,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (IS_ERR_P(data) || data == NULL) { /* Note that Graphene currently doesn't handle 0x0 addresses */ - log_error("Allocating memory failed\n"); + log_error("Allocating memory failed"); ret = -ENOMEM; goto out; } @@ -466,14 +466,14 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ INLINE_SYSCALL(munmap, 2, data, areas[i].size); if (ret < 0) { - log_error("Adding pages (%s) to enclave failed: %d\n", areas[i].desc, ret); + log_error("Adding pages (%s) to enclave failed: %d", areas[i].desc, ret); goto out; } } ret = init_enclave(&enclave_secs, &enclave_sigstruct, &enclave_token); if (ret < 0) { - log_error("Initializing enclave failed: %d\n", ret); + log_error("Initializing enclave failed: %d", ret); goto out; } @@ -483,7 +483,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ mmap, 6, DBGINFO_ADDR, sizeof(struct enclave_dbginfo), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); if (IS_ERR_P(dbg)) { - log_warning("Cannot allocate debug information (GDB will not work)\n"); + log_warning("Cannot allocate debug information (GDB will not work)"); } else { dbg->pid = INLINE_SYSCALL(getpid, 0); dbg->base = enclave->baseaddr; @@ -500,7 +500,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ /* set TCS.FLAGS.DBGOPTIN in all enclave threads to enable perf counters, Intel PT, etc */ ret = INLINE_SYSCALL(open, 3, "/proc/self/mem", O_RDWR | O_LARGEFILE, 0); if (ret < 0) { - log_error("Setting TCS.FLAGS.DBGOPTIN failed: %d\n", ret); + log_error("Setting TCS.FLAGS.DBGOPTIN failed: %d", ret); goto out; } enclave_mem = ret; @@ -512,7 +512,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ ret = INLINE_SYSCALL(pread, 4, enclave_mem, &tcs_flags, sizeof(tcs_flags), (off_t)tcs_flags_ptr); if (ret < 0) { - log_error("Reading TCS.FLAGS.DBGOPTIN failed: %d\n", ret); + log_error("Reading TCS.FLAGS.DBGOPTIN failed: %d", ret); goto out; } @@ -521,7 +521,7 @@ static int initialize_enclave(struct pal_enclave* enclave, const char* manifest_ ret = INLINE_SYSCALL(pwrite, 4, enclave_mem, &tcs_flags, sizeof(tcs_flags), (off_t)tcs_flags_ptr); if (ret < 0) { - log_error("Writing TCS.FLAGS.DBGOPTIN failed: %d\n", ret); + log_error("Writing TCS.FLAGS.DBGOPTIN failed: %d", ret); goto out; } } @@ -572,7 +572,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) log_error( "PAL failed at parsing the manifest: %s\n" " Graphene switched to the TOML format recently, please update the manifest\n" - " (in particular, string values must be put in double quotes)\n", errbuf); + " (in particular, string values must be put in double quotes)", errbuf); ret = -EINVAL; goto out; } @@ -580,13 +580,13 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_sizestring_in(manifest_root, "sgx.enclave_size", /*defaultval=*/0, &enclave_info->size); if (ret < 0) { - log_error("Cannot parse 'sgx.enclave_size' (the value must be put in double quotes!)\n"); + log_error("Cannot parse 'sgx.enclave_size' (the value must be put in double quotes!)"); ret = -EINVAL; goto out; } if (!enclave_info->size || !IS_POWER_OF_2(enclave_info->size)) { - log_error("Enclave size not a power of two (an SGX-imposed requirement)\n"); + log_error("Enclave size not a power of two (an SGX-imposed requirement)"); ret = -EINVAL; goto out; } @@ -594,13 +594,13 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) int64_t thread_num_int64; ret = toml_int_in(manifest_root, "sgx.thread_num", /*defaultval=*/0, &thread_num_int64); if (ret < 0) { - log_error("Cannot parse 'sgx.thread_num'\n"); + log_error("Cannot parse 'sgx.thread_num'"); ret = -EINVAL; goto out; } if (thread_num_int64 < 0) { - log_error("Negative 'sgx.thread_num' is impossible\n"); + log_error("Negative 'sgx.thread_num' is impossible"); ret = -EINVAL; goto out; } @@ -609,12 +609,12 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) if (!enclave_info->thread_num) { log_warning("Number of enclave threads ('sgx.thread_num') is not specified; assumed " - "to be 1\n"); + "to be 1"); enclave_info->thread_num = 1; } if (enclave_info->thread_num > MAX_DBG_THREADS) { - log_error("Too large 'sgx.thread_num', maximum allowed is %d\n", MAX_DBG_THREADS); + log_error("Too large 'sgx.thread_num', maximum allowed is %d", MAX_DBG_THREADS); ret = -EINVAL; goto out; } @@ -622,13 +622,13 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) int64_t rpc_thread_num_int64; ret = toml_int_in(manifest_root, "sgx.rpc_thread_num", /*defaultval=*/0, &rpc_thread_num_int64); if (ret < 0) { - log_error("Cannot parse 'sgx.rpc_thread_num'\n"); + log_error("Cannot parse 'sgx.rpc_thread_num'"); ret = -EINVAL; goto out; } if (rpc_thread_num_int64 < 0) { - log_error("Negative 'sgx.rpc_thread_num' is impossible\n"); + log_error("Negative 'sgx.rpc_thread_num' is impossible"); ret = -EINVAL; goto out; } @@ -636,13 +636,13 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) enclave_info->rpc_thread_num = rpc_thread_num_int64; if (enclave_info->rpc_thread_num > MAX_RPC_THREADS) { - log_error("Too large 'sgx.rpc_thread_num', maximum allowed is %d\n", MAX_RPC_THREADS); + log_error("Too large 'sgx.rpc_thread_num', maximum allowed is %d", MAX_RPC_THREADS); ret = -EINVAL; goto out; } if (enclave_info->rpc_thread_num && enclave_info->thread_num > RPC_QUEUE_SIZE) { - log_error("Too many threads for exitless feature (more than capacity of RPC queue)\n"); + log_error("Too many threads for exitless feature (more than capacity of RPC queue)"); ret = -EINVAL; goto out; } @@ -650,7 +650,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) bool nonpie_binary; ret = toml_bool_in(manifest_root, "sgx.nonpie_binary", /*defaultval=*/false, &nonpie_binary); if (ret < 0) { - log_error("Cannot parse 'sgx.nonpie_binary' (the value must be `true` or `false`)\n"); + log_error("Cannot parse 'sgx.nonpie_binary' (the value must be `true` or `false`)"); ret = -EINVAL; goto out; } @@ -659,7 +659,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_bool_in(manifest_root, "sgx.enable_stats", /*defaultval=*/false, &g_sgx_enable_stats); if (ret < 0) { - log_error("Cannot parse 'sgx.enable_stats' (the value must be `true` or `false`)\n"); + log_error("Cannot parse 'sgx.enable_stats' (the value must be `true` or `false`)"); ret = -EINVAL; goto out; } @@ -668,7 +668,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_string_in(manifest_root, "sgx.sigfile", &dummy_sigfile_str); if (ret < 0 || dummy_sigfile_str) { log_error("sgx.sigfile is not supported anymore. Please update your manifest according to " - "the current documentation.\n"); + "the current documentation."); ret = -EINVAL; goto out; } @@ -678,7 +678,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_bool_in(manifest_root, "sgx.remote_attestation", /*defaultval=*/false, &sgx_remote_attestation_enabled); if (ret < 0) { - log_error("Cannot parse 'sgx.remote_attestation' (the value must be `true` or `false`)\n"); + log_error("Cannot parse 'sgx.remote_attestation' (the value must be `true` or `false`)"); ret = -EINVAL; goto out; } @@ -686,7 +686,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_string_in(manifest_root, "sgx.ra_client_spid", &sgx_ra_client_spid_str); if (ret < 0) { - log_error("Cannot parse 'sgx.ra_client_spid' (the value must be put in double quotes!)\n"); + log_error("Cannot parse 'sgx.ra_client_spid' (the value must be put in double quotes!)"); ret = -EINVAL; goto out; } @@ -699,7 +699,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) log_error( "Detected EPID remote attestation parameters 'ra_client_spid' and/or " "'ra_client_linkable' in the manifest but no 'remote_attestation' parameter. " - "Please add 'sgx.remote_attestation = true' to the manifest.\n"); + "Please add 'sgx.remote_attestation = true' to the manifest."); ret = -EINVAL; goto out; } @@ -711,7 +711,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_string_in(manifest_root, "sgx.profile.enable", &profile_str); if (ret < 0) { log_error("Cannot parse 'sgx.profile.enable' " - "(the value must be \"none\", \"main\" or \"all\")\n"); + "(the value must be \"none\", \"main\" or \"all\")"); ret = -EINVAL; goto out; } @@ -734,7 +734,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) SGX_PROFILE_FILENAME_WITH_PID, (int)INLINE_SYSCALL(getpid, 0)); } else { log_error("Invalid 'sgx.profile.enable' " - "(the value must be \"none\", \"main\" or \"all\")\n"); + "(the value must be \"none\", \"main\" or \"all\")"); ret = -EINVAL; goto out; } @@ -743,7 +743,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_string_in(manifest_root, "sgx.profile.mode", &profile_mode_str); if (ret < 0) { log_error("Cannot parse 'sgx.profile.mode' " - "(the value must be \"aex\", \"ocall_inner\" or \"ocall_outer\")\n"); + "(the value must be \"aex\", \"ocall_inner\" or \"ocall_outer\")"); ret = -EINVAL; goto out; } @@ -757,7 +757,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) enclave_info->profile_mode = SGX_PROFILE_MODE_OCALL_OUTER; } else { log_error("Invalid 'sgx.profile.mode' " - "(the value must be \"aex\", \"ocall_inner\" or \"ocall_outer\")\n"); + "(the value must be \"aex\", \"ocall_inner\" or \"ocall_outer\")"); ret = -EINVAL; goto out; } @@ -766,7 +766,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_bool_in(manifest_root, "sgx.profile.with_stack", /*defaultval=*/false, &profile_with_stack); if (ret < 0) { - log_error("Cannot parse 'sgx.profile.with_stack' (the value must be `true` or `false`)\n"); + log_error("Cannot parse 'sgx.profile.with_stack' (the value must be `true` or `false`)"); ret = -EINVAL; goto out; } @@ -776,7 +776,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) enclave_info->profile_mode == SGX_PROFILE_MODE_OCALL_OUTER) { log_error("Invalid 'sgx.profile.mode' and 'sgx.profile.with_stack' combination " - "(\"ocall_outer\" mode cannot be used with stack)\n"); + "(\"ocall_outer\" mode cannot be used with stack)"); ret = -EINVAL; goto out; } @@ -785,8 +785,8 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = toml_int_in(manifest_root, "sgx.profile.frequency", SGX_PROFILE_DEFAULT_FREQUENCY, &profile_frequency); if (ret < 0 || !(0 < profile_frequency && profile_frequency <= SGX_PROFILE_MAX_FREQUENCY)) { - log_error("Cannot parse 'sgx.profile.frequency' " - "(the value must be between 1 and %d)\n", SGX_PROFILE_MAX_FREQUENCY); + log_error("Cannot parse 'sgx.profile.frequency' (the value must be between 1 and %d)", + SGX_PROFILE_MAX_FREQUENCY); ret = -EINVAL; goto out; } @@ -794,7 +794,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) #else if (profile_str && strcmp(profile_str, "none")) { log_error("Invalid 'sgx.profile.enable' " - "(SGX profiling works only when Graphene is compiled with DEBUG=1)\n"); + "(SGX profiling works only when Graphene is compiled with DEBUG=1)"); ret = -EINVAL; goto out; } @@ -804,7 +804,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) char* log_level_str = NULL; ret = toml_string_in(manifest_root, "loader.log_level", &log_level_str); if (ret < 0) { - log_error("Cannot parse 'loader.log_level'\n"); + log_error("Cannot parse 'loader.log_level'"); ret = -EINVAL; goto out; } @@ -822,7 +822,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) } else if (!strcmp(log_level_str, "all")) { log_level = LOG_LEVEL_ALL; } else { - log_error("Unknown 'loader.log_level'\n"); + log_error("Unknown 'loader.log_level'"); ret = -EINVAL; goto out; } @@ -832,7 +832,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) char* log_file = NULL; ret = toml_string_in(manifest_root, "loader.log_file", &log_file); if (ret < 0) { - log_error("Cannot parse 'loader.log_file'\n"); + log_error("Cannot parse 'loader.log_file'"); ret = -EINVAL; goto out; } @@ -840,7 +840,7 @@ static int parse_loader_config(char* manifest, struct pal_enclave* enclave_info) ret = urts_log_init(log_file); if (ret < 0) { - log_error("Cannot open log file: %d\n", ret); + log_error("Cannot open log file: %d", ret); goto out; } } @@ -870,7 +870,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz ret = parse_loader_config(enclave->raw_manifest_data, enclave); if (ret < 0) { - log_error("Parsing manifest failed\n"); + log_error("Parsing manifest failed"); return -EINVAL; } @@ -902,7 +902,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz /* TODO: correctly support offline cores */ if (possible_logical_cores > 0 && possible_logical_cores > online_logical_cores) { log_warning("some CPUs seem to be offline; Graphene doesn't take this into account " - "which may lead to subpar performance\n"); + "which may lead to subpar performance"); } int core_siblings = get_hw_resource("/sys/devices/system/cpu/cpu0/topology/core_siblings_list", @@ -927,7 +927,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", idx); cpu_socket[idx] = get_hw_resource(filename, /*count=*/false); if (cpu_socket[idx] < 0) { - log_error("Cannot read %s\n", filename); + log_error("Cannot read %s", filename); ret = cpu_socket[idx]; free(cpu_socket); return ret; @@ -943,7 +943,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz size_t env_i = 0; while (env_i < env_size) { if (!strcmp(&env[env_i], "IN_GDB=1")) { - log_warning("[ Running under GDB ]\n"); + log_warning("[ Running under GDB ]"); pal_sec->in_gdb = true; } @@ -953,12 +953,12 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz enclave->libpal_uri = alloc_concat(URI_PREFIX_FILE, URI_PREFIX_FILE_LEN, g_libpal_path, -1); if (!enclave->libpal_uri) { - log_error("Out of memory for enclave->libpal_uri\n"); + log_error("Out of memory for enclave->libpal_uri"); return -ENOMEM; } if (enclave->libpal_uri[URI_PREFIX_FILE_LEN] != '/') { - log_error("Path to in-enclave PAL (%s) must be absolute\n", enclave->libpal_uri); + log_error("Path to in-enclave PAL (%s) must be absolute", enclave->libpal_uri); return -EINVAL; } @@ -969,7 +969,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz enclave->sigfile = INLINE_SYSCALL(open, 3, sig_path, O_RDONLY | O_CLOEXEC, 0); if (enclave->sigfile < 0) { - log_error("Cannot open sigstruct file %s\n", sig_path); + log_error("Cannot open sigstruct file %s", sig_path); return -EINVAL; } free(sig_path); @@ -983,11 +983,11 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz if (enclave->token < 0) { log_error( "Cannot open token %s. Use graphene-sgx-get-token on the runtime host or run " - "`make SGX=1 sgx-tokens` in the Graphene source to create the token file.\n", + "`make SGX=1 sgx-tokens` in the Graphene source to create the token file.", token_path); return -EINVAL; } - log_debug("Token file: %s\n", token_path); + log_debug("Token file: %s", token_path); free(token_path); ret = initialize_enclave(enclave, enclave->raw_manifest_data); @@ -1004,7 +1004,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz if (enclave->remote_attestation_enabled) { /* initialize communication with Quoting Enclave only if app requests attestation */ bool is_epid = enclave->use_epid_attestation; - log_debug("Using SGX %s attestation\n", is_epid ? "EPID" : "DCAP/ECDSA"); + log_debug("Using SGX %s attestation", is_epid ? "EPID" : "DCAP/ECDSA"); ret = init_quoting_enclave_targetinfo(is_epid, &pal_sec->qe_targetinfo); if (ret < 0) return ret; @@ -1031,7 +1031,7 @@ static int load_enclave(struct pal_enclave* enclave, char* args, size_t args_siz /* This shows the time for Graphene + the Intel SGX driver to initialize the untrusted * PAL, config and create the SGX enclave, add enclave pages, measure and init it. */ - log_always("----- SGX enclave loading time = %10lu microseconds -----\n", + log_always("----- SGX enclave loading time = %10lu microseconds -----", end_time - start_time); } @@ -1056,10 +1056,10 @@ noreturn static void print_usage_and_exit(const char* argv_0) { const char* self = argv_0 ?: ""; log_always("USAGE:\n" "\tFirst process: %s init args...\n" - "\tChildren: %s child args...\n", + "\tChildren: %s child args...", self, self); log_always("This is an internal interface. Use pal_loader to launch applications in " - "Graphene.\n"); + "Graphene."); INLINE_SYSCALL(exit_group, 1, 1); die_or_inf_loop(); } @@ -1105,10 +1105,10 @@ int main(int argc, char* argv[], char* envp[]) { return -ENOMEM; } - log_debug("Manifest file: %s\n", manifest_path); + log_debug("Manifest file: %s", manifest_path); ret = read_text_file_to_cstr(manifest_path, &manifest); if (ret < 0) { - log_error("Reading manifest failed\n"); + log_error("Reading manifest failed"); return ret; } free(manifest_path); @@ -1150,7 +1150,7 @@ int main(int argc, char* argv[], char* envp[]) { ret = load_enclave(&g_pal_enclave, args, args_size, env, env_size, need_gsgx); if (ret < 0) { - log_error("load_enclave() failed with error %d\n", ret); + log_error("load_enclave() failed with error %d", ret); } return 0; } diff --git a/Pal/src/host/Linux-SGX/sgx_perf_data.c b/Pal/src/host/Linux-SGX/sgx_perf_data.c index 959a4add45..5952dc2b40 100644 --- a/Pal/src/host/Linux-SGX/sgx_perf_data.c +++ b/Pal/src/host/Linux-SGX/sgx_perf_data.c @@ -144,7 +144,7 @@ struct perf_data* pd_open(const char* file_name, bool with_stack) { int fd = INLINE_SYSCALL(open, 3, file_name, O_WRONLY | O_TRUNC | O_CREAT, PERM_rw_r__r__); if (fd < 0) { - log_error("pd_open: cannot open %s for writing: %d\n", file_name, fd); + log_error("pd_open: cannot open %s for writing: %d", file_name, fd); return NULL; } @@ -163,7 +163,7 @@ struct perf_data* pd_open(const char* file_name, bool with_stack) { struct perf_data* pd = malloc(sizeof(*pd)); if (!pd) { - log_error("pd_open: out of memory\n"); + log_error("pd_open: out of memory"); goto fail; } @@ -175,7 +175,7 @@ struct perf_data* pd_open(const char* file_name, bool with_stack) { fail: ret = INLINE_SYSCALL(close, 1, fd); if (ret < 0) - log_error("pd_open: close failed: %d\n", ret); + log_error("pd_open: close failed: %d", ret); return NULL; }; @@ -284,7 +284,7 @@ ssize_t pd_close(struct perf_data* pd) { out: close_ret = INLINE_SYSCALL(close, 1, pd->fd); if (close_ret < 0) - log_error("pd_close: close failed: %d\n", close_ret); + log_error("pd_close: close failed: %d", close_ret); free(pd); return ret; diff --git a/Pal/src/host/Linux-SGX/sgx_platform.c b/Pal/src/host/Linux-SGX/sgx_platform.c index 5cf490bc81..4f26f1d428 100644 --- a/Pal/src/host/Linux-SGX/sgx_platform.c +++ b/Pal/src/host/Linux-SGX/sgx_platform.c @@ -77,7 +77,7 @@ static int connect_aesm_service(void) { INLINE_SYSCALL(close, 1, sock); log_error("Cannot connect to aesm_service (tried " AESM_SOCKET_NAME_LEGACY " and " AESM_SOCKET_NAME_NEW " UNIX sockets).\nPlease check its status! (`service aesmd " - "status` on Ubuntu)\n"); + "status` on Ubuntu)"); return ret; } @@ -125,7 +125,7 @@ static int request_aesm_service(Request* req, Response** res) { INLINE_SYSCALL(close, 1, aesm_socket); if (ret < 0) { log_error("Cannot communicate with aesm_service (read/write returned error %d).\n" - "Please check its status! (`service aesmd status` on Ubuntu)\n", ret); + "Please check its status! (`service aesmd status` on Ubuntu)", ret); } return ret; } @@ -146,18 +146,18 @@ int init_quoting_enclave_targetinfo(bool is_epid, sgx_target_info_t* qe_targetin ret = -EPERM; if (!res->initquoteres) { - log_error("aesm_service returned wrong message\n"); + log_error("aesm_service returned wrong message"); goto failed; } Response__InitQuoteResponse* r = res->initquoteres; if (r->errorcode != 0) { - log_error("aesm_service returned error: %d\n", r->errorcode); + log_error("aesm_service returned error: %d", r->errorcode); goto failed; } if (r->targetinfo.len != sizeof(*qe_targetinfo)) { - log_error("Quoting Enclave returned invalid target info\n"); + log_error("Quoting Enclave returned invalid target info"); goto failed; } @@ -183,18 +183,18 @@ int init_quoting_enclave_targetinfo(bool is_epid, sgx_target_info_t* qe_targetin ret = -EPERM; if (!res->initquoteexres) { - log_error("aesm_service returned wrong message\n"); + log_error("aesm_service returned wrong message"); goto failed; } Response__InitQuoteExResponse* r = res->initquoteexres; if (r->errorcode != 0) { - log_error("aesm_service returned error: %d\n", r->errorcode); + log_error("aesm_service returned error: %d", r->errorcode); goto failed; } if (r->target_info.len != sizeof(*qe_targetinfo)) { - log_error("Quoting Enclave returned invalid target info\n"); + log_error("Quoting Enclave returned invalid target info"); goto failed; } @@ -246,18 +246,18 @@ int retrieve_quote(const sgx_spid_t* spid, bool linkable, const sgx_report_t* re ret = -EPERM; if (!res->getquoteexres) { - log_error("aesm_service returned wrong message\n"); + log_error("aesm_service returned wrong message"); goto out; } Response__GetQuoteExResponse* r = res->getquoteexres; if (r->errorcode != 0) { - log_error("aesm_service returned error: %d\n", r->errorcode); + log_error("aesm_service returned error: %d", r->errorcode); goto out; } if (!r->has_quote || r->quote.len < sizeof(sgx_quote_t)) { - log_error("aesm_service returned invalid quote\n"); + log_error("aesm_service returned invalid quote"); goto out; } @@ -284,18 +284,18 @@ int retrieve_quote(const sgx_spid_t* spid, bool linkable, const sgx_report_t* re ret = -EPERM; if (!res->getquoteres) { - log_error("aesm_service returned wrong message\n"); + log_error("aesm_service returned wrong message"); goto out; } Response__GetQuoteResponse* r = res->getquoteres; if (r->errorcode != 0) { - log_error("aesm_service returned error: %d\n", r->errorcode); + log_error("aesm_service returned error: %d", r->errorcode); goto out; } if (!r->has_quote || r->quote.len < sizeof(sgx_quote_t)) { - log_error("aesm_service returned invalid quote\n"); + log_error("aesm_service returned invalid quote"); goto out; } @@ -307,7 +307,7 @@ int retrieve_quote(const sgx_spid_t* spid, bool linkable, const sgx_report_t* re * by peeking into the quote and determining the size of the signature. */ size_t actual_quote_size = sizeof(sgx_quote_t) + actual_quote->signature_len; if (actual_quote_size > SGX_QUOTE_MAX_SIZE) { - log_error("Size of the obtained SGX quote exceeds %d\n", SGX_QUOTE_MAX_SIZE); + log_error("Size of the obtained SGX quote exceeds %d", SGX_QUOTE_MAX_SIZE); goto out; } @@ -315,7 +315,7 @@ int retrieve_quote(const sgx_spid_t* spid, bool linkable, const sgx_report_t* re PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (IS_ERR_P(mmapped)) { - log_error("Failed to allocate memory for the quote\n"); + log_error("Failed to allocate memory for the quote"); goto out; } diff --git a/Pal/src/host/Linux-SGX/sgx_process.c b/Pal/src/host/Linux-SGX/sgx_process.c index 250344ccd4..e23979bad6 100644 --- a/Pal/src/host/Linux-SGX/sgx_process.c +++ b/Pal/src/host/Linux-SGX/sgx_process.c @@ -56,7 +56,7 @@ static int __attribute_noinline vfork_exec(int parent_stream, const char** argv) ret = INLINE_SYSCALL(execve, 3, g_pal_loader_path, argv, environ); /* shouldn't get to here */ - log_error("unexpected failure of execve\n"); + log_error("unexpected failure of execve"); __asm__ volatile("hlt"); return 0; } diff --git a/Pal/src/host/Linux-SGX/sgx_profile.c b/Pal/src/host/Linux-SGX/sgx_profile.c index 45fcb26a92..741d002ae0 100644 --- a/Pal/src/host/Linux-SGX/sgx_profile.c +++ b/Pal/src/host/Linux-SGX/sgx_profile.c @@ -108,14 +108,14 @@ int sgx_profile_init(void) { ret = INLINE_SYSCALL(open, 3, "/proc/self/mem", O_RDONLY | O_LARGEFILE, 0); if (ret < 0) { - log_error("sgx_profile_init: opening /proc/self/mem failed: %d\n", ret); + log_error("sgx_profile_init: opening /proc/self/mem failed: %d", ret); goto out; } g_mem_fd = ret; struct perf_data* pd = pd_open(g_pal_enclave.profile_filename, g_pal_enclave.profile_with_stack); if (!pd) { - log_error("sgx_profile_init: pd_open failed\n"); + log_error("sgx_profile_init: pd_open failed"); ret = -EINVAL; goto out; } @@ -124,7 +124,7 @@ int sgx_profile_init(void) { pid_t pid = g_pal_enclave.pal_sec.pid; ret = pd_event_command(pd, "pal-sgx", pid, /*tid=*/pid); if (!pd) { - log_error("sgx_profile_init: reporting command failed: %d\n", ret); + log_error("sgx_profile_init: reporting command failed: %d", ret); goto out; } @@ -135,14 +135,14 @@ int sgx_profile_init(void) { if (g_mem_fd > 0) { int close_ret = INLINE_SYSCALL(close, 1, g_mem_fd); if (close_ret < 0) - log_error("sgx_profile_init: closing /proc/self/mem failed: %d\n", close_ret); + log_error("sgx_profile_init: closing /proc/self/mem failed: %d", close_ret); g_mem_fd = -1; } if (g_perf_data) { ssize_t close_ret = pd_close(g_perf_data); if (close_ret < 0) - log_error("sgx_profile_init: pd_close failed: %ld\n", close_ret); + log_error("sgx_profile_init: pd_close failed: %ld", close_ret); g_perf_data = NULL; } return ret; @@ -159,17 +159,17 @@ void sgx_profile_finish(void) { size = pd_close(g_perf_data); if (size < 0) - log_error("sgx_profile_finish: pd_close failed: %ld\n", size); + log_error("sgx_profile_finish: pd_close failed: %ld", size); g_perf_data = NULL; spinlock_unlock(&g_perf_data_lock); ret = INLINE_SYSCALL(close, 1, g_mem_fd); if (ret < 0) - log_error("sgx_profile_finish: closing /proc/self/mem failed: %d\n", ret); + log_error("sgx_profile_finish: closing /proc/self/mem failed: %d", ret); g_mem_fd = -1; - log_debug("Profile data written to %s (%lu bytes)\n", g_pal_enclave.profile_filename, size); + log_debug("Profile data written to %s (%lu bytes)", g_pal_enclave.profile_filename, size); g_profile_enabled = false; } @@ -186,7 +186,7 @@ static void sample_simple(uint64_t rip) { spinlock_unlock(&g_perf_data_lock); if (ret < 0) { - log_error("error recording sample: %d\n", ret); + log_error("error recording sample: %d", ret); } } @@ -201,7 +201,7 @@ static void sample_stack(sgx_pal_gpr_t* gpr) { size_t stack_size; ret = debug_read(stack, (void*)gpr->rsp, sizeof(stack)); if (ret < 0) { - log_error("error reading stack: %d\n", ret); + log_error("error reading stack: %d", ret); return; } stack_size = ret; @@ -212,7 +212,7 @@ static void sample_stack(sgx_pal_gpr_t* gpr) { spinlock_unlock(&g_perf_data_lock); if (ret < 0) { - log_error("error recording sample: %d\n", ret); + log_error("error recording sample: %d", ret); } } @@ -229,7 +229,7 @@ static bool update_time(void) { struct timespec ts; int ret = INLINE_SYSCALL(clock_gettime, 2, CLOCK_THREAD_CPUTIME_ID, &ts); if (ret < 0) { - log_error("sgx_profile_sample: clock_gettime failed: %d\n", ret); + log_error("sgx_profile_sample: clock_gettime failed: %d", ret); return false; } uint64_t sample_time = ts.tv_sec * NSEC_IN_SEC + ts.tv_nsec; @@ -261,7 +261,7 @@ void sgx_profile_sample_aex(void* tcs) { sgx_pal_gpr_t gpr; ret = get_sgx_gpr(&gpr, tcs); if (ret < 0) { - log_error("sgx_profile_sample_aex: error reading GPR: %d\n", ret); + log_error("sgx_profile_sample_aex: error reading GPR: %d", ret); return; } @@ -284,7 +284,7 @@ void sgx_profile_sample_ocall_inner(void* enclave_gpr) { sgx_pal_gpr_t gpr; ret = debug_read_all(&gpr, enclave_gpr, sizeof(gpr)); if (ret < 0) { - log_error("sgx_profile_sample_ocall_inner: error reading GPR: %d\n", ret); + log_error("sgx_profile_sample_ocall_inner: error reading GPR: %d", ret); return; } @@ -321,7 +321,7 @@ void sgx_profile_report_elf(const char* filename, void* addr) { char buf[PATH_MAX]; char* path = realpath(filename, buf); if (!path) { - log_error("sgx_profile_report_elf(%s): realpath failed\n", filename); + log_error("sgx_profile_report_elf(%s): realpath failed", filename); return; } @@ -329,19 +329,19 @@ void sgx_profile_report_elf(const char* filename, void* addr) { int fd = INLINE_SYSCALL(open, 3, path, O_RDONLY, 0); if (fd < 0) { - log_error("sgx_profile_report_elf(%s): open failed: %d\n", filename, fd); + log_error("sgx_profile_report_elf(%s): open failed: %d", filename, fd); return; } off_t elf_length = INLINE_SYSCALL(lseek, 3, fd, 0, SEEK_END); if (elf_length < 0) { - log_error("sgx_profile_report_elf(%s): lseek failed: %ld\n", filename, elf_length); + log_error("sgx_profile_report_elf(%s): lseek failed: %ld", filename, elf_length); goto out_close; } void* elf_addr = (void*)INLINE_SYSCALL(mmap, 6, NULL, elf_length, PROT_READ, MAP_PRIVATE, fd, 0); if (IS_ERR_P(elf_addr)) { - log_error("sgx_profile_report_elf(%s): mmap failed: %ld\n", filename, ERRNO_P(addr)); + log_error("sgx_profile_report_elf(%s): mmap failed: %ld", filename, ERRNO_P(addr)); goto out_close; } @@ -351,7 +351,7 @@ void sgx_profile_report_elf(const char* filename, void* addr) { const ElfW(Ehdr)* ehdr = elf_addr; if (elf_length < (off_t)sizeof(*ehdr) || memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0) { - log_error("sgx_profile_report_elf(%s): invalid ELF binary\n", filename); + log_error("sgx_profile_report_elf(%s): invalid ELF binary", filename); goto out_unmap; } @@ -377,19 +377,19 @@ void sgx_profile_report_elf(const char* filename, void* addr) { spinlock_unlock(&g_perf_data_lock); if (ret < 0) - log_error("sgx_profile_report_elf(%s): pd_event_mmap failed: %d\n", filename, ret); + log_error("sgx_profile_report_elf(%s): pd_event_mmap failed: %d", filename, ret); // Clean up. out_unmap: ret = INLINE_SYSCALL(munmap, 2, elf_addr, elf_length); if (ret < 0) - log_error("sgx_profile_report_elf(%s): munmap failed: %d\n", filename, ret); + log_error("sgx_profile_report_elf(%s): munmap failed: %d", filename, ret); out_close: ret = INLINE_SYSCALL(close, 1, fd); if (ret < 0) - log_error("sgx_profile_report_elf(%s): close failed: %d\n", filename, ret); + log_error("sgx_profile_report_elf(%s): close failed: %d", filename, ret); } #endif /* DEBUG */ diff --git a/Pal/src/host/Linux-SGX/sgx_thread.c b/Pal/src/host/Linux-SGX/sgx_thread.c index 0cd70cd857..e3446a4514 100644 --- a/Pal/src/host/Linux-SGX/sgx_thread.c +++ b/Pal/src/host/Linux-SGX/sgx_thread.c @@ -47,7 +47,7 @@ void update_and_print_stats(bool process_wide) { " # of EEXITs: %lu\n" " # of AEXs: %lu\n" " # of sync signals: %lu\n" - " # of async signals: %lu\n", + " # of async signals: %lu", tid, tcb->eenter_cnt, tcb->eexit_cnt, tcb->aex_cnt, tcb->sync_signal_cnt, tcb->async_signal_cnt); @@ -65,7 +65,7 @@ void update_and_print_stats(bool process_wide) { " # of EEXITs: %lu\n" " # of AEXs: %lu\n" " # of sync signals: %lu\n" - " # of async signals: %lu\n", + " # of async signals: %lu", pid, g_eenter_cnt, g_eexit_cnt, g_aex_cnt, g_sync_signal_cnt, g_async_signal_cnt); } @@ -177,7 +177,7 @@ int pal_thread_init(void* tcbptr) { log_error( "There are no available TCS pages left for a new thread!\n" "Please try to increase sgx.thread_num in the manifest.\n" - "The current value is %d\n", + "The current value is %d", g_enclave_thread_num); ret = -ENOMEM; goto out; diff --git a/Pal/src/host/Linux/arch/x86_64/db_arch_misc.c b/Pal/src/host/Linux/arch/x86_64/db_arch_misc.c index fed87e3c0d..85cca06145 100644 --- a/Pal/src/host/Linux/arch/x86_64/db_arch_misc.c +++ b/Pal/src/host/Linux/arch/x86_64/db_arch_misc.c @@ -128,7 +128,7 @@ int _DkGetCPUInfo(PAL_CPU_INFO* ci) { /* TODO: correctly support offline cores */ if (possible_logical_cores > 0 && possible_logical_cores > online_logical_cores) { log_warning("some CPUs seem to be offline; Graphene doesn't take this into account which " - "may lead to subpar performance\n"); + "may lead to subpar performance"); } int core_siblings = get_hw_resource("/sys/devices/system/cpu/cpu0/topology/core_siblings_list", @@ -159,7 +159,7 @@ int _DkGetCPUInfo(PAL_CPU_INFO* ci) { "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", idx); cpu_socket[idx] = get_hw_resource(filename, /*count=*/false); if (cpu_socket[idx] < 0) { - log_warning("Cannot read %s\n", filename); + log_warning("Cannot read %s", filename); rv = unix_to_pal_error(cpu_socket[idx]); goto out_phy_id; } @@ -212,7 +212,7 @@ int _DkGetCPUInfo(PAL_CPU_INFO* ci) { ci->cpu_bogomips = get_bogomips(); if (ci->cpu_bogomips == 0.0) { - log_warning("bogomips could not be retrieved, passing 0.0 to the application\n"); + log_warning("bogomips could not be retrieved, passing 0.0 to the application"); } return rv; diff --git a/Pal/src/host/Linux/db_exception.c b/Pal/src/host/Linux/db_exception.c index b86f947a75..0d534fcb94 100644 --- a/Pal/src/host/Linux/db_exception.c +++ b/Pal/src/host/Linux/db_exception.c @@ -107,7 +107,7 @@ static void handle_sync_signal(int signum, siginfo_t* info, struct ucontext* uc) } bool in_vdso = is_in_vdso(rip); - log_error("*** Unexpected %s occurred inside %s (PID = %ld, TID = %ld, RIP = +0x%08lx)! ***\n", + log_error("*** Unexpected %s occurred inside %s (PID = %ld, TID = %ld, RIP = +0x%08lx)! ***", name, in_vdso ? "VDSO" : "PAL", INLINE_SYSCALL(getpid, 0), INLINE_SYSCALL(gettid, 0), rip - (in_vdso ? g_vdso_start : (uintptr_t)TEXT_START)); diff --git a/Pal/src/host/Linux/db_main.c b/Pal/src/host/Linux/db_main.c index 2e9e59a7dc..36c26e485c 100644 --- a/Pal/src/host/Linux/db_main.c +++ b/Pal/src/host/Linux/db_main.c @@ -140,10 +140,9 @@ noreturn static void print_usage_and_exit(const char* argv_0) { const char* self = argv_0 ?: ""; log_always("USAGE:\n" "\tFirst process: %s init args...\n" - "\tChildren: %s child args...\n", + "\tChildren: %s child args...", self, self); - log_always("This is an internal interface. Use pal_loader to launch applications in " - "Graphene.\n"); + log_always("This is an internal interface. Use pal_loader to launch applications in Graphene."); _DkProcessExit(1); } @@ -247,7 +246,7 @@ noreturn void pal_linux_main(void* initial_rsp, void* fini_callback) { INIT_FAIL(PAL_ERROR_NOMEM, "Out of memory"); } } else { - log_warning("vdso address range not preloaded, is your system missing vdso?!\n"); + log_warning("vdso address range not preloaded, is your system missing vdso?!"); } if (vvar_start || vvar_end) { ret = add_preloaded_range(vvar_start, vvar_end, "vvar"); @@ -255,7 +254,7 @@ noreturn void pal_linux_main(void* initial_rsp, void* fini_callback) { INIT_FAIL(PAL_ERROR_NOMEM, "Out of memory"); } } else { - log_warning("vvar address range not preloaded, is your system missing vvar?!\n"); + log_warning("vvar address range not preloaded, is your system missing vvar?!"); } if (!g_pal_sec.process_id) diff --git a/Pal/src/host/Linux/db_memory.c b/Pal/src/host/Linux/db_memory.c index 1de85ec9a5..6b5b065a09 100644 --- a/Pal/src/host/Linux/db_memory.c +++ b/Pal/src/host/Linux/db_memory.c @@ -35,7 +35,7 @@ static spinlock_t g_pal_internal_mem_lock = INIT_SPINLOCK_UNLOCKED; bool _DkCheckMemoryMappable(const void* addr, size_t size) { if (addr < DATA_END && addr + size > TEXT_START) { - log_error("Address %p-%p is not mappable\n", addr, addr + size); + log_error("Address %p-%p is not mappable", addr, addr + size); return true; } return false; diff --git a/Pal/src/host/Linux/db_rtld.c b/Pal/src/host/Linux/db_rtld.c index 55d8afec56..226e80c6b9 100644 --- a/Pal/src/host/Linux/db_rtld.c +++ b/Pal/src/host/Linux/db_rtld.c @@ -29,13 +29,13 @@ bool is_in_vdso(uintptr_t addr) { void _DkDebugMapAdd(const char* name, void* addr) { int ret = debug_map_add(name, addr); if (ret < 0) - log_error("debug_map_add(%s, %p) failed: %d\n", name, addr, ret); + log_error("debug_map_add(%s, %p) failed: %d", name, addr, ret); } void _DkDebugMapRemove(void* addr) { int ret = debug_map_remove(addr); if (ret < 0) - log_error("debug_map_remove(%p) failed: %d\n", addr, ret); + log_error("debug_map_remove(%p) failed: %d", addr, ret); } void setup_pal_map(struct link_map* pal_map) { @@ -82,8 +82,7 @@ void setup_vdso_map(ElfW(Addr) addr) { } if (pt_loads_count != 1) { - log_warning("The VDSO has %lu PT_LOAD segments, but only 1 was expected.\n", - pt_loads_count); + log_warning("The VDSO has %lu PT_LOAD segments, but only 1 was expected.", pt_loads_count); g_vdso_start = 0; g_vdso_end = 0; return; diff --git a/Pal/src/printf.c b/Pal/src/printf.c index 5cbcd8952c..ede4d188fc 100644 --- a/Pal/src/printf.c +++ b/Pal/src/printf.c @@ -28,6 +28,7 @@ static void log_vprintf(const char* prefix, const char* fmt, va_list ap) { if (prefix) buf_puts(&buf, prefix); buf_vprintf(&buf, fmt, ap); + buf_printf(&buf, "\n"); buf_flush(&buf); } diff --git a/Pal/src/slab.c b/Pal/src/slab.c index 5b48be56a2..8cc50fd436 100644 --- a/Pal/src/slab.c +++ b/Pal/src/slab.c @@ -73,7 +73,7 @@ static inline void* __malloc(size_t size) { int ret = _DkVirtualMemoryAlloc(&addr, ALLOC_ALIGN_UP(size), PAL_ALLOC_INTERNAL, PAL_PROT_READ | PAL_PROT_WRITE); if (ret < 0) { - log_error("*** Out-of-memory in PAL (try increasing `loader.pal_internal_mem_size`) ***\n"); + log_error("*** Out-of-memory in PAL (try increasing `loader.pal_internal_mem_size`) ***"); _DkProcessExit(ENOMEM); } return addr; @@ -130,7 +130,7 @@ void* malloc(size_t size) { * If malloc() failed internally, we cannot handle the * condition and must terminate the current process. */ - log_error("******** Out-of-memory in PAL ********\n"); + log_error("******** Out-of-memory in PAL ********"); _DkProcessExit(ENOMEM); } return ptr; diff --git a/common/include/assert.h b/common/include/assert.h index 48471da4d6..9a8f2cf6bb 100644 --- a/common/include/assert.h +++ b/common/include/assert.h @@ -24,7 +24,7 @@ #define assert(expr) \ ({ \ if (expr) {} else { \ - log_always("assert failed " __FILE__ ":%d %s\n", __LINE__, #expr); \ + log_always("assert failed " __FILE__ ":%d %s", __LINE__, #expr); \ abort(); \ } \ (void)0; \ diff --git a/common/include/log.h b/common/include/log.h index 7af4056061..29edd434b7 100644 --- a/common/include/log.h +++ b/common/include/log.h @@ -15,6 +15,7 @@ enum { LOG_LEVEL_ALL = 5, }; +/* All of them implicitly append a newline at the end of the message. */ #define log_always(fmt...) _log(LOG_LEVEL_NONE, fmt) #define log_error(fmt...) _log(LOG_LEVEL_ERROR, fmt) #define log_warning(fmt...) _log(LOG_LEVEL_WARNING, fmt) diff --git a/common/include/slabmgr.h b/common/include/slabmgr.h index 4aa86b478a..b695df5cf2 100644 --- a/common/include/slabmgr.h +++ b/common/include/slabmgr.h @@ -354,7 +354,7 @@ static inline size_t slab_get_buf_size(const void* ptr) { } if (level >= SLAB_LEVEL) { - log_always("Heap corruption detected: invalid heap level %u\n", level); + log_always("Heap corruption detected: invalid heap level %u", level); abort(); } @@ -393,7 +393,7 @@ static inline void slab_free(SLAB_MGR mgr, void* obj) { * more likely to be detected by adding a non-zero offset to the level, * so a level of 0 in the header would no longer be a valid level. */ if (level >= SLAB_LEVEL) { - log_always("Heap corruption detected: invalid heap level %d\n", level); + log_always("Heap corruption detected: invalid heap level %d", level); abort(); } diff --git a/common/src/stack_protector.c b/common/src/stack_protector.c index 9e7532a283..71042285e6 100644 --- a/common/src/stack_protector.c +++ b/common/src/stack_protector.c @@ -12,6 +12,6 @@ noreturn void __stack_chk_fail(void); noreturn void __stack_chk_fail(void) { - log_always("Stack protector: Graphene internal stack corruption detected\n"); + log_always("Stack protector: Graphene internal stack corruption detected"); abort(); } diff --git a/common/src/stdlib/printfmt.c b/common/src/stdlib/printfmt.c index 5e67ddae32..710f185c3d 100644 --- a/common/src/stdlib/printfmt.c +++ b/common/src/stdlib/printfmt.c @@ -282,7 +282,7 @@ int __vsnprintf_chk(char* buf, size_t buf_size, int flag, size_t real_size, cons va_list ap) { __UNUSED(flag); if (buf_size > real_size) { - log_always("vsnprintf() check failed\n"); + log_always("vsnprintf() check failed"); abort(); } return vsnprintf(buf, buf_size, fmt, ap); @@ -302,7 +302,7 @@ int snprintf(char* buf, size_t buf_size, const char* fmt, ...) { int __snprintf_chk(char* buf, size_t buf_size, int flag, size_t real_size, const char* fmt, ...) { __UNUSED(flag); if (buf_size > real_size) { - log_always("vsnprintf() check failed\n"); + log_always("vsnprintf() check failed"); abort(); } diff --git a/common/src/string/memcpy.c b/common/src/string/memcpy.c index 01fb52a8a9..df94f68406 100644 --- a/common/src/string/memcpy.c +++ b/common/src/string/memcpy.c @@ -31,7 +31,7 @@ void* memcpy(void* restrict dest, const void* restrict src, size_t count) { void* __memcpy_chk(void* restrict dest, const void* restrict src, size_t count, size_t dest_count) { if (count > dest_count) { - log_always("memcpy() check failed\n"); + log_always("memcpy() check failed"); abort(); } return memcpy(dest, src, count); @@ -59,7 +59,7 @@ void* memmove(void* dest, const void* src, size_t count) { void* __memmove_chk(void* restrict dest, const void* restrict src, size_t count, size_t dest_count) { if (count > dest_count) { - log_always("memmove() check failed\n"); + log_always("memmove() check failed"); abort(); } return memmove(dest, src, count); diff --git a/common/src/string/memset.c b/common/src/string/memset.c index 9dc3283567..8b48093a95 100644 --- a/common/src/string/memset.c +++ b/common/src/string/memset.c @@ -29,7 +29,7 @@ void* memset(void* dest, int ch, size_t count) { void* __memset_chk(void* dest, int ch, size_t count, size_t dest_count) { if (count > dest_count) { - log_always("memset() check failed\n"); + log_always("memset() check failed"); abort(); } return memset(dest, ch, count); diff --git a/common/src/string/toml_utils.c b/common/src/string/toml_utils.c index 1bd0579fdd..e27c33cdb7 100644 --- a/common/src/string/toml_utils.c +++ b/common/src/string/toml_utils.c @@ -85,7 +85,7 @@ int toml_bool_in(const toml_table_t* root, const char* key, bool defaultval, boo ret = toml_int_in(root, key, (int)defaultval, &int64_val); if (ret == 0 && (int64_val == 0 || int64_val == 1)) { log_warning("Manifest contains a deprecated syntax for '%s' key. Please use true/false " - "instead of 1/0\n", key); + "instead of 1/0", key); *retval = (bool)int64_val; } else { ret = -1;