mmu: Fix mmap() to fail if address space is exhausted

Throw an exception from find_hole() if address space is exhausted. This
is needed for supporting MAP_32BIT properly.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Remove dead code umem.c

This removes the opensolaris umem.c defining memory allocation functions
which we do not use.

We should also remove umem.h from the same directory, but the messy
code makes this very difficult... It turns out that we have two
zfs_context.h versions, and one of them includes umem.h. If I try
to remove this version of zfs_context.h, compilation breaks. It
will take more effort to clean this mess up :(

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
app: fix osv::application never getting destroyed

Fixes #434.

The 'app' variable never went out of scope causing shared_ptr to
remain live.

Tested-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Remove bogus taskq implementation from zpool.so

We had two implementation of the taskq_*() functions. One compiled into
the kernel (from bsd/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c)
and a second one compiled into libzfs
(bsd/cddl/contrib/opensolaris/lib/libzpool/common/taskq.c). The latter
is broken (e.g., uses the umem_zalloc() function we didn't even compile)
but was never called. But this causes bug #433, where we load libzfs.so
and forget to unload it (because of another bug), and then
tst-solaris-taskq fails because it uses the wrong taskq implementation.

So this patch drops the second, broken, taskq.c.

Fixes #433.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: stub system() libc function

It uses /bin/sh to execute a command. It can fail if fork fails, and that is what
we emulate here.

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

man page says: "returns the maximum number of files a process can have open".
We're not really doing any limit tuning, so this is equivalent to FDMAX in our
case.

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

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

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
pagecache: don't assume ARC buffer virtual addresses are in 1:1 map

Using the debug allocator, ARC cache virtual addresses can be outside the
1:1 map, so we have to compare using physical addresses.

Fixes total failure with conf-debug_memory=1.

Suggested by Pawel.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
ucontext: implement swapcontext

This function is supposed to atomically get the current context, and set a new one.
It should be just a matter of calling getcontext + setcontext in a row. If the thread
is descheduled, it will come back later with the same set of registers.

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

This adds a submodule of Musl git tag v0.9.12 as an initial step to
moving over to upstream Musl.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/string: Migrate to upstream musl

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/ctype: Migrate to upstream musl

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/locale: Migrate to upstream musl

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build.mk: Include libc/stdio directory

In preparation for switching source files to musl upstream, include
libc/stdio directory which has internal headers that musl needs.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/stdio: Migrate to upstream musl

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/internal: Remove math.h header file

The math.h header file is a broken duplicate of include/api/math.h which
forgets to pull <bits/alltypes.h> which defines "double_t" among others.

This is needed for migrating libc/math source files to upstream musl.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/math: Migrate to upstream musl

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Fix musl submodule URL

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc/math: Migrate to upstream musl, take 2

Migrate more libc/math files to use upstream musl. These ones have only trivial
type changes in osv.git:

diff -ur libc/math/acos.c musl/src/math/acos.c
--- libc/math/acos.c    2013-10-25 12:11:23.991751105 +0300
+++ musl/src/math/acos.c        2014-08-04 17:07:25.449850385 +0300
@@ -51,7 +51,7 @@

 static double R(double z)
 {
-       double p, q;
+       double_t p, q;
        p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
        q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
        return p/q;
diff -ur libc/math/acosf.c musl/src/math/acosf.c
--- libc/math/acosf.c   2013-10-25 12:11:24.009751042 +0300
+++ musl/src/math/acosf.c       2014-08-04 17:07:25.449850385 +0300
@@ -25,7 +25,7 @@

 static float R(float z)
 {
-       float p, q;
+       float_t p, q;
        p = z*(pS0+z*(pS1+z*pS2));
        q = 1.0f+z*qS1;
        return p/q;
diff -ur libc/math/asin.c musl/src/math/asin.c
--- libc/math/asin.c    2013-10-25 12:11:23.999751077 +0300
+++ musl/src/math/asin.c        2014-08-04 17:07:25.450850382 +0300
@@ -58,7 +58,7 @@

 static double R(double z)
 {
-       double p, q;
+       double_t p, q;
        p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
        q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
        return p/q;
diff -ur libc/math/asinf.c musl/src/math/asinf.c
--- libc/math/asinf.c   2013-10-25 12:11:24.025750986 +0300
+++ musl/src/math/asinf.c       2014-08-04 17:07:25.450850382 +0300
@@ -26,7 +26,7 @@

 static float R(float z)
 {
-       float p, q;
+       float_t p, q;
        p = z*(pS0+z*(pS1+z*pS2));
        q = 1.0f+z*qS1;
        return p/q;
diff -ur libc/math/atan.c musl/src/math/atan.c
--- libc/math/atan.c    2013-10-25 12:11:24.006751053 +0300
+++ musl/src/math/atan.c        2014-08-04 17:07:25.450850382 +0300
@@ -62,7 +62,7 @@

 double atan(double x)
 {
-       double w,s1,s2,z;
+       double_t w,s1,s2,z;
        uint32_t ix,sign;
        int id;
diff -ur libc/math/atanf.c musl/src/math/atanf.c
--- libc/math/atanf.c   2013-10-25 12:11:24.028750976 +0300
+++ musl/src/math/atanf.c       2014-08-04 17:07:25.450850382 +0300
@@ -40,7 +40,7 @@

 float atanf(float x)
 {
-       float w,s1,s2,z;
+       float_t w,s1,s2,z;
        uint32_t ix,sign;
        int id;
diff -ur libc/math/__cos.c musl/src/math/__cos.c
--- libc/math/__cos.c   2014-08-04 15:40:10.209333688 +0300
+++ musl/src/math/__cos.c       2014-08-04 17:07:25.448850388 +0300
@@ -60,7 +60,7 @@

 double __cos(double x, double y)
 {
-       double hz,z,r,w;
+       double_t hz,z,r,w;

        z  = x*x;
        w  = z*z;
diff -ur libc/math/__cosdf.c musl/src/math/__cosdf.c
--- libc/math/__cosdf.c 2014-08-04 15:40:10.209333688 +0300
+++ musl/src/math/__cosdf.c     2014-08-04 17:07:25.448850388 +0300
@@ -25,7 +25,7 @@

 float __cosdf(double x)
 {
-       double r, w, z;
+       double_t r, w, z;

        /* Try to optimize for parallel evaluation as in __tandf.c. */
        z = x*x;
diff -ur libc/math/erf.c musl/src/math/erf.c
--- libc/math/erf.c     2013-10-25 12:11:24.026750982 +0300
+++ musl/src/math/erf.c 2014-08-04 17:07:25.451850379 +0300
@@ -176,7 +176,7 @@

 static double erfc1(double x)
 {
-       double s,P,Q;
+       double_t s,P,Q;

        s = fabs(x) - 1;
        P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
@@ -186,7 +186,8 @@

 static double erfc2(uint32_t ix, double x)
 {
-       double s,z,R,S;
+       double_t s,R,S;
+       double z;

        if (ix < 0x3ff40000)  /* |x| < 1.25 */
                return erfc1(x);
diff -ur libc/math/erff.c musl/src/math/erff.c
--- libc/math/erff.c    2013-10-25 12:11:24.003751062 +0300
+++ musl/src/math/erff.c        2014-08-04 17:07:25.451850379 +0300
@@ -86,7 +86,7 @@

 static float erfc1(float x)
 {
-       float s,P,Q;
+       float_t s,P,Q;

        s = fabsf(x) - 1;
        P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
@@ -96,7 +96,8 @@

 static float erfc2(uint32_t ix, float x)
 {
-       float s,z,R,S;
+       float_t s,R,S;
+       float z;

        if (ix < 0x3fa00000)  /* |x| < 1.25 */
                return erfc1(x);
diff -ur libc/math/j0.c musl/src/math/j0.c
--- libc/math/j0.c      2013-10-25 12:11:24.017751014 +0300
+++ musl/src/math/j0.c  2014-08-04 17:07:25.456850364 +0300
@@ -263,7 +263,7 @@
 static double pzero(double x)
 {
        const double *p,*q;
-       double z,r,s;
+       double_t z,r,s;
        uint32_t ix;

        GET_HIGH_WORD(ix, x);
@@ -359,7 +359,7 @@
 static double qzero(double x)
 {
        const double *p,*q;
-       double s,r,z;
+       double_t s,r,z;
        uint32_t ix;

        GET_HIGH_WORD(ix, x);
diff -ur libc/math/j0f.c musl/src/math/j0f.c
--- libc/math/j0f.c     2013-10-25 12:11:23.996751087 +0300
+++ musl/src/math/j0f.c 2014-08-04 17:07:25.456850364 +0300
@@ -201,7 +201,7 @@
 static float pzerof(float x)
 {
        const float *p,*q;
-       float z,r,s;
+       float_t z,r,s;
        uint32_t ix;

        GET_FLOAT_WORD(ix, x);
@@ -297,7 +297,7 @@
 static float qzerof(float x)
 {
        const float *p,*q;
-       float s,r,z;
+       float_t s,r,z;
        uint32_t ix;

        GET_FLOAT_WORD(ix, x);
diff -ur libc/math/j1.c musl/src/math/j1.c
--- libc/math/j1.c      2013-10-25 12:11:23.989751112 +0300
+++ musl/src/math/j1.c  2014-08-04 17:07:25.456850364 +0300
@@ -250,7 +250,7 @@
 static double pone(double x)
 {
        const double *p,*q;
-       double z,r,s;
+       double_t z,r,s;
        uint32_t ix;

        GET_HIGH_WORD(ix, x);
@@ -346,7 +346,7 @@
 static double qone(double x)
 {
        const double *p,*q;
-       double  s,r,z;
+       double_t s,r,z;
        uint32_t ix;

        GET_HIGH_WORD(ix, x);
diff -ur libc/math/j1f.c musl/src/math/j1f.c
--- libc/math/j1f.c     2013-10-25 12:11:24.000751074 +0300
+++ musl/src/math/j1f.c 2014-08-04 17:07:25.456850364 +0300
@@ -198,7 +198,7 @@
 static float ponef(float x)
 {
        const float *p,*q;
-       float z,r,s;
+       float_t z,r,s;
        uint32_t ix;

        GET_FLOAT_WORD(ix, x);
@@ -294,7 +294,7 @@
 static float qonef(float x)
 {
        const float *p,*q;
-       float s,r,z;
+       float_t s,r,z;
        uint32_t ix;

        GET_FLOAT_WORD(ix, x);
diff -ur libc/math/__sin.c musl/src/math/__sin.c
--- libc/math/__sin.c   2014-08-04 15:40:10.211333681 +0300
+++ musl/src/math/__sin.c       2014-08-04 17:07:25.449850385 +0300
@@ -51,7 +51,7 @@

 double __sin(double x, double y, int iy)
 {
-       double z,r,v,w;
+       double_t z,r,v,w;

        z = x*x;
        w = z*z;
diff -ur libc/math/__sindf.c musl/src/math/__sindf.c
--- libc/math/__sindf.c 2014-08-04 15:40:10.211333681 +0300
+++ musl/src/math/__sindf.c     2014-08-04 17:07:25.449850385 +0300
@@ -25,7 +25,7 @@

 float __sindf(double x)
 {
-       double r, s, w, z;
+       double_t r, s, w, z;

        /* Try to optimize for parallel evaluation as in __tandf.c. */
        z = x*x;
diff -ur libc/math/tgamma.c musl/src/math/tgamma.c
--- libc/math/tgamma.c  2013-10-25 12:11:24.008751046 +0300
+++ musl/src/math/tgamma.c      2014-08-04 17:07:25.461850349 +0300
@@ -89,7 +89,7 @@
 /* S(x) rational function for positive x */
 static double S(double x)
 {
-       double num = 0, den = 0;
+       double_t num = 0, den = 0;
        int i;

        /* to avoid overflow handle large x differently */

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