2013-08-21 09:37:21 +00:00
|
|
|
/*
|
|
|
|
* \brief VirtualBox runtime (RT)
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is distributed under the terms of the GNU General Public License
|
|
|
|
* version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <util/string.h>
|
2014-05-23 07:26:57 +00:00
|
|
|
#include <rtc_session/connection.h>
|
2013-08-21 09:37:21 +00:00
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
2014-05-23 07:26:57 +00:00
|
|
|
#include <sys/time.h>
|
2014-09-23 11:01:47 +00:00
|
|
|
#include <sys/mount.h> /* statfs */
|
2016-06-15 15:51:59 +00:00
|
|
|
#include <sys/statvfs.h>
|
2014-05-23 07:26:57 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2014-09-23 11:01:47 +00:00
|
|
|
#include <fcntl.h> /* open */
|
|
|
|
|
2016-06-15 15:51:59 +00:00
|
|
|
#include "libc_errno.h"
|
2014-09-23 11:01:47 +00:00
|
|
|
|
2013-08-21 09:37:21 +00:00
|
|
|
|
|
|
|
/* libc memory allocator */
|
|
|
|
#include <libc_mem_alloc.h>
|
|
|
|
|
|
|
|
/* VirtualBox includes */
|
|
|
|
#include <iprt/mem.h>
|
2014-09-23 11:01:47 +00:00
|
|
|
#include <iprt/assert.h>
|
2013-08-21 09:37:21 +00:00
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
static const bool verbose = false;
|
2013-08-21 09:37:21 +00:00
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
using Genode::size_t;
|
2013-08-21 09:37:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We cannot use the libc's version of malloc because it does not satisfies
|
|
|
|
* the alignment constraints asserted by 'Runtime/r3/alloc.cpp'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern "C" void *malloc(size_t size)
|
|
|
|
{
|
|
|
|
return Libc::mem_alloc()->alloc(size, Genode::log2(RTMEM_ALIGNMENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void *calloc(size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
void *ret = malloc(nmemb*size);
|
2016-06-15 15:51:59 +00:00
|
|
|
if (ret)
|
|
|
|
Genode::memset(ret, 0, nmemb*size);
|
2013-08-21 09:37:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void free(void *ptr)
|
|
|
|
{
|
|
|
|
Libc::mem_alloc()->free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void *realloc(void *ptr, Genode::size_t size)
|
|
|
|
{
|
|
|
|
if (!ptr)
|
|
|
|
return malloc(size);
|
|
|
|
|
|
|
|
if (!size) {
|
|
|
|
free(ptr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine size of old block content (without header) */
|
|
|
|
unsigned long old_size = Libc::mem_alloc()->size_at(ptr);
|
|
|
|
|
|
|
|
/* do not reallocate if new size is less than the current size */
|
|
|
|
if (size <= old_size)
|
|
|
|
return ptr;
|
|
|
|
|
|
|
|
/* allocate new block */
|
|
|
|
void *new_addr = malloc(size);
|
|
|
|
|
|
|
|
/* copy content from old block into new block */
|
|
|
|
if (new_addr)
|
|
|
|
Genode::memcpy(new_addr, ptr, Genode::min(old_size, (unsigned long)size));
|
|
|
|
|
|
|
|
/* free old block */
|
|
|
|
free(ptr);
|
|
|
|
|
|
|
|
return new_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" char *getenv(const char *name)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Logging to the pseudo file '/log' is done via the libc plugin provided
|
|
|
|
* by 'logging.cc'.
|
|
|
|
*/
|
|
|
|
if (Genode::strcmp(name, "VBOX_LOG_DEST") == 0 ||
|
|
|
|
Genode::strcmp(name, "VBOX_RELEASE_LOG_DEST") == 0)
|
|
|
|
return (char *)"file=log";
|
|
|
|
|
|
|
|
if (Genode::strcmp(name, "VBOX_LOG") == 0 ||
|
|
|
|
Genode::strcmp(name, "VBOX_RELEASE_LOG") == 0)
|
|
|
|
return (char *)"+rem_dias.e.l.f"
|
|
|
|
"+rem_printf.e.l.f"
|
|
|
|
// "+rem_run.e.l.f"
|
|
|
|
// "+pgm.e.l.f"
|
|
|
|
"+pdm"
|
2015-01-14 16:31:34 +00:00
|
|
|
// "+cpum.e.l.f"
|
2014-07-02 15:35:56 +00:00
|
|
|
// "+dev_pcnet.e.l.f"
|
2013-08-21 09:37:21 +00:00
|
|
|
// "+dev_pic.e.l.f"
|
|
|
|
// "+dev_apic.e.l.f"
|
2014-09-23 11:01:47 +00:00
|
|
|
"+dev_vmm.e"
|
2015-03-06 15:46:47 +00:00
|
|
|
// "+usb_mouse.e.l.f"
|
2014-05-23 07:26:57 +00:00
|
|
|
// "+main.e.l.f"
|
|
|
|
// "+hgcm.e.l.f"
|
2014-09-23 11:01:47 +00:00
|
|
|
// "+shared_folders.e.l.f"
|
2014-11-28 16:14:54 +00:00
|
|
|
// "+drv_host_serial.e.l.f"
|
2015-06-03 12:39:01 +00:00
|
|
|
// "+dev_audio.e.l.f"
|
2013-08-21 09:37:21 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
if (Genode::strcmp(name, "VBOX_LOG_FLAGS") == 0 ||
|
|
|
|
Genode::strcmp(name, "VBOX_RELEASE_LOG_FLAGS") == 0)
|
|
|
|
return (char *)"thread";
|
|
|
|
|
|
|
|
PWRN("getenv called for non-existent variable \"%s\"", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" int sigaction(int signum, const struct sigaction *act,
|
|
|
|
struct sigaction *oldact)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Break infinite loop at 'VBox/Runtime/r3/init.cpp' :451
|
2015-02-12 10:26:18 +00:00
|
|
|
*/
|
2013-08-21 09:37:21 +00:00
|
|
|
if (oldact)
|
|
|
|
oldact->sa_flags = SA_SIGINFO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-05-23 07:26:57 +00:00
|
|
|
|
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
/* our libc provides a _nanosleep function */
|
|
|
|
extern "C" int _nanosleep(const struct timespec *req, struct timespec *rem);
|
|
|
|
extern "C" int nanosleep(const struct timespec *req, struct timespec *rem)
|
|
|
|
{
|
|
|
|
Assert(req);
|
2016-06-15 15:51:59 +00:00
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
return _nanosleep(req, rem);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Some dummy implementation for LibC functions */
|
|
|
|
|
|
|
|
extern "C" pid_t getpid(void)
|
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
PINF("%s called - rip %p", __func__, __builtin_return_address(0));
|
|
|
|
|
|
|
|
return 1345;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
|
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
PINF("%s called - rip %p", __func__, __builtin_return_address(0));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int _sigaction(int, const struct sigaction *, struct sigaction *)
|
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
PINF("%s called - rip %p", __func__, __builtin_return_address(0));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int futimes(int fd, const struct timeval tv[2])
|
|
|
|
{
|
|
|
|
PINF("%s called - rip %p", __func__, __builtin_return_address(0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int lutimes(const char *filename, const struct timeval tv[2])
|
|
|
|
{
|
|
|
|
PINF("%s called - file '%s' - rip %p", __func__, filename,
|
|
|
|
__builtin_return_address(0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int _sigprocmask()
|
|
|
|
{
|
|
|
|
if (verbose)
|
|
|
|
PINF("%s called - rip %p", __func__, __builtin_return_address(0));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-23 07:26:57 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-23 11:01:47 +00:00
|
|
|
* Used by Shared Folders Guest additions
|
2014-05-23 07:26:57 +00:00
|
|
|
*/
|
2014-09-23 11:01:47 +00:00
|
|
|
extern "C" int statfs(const char *path, struct statfs *buf)
|
|
|
|
{
|
2016-06-15 15:51:59 +00:00
|
|
|
if (!buf)
|
|
|
|
return Libc::Errno(EFAULT);
|
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
int fd = open(path, 0);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return fd;
|
|
|
|
|
2016-06-15 15:51:59 +00:00
|
|
|
struct statvfs result;
|
|
|
|
int res = fstatvfs(fd, &result);
|
2014-09-23 11:01:47 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
2016-06-15 15:51:59 +00:00
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
Genode::memset(buf, 0, sizeof(*buf));
|
|
|
|
|
|
|
|
buf->f_bavail = result.f_bavail;
|
|
|
|
buf->f_bfree = result.f_bfree;
|
|
|
|
buf->f_blocks = result.f_blocks;
|
|
|
|
buf->f_ffree = result.f_ffree;
|
|
|
|
buf->f_files = result.f_files;
|
|
|
|
buf->f_bsize = result.f_bsize;
|
|
|
|
|
|
|
|
bool show_warning = !buf->f_bsize || !buf->f_blocks || !buf->f_bavail;
|
|
|
|
|
|
|
|
if (!buf->f_bsize)
|
|
|
|
buf->f_bsize = 4096;
|
|
|
|
if (!buf->f_blocks)
|
|
|
|
buf->f_blocks = 128 * 1024;
|
|
|
|
if (!buf->f_bavail)
|
|
|
|
buf->f_bavail = buf->f_blocks;
|
|
|
|
|
|
|
|
if (show_warning)
|
|
|
|
PWRN("statfs provides bogus values for '%s' (probably a shared folder)",
|
|
|
|
path);
|
|
|
|
|
2014-09-23 11:01:47 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-05-23 07:26:57 +00:00
|
|
|
extern "C" long pathconf(char const *path, int name)
|
|
|
|
{
|
2014-09-23 11:01:47 +00:00
|
|
|
if (name == _PC_NAME_MAX) return 255;
|
2014-05-23 07:26:57 +00:00
|
|
|
|
|
|
|
PERR("pathconf does not support config option %d", name);
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|