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>