mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-15 11:55:36 +08:00
kern: Add a proc0
- Provides the thread's proc pointer and with that access to creds Update #4475
This commit is contained in:
@@ -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(
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user