java: exclude '.' from default system class loader's class path

If java.class.path is not set the JVM is using '.' by default. This is
causing problems if some of the classes will be put in the root
directory and isolated context will have '.' as part of its class
path.

Let's consider the following command which will start a new isolated
context with classpath consisting of '.' and 'some.jar':

  java.so -cp .:some.jar Main

Suppose that the definition of Main looks like this:

  class Main extends SuperMain {
  }

The SuperMain class definition is in some.jar and Main is defined in
'./Main.class'. When 'Main' class is looked up the parent class
loaders are queried first. Because '.' is on the default system class
loader's class path, that class loader will become a defining class
loader for Main. However, it will not be able to locate the definition
of SuperMain class and loading will fail with
java.lang.NoClassDefFoundError.

To prevent this, we must ensure that the default system class loader
created by the JVM will not "catch" any user classes, which may be
specified on context's class path. Setting "java.lang.classpath" to
/dev/null achieves that goal.

Alternative solution would be to not put the default system class
loader as parent class loader for our app class loader. However the
former one is putting extensions jars on its class path and we need
them to be accessible from isolated constext.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: add test exploiting class path issue

This tests that classes put on '.' are not loaded via global
default system class loader.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
aarch64: handle more page fault cases

we need to handle access faults and permission faults
as well as translation faults, and not only for data
aborts but also for instruction aborts.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Cc: Jani Kokkonen <jani.kokkonen@huawei.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
libc: add finite(), finitef(), finitel()

Signed-off-by: KANATSU Minoru <icc.pot.tyew272@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
libc: use weak_alias(); instead of declare eaccess()

Signed-off-by: KANATSU Minoru <icc.pot.tyew272@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
modules: make run_java() interface more convenient

All of the following uses are now allowed and equivalent:

  api.run_java(args=['-cp', 'jar1:jar2', 'MainClass'])

  api.run_java(args='-cp jar1:jar2 MainClass')

  api.run_java('-cp jar1:jar2 MainClass')

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: Fix misc-readbench

Use stat to follow symbolic links, and get the correct file type.
misc-readbench is supposed to go through jvm directory which now
contains symbolic links.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
libc: implement sethostname()

sethostname() sets the hostname in struct utsname
declared in uname.c
This patch also removes hostname.cc from libc/network
which is a duplicate implementation of gethostname() and
is not used during the build.

Fixes #353

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Jaspal Singh Dhillon <jaspal.iiith@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mgmt: update to latest

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: do not rely on osv::power_off() to sleep

Nadav saw tracing_smoke_test failing when run inside a VM on QEMU
without KVM. The test failed because there was no trace of
osv::power_off() in the backtrace of 'trace prof-wait'. We concluded
that it is best not to rely on this function to always sleep.

I changed the assertion to use 'sched::thread::wait' instead, which
is so generic it should probably always be there.

Reported-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: add inet_addr, inet_aton

The code is taken from musl-libc.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: Add support IP socket options

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio-net: enable multicast

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vmxnet3: enable multicast

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
eventfd: add eventfd support

eventfd is an object used for event notification. Eventfd object
maintains a counter, which can be read or written to using normal read
or write system call. Depending on how eventfd is created, read may
either wipe out counter or reduce it by 1. If a read or write cannot be
services immediately then the execution is blocked until an event
occurs to unblock the execution. For example: read on eventfd would be
blocked if the counter is 0, similarly write on it would be blocked if
counter is ULLONG_MAX-1. Writing to an eventfd unblocks any reader
waiting for it.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: add eventfd unit test

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Remove unnecessary #include

Remove an include of "api/assert.h" from osv/debug.hh. This was not
only unnecessary, it also needlessly causes problems when a program
(such as the httpserver module) combines the host header files and OSv's,
and both <assert.h> and "api/assert.h" end up being used, and they have
a slightly different definition of __assert_fail.

This include was added in commit b40cb27a but I don't know why.
It doesn't seem needed.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: Add API for iterating over all threads

We currently don't provide any method of iterating over all threads (something
which, "top" would like to do, for example). thread_map and thread_map_mutex
are private to sched.cc, and should stay that way.

So this patch provides a new function with_all_friends(f), which iterates
over all threads and calls the given std::function for each one. The
function is supposed to be safe (a thread will not be freed while someone
is running f on it), but it is inefficient as it holds thread_map_mutex
throughout the entire iteration, so it should currently only be used for
debugging purposes, e.g., for implementing "top".

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: hw source of entropy should be conditionally registered

The hardware source of entropy should be only registered when
available, e.g. virtio-rng.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
random: Avoid uneeded buffer allocation/deletion

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>