summaryrefslogtreecommitdiffstats
path: root/sys/compat/linux
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/linux')
-rw-r--r--sys/compat/linux/linux_fork.c12
-rw-r--r--sys/compat/linux/linux_misc.c31
-rw-r--r--sys/compat/linux/linux_socket.c63
-rw-r--r--sys/compat/linux/linux_socket.h25
-rw-r--r--sys/compat/linux/linux_stats.c59
5 files changed, 166 insertions, 24 deletions
diff --git a/sys/compat/linux/linux_fork.c b/sys/compat/linux/linux_fork.c
index 9e7c71f..f96559c 100644
--- a/sys/compat/linux/linux_fork.c
+++ b/sys/compat/linux/linux_fork.c
@@ -213,6 +213,18 @@ linux_clone_proc(struct thread *td, struct linux_clone_args *args)
if (args->flags & LINUX_CLONE_SETTLS)
linux_set_cloned_tls(td2, args->tls);
+ /*
+ * If CLONE_PARENT is set, then the parent of the new process will be
+ * the same as that of the calling process.
+ */
+ if (args->flags & LINUX_CLONE_PARENT) {
+ sx_xlock(&proctree_lock);
+ PROC_LOCK(p2);
+ proc_reparent(p2, td->td_proc->p_pptr);
+ PROC_UNLOCK(p2);
+ sx_xunlock(&proctree_lock);
+ }
+
#ifdef DEBUG
if (ldebug(clone))
printf(LMSG("clone: successful rfork to %d, "
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 538b9dc..e806d87 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -198,24 +198,27 @@ linux_alarm(struct thread *td, struct linux_alarm_args *args)
if (ldebug(alarm))
printf(ARGS(alarm, "%u"), args->secs);
#endif
-
secs = args->secs;
+ /*
+ * Linux alarm() is always successfull. Limit secs to INT32_MAX / 2
+ * to match kern_setitimer()'s limit to avoid error from it.
+ *
+ * XXX. Linux limit secs to INT_MAX on 32 and does not limit on 64-bit
+ * platforms.
+ */
+ if (secs > INT32_MAX / 2)
+ secs = INT32_MAX / 2;
- if (secs > INT_MAX)
- secs = INT_MAX;
-
- it.it_value.tv_sec = (long) secs;
+ it.it_value.tv_sec = secs;
it.it_value.tv_usec = 0;
- it.it_interval.tv_sec = 0;
- it.it_interval.tv_usec = 0;
+ timevalclear(&it.it_interval);
error = kern_setitimer(td, ITIMER_REAL, &it, &old_it);
- if (error)
- return (error);
- if (timevalisset(&old_it.it_value)) {
- if (old_it.it_value.tv_usec != 0)
- old_it.it_value.tv_sec++;
- td->td_retval[0] = old_it.it_value.tv_sec;
- }
+ KASSERT(error == 0, ("kern_setitimer returns %d", error));
+
+ if ((old_it.it_value.tv_sec == 0 && old_it.it_value.tv_usec > 0) ||
+ old_it.it_value.tv_usec >= 500000)
+ old_it.it_value.tv_sec++;
+ td->td_retval[0] = old_it.it_value.tv_sec;
return (0);
}
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index dee4093..c19167a 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -289,6 +289,63 @@ linux_to_bsd_ip_sockopt(int opt)
}
static int
+linux_to_bsd_ip6_sockopt(int opt)
+{
+
+ switch (opt) {
+ case LINUX_IPV6_NEXTHOP:
+ return (IPV6_NEXTHOP);
+ case LINUX_IPV6_UNICAST_HOPS:
+ return (IPV6_UNICAST_HOPS);
+ case LINUX_IPV6_MULTICAST_IF:
+ return (IPV6_MULTICAST_IF);
+ case LINUX_IPV6_MULTICAST_HOPS:
+ return (IPV6_MULTICAST_HOPS);
+ case LINUX_IPV6_MULTICAST_LOOP:
+ return (IPV6_MULTICAST_LOOP);
+ case LINUX_IPV6_ADD_MEMBERSHIP:
+ return (IPV6_JOIN_GROUP);
+ case LINUX_IPV6_DROP_MEMBERSHIP:
+ return (IPV6_LEAVE_GROUP);
+ case LINUX_IPV6_V6ONLY:
+ return (IPV6_V6ONLY);
+ case LINUX_IPV6_DONTFRAG:
+ return (IPV6_DONTFRAG);
+#if 0
+ case LINUX_IPV6_CHECKSUM:
+ return (IPV6_CHECKSUM);
+ case LINUX_IPV6_RECVPKTINFO:
+ return (IPV6_RECVPKTINFO);
+ case LINUX_IPV6_PKTINFO:
+ return (IPV6_PKTINFO);
+ case LINUX_IPV6_RECVHOPLIMIT:
+ return (IPV6_RECVHOPLIMIT);
+ case LINUX_IPV6_HOPLIMIT:
+ return (IPV6_HOPLIMIT);
+ case LINUX_IPV6_RECVHOPOPTS:
+ return (IPV6_RECVHOPOPTS);
+ case LINUX_IPV6_HOPOPTS:
+ return (IPV6_HOPOPTS);
+ case LINUX_IPV6_RTHDRDSTOPTS:
+ return (IPV6_RTHDRDSTOPTS);
+ case LINUX_IPV6_RECVRTHDR:
+ return (IPV6_RECVRTHDR);
+ case LINUX_IPV6_RTHDR:
+ return (IPV6_RTHDR);
+ case LINUX_IPV6_RECVDSTOPTS:
+ return (IPV6_RECVDSTOPTS);
+ case LINUX_IPV6_DSTOPTS:
+ return (IPV6_DSTOPTS);
+ case LINUX_IPV6_RECVPATHMTU:
+ return (IPV6_RECVPATHMTU);
+ case LINUX_IPV6_PATHMTU:
+ return (IPV6_PATHMTU);
+#endif
+ }
+ return (-1);
+}
+
+static int
linux_to_bsd_so_sockopt(int opt)
{
@@ -1515,6 +1572,9 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
case IPPROTO_IP:
name = linux_to_bsd_ip_sockopt(args->optname);
break;
+ case IPPROTO_IPV6:
+ name = linux_to_bsd_ip6_sockopt(args->optname);
+ break;
case IPPROTO_TCP:
name = linux_to_bsd_tcp_sockopt(args->optname);
break;
@@ -1601,6 +1661,9 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args)
case IPPROTO_IP:
name = linux_to_bsd_ip_sockopt(args->optname);
break;
+ case IPPROTO_IPV6:
+ name = linux_to_bsd_ip6_sockopt(args->optname);
+ break;
case IPPROTO_TCP:
name = linux_to_bsd_tcp_sockopt(args->optname);
break;
diff --git a/sys/compat/linux/linux_socket.h b/sys/compat/linux/linux_socket.h
index b32a969..25c0ec3 100644
--- a/sys/compat/linux/linux_socket.h
+++ b/sys/compat/linux/linux_socket.h
@@ -302,6 +302,31 @@ int linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args);
#define LINUX_IP_ADD_MEMBERSHIP 35
#define LINUX_IP_DROP_MEMBERSHIP 36
+#define LINUX_IPV6_CHECKSUM 7
+#define LINUX_IPV6_NEXTHOP 9
+#define LINUX_IPV6_UNICAST_HOPS 16
+#define LINUX_IPV6_MULTICAST_IF 17
+#define LINUX_IPV6_MULTICAST_HOPS 18
+#define LINUX_IPV6_MULTICAST_LOOP 19
+#define LINUX_IPV6_ADD_MEMBERSHIP 20
+#define LINUX_IPV6_DROP_MEMBERSHIP 21
+#define LINUX_IPV6_V6ONLY 26
+
+#define LINUX_IPV6_RECVPKTINFO 49
+#define LINUX_IPV6_PKTINFO 50
+#define LINUX_IPV6_RECVHOPLIMIT 51
+#define LINUX_IPV6_HOPLIMIT 52
+#define LINUX_IPV6_RECVHOPOPTS 53
+#define LINUX_IPV6_HOPOPTS 54
+#define LINUX_IPV6_RTHDRDSTOPTS 55
+#define LINUX_IPV6_RECVRTHDR 56
+#define LINUX_IPV6_RTHDR 57
+#define LINUX_IPV6_RECVDSTOPTS 58
+#define LINUX_IPV6_DSTOPTS 59
+#define LINUX_IPV6_RECVPATHMTU 60
+#define LINUX_IPV6_PATHMTU 61
+#define LINUX_IPV6_DONTFRAG 62
+
#define LINUX_TCP_NODELAY 1
#define LINUX_TCP_MAXSEG 2
#define LINUX_TCP_KEEPIDLE 4
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index f96acc0..2684d82 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -256,7 +256,7 @@ static int
stat_copyout(struct stat *buf, void *ubuf)
{
struct l_stat lbuf;
-
+
bzero(&lbuf, sizeof(lbuf));
lbuf.st_dev = buf->st_dev;
lbuf.st_ino = buf->st_ino;
@@ -302,7 +302,7 @@ linux_stat(struct thread *td, struct linux_stat_args *args)
return (error);
}
LFREEPATH(path);
- return(stat_copyout(&buf, args->up));
+ return (stat_copyout(&buf, args->up));
}
int
@@ -324,7 +324,7 @@ linux_lstat(struct thread *td, struct linux_lstat_args *args)
return (error);
}
LFREEPATH(path);
- return(stat_copyout(&buf, args->up));
+ return (stat_copyout(&buf, args->up));
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -380,10 +380,22 @@ bsd_to_linux_ftype(const char *fstypename)
return (0L);
}
-static void
+static int
bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs)
{
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+ uint64_t tmp;
+#define LINUX_HIBITS 0xffffffff00000000ULL
+
+ tmp = bsd_statfs->f_blocks | bsd_statfs->f_bfree | bsd_statfs->f_files |
+ bsd_statfs->f_bsize;
+ if ((bsd_statfs->f_bavail != -1 && (bsd_statfs->f_bavail & LINUX_HIBITS)) ||
+ (bsd_statfs->f_ffree != -1 && (bsd_statfs->f_ffree & LINUX_HIBITS)) ||
+ (tmp & LINUX_HIBITS))
+ return (EOVERFLOW);
+#undef LINUX_HIBITS
+#endif
linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
linux_statfs->f_bsize = bsd_statfs->f_bsize;
linux_statfs->f_blocks = bsd_statfs->f_blocks;
@@ -394,6 +406,8 @@ bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs)
linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
linux_statfs->f_namelen = MAXNAMLEN;
+
+ return (0);
}
int
@@ -414,8 +428,10 @@ linux_statfs(struct thread *td, struct linux_statfs_args *args)
LFREEPATH(path);
if (error)
return (error);
- bsd_to_linux_statfs(&bsd_statfs, &linux_statfs);
- return copyout(&linux_statfs, args->buf, sizeof(linux_statfs));
+ error = bsd_to_linux_statfs(&bsd_statfs, &linux_statfs);
+ if (error)
+ return (error);
+ return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
}
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
@@ -457,7 +473,28 @@ linux_statfs64(struct thread *td, struct linux_statfs64_args *args)
if (error)
return (error);
bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs);
- return copyout(&linux_statfs, args->buf, sizeof(linux_statfs));
+ return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
+}
+
+int
+linux_fstatfs64(struct thread *td, struct linux_fstatfs64_args *args)
+{
+ struct l_statfs64 linux_statfs;
+ struct statfs bsd_statfs;
+ int error;
+
+#ifdef DEBUG
+ if (ldebug(fstatfs64))
+ printf(ARGS(fstatfs64, "%d, *"), args->fd);
+#endif
+ if (args->bufsize != sizeof(struct l_statfs64))
+ return (EINVAL);
+
+ error = kern_fstatfs(td, args->fd, &bsd_statfs);
+ if (error)
+ return error;
+ bsd_to_linux_statfs64(&bsd_statfs, &linux_statfs);
+ return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -474,9 +511,11 @@ linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args)
#endif
error = kern_fstatfs(td, args->fd, &bsd_statfs);
if (error)
- return error;
- bsd_to_linux_statfs(&bsd_statfs, &linux_statfs);
- return copyout(&linux_statfs, args->buf, sizeof(linux_statfs));
+ return (error);
+ error = bsd_to_linux_statfs(&bsd_statfs, &linux_statfs);
+ if (error)
+ return (error);
+ return (copyout(&linux_statfs, args->buf, sizeof(linux_statfs)));
}
struct l_ustat
OpenPOWER on IntegriCloud