Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions api/posix/sys/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ extern "C" {
#endif

#include <string.h>
#include <sys/types.h>
typedef _off_t off_t;

void *mmap(void* addr, size_t length,
int prot, int flags,
int fd, off_t offset);
int munmap(void* addr, size_t length);
struct posix_typed_mem_info
{
size_t posix_tmi_length;
};

int mlock(const void *, size_t);
int mlockall(int);
void *mmap(void *, size_t, int, int, int, off_t);
int mprotect(void *, size_t, int);
int msync(void *, size_t, int);
int munlock(const void *, size_t);
int munlockall(void);
int munmap(void *, size_t);
int posix_madvise(void *, size_t, int);
int posix_mem_offset(const void *__restrict__, size_t, off_t *__restrict__,
size_t *__restrict__, int *__restrict__);
int posix_typed_mem_get_info(int, struct posix_typed_mem_info *);
int posix_typed_mem_open(const char *, int, int);
int shm_open(const char *, int, mode_t);
int shm_unlink(const char *);

// Page can be executed.
#define PROT_EXEC 0x1
Expand Down
25 changes: 25 additions & 0 deletions api/sys/dlfcn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void *dlopen(const char *filename, int flag);
char *dlerror(void);
void *dlsym(void *handle, const char *symbol);
int dlclose(void *handle);


#define RTLD_LAZY 1
#define RTLD_NOW 2
#define RTLD_GLOBAL 3
#define RTLD_LOCAL 4
#define RTLD_NODELETE 6
#define RTLD_NOLOAD 7
#define RTLD_DEEPBIND 8

#define RTLD_DEFAULT 1

#ifdef __cplusplus
}
#endif
42 changes: 42 additions & 0 deletions api/sys/signal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2016 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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
#ifndef SYS_SIGNAL_H
#define SYS_SIGNAL_H

#ifdef __cplusplus
extern "C" {
#endif

struct siginfo_t
{
int si_signo; // Signal number.
int si_code; // Signal code.

int sa_sigaction;
};

#define SA_RESETHAND 666

#ifdef __cplusplus
}
#endif

#include_next <signal.h>

#endif
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ set(OS_OBJECTS
posix/fd.cpp posix/tcp_fd.cpp posix/udp_fd.cpp posix/unistd.cpp posix/fcntl.cpp posix/syslog.cpp
posix/sys/socket.cpp posix/sys/select.cpp posix/sys/utsname.cpp posix/sys/mman.cpp posix/arpa/inet.cpp
posix/ucontext.cpp posix/ucontext_asm.asm
posix/sys/stat.cpp posix/ftw.cpp
posix/file_fd.cpp
posix/sys/stat.cpp posix/ftw.cpp posix/file_fd.cpp posix/dlfcn.cpp
)

add_library(os STATIC ${OS_OBJECTS} apic_boot.o)
Expand Down
54 changes: 31 additions & 23 deletions src/crt/c_abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string.h>
#include <kprint>

#define HEAP_ALIGNMENT 16
#define HEAP_ALIGNMENT 63
caddr_t heap_begin;
caddr_t heap_end;

Expand All @@ -47,28 +47,26 @@ void _init_c_runtime()
extern char _end;

/// init backtrace functionality
extern void _move_elf_symbols(void*, void*);
extern void _apply_parser_data(void*);
extern int _get_elf_section_size(const void*);
// first measure the size of symbols
int symsize = _get_elf_section_size(&_ELF_SYM_START_);
// estimate somewhere in heap its safe to move them
char* SYM_LOCATION = &_end + 2 * (4096 + symsize);
_move_elf_symbols(&_ELF_SYM_START_, SYM_LOCATION);
extern int _get_elf_section_datasize(const void*);
extern void _move_elf_syms_location(const void*, void*);
// store symbols temporarily in a safe location
char* sym_temp = &_end +
2*4096 + _get_elf_section_datasize(&_ELF_SYM_START_);
_move_elf_syms_location(&_ELF_SYM_START_, sym_temp);

