aboutsummaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/cloudabi64/cloudabi64_module.c8
-rw-r--r--sys/compat/cloudabi64/cloudabi64_thread.c10
-rw-r--r--sys/compat/cloudabi64/cloudabi64_util.h4
-rw-r--r--sys/compat/linprocfs/linprocfs.c113
-rw-r--r--sys/compat/linux/linux_misc.h7
5 files changed, 94 insertions, 48 deletions
diff --git a/sys/compat/cloudabi64/cloudabi64_module.c b/sys/compat/cloudabi64/cloudabi64_module.c
index de890bc5c652..246a887105cb 100644
--- a/sys/compat/cloudabi64/cloudabi64_module.c
+++ b/sys/compat/cloudabi64/cloudabi64_module.c
@@ -112,7 +112,13 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
{ .a_type = CLOUDABI_AT_NULL },
};
*stack_base -= howmany(sizeof(auxv), sizeof(register_t));
- return (copyout(auxv, *stack_base, sizeof(auxv)));
+ error = copyout(auxv, *stack_base, sizeof(auxv));
+ if (error != 0)
+ return (error);
+
+ /* Reserve space for storing the TCB. */
+ *stack_base -= howmany(sizeof(cloudabi64_tcb_t), sizeof(register_t));
+ return (0);
}
static int
diff --git a/sys/compat/cloudabi64/cloudabi64_thread.c b/sys/compat/cloudabi64/cloudabi64_thread.c
index 51961f8ad29b..429ad3398be6 100644
--- a/sys/compat/cloudabi64/cloudabi64_thread.c
+++ b/sys/compat/cloudabi64/cloudabi64_thread.c
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
struct thread_create_args {
cloudabi64_threadattr_t attr;
+ uint64_t tcb;
lwpid_t tid;
};
@@ -49,8 +50,7 @@ initialize_thread(struct thread *td, void *thunk)
args->tid = td->td_tid;
/* Set up initial register contents. */
- cloudabi64_thread_setregs(td, &args->attr);
- return (0);
+ return (cloudabi64_thread_setregs(td, &args->attr, args->tcb));
}
int
@@ -63,6 +63,12 @@ cloudabi64_sys_thread_create(struct thread *td,
error = copyin(uap->attr, &args.attr, sizeof(args.attr));
if (error != 0)
return (error);
+
+ /* Remove some space on the top of the stack for the TCB. */
+ args.tcb = rounddown(args.attr.stack + args.attr.stack_size -
+ sizeof(cloudabi64_tcb_t), _Alignof(cloudabi64_tcb_t));
+ args.attr.stack_size = args.tcb - args.attr.stack;
+
error = thread_create(td, NULL, initialize_thread, &args);
if (error != 0)
return (error);
diff --git a/sys/compat/cloudabi64/cloudabi64_util.h b/sys/compat/cloudabi64/cloudabi64_util.h
index dcec70ece5f4..29a90d779821 100644
--- a/sys/compat/cloudabi64/cloudabi64_util.h
+++ b/sys/compat/cloudabi64/cloudabi64_util.h
@@ -42,7 +42,7 @@ extern Elf64_Brandinfo cloudabi64_brand;
register_t *cloudabi64_copyout_strings(struct image_params *);
int cloudabi64_fixup(register_t **, struct image_params *);
-void cloudabi64_thread_setregs(struct thread *,
- const cloudabi64_threadattr_t *);
+int cloudabi64_thread_setregs(struct thread *,
+ const cloudabi64_threadattr_t *, uint64_t);
#endif
diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 86c4b050a959..395c94fd6129 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -640,7 +640,7 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
} else {
startcode = 0;
startdata = 0;
- };
+ }
sbuf_printf(sb, "%d", p->p_pid);
#define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg)
PS_ADD("comm", "(%s)", p->p_comm);
@@ -1370,65 +1370,92 @@ linprocfs_dofdescfs(PFS_FILL_ARGS)
/*
* Filler function for proc/pid/limits
*/
-
-#define RLIM_NONE -1
-
-static const struct limit_info {
+static const struct linux_rlimit_ident {
const char *desc;
const char *unit;
- unsigned long long rlim_id;
-} limits_info[] = {
- { "Max cpu time", "seconds", RLIMIT_CPU },
- { "Max file size", "bytes", RLIMIT_FSIZE },
- { "Max data size", "bytes", RLIMIT_DATA },
- { "Max stack size", "bytes", RLIMIT_STACK },
- { "Max core file size", "bytes", RLIMIT_CORE },
- { "Max resident set", "bytes", RLIMIT_RSS },
- { "Max processes", "processes", RLIMIT_NPROC },
- { "Max open files", "files", RLIMIT_NOFILE },
- { "Max locked memory", "bytes", RLIMIT_MEMLOCK },
- { "Max address space", "bytes", RLIMIT_AS },
- { "Max file locks", "locks", RLIM_INFINITY },
- { "Max pending signals", "signals", RLIM_INFINITY },
- { "Max msgqueue size", "bytes", RLIM_NONE },
- { "Max nice priority", "", RLIM_NONE },
- { "Max realtime priority", "", RLIM_NONE },
- { "Max realtime timeout", "us", RLIM_INFINITY },
+ unsigned int rlim_id;
+} linux_rlimits_ident[] = {
+ { "Max cpu time", "seconds", RLIMIT_CPU },
+ { "Max file size", "bytes", RLIMIT_FSIZE },
+ { "Max data size", "bytes", RLIMIT_DATA },
+ { "Max stack size", "bytes", RLIMIT_STACK },
+ { "Max core file size", "bytes", RLIMIT_CORE },
+ { "Max resident set", "bytes", RLIMIT_RSS },
+ { "Max processes", "processes", RLIMIT_NPROC },
+ { "Max open files", "files", RLIMIT_NOFILE },
+ { "Max locked memory", "bytes", RLIMIT_MEMLOCK },
+ { "Max address space", "bytes", RLIMIT_AS },
+ { "Max file locks", "locks", LINUX_RLIMIT_LOCKS },
+ { "Max pending signals", "signals", LINUX_RLIMIT_SIGPENDING },
+ { "Max msgqueue size", "bytes", LINUX_RLIMIT_MSGQUEUE },
+ { "Max nice priority", "", LINUX_RLIMIT_NICE },
+ { "Max realtime priority", "", LINUX_RLIMIT_RTPRIO },
+ { "Max realtime timeout", "us", LINUX_RLIMIT_RTTIME },
{ 0, 0, 0 }
};
static int
linprocfs_doproclimits(PFS_FILL_ARGS)
{
- const struct limit_info *li;
- struct rlimit li_rlimits;
- struct plimit *cur_proc_lim;
+ const struct linux_rlimit_ident *li;
+ struct plimit *limp;
+ struct rlimit rl;
+ ssize_t size;
+ int res, error;
- cur_proc_lim = lim_alloc();
- lim_copy(cur_proc_lim, p->p_limit);
- sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n", "Limit", "Soft Limit",
+ PROC_LOCK(p);
+ limp = lim_hold(p->p_limit);
+ PROC_UNLOCK(p);
+ size = sizeof(res);
+ sbuf_printf(sb, "%-26s%-21s%-21s%-21s\n", "Limit", "Soft Limit",
"Hard Limit", "Units");
- for (li = limits_info; li->desc != NULL; ++li) {
- if (li->rlim_id != RLIM_INFINITY && li->rlim_id != RLIM_NONE)
- li_rlimits = cur_proc_lim->pl_rlimit[li->rlim_id];
- else {
- li_rlimits.rlim_cur = 0;
- li_rlimits.rlim_max = 0;
+ for (li = linux_rlimits_ident; li->desc != NULL; ++li) {
+ switch (li->rlim_id)
+ {
+ case LINUX_RLIMIT_LOCKS:
+ /* FALLTHROUGH */
+ case LINUX_RLIMIT_RTTIME:
+ rl.rlim_cur = RLIM_INFINITY;
+ break;
+ case LINUX_RLIMIT_SIGPENDING:
+ error = kernel_sysctlbyname(td,
+ "kern.sigqueue.max_pending_per_proc",
+ &res, &size, 0, 0, 0, 0);
+ if (error != 0)
+ break;
+ rl.rlim_cur = res;
+ rl.rlim_max = res;
+ break;
+ case LINUX_RLIMIT_MSGQUEUE:
+ error = kernel_sysctlbyname(td,
+ "kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0);
+ if (error != 0)
+ break;
+ rl.rlim_cur = res;
+ rl.rlim_max = res;
+ break;
+ case LINUX_RLIMIT_NICE:
+ /* FALLTHROUGH */
+ case LINUX_RLIMIT_RTPRIO:
+ rl.rlim_cur = 0;
+ rl.rlim_max = 0;
+ break;
+ default:
+ rl = limp->pl_rlimit[li->rlim_id];
+ break;
}
- if (li->rlim_id == RLIM_INFINITY ||
- li_rlimits.rlim_cur == RLIM_INFINITY)
+ if (rl.rlim_cur == RLIM_INFINITY)
sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n",
li->desc, "unlimited", "unlimited", li->unit);
else
- sbuf_printf(sb, "%-26s%-21ld%-21ld%-10s\n",
- li->desc, (long)li_rlimits.rlim_cur,
- (long)li_rlimits.rlim_max, li->unit);
+ sbuf_printf(sb, "%-26s%-21llu%-21llu%-10s\n",
+ li->desc, (unsigned long long)rl.rlim_cur,
+ (unsigned long long)rl.rlim_max, li->unit);
}
- lim_free(cur_proc_lim);
- return (0);
+ lim_free(limp);
+ return (error);
}
-
/*
* Filler function for proc/sys/kernel/random/uuid
*/
diff --git a/sys/compat/linux/linux_misc.h b/sys/compat/linux/linux_misc.h
index 08bc85fd936c..0d2d86ce63ac 100644
--- a/sys/compat/linux/linux_misc.h
+++ b/sys/compat/linux/linux_misc.h
@@ -143,6 +143,13 @@ extern int stclohz;
#define LINUX_P_PID 1
#define LINUX_P_PGID 2
+#define LINUX_RLIMIT_LOCKS RLIM_NLIMITS + 1
+#define LINUX_RLIMIT_SIGPENDING RLIM_NLIMITS + 2
+#define LINUX_RLIMIT_MSGQUEUE RLIM_NLIMITS + 3
+#define LINUX_RLIMIT_NICE RLIM_NLIMITS + 4
+#define LINUX_RLIMIT_RTPRIO RLIM_NLIMITS + 5
+#define LINUX_RLIMIT_RTTIME RLIM_NLIMITS + 6
+
#define LINUX_RLIM_INFINITY (~0UL)
int linux_common_wait(struct thread *td, int pid, int *status,