mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-06 22:01:29 +00:00
Cleanup and uppercase C macros
This commit is contained in:
@@ -30,10 +30,10 @@
|
||||
|
||||
#define attribute_hidden __attribute__ ((visibility ("hidden")))
|
||||
|
||||
#define alias_str(name) #name
|
||||
#define ALIAS_STR(name) #name
|
||||
|
||||
#define extern_alias(name) \
|
||||
extern __typeof__(name) shim_##name __attribute ((alias (alias_str(name))))
|
||||
#define EXTERN_ALIAS(name) \
|
||||
extern __typeof__(name) shim_##name __attribute ((alias (ALIAS_STR(name))))
|
||||
|
||||
#define static_always_inline static inline __attribute__((always_inline))
|
||||
|
||||
@@ -63,26 +63,26 @@ struct debug_buf {
|
||||
char buf[DEBUGBUF_SIZE];
|
||||
};
|
||||
|
||||
# include <pal.h>
|
||||
# include <pal_debug.h>
|
||||
# include <pal_error.h>
|
||||
#include <pal.h>
|
||||
#include <pal_debug.h>
|
||||
#include <pal_error.h>
|
||||
|
||||
extern PAL_HANDLE debug_handle;
|
||||
|
||||
# include <stdarg.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void debug_printf (const char * fmt, ...) __attribute__((format (printf, 1, 2)));
|
||||
void debug_puts (const char * str);
|
||||
void debug_putch (int ch);
|
||||
void debug_vprintf (const char * fmt, va_list * ap) __attribute__((format (printf, 1, 0)));
|
||||
|
||||
# define VMID_PREFIX "[P%05u] "
|
||||
# define TID_PREFIX "[%-6u] "
|
||||
# define NOID_PREFIX "[ ] "
|
||||
# define debug(fmt, ...) \
|
||||
#define VMID_PREFIX "[P%05u] "
|
||||
#define TID_PREFIX "[%-6u] "
|
||||
#define NOID_PREFIX "[ ] "
|
||||
#define debug(fmt, ...) \
|
||||
do { \
|
||||
if (debug_handle) \
|
||||
debug_printf((fmt), ##__VA_ARGS__); \
|
||||
debug_printf(fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/* print system messages */
|
||||
@@ -91,38 +91,38 @@ void debug_vprintf (const char * fmt, va_list * ap) __attribute__((format (print
|
||||
void handle_printf (PAL_HANDLE hdl, const char * fmt, ...) __attribute__((format (printf, 2, 3)));
|
||||
void handle_vprintf (PAL_HANDLE hdl, const char * fmt, va_list * ap) __attribute__((format (printf, 2, 0)));
|
||||
|
||||
#define __sys_printf(fmt, ...) \
|
||||
#define __SYS_PRINTF(fmt, ...) \
|
||||
do { \
|
||||
PAL_HANDLE _hdl = __open_shim_stdio(); \
|
||||
if (_hdl) \
|
||||
handle_printf(_hdl, (fmt), ##__VA_ARGS__); \
|
||||
handle_printf(_hdl, fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define __sys_vprintf(fmt, va) \
|
||||
#define __SYS_VPRINTF(fmt, va) \
|
||||
do { \
|
||||
PAL_HANDLE _hdl = __open_shim_stdio(); \
|
||||
if (_hdl) \
|
||||
handle_vprintf(_hdl, (fmt), (va)); \
|
||||
handle_vprintf(_hdl, fmt, va); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define __sys_fprintf(hdl, fmt, ...) \
|
||||
#define __SYS_FPRINTF(hdl, fmt, ...) \
|
||||
do { \
|
||||
handle_printf((hdl), (fmt), ##__VA_ARGS__); \
|
||||
handle_printf(hdl, fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define sys_printf(fmt, ...) \
|
||||
#define SYS_PRINTF(fmt, ...) \
|
||||
do { \
|
||||
master_lock(); \
|
||||
__sys_printf((fmt), ##__VA_ARGS__); \
|
||||
master_unlock(); \
|
||||
MASTER_LOCK(); \
|
||||
__SYS_PRINTF(fmt, ##__VA_ARGS__); \
|
||||
MASTER_UNLOCK(); \
|
||||
} while (0)
|
||||
|
||||
#define sys_fprintf(hdl, fmt, ...) \
|
||||
#define SYS_FPRINTF(hdl, fmt, ...) \
|
||||
do { \
|
||||
master_lock(); \
|
||||
__sys_fprintf((hdl), (fmt), ##__VA_ARGS__); \
|
||||
master_unlock(); \
|
||||
MASTER_LOCK(); \
|
||||
__SYS_FPRINTF(hdl, fmt, ##__VA_ARGS__); \
|
||||
MASTER_UNLOCK(); \
|
||||
} while (0)
|
||||
|
||||
extern PAL_HANDLE shim_stdio;
|
||||
@@ -154,15 +154,15 @@ int shim_terminate (int err);
|
||||
static inline void do_pause (void);
|
||||
|
||||
#if USE_PAUSE == 1
|
||||
# define pause() do { do_pause(); } while (0)
|
||||
# define PAUSE() do { do_pause(); } while (0)
|
||||
#else
|
||||
# define pause() do { __asm__ volatile ("int $3"); } while (0)
|
||||
# define PAUSE() do { __asm__ volatile ("int $3"); } while (0)
|
||||
#endif
|
||||
|
||||
#define bug() \
|
||||
#define BUG() \
|
||||
do { \
|
||||
__sys_printf("bug() " __FILE__ ":%d\n", __LINE__); \
|
||||
pause(); \
|
||||
__SYS_PRINTF("BUG() " __FILE__ ":%d\n", __LINE__); \
|
||||
PAUSE(); \
|
||||
shim_terminate(-ENOTRECOVERABLE); \
|
||||
} while (0)
|
||||
|
||||
@@ -559,28 +559,28 @@ static inline bool locked(struct shim_lock* l)
|
||||
extern struct shim_lock __master_lock;
|
||||
|
||||
#if DEBUG_MASTER_LOCK == 1
|
||||
# define master_lock() \
|
||||
# define MASTER_LOCK() \
|
||||
do { \
|
||||
lock(&__master_lock); \
|
||||
pal_printf("master lock " __FILE__ ":%d\n", __LINE__); \
|
||||
} while (0)
|
||||
# define master_unlock() \
|
||||
# define MASTER_UNLOCK() \
|
||||
do { \
|
||||
pal_printf("master unlock " __FILE__ ":%d\n", __LINE__); \
|
||||
unlock(&__master_lock); \
|
||||
} while (0)
|
||||
#else
|
||||
# define master_lock() do { lock(&__master_lock); } while (0)
|
||||
# define master_unlock() do { unlock(&__master_lock); } while (0)
|
||||
# define MASTER_LOCK() do { lock(&__master_lock); } while (0)
|
||||
# define MASTER_UNLOCK() do { unlock(&__master_lock); } while (0)
|
||||
#endif
|
||||
|
||||
static inline void create_lock_runtime(struct shim_lock* l)
|
||||
{
|
||||
if (!lock_created(l)) {
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
if (!lock_created(l))
|
||||
create_lock(l);
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,7 +672,7 @@ static inline int __ref_dec (REFTYPE * ref)
|
||||
_c = atomic_read(ref);
|
||||
if (!_c) {
|
||||
debug("Fail: Trying to drop reference count below 0\n");
|
||||
bug();
|
||||
BUG();
|
||||
return 0;
|
||||
}
|
||||
} while (atomic_cmpxchg(ref, _c, _c - 1) != _c);
|
||||
@@ -716,8 +716,8 @@ extern unsigned long allocmask;
|
||||
void * __system_malloc (size_t size);
|
||||
void __system_free (void * addr, size_t size);
|
||||
|
||||
#define system_malloc(size) __system_malloc(size)
|
||||
#define system_free(addr, size) __system_free(addr, size)
|
||||
#define system_malloc __system_malloc
|
||||
#define system_free __system_free
|
||||
|
||||
extern void * migrated_memory_start;
|
||||
extern void * migrated_memory_end;
|
||||
@@ -760,7 +760,7 @@ bool test_user_string (const char * addr);
|
||||
int object_wait_with_retry(PAL_HANDLE handle);
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define switch_stack(stack_top) \
|
||||
#define SWITCH_STACK(stack_top) \
|
||||
({ \
|
||||
void * _rsp, * _rbp; \
|
||||
void * _stack = (stack_top); \
|
||||
@@ -792,10 +792,9 @@ static_always_inline bool __range_not_ok(unsigned long addr, unsigned long size)
|
||||
|
||||
/* Check if pointer to memory region is valid. Return true if the memory
|
||||
* region may be valid, false if it is definitely invalid. */
|
||||
#define access_ok(addr, size) \
|
||||
({ \
|
||||
!__range_not_ok((unsigned long)addr, (unsigned long)size); \
|
||||
})
|
||||
static inline bool access_ok(const volatile void* addr, size_t size) {
|
||||
return !__range_not_ok((unsigned long)addr, (unsigned long)size);
|
||||
}
|
||||
|
||||
#else
|
||||
# error "Unsupported architecture"
|
||||
|
||||
@@ -204,7 +204,7 @@ void set_cur_thread (struct shim_thread * thread)
|
||||
put_thread(tcb->tp);
|
||||
tcb->tp = NULL;
|
||||
} else {
|
||||
bug();
|
||||
BUG();
|
||||
}
|
||||
|
||||
if (tcb->tid != tid) {
|
||||
|
||||
@@ -66,7 +66,7 @@ struct sigcp {
|
||||
int si_session;
|
||||
};
|
||||
|
||||
#define si_cp_session(info) \
|
||||
#define SI_CP_SESSION(info) \
|
||||
(((struct sigcp *) (info)->_sifields._pad)->si_session)
|
||||
|
||||
#define SIGCP 33
|
||||
|
||||
@@ -159,12 +159,12 @@ int init_slab (void);
|
||||
|
||||
#if defined(SLAB_DEBUG_PRINT) || defined(SLAB_DEBUG_TRACE)
|
||||
void * __malloc_debug (size_t size, const char * file, int line);
|
||||
#define malloc(size) __malloc_debug((size), __FILE__, __LINE__)
|
||||
#define malloc(size) __malloc_debug(size, __FILE__, __LINE__)
|
||||
void __free_debug (void * mem, const char * file, int line);
|
||||
#define free(mem) __free_debug((mem), __FILE__, __LINE__)
|
||||
#define free(mem) __free_debug(mem, __FILE__, __LINE__)
|
||||
void * __malloc_copy_debug (const void * mem, size_t size,
|
||||
const char * file, int line);
|
||||
#define malloc_copy(mem, size) __malloc_copy_debug((mem), (size), __FILE__, __LINE__)
|
||||
#define malloc_copy(mem, size) __malloc_copy_debug(mem, size, __FILE__, __LINE__)
|
||||
#else
|
||||
void * malloc (size_t size);
|
||||
void free (void * mem);
|
||||
|
||||
@@ -36,8 +36,8 @@ static struct shim_lock handle_mgr_lock;
|
||||
|
||||
#define HANDLE_MGR_ALLOC 32
|
||||
|
||||
#define system_lock() lock(&handle_mgr_lock)
|
||||
#define system_unlock() unlock(&handle_mgr_lock)
|
||||
#define SYSTEM_LOCK() lock(&handle_mgr_lock)
|
||||
#define SYSTEM_UNLOCK() unlock(&handle_mgr_lock)
|
||||
#define PAGE_SIZE allocsize
|
||||
|
||||
#define OBJ_TYPE struct shim_handle
|
||||
|
||||
@@ -174,7 +174,7 @@ void deliver_signal (siginfo_t * info, PAL_CONTEXT * context)
|
||||
*signal_log = signal;
|
||||
}
|
||||
if (signal && !signal_log) {
|
||||
sys_printf("signal queue is full (TID = %u, SIG = %d)\n",
|
||||
SYS_PRINTF("signal queue is full (TID = %u, SIG = %d)\n",
|
||||
tcb->tid, sig);
|
||||
free(signal);
|
||||
}
|
||||
@@ -214,15 +214,15 @@ static inline void internal_fault(const char* errstr,
|
||||
{
|
||||
IDTYPE tid = get_cur_tid();
|
||||
if (context_is_internal(context))
|
||||
sys_printf("%s at 0x%08lx (IP = +0x%lx, VMID = %u, TID = %u)\n", errstr,
|
||||
SYS_PRINTF("%s at 0x%08lx (IP = +0x%lx, VMID = %u, TID = %u)\n", errstr,
|
||||
addr, (void *) context->IP - (void *) &__load_address,
|
||||
cur_process.vmid, is_internal_tid(tid) ? 0 : tid);
|
||||
else
|
||||
sys_printf("%s at 0x%08lx (IP = 0x%08lx, VMID = %u, TID = %u)\n", errstr,
|
||||
SYS_PRINTF("%s at 0x%08lx (IP = 0x%08lx, VMID = %u, TID = %u)\n", errstr,
|
||||
addr, context ? context->IP : 0,
|
||||
cur_process.vmid, is_internal_tid(tid) ? 0 : tid);
|
||||
|
||||
pause();
|
||||
PAUSE();
|
||||
}
|
||||
|
||||
static void arithmetic_error_upcall (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
|
||||
@@ -324,10 +324,10 @@ static bool is_sgx_pal(void) {
|
||||
if (!atomic_read(&inited)) {
|
||||
/* Ensure that is_sgx_pal is updated before initialized */
|
||||
atomic_set(&sgx_pal, strcmp_static(PAL_CB(host_type), "Linux-SGX"));
|
||||
mb();
|
||||
MB();
|
||||
atomic_set(&inited, 1);
|
||||
}
|
||||
mb();
|
||||
MB();
|
||||
|
||||
return atomic_read(&sgx_pal) != 0;
|
||||
}
|
||||
@@ -604,7 +604,7 @@ __handle_one_signal (shim_tcb_t * tcb, int sig, struct shim_signal * signal)
|
||||
void (*handler) (int, siginfo_t *, void *) = NULL;
|
||||
|
||||
if (signal->info.si_signo == SIGCP) {
|
||||
join_checkpoint(thread, &signal->context, si_cp_session(&signal->info));
|
||||
join_checkpoint(thread, &signal->context, SI_CP_SESSION(&signal->info));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -746,7 +746,7 @@ void append_signal (struct shim_thread * thread, int sig, siginfo_t * info,
|
||||
DkThreadResume(thread->pal_handle);
|
||||
}
|
||||
} else {
|
||||
sys_printf("signal queue is full (TID = %u, SIG = %d)\n",
|
||||
SYS_PRINTF("signal queue is full (TID = %u, SIG = %d)\n",
|
||||
thread->tid, sig);
|
||||
free(signal);
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ static inline struct shim_vma * __get_new_vma (void)
|
||||
|
||||
/* Should never reach here; if this happens, increase RESERVED_VMAS */
|
||||
debug("failed to allocate new vma\n");
|
||||
bug();
|
||||
BUG();
|
||||
return NULL;
|
||||
|
||||
out:
|
||||
@@ -426,7 +426,7 @@ __assert_vma_flags (const struct shim_vma * vma, int flags)
|
||||
&& VMA_TYPE(vma->flags) != VMA_TYPE(flags)) {
|
||||
debug("Check vma flag failure: vma flags %x, checked flags %x\n",
|
||||
vma->flags, flags);
|
||||
bug();
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,7 +586,7 @@ static inline void __shrink_vma (struct shim_vma * vma, void * start, void * end
|
||||
}
|
||||
|
||||
/* Never reach here */
|
||||
bug();
|
||||
BUG();
|
||||
|
||||
finish:
|
||||
assert(!test_vma_overlap(vma, start, end));
|
||||
@@ -654,7 +654,7 @@ static int __bkeep_munmap (struct shim_vma ** pprev,
|
||||
break;
|
||||
} else {
|
||||
/* __shrink_vma() should never allow this case. */
|
||||
bug();
|
||||
BUG();
|
||||
}
|
||||
|
||||
cont:
|
||||
@@ -767,7 +767,7 @@ static int __bkeep_mprotect (struct shim_vma * prev,
|
||||
assert(!tail);
|
||||
} else {
|
||||
/* __shrink_vma() should never allow this case. */
|
||||
bug();
|
||||
BUG();
|
||||
}
|
||||
|
||||
/* Now insert the new protected vma between prev and cur */
|
||||
@@ -1200,7 +1200,7 @@ BEGIN_RS_FUNC(vma)
|
||||
}
|
||||
|
||||
if (need_mapped < vma->addr + vma->length)
|
||||
sys_printf("vma %p-%p cannot be allocated!\n", need_mapped,
|
||||
SYS_PRINTF("vma %p-%p cannot be allocated!\n", need_mapped,
|
||||
vma->addr + vma->length);
|
||||
}
|
||||
|
||||
@@ -1257,7 +1257,7 @@ END_CP_FUNC_NO_RS(all_vmas)
|
||||
|
||||
void debug_print_vma_list (void)
|
||||
{
|
||||
sys_printf("vma bookkeeping:\n");
|
||||
SYS_PRINTF("vma bookkeeping:\n");
|
||||
|
||||
struct shim_vma * vma;
|
||||
listp_for_each_entry(vma, &vma_list, list) {
|
||||
@@ -1273,7 +1273,7 @@ void debug_print_vma_list (void)
|
||||
}
|
||||
}
|
||||
|
||||
sys_printf("[%p-%p] prot=%08x flags=%08x%s%s offset=%ld%s%s%s%s\n",
|
||||
SYS_PRINTF("[%p-%p] prot=%08x flags=%08x%s%s offset=%ld%s%s%s%s\n",
|
||||
vma->start, vma->end,
|
||||
vma->prot,
|
||||
vma->flags & ~(VMA_INTERNAL|VMA_UNMAPPED|VMA_TAINTED|VMA_CP),
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
* Most of the source codes are imported from GNU C library.
|
||||
*/
|
||||
|
||||
#ifndef __dl_machine_h__
|
||||
#define __dl_machine_h__
|
||||
#ifndef __DL_MACHINE_H__
|
||||
#define __DL_MACHINE_H__
|
||||
|
||||
#define ELF_MACHINE_NAME "x86_64"
|
||||
|
||||
@@ -130,4 +130,4 @@ elf_machine_rela (struct link_map * l, ElfW(Rela) * reloc, Elf64_Sym * sym,
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* !dl_machine_h */
|
||||
#endif /* !DL_MACHINE_H */
|
||||
|
||||
@@ -626,7 +626,7 @@ static int chroot_flush (struct shim_handle * hdl)
|
||||
DkStreamUnmap(mapbuf, mapsize);
|
||||
|
||||
if (bkeep_munmap(mapbuf, mapsize, VMA_INTERNAL) < 0)
|
||||
bug();
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,7 +645,7 @@ static inline int __map_buffer (struct shim_handle * hdl, int size)
|
||||
DkStreamUnmap(file->mapbuf, file->mapsize);
|
||||
|
||||
if (bkeep_munmap(file->mapbuf, file->mapsize, VMA_INTERNAL) < 0)
|
||||
bug();
|
||||
BUG();
|
||||
|
||||
file->mapbuf = NULL;
|
||||
file->mapoffset = 0;
|
||||
|
||||
@@ -336,7 +336,7 @@ retry:
|
||||
*dirent = ptr = buf;
|
||||
struct shim_dirent ** last = dirent;
|
||||
|
||||
#define copy_entry(devname, devtype) \
|
||||
#define COPY_ENTRY(devname, devtype) \
|
||||
do { \
|
||||
int name_len = strlen(devname); \
|
||||
\
|
||||
@@ -352,11 +352,12 @@ retry:
|
||||
ptr = ptr->next; \
|
||||
} while (0)
|
||||
|
||||
copy_entry("null", LINUX_DT_CHR);
|
||||
copy_entry("zero", LINUX_DT_CHR);
|
||||
copy_entry("stdin", LINUX_DT_LNK);
|
||||
copy_entry("stdout", LINUX_DT_LNK);
|
||||
copy_entry("stderr", LINUX_DT_LNK);
|
||||
COPY_ENTRY("null", LINUX_DT_CHR);
|
||||
COPY_ENTRY("zero", LINUX_DT_CHR);
|
||||
COPY_ENTRY("stdin", LINUX_DT_LNK);
|
||||
COPY_ENTRY("stdout", LINUX_DT_LNK);
|
||||
COPY_ENTRY("stderr", LINUX_DT_LNK);
|
||||
#undef COPY_ENTRY
|
||||
|
||||
*last = NULL;
|
||||
return 0;
|
||||
|
||||
@@ -60,8 +60,8 @@ struct shim_mount * builtin_fs [NUM_BUILTIN_FS] = {
|
||||
|
||||
static struct shim_lock mount_mgr_lock;
|
||||
|
||||
#define system_lock() lock(&mount_mgr_lock)
|
||||
#define system_unlock() unlock(&mount_mgr_lock)
|
||||
#define SYSTEM_LOCK() lock(&mount_mgr_lock)
|
||||
#define SYSTEM_UNLOCK() unlock(&mount_mgr_lock)
|
||||
|
||||
#define MOUNT_MGR_ALLOC 64
|
||||
#define PAGE_SIZE allocsize
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <pal_error.h>
|
||||
#include <list.h>
|
||||
|
||||
#define ipc_info_mgr_ALLOC 32
|
||||
#define IPC_INFO_MGR_ALLOC 32
|
||||
#define PAGE_SIZE allocsize
|
||||
|
||||
#define OBJ_TYPE struct shim_ipc_info
|
||||
@@ -63,7 +63,7 @@ int init_ipc (void)
|
||||
|
||||
create_lock(&ipc_info_lock);
|
||||
|
||||
if (!(ipc_info_mgr = create_mem_mgr(init_align_up(ipc_info_mgr_ALLOC))))
|
||||
if (!(ipc_info_mgr = create_mem_mgr(init_align_up(IPC_INFO_MGR_ALLOC))))
|
||||
return -ENOMEM;
|
||||
|
||||
if ((ret = init_ipc_ports()) < 0)
|
||||
@@ -93,7 +93,7 @@ static struct shim_ipc_info * __get_new_ipc_info (IDTYPE vmid, const char * uri,
|
||||
{
|
||||
struct shim_ipc_info * info =
|
||||
get_mem_obj_from_mgr_enlarge(ipc_info_mgr,
|
||||
size_align_up(ipc_info_mgr_ALLOC));
|
||||
size_align_up(IPC_INFO_MGR_ALLOC));
|
||||
if (!info)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -110,10 +110,10 @@ static void ipc_broadcast_exit (struct shim_ipc_port * port, IDTYPE vmid,
|
||||
unsigned exitcode)
|
||||
{
|
||||
if (port == broadcast_port) {
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
broadcast_port = NULL;
|
||||
put_ipc_port(port);
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -839,7 +839,7 @@ static void shim_ipc_helper (void * arg)
|
||||
|
||||
self->stack_top = stack + IPC_HELPER_STACK_SIZE;
|
||||
self->stack = stack;
|
||||
switch_stack(stack + IPC_HELPER_STACK_SIZE);
|
||||
SWITCH_STACK(stack + IPC_HELPER_STACK_SIZE);
|
||||
self = get_cur_thread();
|
||||
stack = self->stack;
|
||||
|
||||
@@ -864,7 +864,7 @@ static void shim_ipc_helper (void * arg)
|
||||
nalive) {
|
||||
/* do a global poll on all the ports */
|
||||
polled = DkObjectsWaitAny(port_num + 1, local_ports, NO_TIMEOUT);
|
||||
barrier();
|
||||
COMPILER_BARRIER();
|
||||
|
||||
if (!polled)
|
||||
continue;
|
||||
@@ -874,7 +874,7 @@ static void shim_ipc_helper (void * arg)
|
||||
if (polled == ipc_event_handle) {
|
||||
clear_event(&ipc_helper_event);
|
||||
update_status:
|
||||
barrier();
|
||||
COMPILER_BARRIER();
|
||||
if (ipc_helper_state == HELPER_NOTALIVE)
|
||||
goto end;
|
||||
else
|
||||
@@ -1031,7 +1031,7 @@ end:
|
||||
* helper lock. Err on the side of caution by adding a barrier to ensure
|
||||
* reading the latest ipc helper state.
|
||||
*/
|
||||
barrier();
|
||||
COMPILER_BARRIER();
|
||||
if (ipc_helper_state == HELPER_HANDEDOVER) {
|
||||
debug("ipc helper thread is the last thread, process exiting\n");
|
||||
shim_terminate(0); // Same as shim_clean(), but this is the official termination function
|
||||
@@ -1131,7 +1131,7 @@ int exit_with_ipc_helper (bool handover, struct shim_thread ** ret)
|
||||
* generated the signal doesn't hang waiting for IPC_RESP. */
|
||||
int loops = 0;
|
||||
while (ipc_helper_thread != NULL && loops++ < 2000) {
|
||||
barrier();
|
||||
COMPILER_BARRIER();
|
||||
DkThreadDelayExecution(1000);
|
||||
}
|
||||
if (ipc_helper_thread != NULL) {
|
||||
|
||||
@@ -119,7 +119,7 @@ static inline LEASETYPE get_lease (void)
|
||||
void CONCAT3(debug_print, NS, ranges) (void)
|
||||
{
|
||||
lock(&range_map_lock);
|
||||
sys_printf(NS_STR " ranges in process %010u:\n", cur_process.vmid);
|
||||
SYS_PRINTF(NS_STR " ranges in process %010u:\n", cur_process.vmid);
|
||||
|
||||
if (!range_map) {
|
||||
unlock(&range_map_lock);
|
||||
@@ -150,7 +150,7 @@ void CONCAT3(debug_print, NS, ranges) (void)
|
||||
IDTYPE base = RANGE_SIZE * off + 1;
|
||||
struct shim_ipc_info * p = r->owner;
|
||||
|
||||
sys_printf("%04u - %04u: owner %010u, port \"%s\" lease %lu\n",
|
||||
SYS_PRINTF("%04u - %04u: owner %010u, port \"%s\" lease %lu\n",
|
||||
base, base + RANGE_SIZE - 1,
|
||||
p->vmid, qstrgetstr(&p->uri), r->lease);
|
||||
|
||||
@@ -163,7 +163,7 @@ void CONCAT3(debug_print, NS, ranges) (void)
|
||||
continue;
|
||||
|
||||
p = s->owner;
|
||||
sys_printf(" %04u: owner %010u, port \"%s\" lease %lu\n",
|
||||
SYS_PRINTF(" %04u: owner %010u, port \"%s\" lease %lu\n",
|
||||
base + k, p->vmid,
|
||||
qstrgetstr(&p->uri), s->lease);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ static void shim_async_helper (void * arg)
|
||||
}
|
||||
|
||||
polled = DkObjectsWaitAny(object_num + 1, local_objects, sleep_time);
|
||||
barrier();
|
||||
COMPILER_BARRIER();
|
||||
|
||||
if (!polled) {
|
||||
if (next_event) {
|
||||
|
||||
@@ -624,7 +624,7 @@ int restore_checkpoint (struct cp_header * cphdr, struct mem_header * memhdr,
|
||||
rs_func rs = (&__rs_func) [cpent->cp_type - CP_FUNC_BASE];
|
||||
ret = (*rs) (cpent, base, offset, rebase);
|
||||
if (ret < 0) {
|
||||
sys_printf("restore_checkpoint() at %s (%d)\n",
|
||||
SYS_PRINTF("restore_checkpoint() at %s (%d)\n",
|
||||
CP_FUNC_NAME(cpent->cp_type), ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -940,7 +940,7 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
|
||||
} else {
|
||||
if (warn_no_gipc) {
|
||||
warn_no_gipc = false;
|
||||
sys_printf("WARNING: no physical memory support, process creation "
|
||||
SYS_PRINTF("WARNING: no physical memory support, process creation "
|
||||
"may be slow.\n");
|
||||
}
|
||||
}
|
||||
@@ -1121,7 +1121,7 @@ err:
|
||||
if (new_process)
|
||||
destroy_process(new_process);
|
||||
|
||||
sys_printf("process creation failed\n");
|
||||
SYS_PRINTF("process creation failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+23
-23
@@ -58,7 +58,7 @@ static void handle_failure (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
|
||||
}
|
||||
|
||||
void __abort(void) {
|
||||
pause();
|
||||
PAUSE();
|
||||
shim_terminate(-ENOTRECOVERABLE);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void warn (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
__sys_vprintf(format, &args);
|
||||
__SYS_VPRINTF(format, &args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
@@ -509,7 +509,7 @@ int init_manifest (PAL_HANDLE manifest_handle)
|
||||
const char * errstring = "Unexpected error";
|
||||
|
||||
if ((ret = read_config(new_root_config, NULL, &errstring)) < 0) {
|
||||
sys_printf("Unable to read manifest file: %s\n", errstring);
|
||||
SYS_PRINTF("Unable to read manifest file: %s\n", errstring);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -520,7 +520,7 @@ fail:
|
||||
if (map_size) {
|
||||
DkStreamUnmap(addr, map_size);
|
||||
if (bkeep_munmap(addr, map_size, MAP_FLAGS) < 0)
|
||||
bug();
|
||||
BUG();
|
||||
}
|
||||
free(new_root_config);
|
||||
return ret;
|
||||
@@ -668,7 +668,7 @@ DEFINE_PROFILE_INTERVAL(init_signal, init);
|
||||
do { \
|
||||
int _err = CALL_INIT(func, ##__VA_ARGS__); \
|
||||
if (_err < 0) { \
|
||||
sys_printf("shim_init() in " #func " (%d)\n", _err); \
|
||||
SYS_PRINTF("shim_init() in " #func " (%d)\n", _err); \
|
||||
shim_terminate(_err); \
|
||||
} \
|
||||
SAVE_PROFILE_INTERVAL(func); \
|
||||
@@ -1056,10 +1056,10 @@ void check_stack_hook (void)
|
||||
|
||||
if (rsp <= cur_thread->stack_top && rsp > cur_thread->stack) {
|
||||
if (rsp - cur_thread->stack < PAL_CB(pagesize))
|
||||
sys_printf("*** stack is almost drained (RSP = %p, stack = %p-%p) ***\n",
|
||||
SYS_PRINTF("*** stack is almost drained (RSP = %p, stack = %p-%p) ***\n",
|
||||
rsp, cur_thread->stack, cur_thread->stack_top);
|
||||
} else {
|
||||
sys_printf("*** context dismatched with thread stack (RSP = %p, stack = %p-%p) ***\n",
|
||||
SYS_PRINTF("*** context dismatched with thread stack (RSP = %p, stack = %p-%p) ***\n",
|
||||
rsp, cur_thread->stack, cur_thread->stack_top);
|
||||
}
|
||||
}
|
||||
@@ -1080,8 +1080,8 @@ static void print_profile_result (PAL_HANDLE hdl, struct shim_profile * root,
|
||||
atomic_read(&profile->val.occurence.count);
|
||||
if (count) {
|
||||
for (int j = 0 ; j < level ; j++)
|
||||
__sys_fprintf(hdl, " ");
|
||||
__sys_fprintf(hdl, "- %s: %u times\n", profile->name, count);
|
||||
__SYS_FPRINTF(hdl, " ");
|
||||
__SYS_FPRINTF(hdl, "- %s: %u times\n", profile->name, count);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1095,22 +1095,22 @@ static void print_profile_result (PAL_HANDLE hdl, struct shim_profile * root,
|
||||
total_interval_time += time;
|
||||
total_interval_count += count;
|
||||
for (int j = 0 ; j < level ; j++)
|
||||
__sys_fprintf(hdl, " ");
|
||||
__sys_fprintf(hdl, "- (%11.11lu) %s: %u times, %lu msec\n",
|
||||
__SYS_FPRINTF(hdl, " ");
|
||||
__SYS_FPRINTF(hdl, "- (%11.11lu) %s: %u times, %lu msec\n",
|
||||
time, profile->name, count, ind_time);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CATAGORY:
|
||||
for (int j = 0 ; j < level ; j++)
|
||||
__sys_fprintf(hdl, " ");
|
||||
__sys_fprintf(hdl, "- %s:\n", profile->name);
|
||||
__SYS_FPRINTF(hdl, " ");
|
||||
__SYS_FPRINTF(hdl, "- %s:\n", profile->name);
|
||||
print_profile_result(hdl, profile, level + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (total_interval_count) {
|
||||
__sys_fprintf(hdl, " - (%11.11u) total: %u times, %lu msec\n",
|
||||
__SYS_FPRINTF(hdl, " - (%11.11u) total: %u times, %lu msec\n",
|
||||
total_interval_time, total_interval_count,
|
||||
total_interval_time / total_interval_count);
|
||||
}
|
||||
@@ -1156,18 +1156,18 @@ int shim_clean (int err)
|
||||
}
|
||||
|
||||
if (ipc_cld_profile_send()) {
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
PAL_HANDLE hdl = __open_shim_stdio();
|
||||
|
||||
if (hdl) {
|
||||
__sys_fprintf(hdl, "******************************\n");
|
||||
__sys_fprintf(hdl, "profiling:\n");
|
||||
__SYS_FPRINTF(hdl, "******************************\n");
|
||||
__SYS_FPRINTF(hdl, "profiling:\n");
|
||||
print_profile_result(hdl, &profile_root, 0);
|
||||
__sys_fprintf(hdl, "******************************\n");
|
||||
__SYS_FPRINTF(hdl, "******************************\n");
|
||||
}
|
||||
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
DkObjectClose(hdl);
|
||||
}
|
||||
#endif
|
||||
@@ -1179,7 +1179,7 @@ int shim_clean (int err)
|
||||
|
||||
shim_stdio = NULL;
|
||||
debug("process %u exited with status %d\n", cur_process.vmid & 0xFFFF, cur_process.exit_code);
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
DkProcessExit(cur_process.exit_code);
|
||||
return 0;
|
||||
}
|
||||
@@ -1201,11 +1201,11 @@ int message_confirm (const char * message, const char * options)
|
||||
*(str++) = ']';
|
||||
*(str++) = ' ';
|
||||
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
PAL_HANDLE hdl = __open_shim_stdio();
|
||||
if (!hdl) {
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
@@ -1226,6 +1226,6 @@ int message_confirm (const char * message, const char * options)
|
||||
|
||||
out:
|
||||
DkObjectClose(hdl);
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return (ret < 0) ? ret : answer;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
|
||||
static struct shim_lock slab_mgr_lock;
|
||||
|
||||
#define system_lock() lock(&slab_mgr_lock)
|
||||
#define system_unlock() unlock(&slab_mgr_lock)
|
||||
#define SYSTEM_LOCK() lock(&slab_mgr_lock)
|
||||
#define SYSTEM_UNLOCK() unlock(&slab_mgr_lock)
|
||||
#define PAGE_SIZE allocsize
|
||||
|
||||
#ifdef SLAB_DEBUG_TRACE
|
||||
@@ -103,7 +103,7 @@ void __system_free (void * addr, size_t size)
|
||||
DkVirtualMemoryFree(addr, ALIGN_UP(size));
|
||||
|
||||
if (bkeep_munmap(addr, ALIGN_UP(size), VMA_INTERNAL) < 0)
|
||||
bug();
|
||||
BUG();
|
||||
}
|
||||
|
||||
int init_slab (void)
|
||||
@@ -113,7 +113,7 @@ int init_slab (void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern_alias(init_slab);
|
||||
EXTERN_ALIAS(init_slab);
|
||||
|
||||
int reinit_slab (void)
|
||||
{
|
||||
@@ -192,7 +192,7 @@ void * malloc (size_t size)
|
||||
* If malloc() failed internally, we cannot handle the
|
||||
* condition and must terminate the current process.
|
||||
*/
|
||||
sys_printf("******** Out-of-memory in library OS ********\n");
|
||||
SYS_PRINTF("******** Out-of-memory in library OS ********\n");
|
||||
__abort();
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ void * malloc (size_t size)
|
||||
return mem;
|
||||
}
|
||||
#if !defined(SLAB_DEBUG_PRINT) && !defined(SLAB_DEBUG_TRACE)
|
||||
extern_alias(malloc);
|
||||
EXTERN_ALIAS(malloc);
|
||||
#endif
|
||||
|
||||
void * calloc (size_t nmemb, size_t size)
|
||||
@@ -216,7 +216,7 @@ void * calloc (size_t nmemb, size_t size)
|
||||
memset(ptr, 0, total);
|
||||
return ptr;
|
||||
}
|
||||
extern_alias(calloc);
|
||||
EXTERN_ALIAS(calloc);
|
||||
|
||||
#if 0 /* Temporarily disabling this code */
|
||||
void * realloc(void * ptr, size_t new_size)
|
||||
@@ -244,7 +244,7 @@ void * realloc(void * ptr, size_t new_size)
|
||||
free(ptr);
|
||||
return new_buf;
|
||||
}
|
||||
extern_alias(realloc);
|
||||
EXTERN_ALIAS(realloc);
|
||||
#endif
|
||||
|
||||
// Copies data from `mem` to a newly allocated buffer of a specified size.
|
||||
@@ -265,7 +265,7 @@ void * malloc_copy (const void * mem, size_t size)
|
||||
return buff;
|
||||
}
|
||||
#if !defined(SLAB_DEBUG_PRINT) && !defined(SLABD_DEBUG_TRACE)
|
||||
extern_alias(malloc_copy);
|
||||
EXTERN_ALIAS(malloc_copy);
|
||||
#endif
|
||||
|
||||
DEFINE_PROFILE_OCCURENCE(free_0, memory);
|
||||
@@ -337,5 +337,5 @@ void free (void * mem)
|
||||
#endif
|
||||
}
|
||||
#if !defined(SLAB_DEBUG_PRINT) && !defined(SLABD_DEBUG_TRACE)
|
||||
extern_alias(free);
|
||||
EXTERN_ALIAS(free);
|
||||
#endif
|
||||
|
||||
@@ -57,16 +57,16 @@ static struct {
|
||||
|
||||
void signal_itimer (IDTYPE target, void * arg)
|
||||
{
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
if (real_itimer.timeout != (unsigned long) arg) {
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return;
|
||||
}
|
||||
|
||||
real_itimer.timeout += real_itimer.reset;
|
||||
real_itimer.reset = 0;
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
}
|
||||
|
||||
#ifndef ITIMER_REAL
|
||||
@@ -93,7 +93,7 @@ int shim_do_setitimer (int which, struct __kernel_itimerval * value,
|
||||
unsigned long next_reset = value->it_interval.tv_sec * 1000000
|
||||
+ value->it_interval.tv_usec;
|
||||
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
unsigned long current_timeout = real_itimer.timeout > setup_time ?
|
||||
real_itimer.timeout - setup_time : 0;
|
||||
@@ -103,14 +103,14 @@ int shim_do_setitimer (int which, struct __kernel_itimerval * value,
|
||||
(void *) (setup_time + next_value));
|
||||
|
||||
if (ret < 0) {
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
real_itimer.timeout = setup_time + next_value;
|
||||
real_itimer.reset = next_reset;
|
||||
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
|
||||
if (ovalue) {
|
||||
ovalue->it_interval.tv_sec = current_reset / 1000000;
|
||||
@@ -134,11 +134,11 @@ int shim_do_getitimer (int which, struct __kernel_itimerval * value)
|
||||
|
||||
unsigned long setup_time = DkSystemTimeQuery();
|
||||
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
unsigned long current_timeout = real_itimer.timeout > setup_time ?
|
||||
real_itimer.timeout - setup_time : 0;
|
||||
unsigned long current_reset = real_itimer.reset;
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
|
||||
value->it_interval.tv_sec = current_reset / 1000000;
|
||||
value->it_interval.tv_usec = current_reset % 1000000;
|
||||
|
||||
@@ -52,11 +52,11 @@ DEFINE_PROFILE_OCCURENCE(brk_migrate_count, memory);
|
||||
|
||||
void get_brk_region (void ** start, void ** end, void ** current)
|
||||
{
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
*start = region.brk_start;
|
||||
*end = region.brk_end;
|
||||
*current = region.brk_current;
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
}
|
||||
|
||||
int init_brk_region (void * brk_region)
|
||||
@@ -108,7 +108,7 @@ int init_brk_region (void * brk_region)
|
||||
*/
|
||||
if (bkeep_mmap(brk_region, brk_max_size, PROT_READ|PROT_WRITE,
|
||||
flags|VMA_UNMAPPED, NULL, 0, "brk") < 0)
|
||||
bug();
|
||||
BUG();
|
||||
} else {
|
||||
brk_region = bkeep_unmapped_heap(brk_max_size, PROT_READ|PROT_WRITE,
|
||||
flags|VMA_UNMAPPED, NULL, 0, "brk");
|
||||
@@ -148,17 +148,17 @@ int init_brk_region (void * brk_region)
|
||||
*/
|
||||
if (bkeep_mmap(brk_region, BRK_SIZE, PROT_READ|PROT_WRITE, flags,
|
||||
NULL, 0, "brk") < 0)
|
||||
bug();
|
||||
BUG();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reset_brk (void)
|
||||
{
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
if (!region.brk_start) {
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -166,19 +166,19 @@ int reset_brk (void)
|
||||
region.brk_end - region.brk_start);
|
||||
|
||||
if (ret < 0) {
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
region.brk_start = region.brk_end = region.brk_current = NULL;
|
||||
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void * shim_do_brk (void * brk)
|
||||
{
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
if (init_brk_region(NULL) < 0) {
|
||||
debug("Failed to initialize brk!\n");
|
||||
@@ -218,7 +218,7 @@ unchanged:
|
||||
region.brk_current = brk;
|
||||
|
||||
out:
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return brk;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ int shim_do_execve_rtld (struct shim_handle * hdl, const char ** argv,
|
||||
|
||||
SAVE_PROFILE_INTERVAL(alloc_new_stack_for_exec);
|
||||
|
||||
switch_stack(new_argp);
|
||||
SWITCH_STACK(new_argp);
|
||||
cur_thread = get_cur_thread();
|
||||
|
||||
UPDATE_PROFILE_INTERVAL();
|
||||
@@ -128,7 +128,7 @@ int shim_do_execve_rtld (struct shim_handle * hdl, const char ** argv,
|
||||
|
||||
if (bkeep_munmap(old_stack, old_stack_top - old_stack, 0) < 0 ||
|
||||
bkeep_munmap(old_stack_red, old_stack - old_stack_red, 0) < 0)
|
||||
bug();
|
||||
BUG();
|
||||
|
||||
remove_loaded_libraries();
|
||||
clean_link_map_list();
|
||||
|
||||
@@ -102,7 +102,7 @@ int create_checkpoint (const char * cpdir, IDTYPE * sid)
|
||||
goto err;
|
||||
|
||||
open_handle(cpsession->cpfile);
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
struct cp_session * s;
|
||||
if (*sid) {
|
||||
@@ -127,11 +127,11 @@ retry:
|
||||
}
|
||||
|
||||
listp_add_tail(cpsession, &cp_sessions, list);
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return 0;
|
||||
|
||||
err_locked:
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
err:
|
||||
if (cpsession->cpfile)
|
||||
close_handle(cpsession->cpfile);
|
||||
@@ -167,7 +167,7 @@ int join_checkpoint (struct shim_thread * thread, ucontext_t * context,
|
||||
int ret = 0;
|
||||
bool do_checkpoint = false;
|
||||
|
||||
master_lock();
|
||||
MASTER_LOCK();
|
||||
|
||||
listp_for_each_entry(s, &cp_sessions, list)
|
||||
if (s->sid == sid) {
|
||||
@@ -176,7 +176,7 @@ int join_checkpoint (struct shim_thread * thread, ucontext_t * context,
|
||||
}
|
||||
|
||||
if (!cpsession) {
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ int join_checkpoint (struct shim_thread * thread, ucontext_t * context,
|
||||
do_checkpoint = true;
|
||||
|
||||
PAL_HANDLE finish_event = cpsession->finish_event;
|
||||
master_unlock();
|
||||
MASTER_UNLOCK();
|
||||
|
||||
if (!do_checkpoint) {
|
||||
debug("waiting for checkpointing\n");
|
||||
|
||||
@@ -199,7 +199,7 @@ int shim_do_munmap (void * addr, size_t length)
|
||||
DkVirtualMemoryFree(addr, length);
|
||||
|
||||
if (bkeep_munmap(addr, length, 0) < 0)
|
||||
bug();
|
||||
BUG();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ void md5_init (mdContext)
|
||||
mdContext->buf[2] = (UINT4)0x98badcfe;
|
||||
mdContext->buf[3] = (UINT4)0x10325476;
|
||||
}
|
||||
extern_alias(md5_init);
|
||||
EXTERN_ALIAS(md5_init);
|
||||
|
||||
void md5_update (mdContext, inBuf, inLen)
|
||||
struct shim_md5_ctx *mdContext;
|
||||
@@ -131,7 +131,7 @@ void md5_update (mdContext, inBuf, inLen)
|
||||
}
|
||||
}
|
||||
}
|
||||
extern_alias(md5_update);
|
||||
EXTERN_ALIAS(md5_update);
|
||||
|
||||
void md5_final (mdContext)
|
||||
struct shim_md5_ctx *mdContext;
|
||||
@@ -273,7 +273,7 @@ static void __transform (buf, in)
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
extern_alias(md5_final);
|
||||
EXTERN_ALIAS(md5_final);
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
|
||||
static struct shim_lock str_mgr_lock;
|
||||
|
||||
#define system_lock() lock(&str_mgr_lock)
|
||||
#define system_unlock() unlock(&str_mgr_lock)
|
||||
#define SYSTEM_LOCK() lock(&str_mgr_lock)
|
||||
#define SYSTEM_UNLOCK() unlock(&str_mgr_lock)
|
||||
|
||||
#define STR_MGR_ALLOC 32
|
||||
#define PAGE_SIZE allocsize
|
||||
|
||||
+7
-7
@@ -45,11 +45,11 @@ Copyright (C) 2005-2014 Rich Felker, et al.
|
||||
*/
|
||||
|
||||
/* Optimization barrier */
|
||||
#define barrier() __asm__ __volatile__("": : :"memory")
|
||||
# define cpu_relax() __asm__ __volatile__("rep; nop" ::: "memory");
|
||||
#define COMPILER_BARRIER() __asm__ __volatile__("": : :"memory")
|
||||
#define CPU_RELAX() __asm__ __volatile__("rep; nop" ::: "memory")
|
||||
|
||||
#ifdef __i386__
|
||||
# define rmb() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
|
||||
# define RMB() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
|
||||
|
||||
struct atomic_int {
|
||||
volatile int32_t counter;
|
||||
@@ -66,12 +66,12 @@ __attribute__((aligned(sizeof(uint32_t))))
|
||||
*/
|
||||
#ifdef __x86_64__
|
||||
/*
|
||||
* Some non-Intel clones support out of order store. wmb() ceases to be a
|
||||
* Some non-Intel clones support out of order store. WMB() ceases to be a
|
||||
* nop for these.
|
||||
*/
|
||||
# define mb() __asm__ __volatile__ ("mfence" ::: "memory")
|
||||
# define rmb() __asm__ __volatile__ ("lfence" ::: "memory")
|
||||
# define wmb() __asm__ __volatile__ ("sfence" ::: "memory")
|
||||
# define MB() __asm__ __volatile__ ("mfence" ::: "memory")
|
||||
# define RMB() __asm__ __volatile__ ("lfence" ::: "memory")
|
||||
# define WMB() __asm__ __volatile__ ("sfence" ::: "memory")
|
||||
|
||||
struct atomic_int {
|
||||
volatile int64_t counter;
|
||||
|
||||
+5
-5
@@ -53,19 +53,19 @@ char * __bytes2hexstr(void * hex, size_t size, char *str, size_t len)
|
||||
|
||||
|
||||
/*
|
||||
* bytes2hexstr converts an array into a hexadecimal string and fills into a
|
||||
* BYTES2HEXSTR converts an array into a hexadecimal string and fills into a
|
||||
* given buffer. The buffer size is given as an extra argument.
|
||||
*/
|
||||
#define bytes2hexstr(array, str, len) ({ \
|
||||
#define BYTES2HEXSTR(array, str, len) ({ \
|
||||
COMPILE_TIME_ASSERT(IS_ARRAY(array)); \
|
||||
__bytes2hexstr((array), sizeof(array), str, len);})
|
||||
|
||||
/*
|
||||
* alloca_bytes2hexstr uses __alloca to allocate a buffer on the current frame
|
||||
* ALLOCA_BYTES2HEXSTR uses __alloca to allocate a buffer on the current frame
|
||||
* and then fills the hexadecimal string into the buffer.
|
||||
* This buffer can only be used within the caller frame (function).
|
||||
*/
|
||||
#define alloca_bytes2hexstr(array) \
|
||||
(bytes2hexstr((array), __alloca(sizeof(array) * 2 + 1), sizeof(array) * 2 + 1))
|
||||
#define ALLOCA_BYTES2HEXSTR(array) \
|
||||
(BYTES2HEXSTR((array), __alloca(sizeof(array) * 2 + 1), sizeof(array) * 2 + 1))
|
||||
|
||||
#endif // HEX_H
|
||||
|
||||
+15
-15
@@ -39,11 +39,11 @@
|
||||
#ifndef system_free
|
||||
#error "macro \"void * system_free (void * ptr, size_t size)\" not declared"
|
||||
#endif
|
||||
#ifndef system_lock
|
||||
#define system_lock() ({})
|
||||
#ifndef SYSTEM_LOCK
|
||||
#define SYSTEM_LOCK() ({})
|
||||
#endif
|
||||
#ifndef system_unlock
|
||||
#define system_unlock() ({})
|
||||
#ifndef SYSTEM_UNLOCK
|
||||
#define SYSTEM_UNLOCK() ({})
|
||||
#endif
|
||||
|
||||
DEFINE_LIST(mem_obj);
|
||||
@@ -150,12 +150,12 @@ static inline MEM_MGR enlarge_mem_mgr (MEM_MGR mgr, unsigned int size)
|
||||
if (!area)
|
||||
return NULL;
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
area->size = size;
|
||||
INIT_LIST_HEAD(area, __list);
|
||||
listp_add(area, &mgr->area_list, __list);
|
||||
__set_free_mem_area(area, mgr);
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
return mgr;
|
||||
}
|
||||
|
||||
@@ -181,9 +181,9 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr (MEM_MGR mgr)
|
||||
{
|
||||
MEM_OBJ mobj;
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
if (mgr->obj == mgr->obj_top && listp_empty(&mgr->free_list)) {
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr (MEM_MGR mgr)
|
||||
} else {
|
||||
mobj = mgr->obj++;
|
||||
}
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
return &mobj->obj;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr_enlarge (MEM_MGR mgr,
|
||||
{
|
||||
MEM_OBJ mobj;
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
if (mgr->obj == mgr->obj_top && listp_empty(&mgr->free_list)) {
|
||||
size_t mgr_size = mgr->size;
|
||||
MEM_AREA area;
|
||||
@@ -215,7 +215,7 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr_enlarge (MEM_MGR mgr,
|
||||
goto alloc;
|
||||
}
|
||||
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
|
||||
if (!size)
|
||||
return NULL;
|
||||
@@ -227,7 +227,7 @@ static inline OBJ_TYPE * get_mem_obj_from_mgr_enlarge (MEM_MGR mgr,
|
||||
if (!area)
|
||||
return NULL;
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
area->size = size;
|
||||
INIT_LIST_HEAD(area, __list);
|
||||
|
||||
@@ -248,7 +248,7 @@ alloc:
|
||||
mobj = mgr->obj++;
|
||||
}
|
||||
assert(mgr->obj <= mgr->obj_top);
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
return &mobj->obj;
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ static inline void free_mem_obj_to_mgr (MEM_MGR mgr, OBJ_TYPE * obj)
|
||||
{
|
||||
MEM_OBJ mobj = container_of(obj, MEM_OBJ_TYPE, obj);
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
MEM_AREA area, found = NULL;
|
||||
listp_for_each_entry(area, &mgr->area_list, __list)
|
||||
if (mobj >= area->objs && mobj < area->objs + area->size) {
|
||||
@@ -270,7 +270,7 @@ static inline void free_mem_obj_to_mgr (MEM_MGR mgr, OBJ_TYPE * obj)
|
||||
check_list_head(MEM_OBJ, &mgr->free_list, __list);
|
||||
}
|
||||
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
}
|
||||
|
||||
#endif /* MEMMGR_H */
|
||||
|
||||
@@ -19,8 +19,13 @@
|
||||
#include "api.h"
|
||||
#include <host_endian.h>
|
||||
|
||||
#define __bswap_16(x) ((uint16_t)(__builtin_bswap32(x) >> 16))
|
||||
#define __bswap_32(x) ((uint32_t)__builtin_bswap32(x))
|
||||
static uint16_t __bswap_16(uint16_t x) {
|
||||
return __builtin_bswap32(x) >> 16;
|
||||
}
|
||||
|
||||
static uint32_t __bswap_32(uint32_t x) {
|
||||
return __builtin_bswap32(x);
|
||||
}
|
||||
|
||||
uint32_t __htonl (uint32_t x)
|
||||
{
|
||||
|
||||
+14
-14
@@ -34,18 +34,18 @@
|
||||
#include <sys/mman.h>
|
||||
|
||||
// Before calling any of `system_malloc` and `system_free` this library will
|
||||
// acquire `system_lock` (the systen_* implementation must not do it).
|
||||
// acquire `SYSTEM_LOCK` (the systen_* implementation must not do it).
|
||||
#ifndef system_malloc
|
||||
#error "macro \"void * system_malloc(int size)\" not declared"
|
||||
#endif
|
||||
#ifndef system_free
|
||||
#error "macro \"void * system_free(void * ptr, int size)\" not declared"
|
||||
#endif
|
||||
#ifndef system_lock
|
||||
#define system_lock() ({})
|
||||
#ifndef SYSTEM_LOCK
|
||||
#define SYSTEM_LOCK() ({})
|
||||
#endif
|
||||
#ifndef system_unlock
|
||||
#define system_unlock() ({})
|
||||
#ifndef SYSTEM_UNLOCK
|
||||
#define SYSTEM_UNLOCK() ({})
|
||||
#endif
|
||||
|
||||
/* malloc is supposed to provide some kind of alignment guarantees, but
|
||||
@@ -297,7 +297,7 @@ static inline void destroy_slab_mgr (SLAB_MGR mgr)
|
||||
system_free(mgr, addr - (void *) mgr);
|
||||
}
|
||||
|
||||
// system_lock needs to be held by the caller on entry.
|
||||
// SYSTEM_LOCK needs to be held by the caller on entry.
|
||||
static inline int enlarge_slab_mgr (SLAB_MGR mgr, int level)
|
||||
{
|
||||
assert(level < SLAB_LEVEL);
|
||||
@@ -318,7 +318,7 @@ static inline int enlarge_slab_mgr (SLAB_MGR mgr, int level)
|
||||
|
||||
/* system_malloc() may be blocking, so we release the lock before
|
||||
* allocating more memory */
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
|
||||
/* If the allocation failed, always try smaller sizes */
|
||||
for (; size > 0; size >>= 1) {
|
||||
@@ -328,11 +328,11 @@ static inline int enlarge_slab_mgr (SLAB_MGR mgr, int level)
|
||||
}
|
||||
|
||||
if (!area) {
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
|
||||
area->size = size;
|
||||
INIT_LIST_HEAD(area, __list);
|
||||
@@ -371,13 +371,13 @@ static inline void * slab_alloc (SLAB_MGR mgr, int size)
|
||||
return OBJ_RAW(mem);
|
||||
}
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
assert(mgr->addr[level] <= mgr->addr_top[level]);
|
||||
if (mgr->addr[level] == mgr->addr_top[level] &&
|
||||
listp_empty(&mgr->free_list[level])) {
|
||||
int ret = enlarge_slab_mgr(mgr, level);
|
||||
if (ret < 0) {
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -391,7 +391,7 @@ static inline void * slab_alloc (SLAB_MGR mgr, int size)
|
||||
}
|
||||
assert(mgr->addr[level] <= mgr->addr_top[level]);
|
||||
OBJ_LEVEL(mobj) = level;
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
|
||||
#ifdef SLAB_CANARY
|
||||
unsigned long * m =
|
||||
@@ -488,10 +488,10 @@ static inline void slab_free (SLAB_MGR mgr, void * obj)
|
||||
|
||||
SLAB_OBJ mobj = RAW_TO_OBJ(obj, SLAB_OBJ_TYPE);
|
||||
|
||||
system_lock();
|
||||
SYSTEM_LOCK();
|
||||
INIT_LIST_HEAD(mobj, __list);
|
||||
listp_add_tail(mobj, &mgr->free_list[level], __list);
|
||||
system_unlock();
|
||||
SYSTEM_UNLOCK();
|
||||
}
|
||||
|
||||
#ifdef SLAB_DEBUG
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
int main() {
|
||||
char x[] = {0xde, 0xad, 0xbe, 0xef};
|
||||
char y[] = {0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd};
|
||||
pal_printf("Hex test 1 is %s\n", alloca_bytes2hexstr(x));
|
||||
pal_printf("Hex test 2 is %s\n", alloca_bytes2hexstr(y));
|
||||
pal_printf("Hex test 1 is %s\n", ALLOCA_BYTES2HEXSTR(x));
|
||||
pal_printf("Hex test 2 is %s\n", ALLOCA_BYTES2HEXSTR(y));
|
||||
return 0;
|
||||
}
|
||||
|
||||
+48
-48
@@ -4,69 +4,69 @@
|
||||
#include "pal.h"
|
||||
#include "pal_debug.h"
|
||||
|
||||
#define symbol_addr(sym) \
|
||||
#define SYMBOL_ADDR(sym) \
|
||||
({ void * _sym; \
|
||||
__asm__ volatile ("movq " #sym "@GOTPCREL(%%rip), %0" \
|
||||
: "=r"(_sym)); \
|
||||
: "=r"(_sym)); \
|
||||
_sym; })
|
||||
|
||||
#define print_symbol(sym) pal_printf(#sym " = %p\n", symbol_addr(sym))
|
||||
#define PRINT_SYMBOL(sym) pal_printf(#sym " = %p\n", SYMBOL_ADDR(sym))
|
||||
|
||||
int main (int argc, char ** argv, char ** envp)
|
||||
{
|
||||
print_symbol(DkVirtualMemoryAlloc);
|
||||
print_symbol(DkVirtualMemoryFree);
|
||||
print_symbol(DkVirtualMemoryProtect);
|
||||
PRINT_SYMBOL(DkVirtualMemoryAlloc);
|
||||
PRINT_SYMBOL(DkVirtualMemoryFree);
|
||||
PRINT_SYMBOL(DkVirtualMemoryProtect);
|
||||
|
||||
print_symbol(DkProcessCreate);
|
||||
print_symbol(DkProcessExit);
|
||||
print_symbol(DkProcessSandboxCreate);
|
||||
PRINT_SYMBOL(DkProcessCreate);
|
||||
PRINT_SYMBOL(DkProcessExit);
|
||||
PRINT_SYMBOL(DkProcessSandboxCreate);
|
||||
|
||||
print_symbol(DkStreamOpen);
|
||||
print_symbol(DkStreamWaitForClient);
|
||||
print_symbol(DkStreamRead);
|
||||
print_symbol(DkStreamWrite);
|
||||
print_symbol(DkStreamDelete);
|
||||
print_symbol(DkStreamMap);
|
||||
print_symbol(DkStreamUnmap);
|
||||
print_symbol(DkStreamSetLength);
|
||||
print_symbol(DkStreamFlush);
|
||||
print_symbol(DkSendHandle);
|
||||
print_symbol(DkReceiveHandle);
|
||||
print_symbol(DkStreamAttributesQuery);
|
||||
print_symbol(DkStreamAttributesQueryByHandle);
|
||||
print_symbol(DkStreamAttributesSetByHandle);
|
||||
print_symbol(DkStreamGetName);
|
||||
print_symbol(DkStreamChangeName);
|
||||
PRINT_SYMBOL(DkStreamOpen);
|
||||
PRINT_SYMBOL(DkStreamWaitForClient);
|
||||
PRINT_SYMBOL(DkStreamRead);
|
||||
PRINT_SYMBOL(DkStreamWrite);
|
||||
PRINT_SYMBOL(DkStreamDelete);
|
||||
PRINT_SYMBOL(DkStreamMap);
|
||||
PRINT_SYMBOL(DkStreamUnmap);
|
||||
PRINT_SYMBOL(DkStreamSetLength);
|
||||
PRINT_SYMBOL(DkStreamFlush);
|
||||
PRINT_SYMBOL(DkSendHandle);
|
||||
PRINT_SYMBOL(DkReceiveHandle);
|
||||
PRINT_SYMBOL(DkStreamAttributesQuery);
|
||||
PRINT_SYMBOL(DkStreamAttributesQueryByHandle);
|
||||
PRINT_SYMBOL(DkStreamAttributesSetByHandle);
|
||||
PRINT_SYMBOL(DkStreamGetName);
|
||||
PRINT_SYMBOL(DkStreamChangeName);
|
||||
|
||||
print_symbol(DkThreadCreate);
|
||||
print_symbol(DkThreadDelayExecution);
|
||||
print_symbol(DkThreadYieldExecution);
|
||||
print_symbol(DkThreadExit);
|
||||
print_symbol(DkThreadResume);
|
||||
PRINT_SYMBOL(DkThreadCreate);
|
||||
PRINT_SYMBOL(DkThreadDelayExecution);
|
||||
PRINT_SYMBOL(DkThreadYieldExecution);
|
||||
PRINT_SYMBOL(DkThreadExit);
|
||||
PRINT_SYMBOL(DkThreadResume);
|
||||
|
||||
print_symbol(DkSetExceptionHandler);
|
||||
print_symbol(DkExceptionReturn);
|
||||
PRINT_SYMBOL(DkSetExceptionHandler);
|
||||
PRINT_SYMBOL(DkExceptionReturn);
|
||||
|
||||
print_symbol(DkMutexCreate);
|
||||
print_symbol(DkMutexRelease);
|
||||
print_symbol(DkNotificationEventCreate);
|
||||
print_symbol(DkSynchronizationEventCreate);
|
||||
print_symbol(DkEventSet);
|
||||
print_symbol(DkEventClear);
|
||||
PRINT_SYMBOL(DkMutexCreate);
|
||||
PRINT_SYMBOL(DkMutexRelease);
|
||||
PRINT_SYMBOL(DkNotificationEventCreate);
|
||||
PRINT_SYMBOL(DkSynchronizationEventCreate);
|
||||
PRINT_SYMBOL(DkEventSet);
|
||||
PRINT_SYMBOL(DkEventClear);
|
||||
|
||||
print_symbol(DkObjectsWaitAny);
|
||||
print_symbol(DkObjectClose);
|
||||
PRINT_SYMBOL(DkObjectsWaitAny);
|
||||
PRINT_SYMBOL(DkObjectClose);
|
||||
|
||||
print_symbol(DkSystemTimeQuery);
|
||||
print_symbol(DkRandomBitsRead);
|
||||
print_symbol(DkInstructionCacheFlush);
|
||||
print_symbol(DkSegmentRegister);
|
||||
print_symbol(DkMemoryAvailableQuota);
|
||||
PRINT_SYMBOL(DkSystemTimeQuery);
|
||||
PRINT_SYMBOL(DkRandomBitsRead);
|
||||
PRINT_SYMBOL(DkInstructionCacheFlush);
|
||||
PRINT_SYMBOL(DkSegmentRegister);
|
||||
PRINT_SYMBOL(DkMemoryAvailableQuota);
|
||||
|
||||
print_symbol(DkCreatePhysicalMemoryChannel);
|
||||
print_symbol(DkPhysicalMemoryCommit);
|
||||
print_symbol(DkPhysicalMemoryMap);
|
||||
PRINT_SYMBOL(DkCreatePhysicalMemoryChannel);
|
||||
PRINT_SYMBOL(DkPhysicalMemoryCommit);
|
||||
PRINT_SYMBOL(DkPhysicalMemoryMap);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+15
-15
@@ -67,7 +67,7 @@ static void load_libraries (void)
|
||||
|
||||
*c = 0;
|
||||
if ((ret = load_elf_object(library_name, OBJECT_PRELOAD)) < 0)
|
||||
init_fail(-ret, "Unable to load preload library");
|
||||
INIT_FAIL(-ret, "Unable to load preload library");
|
||||
|
||||
#if PROFILING == 1
|
||||
pal_state.linking_time +=
|
||||
@@ -197,7 +197,7 @@ static void set_debug_type (void)
|
||||
ret = get_config(pal_state.root_config, "loader.debug_file",
|
||||
cfgbuf, CONFIG_MAX);
|
||||
if (ret <= 0)
|
||||
init_fail(PAL_ERROR_INVAL, "debug file not specified");
|
||||
INIT_FAIL(PAL_ERROR_INVAL, "debug file not specified");
|
||||
|
||||
ret = _DkStreamOpen(&handle, cfgbuf,
|
||||
PAL_ACCESS_RDWR,
|
||||
@@ -209,11 +209,11 @@ static void set_debug_type (void)
|
||||
if (strcmp_static(cfgbuf, "none"))
|
||||
goto out;
|
||||
|
||||
init_fail(PAL_ERROR_INVAL, "unknown debug type");
|
||||
INIT_FAIL(PAL_ERROR_INVAL, "unknown debug type");
|
||||
|
||||
out:
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot open debug stream");
|
||||
INIT_FAIL(-ret, "cannot open debug stream");
|
||||
|
||||
__pal_control.debug_stream = handle;
|
||||
}
|
||||
@@ -264,7 +264,7 @@ void pal_main (
|
||||
if (exec_handle) {
|
||||
ret = _DkStreamGetName(exec_handle, uri_buf, URI_MAX);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot get executable name");
|
||||
INIT_FAIL(-ret, "cannot get executable name");
|
||||
|
||||
exec_uri = malloc_copy(uri_buf, ret + 1);
|
||||
}
|
||||
@@ -272,14 +272,14 @@ void pal_main (
|
||||
if (manifest_handle) {
|
||||
ret = _DkStreamGetName(manifest_handle, uri_buf, URI_MAX);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot get manifest name");
|
||||
INIT_FAIL(-ret, "cannot get manifest name");
|
||||
|
||||
manifest_uri = malloc_copy(uri_buf, ret + 1);
|
||||
goto has_manifest;
|
||||
}
|
||||
|
||||
if (!exec_handle)
|
||||
init_fail(PAL_ERROR_INVAL, "Must have manifest or executable");
|
||||
INIT_FAIL(PAL_ERROR_INVAL, "Must have manifest or executable");
|
||||
|
||||
#if PROFILING == 1
|
||||
unsigned long before_find_manifest = _DkSystemTimeQuery();
|
||||
@@ -319,7 +319,7 @@ has_manifest:
|
||||
PAL_STREAM_ATTR attr;
|
||||
ret = _DkStreamAttributesQueryByHandle(manifest_handle, &attr);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot open manifest file");
|
||||
INIT_FAIL(-ret, "cannot open manifest file");
|
||||
|
||||
void * cfg_addr = NULL;
|
||||
int cfg_size = attr.pending_size;
|
||||
@@ -328,7 +328,7 @@ has_manifest:
|
||||
PAL_PROT_READ, 0,
|
||||
ALLOC_ALIGNUP(cfg_size));
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot open manifest file");
|
||||
INIT_FAIL(-ret, "cannot open manifest file");
|
||||
|
||||
struct config_store * root_config = malloc(sizeof(struct config_store));
|
||||
root_config->raw_data = cfg_addr;
|
||||
@@ -340,7 +340,7 @@ has_manifest:
|
||||
if ((ret = read_config(root_config, loader_filter, &errstring)) < 0) {
|
||||
if (_DkStreamGetName(manifest_handle, uri_buf, URI_MAX) > 0)
|
||||
printf("reading manifest \"%s\" failed\n", uri_buf);
|
||||
init_fail(-ret, errstring);
|
||||
INIT_FAIL(-ret, errstring);
|
||||
}
|
||||
|
||||
pal_state.root_config = root_config;
|
||||
@@ -360,7 +360,7 @@ has_manifest:
|
||||
ret = _DkStreamOpen(&exec_handle, exec_uri, PAL_ACCESS_RDONLY,
|
||||
0, 0, 0);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot open executable");
|
||||
INIT_FAIL(-ret, "cannot open executable");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ has_manifest:
|
||||
if (success) {
|
||||
exec_uri = malloc(exec_strlen + 1);
|
||||
if (!exec_uri)
|
||||
init_fail(-PAL_ERROR_NOMEM, "Cannot allocate URI buf");
|
||||
INIT_FAIL(-PAL_ERROR_NOMEM, "Cannot allocate URI buf");
|
||||
memcpy (exec_uri, manifest_uri, exec_strlen);
|
||||
exec_uri[exec_strlen] = '\0';
|
||||
ret = _DkStreamOpen(&exec_handle, exec_uri, PAL_ACCESS_RDONLY,
|
||||
@@ -400,7 +400,7 @@ has_manifest:
|
||||
|
||||
/* must be a ELF */
|
||||
if (exec_handle && check_elf_object(exec_handle) < 0)
|
||||
init_fail(PAL_ERROR_INVAL, "executable is not a ELF binary");
|
||||
INIT_FAIL(PAL_ERROR_INVAL, "executable is not a ELF binary");
|
||||
|
||||
pal_state.manifest = manifest_uri;
|
||||
pal_state.manifest_handle = manifest_handle;
|
||||
@@ -436,7 +436,7 @@ has_manifest:
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
init_fail(ret, PAL_STRERROR(ret));
|
||||
INIT_FAIL(ret, PAL_STRERROR(ret));
|
||||
|
||||
#if PROFILING == 1
|
||||
pal_state.linking_time += _DkSystemTimeQuery() - before_load_exec;
|
||||
@@ -483,7 +483,7 @@ has_manifest:
|
||||
start_execution(first_argument, arguments, environments);
|
||||
|
||||
/* We wish we will never reached here */
|
||||
init_fail(PAL_ERROR_DENIED, "unexpected termination");
|
||||
INIT_FAIL(PAL_ERROR_DENIED, "unexpected termination");
|
||||
}
|
||||
|
||||
void write_log (int nstrs, ...)
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
* The source code is imported and modified from the GNU C Library.
|
||||
*/
|
||||
|
||||
#ifndef dl_machine_h
|
||||
#define dl_machine_h
|
||||
#ifndef DL_MACHINE_H
|
||||
#define DL_MACHINE_H
|
||||
|
||||
#define ELF_MACHINE_NAME "x86_64"
|
||||
|
||||
@@ -171,4 +171,4 @@ elf_machine_rela_relative (struct link_map *l, const Elf64_Rela *reloc,
|
||||
*reloc_addr = l->l_addr + reloc->r_addend;
|
||||
}
|
||||
|
||||
#endif /* !dl_machine_h */
|
||||
#endif /* !DL_MACHINE_H */
|
||||
|
||||
@@ -561,7 +561,7 @@ void signal_setup (void)
|
||||
return;
|
||||
|
||||
err:
|
||||
init_fail(-ret, "cannot setup signal handlers");
|
||||
INIT_FAIL(-ret, "cannot setup signal handlers");
|
||||
}
|
||||
|
||||
void _DkExceptionReturn (void * event)
|
||||
|
||||
@@ -401,7 +401,7 @@ void signal_setup (void)
|
||||
|
||||
return;
|
||||
err:
|
||||
init_fail(-ret, "cannot setup signal handlers");
|
||||
INIT_FAIL(-ret, "cannot setup signal handlers");
|
||||
}
|
||||
|
||||
void _DkExceptionReturn (void * event)
|
||||
|
||||
@@ -156,7 +156,7 @@ void _DkGetAvailableUserAddressRange (PAL_PTR * start, PAL_PTR * end)
|
||||
|
||||
while (1) {
|
||||
if (start_addr >= end_addr)
|
||||
init_fail(PAL_ERROR_NOMEM, "no user memory available");
|
||||
INIT_FAIL(PAL_ERROR_NOMEM, "no user memory available");
|
||||
|
||||
void * mem = (void *) ARCH_MMAP(start_addr,
|
||||
pal_state.alloc_align,
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(__i386__)
|
||||
#define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
|
||||
#define cpu_relax() asm volatile("rep; nop" ::: "memory");
|
||||
#define RMB() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
|
||||
#define CPU_RELAX() asm volatile("rep; nop" ::: "memory");
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__)
|
||||
#include <unistd.h>
|
||||
#define rmb() asm volatile("lfence" ::: "memory")
|
||||
#define cpu_relax() asm volatile("rep; nop" ::: "memory");
|
||||
#define RMB() asm volatile("lfence" ::: "memory")
|
||||
#define CPU_RELAX() asm volatile("rep; nop" ::: "memory");
|
||||
#endif
|
||||
|
||||
#define MUTEX_SPINLOCK_TIMES 20
|
||||
@@ -68,7 +68,7 @@ int _DkMutexLockTimeout (struct mutex_handle * mut, int timeout)
|
||||
c = atomic_dec_and_test(m);
|
||||
if (c)
|
||||
goto success;
|
||||
cpu_relax();
|
||||
CPU_RELAX();
|
||||
}
|
||||
|
||||
/* The lock is now contended */
|
||||
@@ -132,7 +132,7 @@ int _DkMutexLock (struct mutex_handle * mut)
|
||||
c = atomic_dec_and_test(m);
|
||||
if (c)
|
||||
goto success;
|
||||
cpu_relax();
|
||||
CPU_RELAX();
|
||||
}
|
||||
|
||||
/* The lock is now contended */
|
||||
|
||||
@@ -317,7 +317,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
|
||||
if (IS_ERR(bytes)) {
|
||||
if (ERRNO(bytes) != EBADF)
|
||||
init_fail(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
INIT_FAIL(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
|
||||
/* in the first process */
|
||||
/* occupy PROC_INIT_FD so no one will use it */
|
||||
@@ -327,7 +327,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
|
||||
/* a child must have parent handle and an executable */
|
||||
if (!proc_args->parent_data_size)
|
||||
init_fail(PAL_ERROR_INVAL, "invalid process created");
|
||||
INIT_FAIL(PAL_ERROR_INVAL, "invalid process created");
|
||||
|
||||
int datasz = proc_args->parent_data_size + proc_args->exec_data_size +
|
||||
proc_args->manifest_data_size;
|
||||
@@ -342,13 +342,13 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
|
||||
bytes = INLINE_SYSCALL(read, 3, PROC_INIT_FD, data, datasz);
|
||||
if (IS_ERR(bytes))
|
||||
init_fail(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
INIT_FAIL(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
|
||||
/* now deserialize the parent_handle */
|
||||
PAL_HANDLE parent = NULL;
|
||||
ret = handle_deserialize(&parent, data, proc_args->parent_data_size);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot deseilaize parent process handle");
|
||||
INIT_FAIL(-ret, "cannot deseilaize parent process handle");
|
||||
data += proc_args->parent_data_size;
|
||||
*parent_handle = parent;
|
||||
|
||||
@@ -359,7 +359,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
ret = handle_deserialize(&exec, data,
|
||||
proc_args->exec_data_size);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot deserialize executable handle");
|
||||
INIT_FAIL(-ret, "cannot deserialize executable handle");
|
||||
|
||||
data += proc_args->exec_data_size;
|
||||
*exec_handle = exec;
|
||||
@@ -372,7 +372,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
ret = handle_deserialize(&manifest, data,
|
||||
proc_args->manifest_data_size);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot deserialize manifest handle");
|
||||
INIT_FAIL(-ret, "cannot deserialize manifest handle");
|
||||
|
||||
data += proc_args->manifest_data_size;
|
||||
*manifest_handle = manifest;
|
||||
|
||||
@@ -58,8 +58,7 @@ typedef uint16_t __be16;
|
||||
#define SOL_TCP 6
|
||||
#define TCP_CORK TCP_NOPUSH
|
||||
|
||||
static inline int addr_size (struct sockaddr * addr)
|
||||
{
|
||||
static size_t addr_size(const struct sockaddr* addr) {
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
return sizeof(struct sockaddr_in);
|
||||
|
||||
@@ -98,16 +98,16 @@ int _DkStreamUnmap (void * addr, uint64_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define addr_size(addr) \
|
||||
({ int _size = 0; \
|
||||
switch (((struct sockaddr *) addr)->sa_family) { \
|
||||
case AF_INET: \
|
||||
_size = sizeof(struct sockaddr_in); break; \
|
||||
case AF_INET6: \
|
||||
_size = sizeof(struct sockaddr_in6); break; \
|
||||
default: break; \
|
||||
} _size; \
|
||||
})
|
||||
static size_t addr_size(const struct sockaddr* addr) {
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
return sizeof(struct sockaddr_in);
|
||||
case AF_INET6:
|
||||
return sizeof(struct sockaddr_in6);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int handle_serialize (PAL_HANDLE handle, void ** data)
|
||||
{
|
||||
|
||||
@@ -126,7 +126,7 @@ int _DkMutexUnlock (struct mutex_handle * m)
|
||||
*(m->locked) = MUTEX_UNLOCKED; // TODO: this is not atomic!
|
||||
/* We need to make sure the write to locked is visible to lock-ers
|
||||
* before we read the waiter count. */
|
||||
mb();
|
||||
MB();
|
||||
|
||||
need_wake= atomic_read(&m->nwaiters);
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args)
|
||||
data.keyhash_mac, sizeof(data.keyhash_mac));
|
||||
|
||||
SGX_DBG(DBG_P|DBG_S, "Attestation data: %s\n",
|
||||
alloca_bytes2hexstr(data.keyhash_mac));
|
||||
ALLOCA_BYTES2HEXSTR(data.keyhash_mac));
|
||||
|
||||
ret = _DkStreamAttestationRequest(proc, &data,
|
||||
&check_child_mrenclave, ¶m);
|
||||
@@ -309,7 +309,7 @@ int init_child_process (PAL_HANDLE * parent_handle)
|
||||
data.keyhash_mac, sizeof(data.keyhash_mac));
|
||||
|
||||
SGX_DBG(DBG_P|DBG_S, "Attestation data: %s\n",
|
||||
alloca_bytes2hexstr(data.keyhash_mac));
|
||||
ALLOCA_BYTES2HEXSTR(data.keyhash_mac));
|
||||
|
||||
ret = _DkStreamAttestationRespond(parent, &data,
|
||||
&check_parent_mrenclave,
|
||||
|
||||
@@ -59,8 +59,7 @@ typedef __kernel_pid_t pid_t;
|
||||
address */
|
||||
#define PAL_SOCKADDR_SIZE 96
|
||||
|
||||
static inline int addr_size (struct sockaddr * addr)
|
||||
{
|
||||
static size_t addr_size(const struct sockaddr* addr) {
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
return sizeof(struct sockaddr_in);
|
||||
|
||||
@@ -44,7 +44,7 @@ int _DkSpinLock (struct spinlock * lock)
|
||||
int c = atomic_read(m);
|
||||
if (!c && atomic_cmpxchg(m, 0, 1) == 0)
|
||||
break;
|
||||
cpu_relax();
|
||||
CPU_RELAX();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -84,16 +84,16 @@ int _DkStreamUnmap (void * addr, uint64_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define addr_size(addr) \
|
||||
({ int _size = 0; \
|
||||
switch (((struct sockaddr *) addr)->sa_family) { \
|
||||
case AF_INET: \
|
||||
_size = sizeof(struct sockaddr_in); break; \
|
||||
case AF_INET6: \
|
||||
_size = sizeof(struct sockaddr_in6); break; \
|
||||
default: break; \
|
||||
} _size; \
|
||||
})
|
||||
static size_t addr_size(const struct sockaddr* addr) {
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
return sizeof(struct sockaddr_in);
|
||||
case AF_INET6:
|
||||
return sizeof(struct sockaddr_in6);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int handle_serialize (PAL_HANDLE handle, void ** data)
|
||||
{
|
||||
|
||||
@@ -112,15 +112,15 @@ int sgx_get_report (sgx_arch_hash_t * mrenclave,
|
||||
SGX_DBG(DBG_S, "Generated report:\n");
|
||||
SGX_DBG(DBG_S, " cpusvn: %08lx %08lx\n", report->cpusvn[0],
|
||||
report->cpusvn[1]);
|
||||
SGX_DBG(DBG_S, " mrenclave: %s\n", alloca_bytes2hexstr(report->mrenclave));
|
||||
SGX_DBG(DBG_S, " mrsigner: %s\n", alloca_bytes2hexstr(report->mrsigner));
|
||||
SGX_DBG(DBG_S, " mrenclave: %s\n", ALLOCA_BYTES2HEXSTR(report->mrenclave));
|
||||
SGX_DBG(DBG_S, " mrsigner: %s\n", ALLOCA_BYTES2HEXSTR(report->mrsigner));
|
||||
SGX_DBG(DBG_S, " attributes.flags: %016lx\n", report->attributes.flags);
|
||||
SGX_DBG(DBG_S, " sttributes.xfrm: %016lx\n", report->attributes.xfrm);
|
||||
|
||||
SGX_DBG(DBG_S, " isvprodid: %02x\n", report->isvprodid);
|
||||
SGX_DBG(DBG_S, " isvsvn: %02x\n", report->isvsvn);
|
||||
SGX_DBG(DBG_S, " keyid: %s\n", alloca_bytes2hexstr(report->keyid));
|
||||
SGX_DBG(DBG_S, " mac: %s\n", alloca_bytes2hexstr(report->mac));
|
||||
SGX_DBG(DBG_S, " keyid: %s\n", ALLOCA_BYTES2HEXSTR(report->keyid));
|
||||
SGX_DBG(DBG_S, " mac: %s\n", ALLOCA_BYTES2HEXSTR(report->mac));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ int sgx_verify_report (sgx_arch_report_t * report)
|
||||
}
|
||||
|
||||
SGX_DBG(DBG_S, "Get report key for verification: %s\n",
|
||||
alloca_bytes2hexstr(enclave_key));
|
||||
ALLOCA_BYTES2HEXSTR(enclave_key));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ int init_enclave_key (void)
|
||||
return -PAL_ERROR_DENIED;
|
||||
}
|
||||
|
||||
SGX_DBG(DBG_S, "Get sealing key: %s\n", alloca_bytes2hexstr(enclave_key));
|
||||
SGX_DBG(DBG_S, "Get sealing key: %s\n", ALLOCA_BYTES2HEXSTR(enclave_key));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -950,7 +950,7 @@ int init_enclave (void)
|
||||
sizeof(pal_enclave_state.enclave_identifier));
|
||||
|
||||
SGX_DBG(DBG_S, "enclave (software) key hash: %s\n",
|
||||
alloca_bytes2hexstr(pal_enclave_state.enclave_identifier));
|
||||
ALLOCA_BYTES2HEXSTR(pal_enclave_state.enclave_identifier));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1014,7 +1014,7 @@ int _DkStreamKeyExchange (PAL_HANDLE stream, PAL_SESSION_KEY * keyptr)
|
||||
session_key[i % sizeof(session_key)] ^= agree[i];
|
||||
|
||||
SGX_DBG(DBG_S, "key exchange: (%p) %s\n", session_key,
|
||||
alloca_bytes2hexstr(session_key));
|
||||
ALLOCA_BYTES2HEXSTR(session_key));
|
||||
|
||||
if (keyptr)
|
||||
memcpy(keyptr, session_key, sizeof(PAL_SESSION_KEY));
|
||||
@@ -1051,7 +1051,7 @@ int _DkStreamAttestationRequest (PAL_HANDLE stream, void * data,
|
||||
sizeof(sgx_arch_attributes_t));
|
||||
|
||||
SGX_DBG(DBG_S, "Sending attestation request ... (mrenclave = %s)\n",\
|
||||
alloca_bytes2hexstr(req.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(req.mrenclave));
|
||||
|
||||
for (bytes = 0, ret = 0 ; bytes < sizeof(req) ; bytes += ret) {
|
||||
ret = _DkStreamWrite(stream, 0, sizeof(req) - bytes,
|
||||
@@ -1072,7 +1072,7 @@ int _DkStreamAttestationRequest (PAL_HANDLE stream, void * data,
|
||||
}
|
||||
|
||||
SGX_DBG(DBG_S, "Received attestation (mrenclave = %s)\n",
|
||||
alloca_bytes2hexstr(att.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(att.mrenclave));
|
||||
|
||||
ret = sgx_verify_report(&att.report);
|
||||
if (ret < 0) {
|
||||
@@ -1095,7 +1095,7 @@ int _DkStreamAttestationRequest (PAL_HANDLE stream, void * data,
|
||||
|
||||
if (ret == 1) {
|
||||
SGX_DBG(DBG_S, "Not an allowed enclave (mrenclave = %s)\n",
|
||||
alloca_bytes2hexstr(att.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(att.mrenclave));
|
||||
ret = -PAL_ERROR_DENIED;
|
||||
goto out;
|
||||
}
|
||||
@@ -1113,7 +1113,7 @@ int _DkStreamAttestationRequest (PAL_HANDLE stream, void * data,
|
||||
sizeof(sgx_arch_attributes_t));
|
||||
|
||||
SGX_DBG(DBG_S, "Sending attestation ... (mrenclave = %s)\n",
|
||||
alloca_bytes2hexstr(att.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(att.mrenclave));
|
||||
|
||||
for (bytes = 0, ret = 0 ; bytes < sizeof(att) ; bytes += ret) {
|
||||
ret = _DkStreamWrite(stream, 0, sizeof(att) - bytes,
|
||||
@@ -1150,7 +1150,7 @@ int _DkStreamAttestationRespond (PAL_HANDLE stream, void * data,
|
||||
}
|
||||
|
||||
SGX_DBG(DBG_S, "Received attestation request ... (mrenclave = %s)\n",
|
||||
alloca_bytes2hexstr(req.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(req.mrenclave));
|
||||
|
||||
ret = sgx_get_report(&req.mrenclave, &req.attributes, data, &att.report);
|
||||
if (ret < 0) {
|
||||
@@ -1163,7 +1163,7 @@ int _DkStreamAttestationRespond (PAL_HANDLE stream, void * data,
|
||||
sizeof(sgx_arch_attributes_t));
|
||||
|
||||
SGX_DBG(DBG_S, "Sending attestation ... (mrenclave = %s)\n",
|
||||
alloca_bytes2hexstr(att.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(att.mrenclave));
|
||||
|
||||
for (bytes = 0, ret = 0 ; bytes < sizeof(att) ; bytes += ret) {
|
||||
ret = _DkStreamWrite(stream, 0, sizeof(att) - bytes,
|
||||
@@ -1184,7 +1184,7 @@ int _DkStreamAttestationRespond (PAL_HANDLE stream, void * data,
|
||||
}
|
||||
|
||||
SGX_DBG(DBG_S, "Received attestation (mrenclave = %s)\n",
|
||||
alloca_bytes2hexstr(att.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(att.mrenclave));
|
||||
|
||||
ret = sgx_verify_report(&att.report);
|
||||
if (ret < 0) {
|
||||
@@ -1206,7 +1206,7 @@ int _DkStreamAttestationRespond (PAL_HANDLE stream, void * data,
|
||||
|
||||
if (ret == 1) {
|
||||
SGX_DBG(DBG_S, "Not an allowed enclave (mrenclave = %s)\n",
|
||||
alloca_bytes2hexstr(att.mrenclave));
|
||||
ALLOCA_BYTES2HEXSTR(att.mrenclave));
|
||||
ret = -PAL_ERROR_DENIED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
static PAL_LOCK malloc_lock = LOCK_INIT;
|
||||
static int pagesize = PRESET_PAGESIZE;
|
||||
|
||||
#define system_lock() _DkSpinLock(&malloc_lock)
|
||||
#define system_unlock() _DkSpinUnlock(&malloc_lock)
|
||||
#define SYSTEM_LOCK() _DkSpinLock(&malloc_lock)
|
||||
#define SYSTEM_UNLOCK() _DkSpinUnlock(&malloc_lock)
|
||||
|
||||
#define PAGE_SIZE pagesize
|
||||
|
||||
@@ -61,7 +61,7 @@ void init_untrusted_slab_mgr ()
|
||||
|
||||
untrusted_slabmgr = create_slab_mgr();
|
||||
if (!untrusted_slabmgr)
|
||||
init_fail(PAL_ERROR_NOMEM, "cannot initialize slab manager");
|
||||
INIT_FAIL(PAL_ERROR_NOMEM, "cannot initialize slab manager");
|
||||
}
|
||||
|
||||
void * malloc_untrusted (int size)
|
||||
|
||||
@@ -318,45 +318,50 @@ int initialize_enclave (struct pal_enclave * enclave)
|
||||
__alloca(sizeof(areas[0]) * (10 + enclave->thread_num));
|
||||
int area_num = 0;
|
||||
|
||||
#define set_area(_desc, _skip_eextend, _is_binary, _fd, _addr, _size, _prot, _type)\
|
||||
({ \
|
||||
struct mem_area * _a = &areas[area_num++]; \
|
||||
_a->desc = _desc; _a->skip_eextend = _skip_eextend; \
|
||||
_a->is_binary = _is_binary; \
|
||||
_a->fd = _fd; _a->addr = _addr; _a->size = _size; \
|
||||
_a->prot = _prot; _a->type = _type; _a; \
|
||||
#define SET_AREA(_desc, _skip_eextend, _is_binary, _fd, _addr, _size, _prot, _type) \
|
||||
({ \
|
||||
struct mem_area* _a = &areas[area_num++]; \
|
||||
_a->desc = _desc; \
|
||||
_a->skip_eextend = _skip_eextend; \
|
||||
_a->is_binary = _is_binary; \
|
||||
_a->fd = _fd; \
|
||||
_a->addr = _addr; \
|
||||
_a->size = _size; \
|
||||
_a->prot = _prot; \
|
||||
_a->type = _type; \
|
||||
_a; \
|
||||
})
|
||||
|
||||
/* The manifest needs to be allocated at the upper end of the enclave
|
||||
* memory. That's used by pal_linux_main to find the manifest area. So add
|
||||
* it first to the list with memory areas. */
|
||||
set_area("manifest", false, false, enclave->manifest,
|
||||
SET_AREA("manifest", false, false, enclave->manifest,
|
||||
0, ALLOC_ALIGNUP(manifest_size),
|
||||
PROT_READ, SGX_PAGE_REG);
|
||||
struct mem_area * ssa_area =
|
||||
set_area("ssa", false, false, -1, 0,
|
||||
SET_AREA("ssa", false, false, -1, 0,
|
||||
enclave->thread_num * enclave->ssaframesize * SSAFRAMENUM,
|
||||
PROT_READ|PROT_WRITE, SGX_PAGE_REG);
|
||||
struct mem_area * tcs_area =
|
||||
set_area("tcs", false, false, -1, 0, enclave->thread_num * pagesize,
|
||||
SET_AREA("tcs", false, false, -1, 0, enclave->thread_num * pagesize,
|
||||
0, SGX_PAGE_TCS);
|
||||
struct mem_area * tls_area =
|
||||
set_area("tls", false, false, -1, 0, enclave->thread_num * pagesize,
|
||||
SET_AREA("tls", false, false, -1, 0, enclave->thread_num * pagesize,
|
||||
PROT_READ|PROT_WRITE, SGX_PAGE_REG);
|
||||
|
||||
struct mem_area * stack_areas = &areas[area_num];
|
||||
for (int t = 0 ; t < enclave->thread_num ; t++)
|
||||
set_area("stack", false, false, -1, 0, ENCLAVE_STACK_SIZE,
|
||||
SET_AREA("stack", false, false, -1, 0, ENCLAVE_STACK_SIZE,
|
||||
PROT_READ|PROT_WRITE, SGX_PAGE_REG);
|
||||
|
||||
struct mem_area * pal_area =
|
||||
set_area("pal", false, true, enclave_image, 0, 0, 0, SGX_PAGE_REG);
|
||||
SET_AREA("pal", false, true, enclave_image, 0, 0, 0, SGX_PAGE_REG);
|
||||
TRY(scan_enclave_binary,
|
||||
enclave_image, &pal_area->addr, &pal_area->size, &enclave_entry_addr);
|
||||
|
||||
struct mem_area * exec_area = NULL;
|
||||
if (enclave->exec != -1) {
|
||||
exec_area = set_area("exec", false, true, enclave->exec, 0, 0,
|
||||
exec_area = SET_AREA("exec", false, true, enclave->exec, 0, 0,
|
||||
PROT_WRITE, SGX_PAGE_REG);
|
||||
TRY(scan_enclave_binary,
|
||||
enclave->exec, &exec_area->addr, &exec_area->size, NULL);
|
||||
@@ -384,7 +389,7 @@ int initialize_enclave (struct pal_enclave * enclave)
|
||||
unsigned long addr = exec_area->addr + exec_area->size;
|
||||
if (addr < heap_min)
|
||||
addr = heap_min;
|
||||
set_area("free", true, false, -1, addr, populating - addr,
|
||||
SET_AREA("free", true, false, -1, addr, populating - addr,
|
||||
PROT_READ|PROT_WRITE|PROT_EXEC, SGX_PAGE_REG);
|
||||
}
|
||||
|
||||
@@ -393,7 +398,7 @@ int initialize_enclave (struct pal_enclave * enclave)
|
||||
}
|
||||
|
||||
if (populating > heap_min) {
|
||||
set_area("free", true, false, -1, heap_min, populating - heap_min,
|
||||
SET_AREA("free", true, false, -1, heap_min, populating - heap_min,
|
||||
PROT_READ|PROT_WRITE|PROT_EXEC, SGX_PAGE_REG);
|
||||
}
|
||||
|
||||
@@ -490,6 +495,8 @@ int initialize_enclave (struct pal_enclave * enclave)
|
||||
dbg->tcs_addrs[i] = tcs_addrs[i];
|
||||
|
||||
return 0;
|
||||
#undef SET_AREA
|
||||
#undef TRY
|
||||
}
|
||||
|
||||
static int mcast_s (int port)
|
||||
|
||||
@@ -357,7 +357,7 @@ void signal_setup (void)
|
||||
|
||||
return;
|
||||
err:
|
||||
init_fail(-ret, "cannot setup signal handlers");
|
||||
INIT_FAIL(-ret, "cannot setup signal handlers");
|
||||
}
|
||||
|
||||
void _DkExceptionReturn (void * event)
|
||||
|
||||
@@ -159,7 +159,7 @@ void _DkGetAvailableUserAddressRange (PAL_PTR * start, PAL_PTR * end)
|
||||
|
||||
while (1) {
|
||||
if (start_addr >= end_addr)
|
||||
init_fail(PAL_ERROR_NOMEM, "no user memory available");
|
||||
INIT_FAIL(PAL_ERROR_NOMEM, "no user memory available");
|
||||
|
||||
void * mem = (void *) ARCH_MMAP(start_addr,
|
||||
pal_state.alloc_align,
|
||||
@@ -231,7 +231,7 @@ void pal_linux_main (void * args)
|
||||
|
||||
first_thread = malloc(HANDLE_SIZE(thread));
|
||||
if (!first_thread)
|
||||
init_fail(PAL_ERROR_NOMEM, "Out of memory");
|
||||
INIT_FAIL(PAL_ERROR_NOMEM, "Out of memory");
|
||||
SET_HANDLE_TYPE(first_thread, thread);
|
||||
first_thread->thread.tid = INLINE_SYSCALL(gettid, 0);
|
||||
first_thread->thread.stack = NULL;
|
||||
@@ -239,7 +239,7 @@ void pal_linux_main (void * args)
|
||||
void * alt_stack = NULL;
|
||||
_DkVirtualMemoryAlloc(&alt_stack, ALT_STACK_SIZE, 0, PAL_PROT_READ|PAL_PROT_WRITE);
|
||||
if (!alt_stack)
|
||||
init_fail(PAL_ERROR_NOMEM, "Out of memory");
|
||||
INIT_FAIL(PAL_ERROR_NOMEM, "Out of memory");
|
||||
|
||||
// Initialize TCB at the top of the alternative stack.
|
||||
PAL_TCB * tcb = alt_stack + ALT_STACK_SIZE - sizeof(PAL_TCB);
|
||||
|
||||
@@ -100,7 +100,7 @@ int _DkMutexLockTimeout (struct mutex_handle * m, uint64_t timeout)
|
||||
for (i = 0; i < iterations; i++) {
|
||||
if (MUTEX_UNLOCKED == cmpxchg(&m->locked, MUTEX_UNLOCKED, MUTEX_LOCKED))
|
||||
goto success;
|
||||
cpu_relax();
|
||||
CPU_RELAX();
|
||||
}
|
||||
|
||||
if (timeout == 0) {
|
||||
@@ -180,7 +180,7 @@ int _DkMutexUnlock (struct mutex_handle * m)
|
||||
m->locked = 0;
|
||||
/* We need to make sure the write to locked is visible to lock-ers
|
||||
* before we read the waiter count. */
|
||||
mb();
|
||||
MB();
|
||||
|
||||
need_wake = atomic_read(&m->nwaiters);
|
||||
|
||||
|
||||
@@ -347,7 +347,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
|
||||
if (IS_ERR(bytes)) {
|
||||
if (ERRNO(bytes) != EBADF)
|
||||
init_fail(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
INIT_FAIL(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
|
||||
/* in the first process */
|
||||
/* occupy PROC_INIT_FD so no one will use it */
|
||||
@@ -357,7 +357,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
|
||||
/* a child must have parent handle and an executable */
|
||||
if (!proc_args->parent_data_size)
|
||||
init_fail(PAL_ERROR_INVAL, "invalid process created");
|
||||
INIT_FAIL(PAL_ERROR_INVAL, "invalid process created");
|
||||
|
||||
int datasz = proc_args->parent_data_size + proc_args->exec_data_size +
|
||||
proc_args->manifest_data_size;
|
||||
@@ -372,13 +372,13 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
|
||||
bytes = INLINE_SYSCALL(read, 3, PROC_INIT_FD, data, datasz);
|
||||
if (IS_ERR(bytes))
|
||||
init_fail(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
INIT_FAIL(PAL_ERROR_DENIED, "communication fail with parent");
|
||||
|
||||
/* now deserialize the parent_handle */
|
||||
PAL_HANDLE parent = NULL;
|
||||
ret = handle_deserialize(&parent, data, proc_args->parent_data_size);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot deseilaize parent process handle");
|
||||
INIT_FAIL(-ret, "cannot deseilaize parent process handle");
|
||||
data += proc_args->parent_data_size;
|
||||
*parent_handle = parent;
|
||||
|
||||
@@ -392,7 +392,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
ret = handle_deserialize(&exec, data,
|
||||
proc_args->exec_data_size);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot deserialize executable handle");
|
||||
INIT_FAIL(-ret, "cannot deserialize executable handle");
|
||||
|
||||
data += proc_args->exec_data_size;
|
||||
*exec_handle = exec;
|
||||
@@ -405,7 +405,7 @@ void init_child_process (PAL_HANDLE * parent_handle,
|
||||
ret = handle_deserialize(&manifest, data,
|
||||
proc_args->manifest_data_size);
|
||||
if (ret < 0)
|
||||
init_fail(-ret, "cannot deserialize manifest handle");
|
||||
INIT_FAIL(-ret, "cannot deserialize manifest handle");
|
||||
|
||||
data += proc_args->manifest_data_size;
|
||||
*manifest_handle = manifest;
|
||||
|
||||
@@ -66,8 +66,7 @@ typedef __kernel_pid_t pid_t;
|
||||
address */
|
||||
#define PAL_SOCKADDR_SIZE 96
|
||||
|
||||
static inline int addr_size (struct sockaddr * addr)
|
||||
{
|
||||
static size_t addr_size(const struct sockaddr* addr) {
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
return sizeof(struct sockaddr_in);
|
||||
|
||||
@@ -102,16 +102,16 @@ int _DkStreamUnmap (void * addr, uint64_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define addr_size(addr) \
|
||||
({ int _size = 0; \
|
||||
switch (((struct sockaddr *) addr)->sa_family) { \
|
||||
case AF_INET: \
|
||||
_size = sizeof(struct sockaddr_in); break; \
|
||||
case AF_INET6: \
|
||||
_size = sizeof(struct sockaddr_in6); break; \
|
||||
default: break; \
|
||||
} _size; \
|
||||
})
|
||||
static size_t addr_size(const struct sockaddr* addr) {
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
return sizeof(struct sockaddr_in);
|
||||
case AF_INET6:
|
||||
return sizeof(struct sockaddr_in6);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int handle_serialize (PAL_HANDLE handle, void ** data)
|
||||
{
|
||||
@@ -239,9 +239,9 @@ int handle_deserialize (PAL_HANDLE * handle, const void * data, int size)
|
||||
case pal_type_udpsrv: {
|
||||
int s1 = 0, s2 = 0;
|
||||
if (hdl_data->sock.bind)
|
||||
s1 = addr_size(data);
|
||||
s1 = addr_size((const struct sockaddr*)data);
|
||||
if (hdl_data->sock.conn)
|
||||
s2 = addr_size(data + s1);
|
||||
s2 = addr_size((const struct sockaddr*)(data + s1));
|
||||
hdl = malloc(hdlsz + s1 + s2);
|
||||
if (!hdl)
|
||||
break;
|
||||
|
||||
@@ -361,7 +361,7 @@ int _DkPhysicalMemoryMap (PAL_HANDLE channel, int entries,
|
||||
PAL_PTR * addrs, PAL_NUM * sizes, PAL_FLG * prots);
|
||||
int _DkCpuIdRetrieve (unsigned int leaf, unsigned int subleaf, unsigned int values[4]);
|
||||
|
||||
#define init_fail(exitcode, reason) \
|
||||
#define INIT_FAIL(exitcode, reason) \
|
||||
do { \
|
||||
printf("PAL failed at " __FILE__ ":%s:%u (exitcode = %u, reason=%s)\n", \
|
||||
__FUNCTION__, (unsigned int)__LINE__, \
|
||||
@@ -398,12 +398,12 @@ void free (void * mem);
|
||||
# define __attribute_noinline
|
||||
#endif
|
||||
|
||||
#define alias_str(name) #name
|
||||
#define ALIAS_STR(name) #name
|
||||
#ifdef __GNUC__
|
||||
# define extern_alias(name) \
|
||||
extern __typeof(name) pal_##name __attribute ((alias (alias_str(name))))
|
||||
# define EXTERN_ALIAS(name) \
|
||||
extern __typeof(name) pal_##name __attribute ((alias (ALIAS_STR(name))))
|
||||
#else
|
||||
# define extern_alias(name)
|
||||
# define EXTERN_ALIAS(name)
|
||||
#endif
|
||||
|
||||
void _DkPrintConsole (const void * buf, int size);
|
||||
|
||||
+1
-1
@@ -75,6 +75,6 @@ printf(const char * fmt, ...)
|
||||
|
||||
return cnt;
|
||||
}
|
||||
extern_alias(printf);
|
||||
EXTERN_ALIAS(printf);
|
||||
|
||||
#endif
|
||||
|
||||
+3
-3
@@ -35,8 +35,8 @@
|
||||
static int slab_alignment;
|
||||
static PAL_LOCK slab_mgr_lock = LOCK_INIT;
|
||||
|
||||
#define system_lock() _DkInternalLock(&slab_mgr_lock)
|
||||
#define system_unlock() _DkInternalUnlock(&slab_mgr_lock)
|
||||
#define SYSTEM_LOCK() _DkInternalLock(&slab_mgr_lock)
|
||||
#define SYSTEM_UNLOCK() _DkInternalUnlock(&slab_mgr_lock)
|
||||
|
||||
#if STATIC_SLAB == 1
|
||||
# define POOL_SIZE 64 * 1024 * 1024 /* 64MB by default */
|
||||
@@ -99,7 +99,7 @@ void init_slab_mgr (int alignment)
|
||||
slab_alignment = alignment;
|
||||
slab_mgr = create_slab_mgr();
|
||||
if (!slab_mgr)
|
||||
init_fail(PAL_ERROR_NOMEM, "cannot initialize slab manager");
|
||||
INIT_FAIL(PAL_ERROR_NOMEM, "cannot initialize slab manager");
|
||||
|
||||
#if PROFILING == 1
|
||||
pal_state.slab_time += _DkSystemTimeQuery() - before_slab;
|
||||
|
||||
+4
-4
@@ -6,7 +6,7 @@
|
||||
#include "pal.h"
|
||||
#include "pal_debug.h"
|
||||
|
||||
#define file_uri "file:test.txt"
|
||||
#define FILE_URI "file:test.txt"
|
||||
|
||||
char str[12];
|
||||
|
||||
@@ -14,7 +14,7 @@ int main (int argc, char ** argv, char ** envp)
|
||||
{
|
||||
pal_printf("Enter Main Thread\n");
|
||||
|
||||
PAL_HANDLE out = DkStreamOpen(file_uri, PAL_ACCESS_RDWR,
|
||||
PAL_HANDLE out = DkStreamOpen(FILE_URI, PAL_ACCESS_RDWR,
|
||||
PAL_SHARE_OWNER_W | PAL_SHARE_OWNER_R,
|
||||
PAL_CREATE_TRY, 0);
|
||||
|
||||
@@ -45,7 +45,7 @@ int main (int argc, char ** argv, char ** envp)
|
||||
|
||||
DkObjectClose(out);
|
||||
|
||||
PAL_HANDLE in = DkStreamOpen(file_uri, PAL_ACCESS_RDONLY, 0, 0, 0);
|
||||
PAL_HANDLE in = DkStreamOpen(FILE_URI, PAL_ACCESS_RDONLY, 0, 0, 0);
|
||||
|
||||
bytes = DkStreamRead(in, 0, 20, str, NULL, 0);
|
||||
|
||||
@@ -58,7 +58,7 @@ int main (int argc, char ** argv, char ** envp)
|
||||
|
||||
DkStreamDelete(in, 0);
|
||||
|
||||
PAL_HANDLE del = DkStreamOpen(file_uri, PAL_ACCESS_RDWR, 0, 0, 0);
|
||||
PAL_HANDLE del = DkStreamOpen(FILE_URI, PAL_ACCESS_RDWR, 0, 0, 0);
|
||||
|
||||
if (del) {
|
||||
pal_printf("DkStreamDelete failed\n");
|
||||
|
||||
Reference in New Issue
Block a user