vfs: increase vnode refcount under vnode_lock lock in dentry_alloc()

v_refcnt is protected by vnode_lock and should not be accessed without
holding it.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
pthread: implement pthread yield

trivial wrapper around sched::yield

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: wire get_cyclecount() to processor::ticks()

Currently it is wired to osv::clock::uptime::now() and later trimmed
to 1ms accurracy of a BSD tick. However it is supposed to provide raw
"TSC" access with highest accurracy possible, global monotonicity is
not important. It is used only by entropy harvesting routines. Quoting
the manual:

  "The get_cyclecount() function uses a register available in most
   modern CPUs to return a value that is monotonically increasing inside
   each CPU.

   (...)

   The AMD64 and Intel 64 processors use the TSC register."

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Bump up apps.git pointer

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: Test thread_local support

This is a test for our support of the thread_local C++11 feature.
We support the construction and use of these variables correctly, but as
this test demonstrates, we neglect to run the variable's destructor when
a thread ends, so this test currently fails on OSv (it succeeds on Linux).

Because the test is currently failing, I added it to the blacklist of
ignored tests. But it is still useful to have this test around, to
remember exactly what needs to be fixed for thread_local support.

I also opened issue #373 in our bug tracker to explain and track this issue.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: avoid more tcp_close() in tcp_do_segment()

Commit 8340e21b58b ("net: don't close the tcp connection within
tcp_do_segment()") removed calls to tcp_close() from within tcp_do_segment(),
as preparation for net channels, but missed two cases where tcp_drop() calls
tcp_close().  This causes a locking mismatch when a TH_ACK|TH_RST packet is
received.

Fix by calling a new function tcp_drop_noclose() instead, and set want_close
for deferred closing.

Seen with a Tomcat workload with many (600) connections.

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
random: fix random_harvest visibility for C++ source files

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: import if_nametoindex() from musl

Needed for debug build (some random boost dependency).

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: implement passwd handling functions

We have already some of the user handling functions, but not others, like
getpwent, endpwent, and their group variants.

Those functions read entries from the passwd file, and we can emulate them
easily, by just keeping a counter of whether or not we should return our single
user/group, or go back to the beginning of the file. Those functions are not
reentrant.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
pthread: implement pthread_rwlock functions

Most of them are trivial wrappers around our rwlock. Unfortunately, the
placement trick won't work and we will have to allocate the rwlock through the
lazy_indirect mechanism.

We also have to check if the lock is taken for write or read before unlocking,
because there is only one unlock function in the pthread family. Other than
that, it is the exact same as our pthread_mutex implementation - including the
missing attr handling =)

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: Fix lseek() boundary cases

The lseek() man page says this error cases:

    EINVAL whence is not valid.  Or: the resulting file offset would be
           negative, or beyond the end of a seekable device.

Fix lseek() to return a proper error instead of limiting the offset to
zero. For offsets beyond vnode size, let the underlying filesystem deal
with it.

This fixes a hang when reading "/proc/self/maps" via the OSv CRaSH
shell.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: Test case for lseek()

This adds a test case for lseek() to check for proper error code on
negative offsets.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
user: implement some more user functions

I am interested in the "getlogin" symbol, but for completeness I am implementing
the whole family.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
user: implement getgrgid

We have currently the reentrant version implemented, but we are missing
the non-reentrant symbol

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Remove the Route gathering logic outside of lsroute

The route gathering logic in lsroute can be used by other modules,
specifically the API.

This hides the logic details with a foreach function that iterate over
the routes.

The foreach_route function iterate over the routes and call a lambda
expression function with the current route details.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
user: nitpick for getlogin_r

Nadav corretly noted that we need ERANGE in this case.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
aarch64: implement processor::ticks()

just using the virtual counter.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
drivers: pl011: do not convert \n to \r\n

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: export a meaningful arch-string to be used for OSv

Because we use "x64" while Linux will refer to "x86_64", I am drawing a
distinction between arch and arch_str - the later being the "official"
architecture string, from the uname PoV.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
use the canonical arch string for uname, instead of hard coding it

Fixes #395

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>