// Initialize .bss section
extern char _BSS_START_, _BSS_END_;
streamset8(&_BSS_START_, 0, &_BSS_END_ - &_BSS_START_);

// Initialize the heap before exceptions
heap_begin = &_end + 0xfff;
// page-align heap, because its not aligned
heap_begin = (char*) ((uintptr_t)heap_begin & ~(uintptr_t) 0xfff);
// cache-align heap, because its not aligned
heap_begin = &_end + 64 + HEAP_ALIGNMENT;
heap_begin = (char*) ((uintptr_t)heap_begin & ~(uintptr_t) HEAP_ALIGNMENT);
// heap end tracking, used with sbrk
heap_end = heap_begin;
// validate that heap is page aligned
// validate that heap is aligned
int validate_heap_alignment =
((uintptr_t)heap_begin & (uintptr_t) 0xfff) == 0;
((uintptr_t)heap_begin & (uintptr_t) HEAP_ALIGNMENT) == 0;

/// initialize newlib I/O
_REENT_INIT_PTR(_REENT);
Expand All @@ -77,9 +75,13 @@ void _init_c_runtime()
stdout = _REENT->_stdout; // stdout == 2
stderr = _REENT->_stderr; // stderr == 3

// move symbols (again) to heap, before calling global constructors
extern void* _relocate_to_heap(void*);
void* symheap = _relocate_to_heap(SYM_LOCATION);
/// init ELF / backtrace functionality
extern void _elf_relocate_to_heap();
extern void _init_elf_parser();
// move ELF symbols into heap
_elf_relocate_to_heap();
// enable ELF symbols here (before global constructors)
_init_elf_parser();

/// initialize exceptions before we can run constructors
extern char __eh_frame_start[];
Expand All @@ -91,23 +93,18 @@ void _init_c_runtime()
extern void _init();
_init();

// set ELF symbols location here (after initializing everything else)
_apply_parser_data(symheap);

// sanity checks
assert(heap_begin >= &_end);
assert(heap_end >= heap_begin);
assert(validate_heap_alignment);
}

// global/static objects should never be destructed here, so ignore this
void* __dso_handle;

// stack-protector
__attribute__((noreturn))
void __stack_chk_fail(void)
{
panic("Stack protector: Canary modified");
__builtin_unreachable();
}

// old function result system
Expand All @@ -117,6 +114,17 @@ int* __errno_location(void)
return &errno;
}

#include <setjmp.h>
int _setjmp(jmp_buf env)
{
return setjmp(env);
}
// linux strchr variant (NOTE: not completely the same!)
void *__rawmemchr (const void *s, int c)
{
return strchr((const char*) s, c);
}

/// assert() interface of ISO POSIX (2003)
void __assert_fail(const char * assertion, const char * file, unsigned int line, const char * function)
{
Expand Down
9 changes: 9 additions & 0 deletions src/hw/pci_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#define PCI_HEADER_REG 0x0e
#define PCI_BIST_REG 0x0f

#define PCI_COMMAND_IO 0x01
#define PCI_COMMAND_MEM 0x02
#define PCI_COMMAND_MASTER 0x04

namespace hw {

static const char* classcodes[] {
Expand Down Expand Up @@ -150,6 +154,11 @@ namespace hw {
PCI_Device::PCI_Device(const uint16_t pci_addr, const uint32_t device_id)
: pci_addr_{pci_addr}, device_id_{device_id}
{
// set master, mem and io flags
uint32_t cmd = read_dword(PCI_CMD_REG);
cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEM | PCI_COMMAND_IO;
write_dword(PCI_CMD_REG, cmd);

//We have device, so probe for details
devtype_.reg = read_dword(pci_addr, PCI::CONFIG_CLASS_REV);

Expand Down
Loading