=====================
== The Fides Suite ==
=====================

Version: Walhalla

Warning: This version has only been tested on a Dell Latitude 6510 laptop with an Intel Core i5 560M, other hardware may not be supported

== Compiling ==

To build Fides we require that llvm/clang is build with cmake and installed correctly. The following have been tested (with special thanks to Job Noorman):

	wget http://llvm.org/releases/3.3/llvm-3.3.src.tar.gz
	tar xf llvm-3.3.src.tar.gz
	cd llvm-3.3.src/
	wget https://distrinet.cs.kuleuven.be/software/sancus/downloads/llvm.patch
	patch -p1 < llvm.patch
	cd tools/
	wget http://llvm.org/releases/3.3/cfe-3.3.src.tar.gz
	tar xf cfe-3.3.src.tar.gz
	mv cfe-3.3.src clang
	cd clang
	wget https://distrinet.cs.kuleuven.be/software/sancus/downloads/clang.patch
	patch -p1 < clang.patch
	cd ../..
	mkdir build
	cd build
	cmake -DLLVM_TARGETS_TO_BUILD="X86;MSP430"
	make
	make install


To compile Fides and all it's tools and apps, run the following instructions:
	
	# m4 and yasm are expected ("sudo apt-get install yasm m4" should do the trick on Ubuntu)
	
	# Setup the environment variable (note the <dot><space><dot><slash>)
	# This step is required to find the compiler to compile the apps before it is installed
	. ./setup_environment
	
	# Construct the necessary symbolic links, ...
	> make configure
	
	# Build the entire toolset
	> make

While this works just fine, there are some tweaks that can be applied to Fides. Compiling with:
	
	> make "COPTIONS+=-DDEBUG_MODE"

for example will ensure that some debug code is executed. Other options are:

 = General =
 -DDEBUG_MODE                 Executes some debug checks. Warning: this may impact security in some case (e.g. in debug mode, an EPT violation will only result in disabling EPT tables)

 = VMM =
 -DCUSTOMIZED_CPU_VENDOR      Provides "KULeuven(TM)" as the cpu vendor when requested by the legacy VM

== Running ==
To run Fides, simply execute:

	> make run

This will launch the hypervisor and start a smaller controller application that can be used to output some information from the Fides such as how many VMCALLs happened from each VM. Output is written to the kernel log (execute "tail -f /var/log/syslog")

== Cleaning Build ==

To clean the build, run:
	
	> make clean
	
	# (optional) remove the placed symbolic links, ...
	> make scrub

== Testing ==

To test the environment, simply configure and compile the toolchain and execute:
	
	> make run_tests

== Used environment variables ==

PATH:			to indicate where the compiler is located
PCBAC_PASSES:		to specify where the passes can be found
PCBAC_INCLUDE:		to specify the location of the file containing the available SPM annotations
PCBAC_RESOURCES:	to find the linker script used by the compiler etc.
PCBAC_ICE0:		to locate the ice0.spm
PCBAC_ICE0_EMULATED:	to locate the emulated ice0.spm

== Troubleshooting ==

Problem: Fides tests "instances" and "secure communication" fail OR Applications exit with the error message "Failed to allocate <bytes> bytes to load <spm name>"
Solution: SPMs fail to allocate enough memory. This is caused because allocated pages must be locked in memory, meaning that they should never be swapped to disk. A security setting in the Linux kernel places a limit on the number of pages each process can lock in memory. The number of pages can be checked easy with:

      raoul@navajo:~/Walhalla$ ulimit -a
      core file size          (blocks, -c) 0
      data seg size           (kbytes, -d) unlimited
      scheduling priority             (-e) 0
      file size               (blocks, -f) unlimited
      pending signals                 (-i) 29406
>>    max locked memory       (kbytes, -l) 64            <<
      max memory size         (kbytes, -m) unlimited
      open files                      (-n) 1024
      pipe size            (512 bytes, -p) 8
      POSIX message queues     (bytes, -q) 819200
      real-time priority              (-r) 0
      stack size              (kbytes, -s) 8192
      cpu time               (seconds, -t) unlimited
      max user processes              (-u) 29406
      virtual memory          (kbytes, -v) unlimited
      file locks                      (-x) unlimited

To fix this problem, add the following two lines to /etc/security/limits.conf and reboot

      <username>            soft    memlock         unlimited
      <username>            hard    memlock         unlimited






