mmu: fix a race in fast sigsegv code.

Fast sigsegv code detects COW pages by checking COW bit on write page
fault, but if page was COWed after the fault but before the check COW
bit will not be present. Check pte write permission too to avoid false
positives. If the race happens page will be writable.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mmu: remove unneeded code from cleanup_intermediate_pages

sub_page() is the same as default implementation.

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
elf: Run init functions only after loading object hierarchy

Amnon discovered a bug in our dynamic linker. The bug happens when we load
an object A.so which needs (DT_NEED) a second object B.so, and both have
some identical functions and variables (e.g., using the same C++ header files
with inline functions) and B.so has init functions (e.g., static
constructor). B.so's init function is run first, but the function it uses
belong to A.so, because A.so first on the search list (this is how it should
be, and I verified it is what happens on Linux as well).

In our existing code, when the needed library B.so's init functions are
run, A.so is not yet fully prepared (relocated, global variables resolved,
etc.) so B's use of A's function caused crashes when unrelocated PLT
entries or unresolved global variables get used.

To fix this, we need to split the loading of a hierarchy of objects into
two phases: First, we load the object, its needed objects, their needed
objects, etc., and keep a list of what we loaded. All this without running
any init function yet. After all these objects are fully loaded, their
symbols relocated and resolved as needed, do we finally run the init
functions of all the objects loaded in the first phase. We, of course,
run the init functions in reverse order, so the deepest library's init
functions is run first.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Merge branch 'master' of https://github.com/cloudius-systems/osv