diff --git a/.gitignore b/.gitignore index e72d4a38..396bafc5 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ *.s *.e *.d +pal.map # object file/libraries *.a diff --git a/Jenkinsfiles/Linux b/Jenkinsfiles/Linux index ff29dbe7..9f806b20 100644 --- a/Jenkinsfiles/Linux +++ b/Jenkinsfiles/Linux @@ -17,6 +17,10 @@ pipeline { cd Pal/ipc/linux make KERNELDIR=/lib/modules/4.4.0-161-generic/build ''' + sh ''' + cd Pal/src + make -j 8 PAL_HOST=Skeleton WERROR=1 + ''' } } stage('Test') { diff --git a/Jenkinsfiles/Linux-Debug b/Jenkinsfiles/Linux-Debug index ebd15c44..bf33076d 100644 --- a/Jenkinsfiles/Linux-Debug +++ b/Jenkinsfiles/Linux-Debug @@ -9,6 +9,10 @@ pipeline { make -j 8 DEBUG=1 WERROR=1 make -j 8 DEBUG=1 WERROR=1 test ''' + sh ''' + cd Pal/src + make -j 8 PAL_HOST=Skeleton DEBUG=1 WERROR=1 + ''' } } stage('Test') { diff --git a/Makefile.rules b/Makefile.rules index f61b4335..54d9ef24 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -93,7 +93,7 @@ quiet_cmd_cpp_s_S = [ $@ ] # LD quiet_cmd_ld_so_o = [ $@ ] - cmd_ld_so_o = $(LD) $(LDFLAGS) $(LDFLAGS-$@) -o $@ $(filter-out %.map %.lds,$^) -soname $(notdir $@) + cmd_ld_so_o = $(LD) $(LDFLAGS) $(LDFLAGS-$@) -o $@ $(filter-out pal-symbols %.map %.map.template %.lds,$^) -soname $(notdir $@) # AR quiet_cmd_ar_so_o = [ $@ ] @@ -104,7 +104,7 @@ quiet_cmd_ar_a_o = [ $@ ] # LD only quiet_cmd_ld = [ $@ ] - cmd_ld = $(LD) $(LDFLAGS) $(LDFLAGS-$@) -o $@ $(filter-out %.map %.lds,$^) + cmd_ld = $(LD) $(LDFLAGS) $(LDFLAGS-$@) -o $@ $(filter-out pal-symbols %.map %.map.template %.lds,$^) # OBJCOPY quiet_cmd_objcopy = [ $@ ] @@ -142,3 +142,13 @@ quiet_cmd_sgx_manifest_dependency = [ $@ ] awk -F= '/^\s*sgx.trusted_files./{file=$$2; gsub("file:", "", file); printf(" \\\n\t%s", file)}' $<; \ awk -F= '/^\s*sgx.trusted_children./{file=$$2; gsub("file:", "", file); printf(" \\\n\t%s", file); gsub(".sig", "", file); printf(" \\\n\t%s.manifest.sgx", file)}' $<; \ echo "") > $@ + +# pal map +PAL_SYMBOL_FILE = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))Pal/src/pal-symbols +PAL_SYMBOLS = $(shell sed -e 's|$$|;|g' $(PAL_SYMBOL_FILE)) + +quiet_cmd_pal_map = [ $@ ] + cmd_pal_map = sed -e 's|\$$(PAL_SYMBOLS)|$(PAL_SYMBOLS)|g' $< > $@ + +pal.map: pal.map.template $(PAL_SYMBOL_FILE) + $(call cmd,pal_map) diff --git a/Pal/src/Makefile b/Pal/src/Makefile index 31efd587..de27e49f 100644 --- a/Pal/src/Makefile +++ b/Pal/src/Makefile @@ -59,7 +59,9 @@ export DEBUG # libpal-{Host Name}.so: dynamic-linking library # pal_gdb-{Host Name}: debugger for PAL (as an executable) -runtime_loader = $(RUNTIME_DIR)/pal-$(PAL_HOST) +ifneq ($(pal_loader),) + runtime_loader += $(RUNTIME_DIR)/pal-$(PAL_HOST) +endif ifneq ($(pal_lib),) runtime_lib += $(RUNTIME_DIR)/libpal-$(PAL_HOST)$(suffix $(pal_lib)) @@ -99,8 +101,10 @@ $(host_lib): host_lib_recurse $(pal_loader): $(host_lib) +ifneq ($(pal_loader),) $(runtime_loader): $(pal_loader) $(call cmd,ln_sf) +endif ifneq ($(pal_lib),) $(pal_lib): $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(objs))) \ diff --git a/Pal/src/host/FreeBSD/Makefile b/Pal/src/host/FreeBSD/Makefile index 30457ccd..7c8bd388 100644 --- a/Pal/src/host/FreeBSD/Makefile +++ b/Pal/src/host/FreeBSD/Makefile @@ -5,7 +5,7 @@ CFLAGS += -I. -Iinclude -I../.. -I../../../include -I../../../lib -I../../../ipc -I../../../linux-kernel/graphene ASFLAGS += -I. -Iinclude -I../.. -I../../../include -host_target = libpal-FreeBSD.a ../../pal-gdb +host_files = libpal-FreeBSD.a pal.map ../../pal-gdb defs = -DIN_PAL -DPAL_DIR="$(PAL_DIR)" CFLAGS += $(defs) @@ -17,7 +17,7 @@ graphene_lib = .lib/graphene-lib.a headers = $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h) .PHONY: all -all: $(host_target) +all: $(host_files) ifeq ($(DEBUG),1) CC += -g -gdwarf-2 -gstrict-dwarf @@ -50,8 +50,8 @@ libpal-FreeBSD.a: $(addsuffix .o,$(objs)) $(graphene_lib) include ../../../../Makefile.rules -CLEAN_FILES += $(notdir $(pal_static) $(pal_lib) $(pal_loader)) +CLEAN_FILES += $(notdir $(pal_static) $(pal_lib) $(pal_sec) $(pal_loader)) .PHONY: clean clean: - rm -f $(addsuffix .o,$(objs)) $(host_target) $(CLEAN_FILES) + rm -f $(addsuffix .o,$(objs)) $(host_files) $(CLEAN_FILES) diff --git a/Pal/src/host/FreeBSD/Makefile.am b/Pal/src/host/FreeBSD/Makefile.am index 4e6cb3ac..1ec58780 100644 --- a/Pal/src/host/FreeBSD/Makefile.am +++ b/Pal/src/host/FreeBSD/Makefile.am @@ -16,6 +16,6 @@ endif pal_loader = $(HOST_DIR)/libpal.so pal_lib = $(HOST_DIR)/libpal.so -pal_lib_deps = $(HOST_DIR)/pal.map $(HOST_DIR)/pal.lds +pal_lib_deps = pal-symbols $(HOST_DIR)/pal.map.template $(HOST_DIR)/pal.lds pal_lib_post = pal_static = $(HOST_DIR)/libpal.a diff --git a/Pal/src/host/FreeBSD/pal.map b/Pal/src/host/FreeBSD/pal.map deleted file mode 100644 index f21eeb25..00000000 --- a/Pal/src/host/FreeBSD/pal.map +++ /dev/null @@ -1,54 +0,0 @@ -PAL { - global: - # Drawbridge ABIs - DkVirtualMemoryAlloc; DkVirtualMemoryFree; DkVirtualMemoryProtect; - DkThreadCreate; DkThreadDelayExecution; - DkThreadYieldExecution; DkThreadExit; DkThreadResume; - - DkSemaphoreCreate; DkNotificationEventCreate; - DkSynchronizationEventCreate; - DkSemaphoreRelease; - DkEventSet; DkEventClear; - DkObjectsWaitAny; - - DkStreamOpen; DkStreamRead; DkStreamWrite; - DkStreamMap; DkStreamUnmap; DkStreamSetLength; - DkStreamFlush; DkStreamDelete; - DkSendHandle; DkReceiveHandle; # Added by us - DkStreamWaitForClient; - DkStreamGetName; - DkStreamAttributesQueryByHandle; DkStreamAttributesQuery; - - DkProcessCreate; DkProcessExit; - - DkSystemTimeQuery; DkRandomBitsRead; - DkInstructionCacheFlush; - DkObjectReference; DkObjectClose; - # objects checkpoint? - # objects reload? - - # The ABIs we added in the paper - DkSetExceptionHandler; DkExceptionReturn; # exceptions - DkCreatePhysicalMemoryChannel; # IPC - DkPhysicalMemoryCommit; # IPC - DkPhysicalMemoryMap; # IPC - DkSegmentRegister; # set segmentation registers - DkStreamChangeName; - DkStreamAttributesSetByHandle; - DkMemoryAvailableQuota; - - # Debugging ABIs - pal_printf; DkDebugAttachBinary; DkDebugDetachBinary; - - # Control block - pal_control_addr; pal_sec; - - # debugger interface - r_debug; - - local: *; -}; -PAL_PRIVATE { - global: - r_debug_state; -}; diff --git a/Pal/src/host/FreeBSD/pal.map.template b/Pal/src/host/FreeBSD/pal.map.template new file mode 100644 index 00000000..21ddc7f2 --- /dev/null +++ b/Pal/src/host/FreeBSD/pal.map.template @@ -0,0 +1,8 @@ +PAL { + global: $(PAL_SYMBOLS) r_debug; + local: *; +}; +PAL_PRIVATE { + global: + r_debug_state; +}; diff --git a/Pal/src/host/Linux-SGX/Makefile b/Pal/src/host/Linux-SGX/Makefile index 19fc731c..49be0441 100644 --- a/Pal/src/host/Linux-SGX/Makefile +++ b/Pal/src/host/Linux-SGX/Makefile @@ -4,7 +4,7 @@ include Makefile.am CFLAGS += -I. -Iinclude -I../.. -I../../../include -I../../../lib -Isgx-driver ASFLAGS += -I. -I../.. -I../../../include -host_files = libpal-Linux-SGX.a pal-sgx debugger/sgx_gdb.so generated_offsets.py +host_files = libpal-Linux-SGX.a pal-sgx debugger/sgx_gdb.so pal.map generated_offsets.py defs = -DIN_PAL -DPAL_DIR=$(PAL_DIR) -DRUNTIME_DIR=$(RUNTIME_DIR) CFLAGS += $(defs) diff --git a/Pal/src/host/Linux-SGX/Makefile.am b/Pal/src/host/Linux-SGX/Makefile.am index 09d592e9..be4a2f4f 100644 --- a/Pal/src/host/Linux-SGX/Makefile.am +++ b/Pal/src/host/Linux-SGX/Makefile.am @@ -25,7 +25,7 @@ endif pal_loader = $(HOST_DIR)/pal-sgx pal_lib = $(HOST_DIR)/libpal.so -pal_lib_deps = $(HOST_DIR)/enclave.lds $(HOST_DIR)/pal.map +pal_lib_deps = pal-symbols $(HOST_DIR)/pal.map.template $(HOST_DIR)/enclave.lds pal_static = $(HOST_DIR)/libpal.a pal_gdb = $(HOST_DIR)/debugger/gdb pal_signer = pal-sgx-get-token pal-sgx-sign aesm_pb2.py diff --git a/Pal/src/host/Linux-SGX/pal.map b/Pal/src/host/Linux-SGX/pal.map deleted file mode 100644 index e20bcf18..00000000 --- a/Pal/src/host/Linux-SGX/pal.map +++ /dev/null @@ -1,51 +0,0 @@ -PAL { - global: - # Drawbridge ABIs - DkVirtualMemoryAlloc; DkVirtualMemoryFree; DkVirtualMemoryProtect; - DkThreadCreate; DkThreadDelayExecution; - DkThreadYieldExecution; DkThreadExit; DkThreadResume; - - DkMutexCreate; DkNotificationEventCreate; - DkSynchronizationEventCreate; - DkMutexRelease; - DkEventSet; DkEventClear; - DkObjectsWaitAny; - - DkStreamOpen; DkStreamRead; DkStreamWrite; - DkStreamMap; DkStreamUnmap; DkStreamSetLength; - DkStreamFlush; DkStreamDelete; - DkSendHandle; DkReceiveHandle; # Added by us - DkStreamWaitForClient; - DkStreamGetName; - DkStreamAttributesQueryByHandle; DkStreamAttributesQuery; - - DkProcessCreate; DkProcessExit; - - DkSystemTimeQuery; DkRandomBitsRead; - DkInstructionCacheFlush; - DkObjectReference; DkObjectClose; - # objects checkpoint? - # objects reload? - - # The ABIs we added in the paper - DkSetExceptionHandler; DkExceptionReturn; # exceptions - DkCreatePhysicalMemoryChannel; # IPC - DkPhysicalMemoryCommit; # IPC - DkPhysicalMemoryMap; # IPC - DkThreadStackSet; # set stack range - DkThreadPrivateSet; DkThreadPrivateGet; # set/get thread private area - DkThreadGetCurrent; # get a handle to describe the current thread - DkStreamChangeName; - DkStreamAttributesSetByHandle; - DkSegmentRegister; # set segment register - DkMemoryAvailableQuota; - DkCpuIdRetrieve; # retrieve CPUID - - # Debugging ABIs - pal_printf; pal_snprintf; DkDebugAttachBinary; DkDebugDetachBinary; - - # Control block - pal_control; pal_control_addr; - - local: *; -}; diff --git a/Pal/src/host/Linux-SGX/pal.map.template b/Pal/src/host/Linux-SGX/pal.map.template new file mode 100644 index 00000000..54dd39c4 --- /dev/null +++ b/Pal/src/host/Linux-SGX/pal.map.template @@ -0,0 +1,4 @@ +PAL { + global: $(PAL_SYMBOLS) + local: *; +}; diff --git a/Pal/src/host/Linux/Makefile b/Pal/src/host/Linux/Makefile index 52b3950c..1b8334c0 100644 --- a/Pal/src/host/Linux/Makefile +++ b/Pal/src/host/Linux/Makefile @@ -10,7 +10,7 @@ ifeq ($(PROFILING),1) CFLAGS += -DPROFILING=1 endif -host_files = libpal-Linux.a +host_files = libpal-Linux.a pal.map defs = -DIN_PAL -DPAL_DIR=$(PAL_DIR) -DRUNTIME_DIR=$(RUNTIME_DIR) CFLAGS += $(defs) @@ -51,7 +51,7 @@ include ../../../../Makefile.rules -include $(addsuffix .d,$(objs)) $(addsuffix .i.d,$(objs)) $(addsuffix .s.d,$(objs)) -CLEAN_FILES += $(notdir $(pal_static) $(pal_lib) $(pal_loader)) +CLEAN_FILES += $(notdir $(pal_static) $(pal_lib) $(pal_sec) $(pal_loader)) .PHONY: clean clean: diff --git a/Pal/src/host/Linux/Makefile.am b/Pal/src/host/Linux/Makefile.am index b9241389..f400053c 100644 --- a/Pal/src/host/Linux/Makefile.am +++ b/Pal/src/host/Linux/Makefile.am @@ -22,7 +22,7 @@ endif pal_loader = $(HOST_DIR)/libpal.so pal_lib = $(HOST_DIR)/libpal.so -pal_lib_deps = $(HOST_DIR)/pal.map $(HOST_DIR)/pal.lds +pal_lib_deps = pal-symbols $(HOST_DIR)/pal.map.template $(HOST_DIR)/pal.lds pal_lib_post = pal_static = $(HOST_DIR)/libpal.a pal_gdb = diff --git a/Pal/src/host/Linux/pal.map b/Pal/src/host/Linux/pal.map deleted file mode 100644 index edcf7d25..00000000 --- a/Pal/src/host/Linux/pal.map +++ /dev/null @@ -1,55 +0,0 @@ -PAL { - global: - # Drawbridge ABIs - DkVirtualMemoryAlloc; DkVirtualMemoryFree; DkVirtualMemoryProtect; - DkThreadCreate; DkThreadDelayExecution; - DkThreadYieldExecution; DkThreadExit; DkThreadResume; - - DkMutexCreate; DkNotificationEventCreate; - DkSynchronizationEventCreate; - DkMutexRelease; - DkEventSet; DkEventClear; - DkObjectsWaitAny; - - DkStreamOpen; DkStreamRead; DkStreamWrite; - DkStreamMap; DkStreamUnmap; DkStreamSetLength; - DkStreamFlush; DkStreamDelete; - DkSendHandle; DkReceiveHandle; # Added by us - DkStreamWaitForClient; - DkStreamGetName; - DkStreamAttributesQueryByHandle; DkStreamAttributesQuery; - - DkProcessCreate; DkProcessExit; - - DkSystemTimeQuery; DkRandomBitsRead; - DkInstructionCacheFlush; - DkCpuIdRetrieve; - DkObjectClose; - # objects checkpoint? - # objects reload? - - # The ABIs we added in the paper - DkSetExceptionHandler; DkExceptionReturn; # exceptions - DkCreatePhysicalMemoryChannel; # IPC - DkPhysicalMemoryCommit; # IPC - DkPhysicalMemoryMap; # IPC - DkSegmentRegister; # set segmentation registers - DkStreamChangeName; - DkStreamAttributesSetByHandle; - DkMemoryAvailableQuota; - - # Debugging ABIs - pal_printf; DkDebugAttachBinary; DkDebugDetachBinary; - - # Control block - pal_control_addr; pal_sec; - - # debugger - _r_debug; - - local: *; -}; -PAL_PRIVATE { - global: - _dl_debug_state; -}; diff --git a/Pal/src/host/Linux/pal.map.template b/Pal/src/host/Linux/pal.map.template new file mode 100644 index 00000000..b8d5c3a2 --- /dev/null +++ b/Pal/src/host/Linux/pal.map.template @@ -0,0 +1,9 @@ +PAL { + global: $(PAL_SYMBOLS) _r_debug; + + local: *; +}; +PAL_PRIVATE { + global: + _dl_debug_state; +}; diff --git a/Pal/src/host/Skeleton/Makefile b/Pal/src/host/Skeleton/Makefile index 1c1e59c4..8adfe949 100644 --- a/Pal/src/host/Skeleton/Makefile +++ b/Pal/src/host/Skeleton/Makefile @@ -4,18 +4,17 @@ include Makefile.am CFLAGS += -I. -I../.. -I../../../include -I../../../lib ASFLAGS += -I. -I../.. -I../../../include -host_target = libpal-Skeleton.a +host_files = libpal-Skeleton.a pal.map defs = -DIN_PAL CFLAGS += $(defs) ASFLAGS += $(defs) objs = $(addprefix db_,files devices pipes sockets streams memory threading \ - semaphore events process object main rtld misc ipc exception) -graphene_lib = ../../../lib/graphene-lib.a + mutex events process object main rtld misc ipc exception) headers = $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h) .PHONY: all -all: $(host_target) +all: $(host_files) ifeq ($(DEBUG),1) CC += -gdwarf-2 -g3 @@ -26,7 +25,7 @@ endif ../../host_endian.h: host_endian.h $(MAKE) -C ../../ $< -libpal-Skeleton.a: $(addsuffix .o,$(objs)) $(graphene_lib) +libpal-Skeleton.a: $(addsuffix .o,$(objs)) $(call cmd,ar_a_o) %.o: %.c $(headers) @@ -39,4 +38,4 @@ include ../../../../Makefile.rules .PHONY: clean clean: - rm -f $(addsuffix .o,$(objs)) $(host_target) + rm -f $(addsuffix .o,$(objs)) $(host_files) diff --git a/Pal/src/host/Skeleton/Makefile.am b/Pal/src/host/Skeleton/Makefile.am index 267877e9..58a0be46 100644 --- a/Pal/src/host/Skeleton/Makefile.am +++ b/Pal/src/host/Skeleton/Makefile.am @@ -1,9 +1,26 @@ # Add host-specific compilation rules here -CFLAGS = -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -Wall -U_FORTIFY_SOURCE -fno-builtin -ASFLAGS = -DPIC -DSHARED -fPIC -DASSEMBLER -Wa,--noexecstack -x assembler-with-cpp +CFLAGS = -Wall -fPIC -O2 -std=c11 -U_FORTIFY_SOURCE \ + -fno-stack-protector -fno-builtin + +EXTRAFLAGS = -Wextra -Wno-unused-parameter -Wno-sign-compare $(call cc-option,-Wnull-dereference) + +CFLAGS += $(EXTRAFLAGS) + +ASFLAGS = -DPIC -DSHARED -fPIC -DASSEMBLER -Wa,--noexecstack \ + -x assembler-with-cpp +LDFLAGS = -shared -nostdlib -z combreloc -z defs \ + --version-script $(HOST_DIR)/pal.map -T $(HOST_DIR)/pal.lds ARFLAGS = ifeq ($(WERROR),1) CFLAGS += -Werror endif + +pal_loader = +pal_sec = +pal_lib = $(HOST_DIR)/libpal.so +pal_lib_deps = pal-symbols $(HOST_DIR)/pal.map.template $(HOST_DIR)/pal.lds +pal_lib_post = +pal_static = +pal_gdb = diff --git a/Pal/src/host/Skeleton/db_devices.c b/Pal/src/host/Skeleton/db_devices.c index 4c346932..187682df 100644 --- a/Pal/src/host/Skeleton/db_devices.c +++ b/Pal/src/host/Skeleton/db_devices.c @@ -204,7 +204,7 @@ static int dev_attrquery (const char * type, const char * uri, PAL_STREAM_ATTR * attr) { struct handle_ops * ops = NULL; - const char * dev_type = NULL; + char * dev_type = NULL; int ret = 0; ret = parse_device_uri(&uri, &dev_type, &ops); diff --git a/Pal/src/host/Skeleton/db_events.c b/Pal/src/host/Skeleton/db_events.c index 71ac9630..e67da757 100644 --- a/Pal/src/host/Skeleton/db_events.c +++ b/Pal/src/host/Skeleton/db_events.c @@ -41,7 +41,7 @@ int _DkEventSet (PAL_HANDLE event, int wakeup) return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkEventWaitTimeout (PAL_HANDLE event, uint64_t timeout) +int _DkEventWaitTimeout (PAL_HANDLE event, int64_t timeout_us) { return -PAL_ERROR_NOTIMPLEMENTED; } @@ -55,3 +55,18 @@ int _DkEventClear (PAL_HANDLE event) { return -PAL_ERROR_NOTIMPLEMENTED; } + +static int event_close (PAL_HANDLE handle) +{ + return -PAL_ERROR_NOTIMPLEMENTED; +} + +static int event_wait (PAL_HANDLE handle, int64_t timeout_us) +{ + return -PAL_ERROR_NOTIMPLEMENTED; +} + +struct handle_ops event_ops = { + .close = &event_close, + .wait = &event_wait, + }; diff --git a/Pal/src/host/Skeleton/db_files.c b/Pal/src/host/Skeleton/db_files.c index 98f202dd..2a465361 100644 --- a/Pal/src/host/Skeleton/db_files.c +++ b/Pal/src/host/Skeleton/db_files.c @@ -102,7 +102,7 @@ static int file_rename (PAL_HANDLE handle, const char * type, return -PAL_ERROR_NOTIMPLEMENTED; } -static int file_getname (PAL_HANDLE handle, char * buffer, int count) +static int file_getname (PAL_HANDLE handle, char * buffer, size_t count) { return -PAL_ERROR_NOTIMPLEMENTED; } @@ -169,7 +169,7 @@ static int dir_rename (PAL_HANDLE handle, const char * type, return -PAL_ERROR_NOTIMPLEMENTED; } -static int dir_getname (PAL_HANDLE handle, char * buffer, int count) +static int dir_getname (PAL_HANDLE handle, char * buffer, size_t count) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/Pal/src/host/Skeleton/db_main.c b/Pal/src/host/Skeleton/db_main.c index d9c3d424..d865ecb7 100644 --- a/Pal/src/host/Skeleton/db_main.c +++ b/Pal/src/host/Skeleton/db_main.c @@ -60,7 +60,8 @@ PAL_NUM _DkGetHostId (void) return 0; } -void _DkGetCPUInfo (PAL_CPU_INFO * ci) +int _DkGetCPUInfo (PAL_CPU_INFO * ci) { /* need to be implemented */ + return 0; } diff --git a/Pal/src/host/Skeleton/db_misc.c b/Pal/src/host/Skeleton/db_misc.c index 495e9170..ba808c51 100644 --- a/Pal/src/host/Skeleton/db_misc.c +++ b/Pal/src/host/Skeleton/db_misc.c @@ -41,7 +41,7 @@ unsigned long _DkSystemTimeQuery (void) return 0; } -int _DkRandomBitsRead (void * buffer, int size) +size_t _DkRandomBitsRead (void * buffer, size_t size) { return -PAL_ERROR_NOTIMPLEMENTED; } @@ -60,3 +60,9 @@ int _DkInstructionCacheFlush (const void * addr, int size) { return -PAL_ERROR_NOTIMPLEMENTED; } + +int _DkCpuIdRetrieve (unsigned int leaf, unsigned int subleaf, + unsigned int values[4]) +{ + return -PAL_ERROR_NOTIMPLEMENTED; +} diff --git a/Pal/src/host/Skeleton/db_semaphore.c b/Pal/src/host/Skeleton/db_mutex.c similarity index 63% rename from Pal/src/host/Skeleton/db_semaphore.c rename to Pal/src/host/Skeleton/db_mutex.c index 002b35e6..1c14ccf8 100644 --- a/Pal/src/host/Skeleton/db_semaphore.c +++ b/Pal/src/host/Skeleton/db_mutex.c @@ -15,9 +15,7 @@ along with this program. If not, see . */ /* - * db_semaphore.c - * - * This file contains APIs that provides operations of semaphores. + * db_mutex.c */ #include "api.h" @@ -26,26 +24,42 @@ #include "pal_error.h" #include "pal_internal.h" -int _DkSemaphoreCreate(PAL_HANDLE handle, int initialCount, int maxCount) { +int +_DkMutexCreate (PAL_HANDLE * handle, int initialCount) +{ return -PAL_ERROR_NOTIMPLEMENTED; } -void _DkSemaphoreDestroy(PAL_HANDLE semaphoreHandle) { - /* need to be implemented */ -} - -int _DkSemaphoreAcquire(PAL_HANDLE sem, int count) { +int _DkMutexLockTimeout (struct mutex_handle * m, int64_t timeout_us) +{ return -PAL_ERROR_NOTIMPLEMENTED; } -int _DkSemaphoreAcquireTimeout(PAL_HANDLE sem, int count, int timeout) { +int _DkMutexLock (struct mutex_handle * m) +{ return -PAL_ERROR_NOTIMPLEMENTED; } -void _DkSemaphoreRelease(PAL_HANDLE sem, int count) { - /* need to be implemented */ -} - -int _DkSemaphoreGetCurrentCount(PAL_HANDLE sem) { +int _DkMutexAcquireTimeout (PAL_HANDLE handle, int64_t timeout_us) +{ return -PAL_ERROR_NOTIMPLEMENTED; } + +int _DkMutexUnlock (struct mutex_handle * m) +{ + return -PAL_ERROR_NOTIMPLEMENTED; +} + +void _DkMutexRelease (PAL_HANDLE handle) +{ + /* Not implemented yet */ +} + +static int mutex_wait (PAL_HANDLE handle, int64_t timeout_us) +{ + return -PAL_ERROR_NOTIMPLEMENTED; +} + +struct handle_ops mutex_ops = { + .wait = &mutex_wait, + }; diff --git a/Pal/src/host/Skeleton/db_object.c b/Pal/src/host/Skeleton/db_object.c index 68dce42a..8e92cb27 100644 --- a/Pal/src/host/Skeleton/db_object.c +++ b/Pal/src/host/Skeleton/db_object.c @@ -29,6 +29,6 @@ /* _DkObjectsWaitAny for internal use. The function wait for any of the handle in the handle array. timeout can be set for the wait. */ -int _DkObjectsWaitAny(int count, PAL_HANDLE* handleArray, uint64_t timeout, PAL_HANDLE* polled) { +int _DkObjectsWaitAny(int count, PAL_HANDLE* handleArray, int64_t timeout_us, PAL_HANDLE* polled) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/Pal/src/host/Skeleton/db_pipes.c b/Pal/src/host/Skeleton/db_pipes.c index d797888e..0bb8e5b0 100644 --- a/Pal/src/host/Skeleton/db_pipes.c +++ b/Pal/src/host/Skeleton/db_pipes.c @@ -109,7 +109,7 @@ static int pipe_delete (PAL_HANDLE handle, int access) return -PAL_ERROR_NOTIMPLEMENTED; } -static int pipe_getname (PAL_HANDLE handle, char * buffer, int count) +static int pipe_getname (PAL_HANDLE handle, char * buffer, size_t count) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/Pal/src/host/Skeleton/db_process.c b/Pal/src/host/Skeleton/db_process.c index a2e8afe8..a356e6ab 100644 --- a/Pal/src/host/Skeleton/db_process.c +++ b/Pal/src/host/Skeleton/db_process.c @@ -32,15 +32,16 @@ #include "pal_error.h" #include "api.h" -int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, - int flags, const char ** args) +int _DkProcessCreate (PAL_HANDLE * handle, const char * uri, const char ** args) { return -PAL_ERROR_NOTIMPLEMENTED; } noreturn void _DkProcessExit (int exitcode) { - /* need to be implemented */ + while (true) { + /* nothing */; + } } static int64_t proc_read (PAL_HANDLE handle, uint64_t offset, uint64_t count, diff --git a/Pal/src/host/Skeleton/db_sockets.c b/Pal/src/host/Skeleton/db_sockets.c index e7ab6e8c..b4563348 100644 --- a/Pal/src/host/Skeleton/db_sockets.c +++ b/Pal/src/host/Skeleton/db_sockets.c @@ -54,7 +54,7 @@ static int tcp_connect (PAL_HANDLE * handle, char * uri, int create) static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri, int access, int share, int create, int options) { - int uri_len = strlen(uri) + 1; + size_t uri_len = strlen(uri) + 1; if (uri_len > PAL_SOCKADDR_SIZE) return -PAL_ERROR_TOOLONG; @@ -72,13 +72,13 @@ static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri, } /* 'read' operation of tcp stream */ -static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, uint64_t len, void * buf) +static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, size_t len, void * buf) { return -PAL_ERROR_NOTIMPLEMENTED; } /* write' operation of tcp stream */ -static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, uint64_t len, const void * buf) +static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, size_t len, const void * buf) { return -PAL_ERROR_NOTIMPLEMENTED; } @@ -99,7 +99,7 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri, int access, int share, int create, int options) { char buf[PAL_SOCKADDR_SIZE]; - int len = strlen(uri); + size_t len = strlen(uri); if (len >= PAL_SOCKADDR_SIZE) return -PAL_ERROR_TOOLONG; @@ -115,24 +115,24 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri, return -PAL_ERROR_NOTSUPPORT; } -static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, uint64_t len, void * buf) +static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, size_t len, void * buf) { return -PAL_ERROR_NOTIMPLEMENTED; } -static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len, - void * buf, char * addr, int addrlen) +static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, size_t len, + void * buf, char * addr, size_t addrlen) { return -PAL_ERROR_NOTIMPLEMENTED; } -static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, uint64_t len, const void * buf) +static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, size_t len, const void * buf) { return -PAL_ERROR_NOTIMPLEMENTED; } -static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len, - const void * buf, const char * addr, int addrlen) +static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, size_t len, + const void * buf, const char * addr, size_t addrlen) { return -PAL_ERROR_NOTIMPLEMENTED; } @@ -152,7 +152,7 @@ static int socket_attrquerybyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr) return -PAL_ERROR_NOTIMPLEMENTED; } -static int socket_getname (PAL_HANDLE handle, char * buffer, int count) +static int socket_getname (PAL_HANDLE handle, char * buffer, size_t count) { return -PAL_ERROR_NOTIMPLEMENTED; } diff --git a/Pal/src/host/Skeleton/pal.lds b/Pal/src/host/Skeleton/pal.lds new file mode 100644 index 00000000..93d87516 --- /dev/null +++ b/Pal/src/host/Skeleton/pal.lds @@ -0,0 +1,82 @@ +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") +OUTPUT_ARCH(i386:x86-64) +ENTRY(pal_start); + +SECTIONS +{ + /* Read-only sections, merged into text segment; */ + __text_start = .; + . = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS; + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*) + *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*) + *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*) + *(.rela.ifunc) + } + .rela.plt : + { + *(.rela.plt) + *(.rela.iplt) + } + .init : { *(.init) } + .plt : { *(.plt) *(.iplt) } + .text : + { + /* the rest of text segments */ + *(.text .stub .text.*); + } + .fini : { *(.fini) } + .rodata : + { + /* the rest of rodata */ + *(.rodata .rodata.*) + } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { *(.eh_frame) } + __text_end = .; + + /* now adjust the address for the data segment */ + . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); + __data_start = .; + .eh_frame : ONLY_IF_RW { *(.eh_frame) } + .data.rel.ro : { *(.data.rel.ro) } + .ctors : { *(.ctors) } + .dtors : { *(.dtors) } + .jcr : { *(.jcr) } + .dynamic : { *(.dynamic) } + .got : { *(.got) *(.igot) } + .got.plt : { *(.got.plt) *(.igot.plt) } + .data : + { + /* the rest of data segment */ + *(.data .data.*); + } + .bss : + { + *(.bss .bss.*) + *(COMMON) + } + . = DATA_SEGMENT_END(.); + __data_end = .; +} + diff --git a/Pal/src/host/Skeleton/pal.map b/Pal/src/host/Skeleton/pal.map deleted file mode 100644 index 266e1955..00000000 --- a/Pal/src/host/Skeleton/pal.map +++ /dev/null @@ -1,54 +0,0 @@ -PAL { - global: - # Drawbridge ABIs - DkVirtualMemoryAlloc; DkVirtualMemoryFree; DkVirtualMemoryProtect; - DkThreadCreate; DkThreadDelayExecution; - DkThreadYieldExecution; DkThreadExit; DkThreadResume; - - DkSemaphoreCreate; DkNotificationEventCreate; - DkSynchronizationEventCreate; - DkSemaphoreRelease; - DkEventSet; DkEventClear; - DkObjectsWaitAny; - - DkStreamOpen; DkStreamRead; DkStreamWrite; - DkStreamMap; DkStreamUnmap; DkStreamSetLength; - DkStreamFlush; DkStreamDelete; - DkSendHandle; DkReceiveHandle; # Added by us - DkStreamWaitForClient; - DkStreamGetName; - DkStreamAttributesQueryByHandle; DkStreamAttributesQuery; - - DkProcessCreate; DkProcessExit; - - DkSystemTimeQuery; DkRandomBitsRead; - DkInstructionCacheFlush; - DkObjectReference; DkObjectClose; - # objects checkpoint? - # objects reload? - - # The ABIs we added in the paper - DkSetExceptionHandler; DkExceptionReturn; # exceptions - DkCreatePhysicalMemoryChannel; # IPC - DkPhysicalMemoryCommit; # IPC - DkPhysicalMemoryMap; # IPC - DkSegmentRegister; # set segmentation registers - DkStreamChangeName; - DkStreamAttributesSetByHandle; - DkMemoryAvailableQuota; - - # Debugging ABIs - pal_printf; DkDebugAttachBinary; DkDebugDetachBinary; - - # Control block - pal_control_addr; pal_sec; - - # debugger interface - _r_debug; - - local: *; -}; -PAL_PRIVATE { - global: - _dl_debug_state; -}; diff --git a/Pal/src/host/Skeleton/pal.map.template b/Pal/src/host/Skeleton/pal.map.template new file mode 100644 index 00000000..54dd39c4 --- /dev/null +++ b/Pal/src/host/Skeleton/pal.map.template @@ -0,0 +1,4 @@ +PAL { + global: $(PAL_SYMBOLS) + local: *; +}; diff --git a/Pal/src/host/Skeleton/pal_host.h b/Pal/src/host/Skeleton/pal_host.h index d9e2f2da..cebacd4f 100644 --- a/Pal/src/host/Skeleton/pal_host.h +++ b/Pal/src/host/Skeleton/pal_host.h @@ -27,8 +27,13 @@ # error "cannot be included outside PAL" #endif -typedef int PAL_LOCK; -#define LOCK_INIT 0 +typedef struct mutex_handle { + int unused; +} PAL_LOCK; + +#define LOCK_INIT {} +#define INIT_LOCK(lock) do {} while (0) + #define MAX_FDS 3 typedef struct pal_handle @@ -79,20 +84,20 @@ typedef struct pal_handle } sock; struct { - PAL_IDX fd; + PAL_IDX unused; } process; struct { - PAL_IDX fd; + PAL_IDX unused; } mcast; struct { - PAL_IDX fd; + PAL_IDX unused; } thread; struct { PAL_IDX fd; - } semaphore; + } mutex; struct { PAL_IDX fd; diff --git a/Pal/src/pal-symbols b/Pal/src/pal-symbols new file mode 100644 index 00000000..112c7deb --- /dev/null +++ b/Pal/src/pal-symbols @@ -0,0 +1,50 @@ +DkVirtualMemoryAlloc +DkVirtualMemoryFree +DkVirtualMemoryProtect +DkThreadCreate +DkThreadDelayExecution +DkThreadYieldExecution +DkThreadExit +DkThreadResume +DkMutexCreate +DkNotificationEventCreate +DkSynchronizationEventCreate +DkMutexRelease +DkEventSet +DkEventClear +DkObjectsWaitAny +DkStreamOpen +DkStreamRead +DkStreamWrite +DkStreamMap +DkStreamUnmap +DkStreamSetLength +DkStreamFlush +DkStreamDelete +DkSendHandle +DkReceiveHandle +DkStreamWaitForClient +DkStreamGetName +DkStreamAttributesQueryByHandle +DkStreamAttributesQuery +DkProcessCreate +DkProcessExit +DkProcessSandboxCreate +DkSystemTimeQuery +DkRandomBitsRead +DkInstructionCacheFlush +DkCpuIdRetrieve +DkObjectClose +DkSetExceptionHandler +DkExceptionReturn +DkCreatePhysicalMemoryChannel +DkPhysicalMemoryCommit +DkPhysicalMemoryMap +DkSegmentRegister +DkStreamChangeName +DkStreamAttributesSetByHandle +DkMemoryAvailableQuota +DkDebugAttachBinary +DkDebugDetachBinary +pal_printf +pal_control_addr