Skip to content

Commit

Permalink
merged upstream dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alfreb committed Mar 31, 2017
2 parents b8bf028 + 8910c7a commit 9c8f9a6
Show file tree
Hide file tree
Showing 60 changed files with 648 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ before_script:
- mkdir darwin && cd darwin

script:
- cmake .. -DTRAVIS=ON
- cmake .. -DTRAVIS=ON -DEXTRA_TESTS=ON
- make VERBOSE=1 && ./unittests --pass
43 changes: 35 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(SCRIPTS ${CMAKE_INSTALL_PREFIX}/includeos/scripts)
if(CMAKE_COMPILER_IS_GNUCC)
# currently gcc is not supported due to problems cross-compiling a unikernel
# (i.e., building a 32bit unikernel (only supported for now) on a 64bit system)
message(FATAL_ERROR "Building IncludeOS with gcc is not currently supported. Please clean-up build directory and configure for clang through CC and CXX environmental variables.")
# message(FATAL_ERROR "Building IncludeOS with gcc is not currently supported. Please clean-up build directory and configure for clang through CC and CXX environmental variables.")
endif(CMAKE_COMPILER_IS_GNUCC)

# create OS version string from git describe (used in CXX flags)
Expand All @@ -23,10 +23,21 @@ execute_process(COMMAND git describe --dirty
OUTPUT_VARIABLE OS_VERSION)
string(STRIP ${OS_VERSION} OS_VERSION)

option(cpu_feat_vanilla "Restrict use of CPU features to vanilla" ON)
if(cpu_feat_vanilla)
include("cmake/vanilla.cmake")
set(DEFAULT_SETTINGS_CMAKE "vanilla.cmake") # for service cmake
set(DEFAULT_VM "vm.vanilla.json") # vmrunner
else()
include("cmake/cpu_feat.cmake")
set(DEFAULT_SETTINGS_CMAKE "cpu_feat.cmake") # for service cmake
set(DEFAULT_VM "vm.cpu_feat.json") # vmrunner
endif(cpu_feat_vanilla)

# create random hex string as stack protector canary
string(RANDOM LENGTH 8 ALPHABET 0123456789ABCDEF STACK_PROTECTOR_VALUE)

set(CAPABS "-msse3 -fstack-protector-strong -D_STACK_GUARD_VALUE_=0x${STACK_PROTECTOR_VALUE} ")
set(CAPABS "${CAPABS} -fstack-protector-strong -D_STACK_GUARD_VALUE_=0x${STACK_PROTECTOR_VALUE}")

# Various global defines
# * NO_DEBUG disables output from the debug macro
Expand Down Expand Up @@ -81,9 +92,15 @@ endif(silent)
# Append optimization level
set(CAPABS "${CAPABS} ${OPTIMIZE}")

# these kinda work with llvm
set(CMAKE_CXX_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -nostdlibinc -c -m32 -std=c++14 -D_LIBCPP_HAS_NO_THREADS=1 -DOS_VERSION=\\\"${OS_VERSION}\\\"")
set(CMAKE_C_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -nostdlibinc -c -m32 -DOS_VERSION=\"\"${OS_VERSION}\"\"")
if (CMAKE_COMPILER_IS_GNUCC)
# gcc/g++ settings
set(CMAKE_CXX_FLAGS "-m32 -MMD ${CAPABS} ${WARNS} -Wno-frame-address -nostdlib -c -std=c++14 -D_LIBCPP_HAS_NO_THREADS=1 -DOS_VERSION=\\\"${OS_VERSION}\\\"")
set(CMAKE_C_FLAGS "-m32 -MMD ${CAPABS} ${WARNS} -nostdlib -c -DOS_VERSION=\"\"${OS_VERSION}\"\"")
else()
# these kinda work with llvm
set(CMAKE_CXX_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -nostdlibinc -c -m32 -std=c++14 -D_LIBCPP_HAS_NO_THREADS=1 -DOS_VERSION=\\\"${OS_VERSION}\\\"")
set(CMAKE_C_FLAGS "-target i686 -MMD ${CAPABS} ${WARNS} -nostdlib -nostdlibinc -c -m32 -DOS_VERSION=\"\"${OS_VERSION}\"\"")
endif()

# either download or cross-compile needed libraries
#option(from_bundle "Download and use pre-compiled libraries for cross-comilation" ON)
Expand Down Expand Up @@ -161,10 +178,20 @@ endif(rapidjson)
#
# Installation
#
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/etc/service.cmake DESTINATION includeos)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/etc/library.cmake DESTINATION includeos)
install(DIRECTORY vmrunner DESTINATION includeos/)

# Install cmake files
install(FILES etc/service.cmake DESTINATION includeos)
install(FILES etc/library.cmake DESTINATION includeos)
install(FILES cmake/${DEFAULT_SETTINGS_CMAKE} DESTINATION includeos RENAME settings.cmake) # cpu_feat_vanilla opt

