random: Add debug messages for available hw sources

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tcp: Increase TCBHASHSIZE from 512 to 4096

In netperf TCP_CC test, in_pcblookup_hash_locked() is observed as high as
~50% cpu usage. Increasing TCBHASHSIZE to 4096 imporves TCP_CC by 57%
while drops cpu usage to ~13%.

Before:
TCBHASHSIZE 512  -> 57% cpu usage -> 7K  Rate/Sec

After:
TCBHASHSIZE 1024 -> 40% cpu usage -> 9K  Rate/sec
TCBHASHSIZE 4096 -> 13% cpu usage -> 11K Rate/sec

Signed-off-by: Asias He <asias@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
core/elf: validate NOTE segment length

we have the PT_NOTE segment in the linker scripts,
but if we have no note sections we will end up with
a zero length segment. Handle this case by validating
the phdr length.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Cc: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: regex functions

I am interested in the fnmatch function for an application. To avoid future
problems, I am also importing the glob function. Those functions are regular
expression parsers, but they work with shell wildcards instead of the usual
posix re. Because of that, I am taking it from musl instead of implementing
them on top of boost's re engine. This is a 100 % verbatim copy of the relevant
musl files.

Aside from the verbatim copy, I am moving some of the definitions in fnmatch.h
outside GNU_SOURCE. Musl code does not expect them there.

v2: remove the other re functions from the patch. Leave only the wildcard ones.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Http Server: Make file git pull should pull from the root directory

The http server in its new location is placed two level below the the
root module directory.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: Add __fdelt_chk

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
command line: fix issues with commited code

After the patch was commited, Nadav realized that we could have an off-by-one
in the way we were handling the maximum string size. He also wanted to see the
API taking a const char instead of a char, and that is done here.

We were also leaking the string, because as far as I know, since we have an
std::vector of char *s, not std::strings, args.resize(0) won't call free.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
java: Add chained exception to ContextIsolator:runjar

This is for somewhat better error reporting.

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
java: Fix JVM stack protection issues

Run JVM init, main thread, JVM destroy in child thread to avoid stack
protection issues in HS.

Tomek captured a JVM crash in one of the Jenkins builds:

  Aborted

  [backtrace]
  0x0000100000fd1ea8 <JVM_FindSignal+1647320>
  0x00001000011595fe <JVM_handle_linux_signal+1569582>
  0x0000100000fda4f6 <JVM_handle_linux_signal+550>
  0x0000000000368722 <call_signal_handler+338>
  0x000000000036c53d <call_signal_handler_thunk+7>
  0x000010000103f079 <JVM_handle_linux_signal+413097>
  0x0000100000d48c61 <AsyncGetCallTrace+238721>
  0x0000100000fd0f21 <JVM_FindSignal+1643345>
  0x0000000000419ad5 <setpgid()+229>
  0x00000000003b6dca <thread_main_c+26>
  0x000000000036c535 <thread_main+7>

Calle explains:

  So, this is the problem:

  * java.so does CreateJavaVM

      - This attaches the thread to the JVM, the "initial thread", which
	on linuxes are somewhat special, as in it is hard to get
	accurate stack info on it, thus the attach/init code is filles
	with horrendous stuff to figure out what is reasonable stack
	bounds for it, all in order to add stack guard pages somewhere
        appropriately.

      - This goes pretty fine, it finds something reasonable and
        continues. Lets call the now protected region X.

  * java.so calls io.osv.MultiJarLoader, which in turn starts a bunch of
    threads, then returns.

  * java.so main thread detaches. HS now "unprotects" the stack guard
    pages. However, due to Linux and its somewhat glued-on thread
   library,this is actually done by munmap:ing the pages in question (X).

  Now, at the same time:

  * A java thread loads a zip file. It asks to map a section of the
    file. The vma code finds a nice, empty hole at X and uses it.

  And at the same time:

  * Main thread calls DestroyJavaVM. This re-attaches the main thread.
    Now, main thread stack info is already collected, so HS just
    re-protects region X (mmap fixed). Woho. Except we just wrote over the
    file mapping above.

  So, in a way the problem is that OSv does not treat memory regions
  that are / has been / could be stack area (or be interpreted as it by
  HS) special, and allows mmap to give back these pages.

  But, the solution is way easier, and is in fact that which all JDK
  launchers have employed for quite some time now, namely _never_ use the
  main thread for anything Java.

  All java launchers will create, run and destroy the JVM from an
  immediate child thread to avoid just this problem above, with
  misinterpreted stack areas. By doing this, the VM will only use
  (hopefully) the info returned by pthread_attr_getstack-blabla.

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mmu: file-mapped vma flag

Add flag bit to mark if a vma region is file mapped or not + add gdb
script to query individual vma entry.

Signed-off-by: Calle Wilund <calle@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: snprintf for "infinite" lengths

Fixes #111.

The standard C snprintf() has an interesting design flaw: snprintf()
takes a "size_t" length, and returns an "int". Unfortunately, size_t
is 64-bit while int is 32-bit, so it is theoretically possible for
snprintf() to succeed writing over 4 gigabytes, and not be able to return
the actual size it wrote!
This is why Posix mandates that when snprintf() is given a length that
cannot fit in 32 bits, it must immediately fail and set errno=EOVERFLOW.
Our implementation, copied from Musl, did this.

However, it turns out that neither glibc nor gcc's builtin snprintf
goes along with this decision, as the test in this patch demonstrates.
We can snprintf with maximum lengths = 2^64-1 or 2^40, and it works well.
This patch tests that we do this like Linux (the test can be run on both
OSv and Linux), and removes the EOVERFLOW case to be more like Linux.

Interestingly, this issue caused bug #111. With -D_FORTIFY_SOURCE=2,
ncurses's use of sprintf() was converted to __sprintf_chk() with a "len"
of -1 (2^64-1). Our implementation of this function called snprintf()
with that len - and failed because our implementation refused to work
when given len=-1.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Add __longjmp_chk()

When compiled with -D_FORTIFY_SOURCE=1 (this is the default in Ubuntu),
a program that uses longjmp() can end up calling __longjmp_chk() instead.
This patch adds a trivial implementation of this missing function.

Ideally, __longjmp_chk() should do some sanity checks on the "env" we're
jumping to, namely that it actually points to a stack frame earlier on
our stack. This patch is functionally-correct, but includes no such checks.
Glibc does some checks, but they are also far from being bulletproof (they
do little more than checking the env address is higher than the current
stack pointer).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Increases maxsockets and TCP_SYNCACHE_HASHSIZE

Signed-off-by: Asias He <asias@cloudius-systems.com>
TCBHASHSIZE    16384

Signed-off-by: Asias He <asias@cloudius-systems.com>
debug

Signed-off-by: Asias He <asias@cloudius-systems.com>
uma_zone_set_max

Signed-off-by: Asias He <asias@cloudius-systems.com>
tcptw_auto_size

Signed-off-by: Asias He <asias@cloudius-systems.com>
no print tcp_twstart

Signed-off-by: Asias He <asias@cloudius-systems.com>
ci
debug