libc: take rand() and rand_r() from musl

Replace our own libc/prng/rand.c by musl's rand.c and rand_r.c.

In addition to adopting more unmodified musl, this patch also improves
two problems in our existing code:

First, we copied rand_r() from an old version of Musl, which didn't
include this improvement of rand_r()'s quality:
http://git.musl-libc.org/cgit/musl/commit/?id=20d01d83b5a13c77805976e7c520f566244ba3ff

Second, our code built rand() on top of rand_r(). This sounds like a
good idea, but in reality we can achieve better quality for rand() by
not being constrained (like rand_r()) to a 32-bit key.  Musl's version
uses a 64-bit key and returns the 32 high-order bits, which in linear
congruential generators provide better quality random numbers.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
cli: Small fixes in lib/osv_api

* Removed global declarations from create_socket() and osv_schema().
* Removed BODY from HTTP request.
* Fix renderer to support recent changes to API definitions.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
cli: Various fixes and improvements to osv command

Fix output to use io.stdout instead of print(), handle APIs with named
path parameters better, add help for specfic API with parameters.

Closes #422.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
cli: Rename osv command to api

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
cli: Fix test for ls

Previous patch had squelched whitespaces.

Signed-off-by: Or Cohen <orc@fewbytes.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
scripts, modules: massive cleaning of unused import

Signed-off-by: William Dauchy <william@gandi.net>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
modules: BaseException is not meant to be directly inherited

see https://docs.python.org/2/library/exceptions.html#exceptions.BaseException

Cc: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: William Dauchy <william@gandi.net>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
elf: function for finding shared-object containing an address

Add a function program::object_containing_addr() which looks for a loaded
module (elf::object *) which contains a symbol with a given address.

This function is linear in the number of loaded modules, but when only
a few modules are loaded it is pretty quick - for each module we just
need to check if the given address is between the module's start and
end addresses.

I'll need this function in the next patch.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix thread_local support on recent gcc

Recently (see https://gcc.gnu.org/ml/gcc-patches/2014-07/msg02091.html)
gcc changed the way they implement destruction of thread_local variables.
It now requires us to implement a function __cxa_thread_atexit_impl(),
but we only had a do-nothing implementation.

Without a complete implementation, thread_local objects do not get
destroyed when threads end, and tests/tst-thread-local.so fails.

This patch adds the missing implementation, and the test now succeeds
again.

Fixes #501.

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