X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/1c79356b52d46aa6b508fb032f5ae709b1f2897b..5eebf7385fedb1517b66b53c28e5aa6bb0a2be50:/bsd/kern/bsd_stubs.c diff --git a/bsd/kern/bsd_stubs.c b/bsd/kern/bsd_stubs.c index 1952e98cc..0597434fa 100644 --- a/bsd/kern/bsd_stubs.c +++ b/bsd/kern/bsd_stubs.c @@ -29,6 +29,7 @@ #include #include #include /* for SET */ +#include /* Just to satisfy pstat command */ int dmmin, dmmax, dmtext; @@ -39,23 +40,37 @@ kmem_mb_alloc(vm_map_t mbmap, int size) if (kernel_memory_allocate(mbmap, &addr, size, 0, KMA_NOPAGEWAIT|KMA_KOBJECT) == KERN_SUCCESS) - return((void *)addr); + return(addr); else return(0); } pcb_synch() {} -unix_master() {} -unix_release() {} struct proc * current_proc(void) { /* Never returns a NULL */ - struct proc *p = (struct proc *)get_bsdtask_info(current_task()); + struct uthread * ut; + struct proc *p; + thread_act_t thr_act = current_act(); + + ut = (struct uthread *)get_bsdthread_info(thr_act); + if (ut && (ut->uu_flag & P_VFORK) && ut->uu_proc) { + p = ut->uu_proc; + if ((p->p_flag & P_INVFORK) == 0) + panic("returning child proc not under vfork"); + if (p->p_vforkact != (void *)thr_act) + panic("returning child proc which is not cur_act"); + return(p); + } + + p = (struct proc *)get_bsdtask_info(current_task()); + if (p == NULL) - p = kernproc; + return (kernproc); + return (p); } @@ -83,6 +98,9 @@ bdevsw_isfree(int index) sizeof(struct bdevsw)) == 0) break; } + } else { + /* NB: Not used below unless index is in range */ + devsw = &bdevsw[index]; } if ((index < 0) || (index >= nblkdev) || @@ -105,8 +123,9 @@ bdevsw_add(int index, struct bdevsw * bsw) struct bdevsw *devsw; if (index == -1) { - devsw = bdevsw; - for(index=0; index < nblkdev; index++, devsw++) { + devsw = &bdevsw[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */ + /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */ + for(index=1; index < nblkdev; index++, devsw++) { if(memcmp((char *)devsw, (char *)&nobdev, sizeof(struct bdevsw)) == 0) @@ -221,17 +240,28 @@ cdevsw_remove(int index, struct cdevsw * csw) return(index); } -int -memcmp(s1, s2, n) - register char *s1, *s2; - register n; +static int +cdev_set_bdev(int cdev, int bdev) { - while (--n >= 0) - if (*s1++ != *s2++) - return (*--s1 - *--s2); - return (0); + extern int chrtoblk_add(int cdev, int bdev); + + return (chrtoblk_set(cdev, bdev)); } -int + +int +cdevsw_add_with_bdev(int index, struct cdevsw * csw, int bdev) +{ + index = cdevsw_add(index, csw); + if (index < 0) { + return (index); + } + if (cdev_set_bdev(index, bdev) < 0) { + cdevsw_remove(index, csw); + return (-1); + } + return (index); +} + issingleuser(void) { char namep[16];