# Install vmrunner
install(DIRECTORY vmrunner DESTINATION includeos)
install(FILES vmrunner/${DEFAULT_VM} DESTINATION includeos/vmrunner/ RENAME vm.default.json) # cpu_feat_vanilla opt

# Install toolchain
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/i686-elf-toolchain.cmake DESTINATION includeos)

# Install seed
install(DIRECTORY seed/ DESTINATION includeos/seed)

# Install boot util
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ IncludeOS is free software, with "no warranties or restrictions of any kind".
### Key features

* **Extreme memory footprint**: A minimal bootable image, including bootloader, operating system components and a complete C++ standard library is currently 707K when optimized for size.
* **KVM and VirtualBox support** with full virtualization, using [x86 hardware virtualization](https://en.wikipedia.org/wiki/X86_virtualization), available on any modern x86 CPUs). In principle IncludeOS should run on any x86 hardware platform, even on a physical x86 computer, given appropriate drivers. Officially, we develop for- and test on [Linux KVM](http://www.linux-kvm.org/page/Main_Page), which power the [OpenStack IaaS cloud](https://www.openstack.org/), and [VirtualBox](https://www.virtualbox.org), which means that you can run your IncludeOS service on both Linux, Microsoft Windows and macOS.
* **KVM, VirtualBox and VMWare support** with full virtualization, using [x86 hardware virtualization](https://en.wikipedia.org/wiki/X86_virtualization), available on any modern x86 CPUs). In principle IncludeOS should run on any x86 hardware platform, even on a physical x86 computer, given appropriate drivers. Officially, we develop for- and test on [Linux KVM](http://www.linux-kvm.org/page/Main_Page), which power the [OpenStack IaaS cloud](https://www.openstack.org/), and [VirtualBox](https://www.virtualbox.org), which means that you can run your IncludeOS service on both Linux, Microsoft Windows and macOS.
* **C++11/14 support**
* Full C++11/14 language support with [clang](http://clang.llvm.org) v3.8 and later.
* Standard C++ library (STL) [libc++](http://libcxx.llvm.org) from [LLVM](http://llvm.org/).
Expand Down
2 changes: 1 addition & 1 deletion api/fs/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace fs {
using on_init_func = delegate<void(error_t, File_system&)>;
using on_ls_func = delegate<void(error_t, dirvec_t)>;
using on_read_func = delegate<void(error_t, buffer_t, uint64_t)>;
using on_stat_func = delegate<void(error_t, const Dirent&)>;
using on_stat_func = delegate<void(error_t, Dirent)>;


struct List
Expand Down
10 changes: 5 additions & 5 deletions api/http
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
// limitations under the License.

#pragma once
#ifndef ___HTTP_API___
#define ___HTTP_API___
#ifndef INCLUDEOS_HTTP_API_HPP
#define INCLUDEOS_HTTP_API_HPP

#include "net/http/response.hpp"
#include "net/http/request.hpp"
#include "net/http/client.hpp"
#include "net/http/server.hpp"

#endif //< ___HTTP_API___
#endif //< INCLUDEOS_HTTP_API_HPP
175 changes: 126 additions & 49 deletions api/hw/block_device.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
// Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,71 +16,148 @@
// limitations under the License.

#pragma once
#ifndef HW_DRIVE_HPP
#define HW_DRIVE_HPP
#ifndef HW_BLOCK_DEVICE_HPP
#define HW_BLOCK_DEVICE_HPP

#include <memory>
#include <cstdint>
#include <delegate>
#include <memory>

namespace hw
{

/**
* Abstract interface for block devices of various driver types
**/
class Block_device {
public:
using block_t = uint64_t; //< Disk device block size
using buffer_t = std::shared_ptr<uint8_t>;

// Delegate for result of reading a disk sector
//using on_read_func = delegate<void(buffer_t)>;
using on_read_func = delegate<void(buffer_t)>;
namespace hw {

using Device_id = int;
/**
* This class is an abstract interface for block devices
*/
class Block_device {
public:
using block_t = uint64_t; //< Representation for a device's block size
using buffer_t = std::shared_ptr<uint8_t>; //< Representation for a block device's buffer
using Device_id = int32_t; //< Representation for a block device's identifier
using on_read_func = delegate<void(buffer_t)>; //< Delegate for result of reading from a block device

static const char* device_type()
{ return "Block device"; }
/**
* Method to get the type of device
*
* @return The type of device as a C-String
*/
static const char* device_type() noexcept
{ return "Block device"; }

virtual std::string device_name() const = 0;
/**
* Method to get the name of the device
*
* @return The name of the device as a std::string
*/
virtual std::string device_name() const = 0;

Device_id id() const { return id_; }
/**
* Method to get the device's identifier
*
* @return The device's identifier
*/
Device_id id() const noexcept
{ return id_; }

/** Human-readable name of this disk controller */
virtual const char* driver_name() const noexcept = 0;
/**
* Get the human-readable name of this device's controller
*
* @return The human-readable name of this device's controller
*/
virtual const char* driver_name() const noexcept = 0;

/** The size of the disk in whole sectors */
virtual block_t size() const noexcept = 0;
/**
* Get the size of the device as total number of blocks
*
* @return The size of the device as total number of blocks
*/
virtual block_t size() const noexcept = 0;

/** Returns the optimal block size for this device */
virtual block_t block_size() const noexcept = 0;
/**
* Get the optimal block size for this device
*
* @return The optimal block size for this device
*/
virtual block_t block_size() const noexcept = 0;

/**
* Read block(s) from blk and call func with result
* A null-pointer is passed to result if something bad happened
* Validate using !buffer_t:
* if (!buffer)
* error("Device failed to read sector");
**/
virtual void read(block_t blk, on_read_func func) = 0;
virtual void read(block_t blk, size_t count, on_read_func) = 0;
/**
* Read a block of data asynchronously from the device
*
* @param blk
* The block of data to read from the device
*
* @param reader
* An operation to perform asynchronously
*
* @note A nullptr is passed to the reader if an error occurred
* @note Validate the reader's input
*
* @example
* if (buffer == nullptr) {
* error("Device failed to read sector");
* }
*/
virtual void read(block_t blk, on_read_func reader) = 0;

/** read synchronously the block @blk */
virtual buffer_t read_sync(block_t blk) = 0;
virtual buffer_t read_sync(block_t blk, size_t count) = 0;
/**
* Read blocks of data asynchronously from the device
*
* @param blk
* The starting block of data to read from the device
*
* @param count
* The number of blocks to read from the device
*
* @param reader
* An operation to perform asynchronously
*
* @note A nullptr is passed to the reader if an error occurred
* @note Validate the reader's input
*
* @example
* if (buffer == nullptr) {
* error("Device failed to read sector");
* }
*/
virtual void read(block_t blk, size_t count, on_read_func reader) = 0;

virtual void deactivate() = 0;
/**
* Read a block of data synchronously from the device
*
* @param blk
* The block of data to read from the device
*
* @return A buffer containing the data or nullptr if an error occurred
*/
virtual buffer_t read_sync(block_t blk) = 0;

virtual ~Block_device() noexcept = default;
/**
* Read blocks of data synchronously from the device
*
* @param blk
* The starting block of data to read from the device
*
* @param count
* The number of blocks to read from the device
*
* @return A buffer containing the data or nullptr if an error occurred
*/
virtual buffer_t read_sync(block_t blk, size_t count) = 0;

protected:
Block_device();
/**
* Method to deactivate the block device
*/
virtual void deactivate() = 0;

private:
int id_;
}; //< class Drive
/**
* Default destructor
*/
virtual ~Block_device() noexcept = default;
protected:
Block_device();
private:
Device_id id_;
}; //< class Block_device

} //< namespace hw

#endif //< HW_DRIVE_HPP
#endif //< HW_BLOCK_DEVICE_HPP
4 changes: 2 additions & 2 deletions api/net/ethernet/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once

#pragma once
#ifndef NET_ETHERNET_HEADER_HPP
#define NET_ETHERNET_HEADER_HPP

Expand All @@ -40,7 +40,7 @@ class Header {
const MAC::Addr& src() const noexcept
{ return src_; }

const Ethertype& type() const noexcept
Ethertype type() const noexcept
{ return type_; }

void set_dest(const MAC::Addr& dest)
Expand Down
2 changes: 1 addition & 1 deletion api/net/inet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace net {
///

/** Get Maximum Transmission Unit **/
virtual constexpr uint16_t MTU() const = 0;
virtual uint16_t MTU() const = 0;

/** Provision empty anonymous packet **/
virtual Packet_ptr create_packet() = 0;
Expand Down
2 changes: 2 additions & 0 deletions api/net/ip4/icmp4_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ namespace net {
return "TIMESTAMP REPLY (14)";
case Type::NO_REPLY:
return "NO REPLY";
default:
return "UNKNOWN";
};
}();
}
Expand Down
2 changes: 1 addition & 1 deletion api/net/ip4/ip4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace net {
/*
Maximum Datagram Data Size
*/
constexpr uint16_t MDDS() const
uint16_t MDDS() const
{ return stack_.MTU() - sizeof(ip4::Header); }

/** Upstream: Input from link layer */
Expand Down
2 changes: 1 addition & 1 deletion api/net/ip4/udp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace net {
// create and transmit @num packets from sendq
void process_sendq(size_t num);

inline constexpr uint16_t max_datagram_size() noexcept {
uint16_t max_datagram_size() noexcept {
return stack().ip_obj().MDDS() - sizeof(header);
}

Expand Down
Loading

0 comments on commit 9c8f9a6

Please sign in to comment.