summaryrefslogtreecommitdiffstats
path: root/rtemsbsd
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2021-07-21 13:46:45 +1000
committerChris Johns <chrisj@rtems.org>2021-08-28 10:24:38 +1000
commitc7427fc1548755104a929fc55f7a659937b6cd46 (patch)
tree27e6a6231aab923704b9b188b00f9bb792e4bfc6 /rtemsbsd
parentkern: Import kern_prot.c fnd kern_resource.c for proc0 (diff)
downloadrtems-libbsd-c7427fc1548755104a929fc55f7a659937b6cd46.tar.bz2
kern: Add a proc0
- Provides the thread's proc pointer and with that access to creds Update #4475
Diffstat (limited to 'rtemsbsd')
-rw-r--r--rtemsbsd/rtems/rtems-kernel-init.c38
-rw-r--r--rtemsbsd/rtems/rtems-kernel-thread.c25
2 files changed, 54 insertions, 9 deletions
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c b/rtemsbsd/rtems/rtems-kernel-init.c
index 7112914e..f76e7cd7 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -50,6 +50,9 @@
#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/kbio.h>
+#include <sys/resourcevar.h>
+#include <sys/jail.h>
+#include <uuid/uuid.h>
#include <limits.h>
@@ -94,6 +97,7 @@ sbintime_t sbt_timethreshold;
sbintime_t sbt_tickthreshold;
struct bintime tc_tick_bt;
sbintime_t tc_tick_sbt;
+int maxproc;
int tc_precexp;
static SYSCTL_NODE(_kern, OID_AUTO, smp, CTLFLAG_RD|CTLFLAG_CAPRD, NULL,
@@ -107,6 +111,38 @@ SYSCTL_INT(_kern_smp, OID_AUTO, maxid, CTLFLAG_RD|CTLFLAG_CAPRD,
SYSCTL_INT(_kern_smp, OID_AUTO, maxcpus, CTLFLAG_RD|CTLFLAG_CAPRD,
&maxid_maxcpus, 0, "Max number of CPUs that the system was compiled for.");
+/*
+ * Create a single process. RTEMS is a single address, single process OS.
+ */
+static void
+proc0_init(void* dummy)
+{
+ struct proc *p = &proc0;
+ struct ucred *newcred;
+ struct uidinfo tmpuinfo;
+ uuid_t uuid;
+ uihashinit();
+ /* Create the file descriptor table. */
+ newcred = crget();
+ newcred->cr_uid = 0;
+ newcred->cr_ruid = 0;
+ newcred->cr_ngroups = 1; /* group 0 */
+ newcred->cr_groups[0] = 0;
+ newcred->cr_rgid = 0;
+ tmpuinfo.ui_uid = 1;
+ curthread->td_ucred = newcred;
+ newcred->cr_uidinfo = newcred->cr_ruidinfo = &tmpuinfo;
+ newcred->cr_uidinfo = uifind(0);
+ newcred->cr_ruidinfo = uifind(0);
+ p->p_ucred = newcred;
+ p->p_pid = getpid();
+ p->p_fd = NULL;
+ p->p_fdtol = NULL;
+ uuid_generate(uuid);
+ uuid_unparse(uuid, prison0.pr_hostuuid);
+}
+SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL);
+
rtems_status_code
rtems_bsd_initialize(void)
{
@@ -135,6 +171,8 @@ rtems_bsd_initialize(void)
sbt_tickthreshold = bttosbt(bt_tickthreshold);
maxid_maxcpus = (int) rtems_scheduler_get_processor_maximum();
+ maxproc = 16;
+
mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO);
sc = rtems_timer_initiate_server(
diff --git a/rtemsbsd/rtems/rtems-kernel-thread.c b/rtemsbsd/rtems/rtems-kernel-thread.c
index 8e3344ef..3e1e44b9 100644
--- a/rtemsbsd/rtems/rtems-kernel-thread.c
+++ b/rtemsbsd/rtems/rtems-kernel-thread.c
@@ -90,15 +90,19 @@ struct thread *
rtems_bsd_thread_create(Thread_Control *thread, int wait)
{
struct thread *td = malloc(sizeof(*td), M_TEMP, M_ZERO | wait);
- struct sleepqueue *sq = sleepq_alloc();
- if (td != NULL && sq != NULL) {
- td->td_thread = thread;
- td->td_sleepqueue = sq;
- } else {
- free(td, M_TEMP);
- sleepq_free(sq);
- td = NULL;
+ if (td != NULL) {
+ struct sleepqueue *sq = sleepq_alloc();
+ if (sq != NULL) {
+ td->td_proc = &proc0;
+ td->td_ucred = proc0.p_ucred;
+ td->td_thread = thread;
+ td->td_sleepqueue = sq;
+ crhold(td->td_ucred);
+ } else {
+ free(td, M_TEMP);
+ td = NULL;
+ }
}
thread->extensions[rtems_bsd_extension_index] = td;
@@ -167,6 +171,7 @@ rtems_bsd_extension_thread_delete(
if (td != NULL) {
seltdfini(td);
sleepq_free(td->td_sleepqueue);
+ crfree(td->td_ucred);
free(td, M_TEMP);
}
}
@@ -303,7 +308,7 @@ kproc_create(void (*func)(void *), void *arg, struct proc **newpp, int flags, in
va_list ap;
va_start(ap, fmt);
- eno = rtems_bsd_thread_start(newpp, func, arg, flags, pages, fmt, ap);
+ eno = rtems_bsd_thread_start((struct thread**) newpp, func, arg, flags, pages, fmt, ap);
va_end(ap);
return eno;
@@ -331,6 +336,8 @@ kthread_add(void (*func)(void *), void *arg, struct proc *p, struct thread **new
va_list ap;
va_start(ap, fmt);
+ /* the cast here is a hack but passing a proc as a thread struct is just wrong and I
+ * have no idea why it is like this */
eno = rtems_bsd_thread_start(newtdp, func, arg, flags, pages, fmt, ap);
va_end(ap);