file: make sys_open() allocate the file structure

Currently sys_open() receives an uninitialized file structure from its
callers, which is awkward as the callers must handle opening a file in
two steps.  It also doesn't fit well with C++'s notion of an object being
always fully initialized and valid.

Fix by making sys_open() allocate and return the file structure.  This also
fixes a window in open() where an fd would point to an uninitialized file
(between fdalloc() and sys_open()).

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
uipc_syscalls.c: convert to C++

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
fdesc: make it a little more efficient

Copying filerefs is expensive since the reference count is incremented,
avoid it.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: avoid falloc() in sys_close()

falloc() is racy since it installs an uninitialized file in an accessible fd.
Convert sys_close() to C++ and avoid the race; also fixes an fd leak in case
of an error.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: avoid falloc() in kern_accept()

falloc() is racy since it installs an uninitialized file in an accessible fd.
Use falloc_noinstall() and fdalloc() instead; also fixes an fd leak on error.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
net: avoid falloc() in kern_socketpair()

falloc() is racy since it installs an uninitialized file in an accessible fd.
Use falloc_noinstall() and fdalloc() instead; also fixes fd leaks on error.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: drop falloc()

falloc() is inherently racy in that it installs an uninitialized file
descriptor in a user accessible fd.  It is also hard to use correctly when
an error occurs.  Luckily, we don't use it anywhere, so we can just remove it.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Merge branch 'file++'

falloc() is inherently racy in that it makes visible (via an fd) a file
structure that is not initialized.

Remove its uses and falloc() itself.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>