Skip to content

Commit

Permalink
xnu-792.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Jun 4, 2017
1 parent fd2cc54 commit 782d0a0
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 225 deletions.
10 changes: 10 additions & 0 deletions bsd/dev/ppc/systemcalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ unix_syscall(struct savearea *regs)
else
proc = current_proc();

/* Make sure there is a process associated with this task */
if (proc == NULL) {
regs->save_r3 = (long long)EPERM;
/* set the "pc" to execute cerror routine */
regs->save_srr0 -= 4;
task_terminate_internal(current_task());
thread_exception_return();
/* NOTREACHED */
}

/*
* Delayed binding of thread credential to process credential, if we
* are not running with an explicitly set thread credential.
Expand Down
27 changes: 11 additions & 16 deletions bsd/hfs/hfs_hotfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,11 +1225,13 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)
filefork_t * filefork;
hotfilelist_t *listp;
enum hfc_stage stage;
u_int32_t savedtemp;
int blksmoved;
int filesmoved;
int fileblocks;
int error = 0;
int startedtrans = 0;
int bt_op;

if (hfsmp->hfc_stage != HFC_EVICTION) {
return (EBUSY);
Expand All @@ -1246,6 +1248,7 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)
hfsmp->hfc_stage = HFC_BUSY;

filesmoved = blksmoved = 0;
bt_op = kBTreeFirstRecord;

MALLOC(iterator, BTreeIterator *, sizeof(*iterator), M_TEMP, M_WAITOK);
bzero(iterator, sizeof(*iterator));
Expand All @@ -1260,7 +1263,7 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)
/*
* Obtain the first record (ie the coldest one).
*/
if (BTIterateRecord(filefork, kBTreeFirstRecord, iterator, NULL, NULL) != 0) {
if (BTIterateRecord(filefork, bt_op, iterator, NULL, NULL) != 0) {
#if HFC_VERBOSE
printf("hotfiles_evict: no more records\n");
#endif
Expand Down Expand Up @@ -1299,10 +1302,7 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)

if (error) {
if (error == ENOENT) {
(void) BTDeleteRecord(filefork, iterator);
key->temperature = HFC_LOOKUPTAG;
(void) BTDeleteRecord(filefork, iterator);
goto next; /* stale entry, go to next */
goto delete; /* stale entry, go to next */
} else {
printf("hotfiles_evict: err %d getting file %d\n",
error, key->fileID);
Expand All @@ -1313,10 +1313,7 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)
printf("hotfiles_evict: huh, not a file %d\n", key->fileID);
hfs_unlock(VTOC(vp));
vnode_put(vp);
(void) BTDeleteRecord(filefork, iterator);
key->temperature = HFC_LOOKUPTAG;
(void) BTDeleteRecord(filefork, iterator);
goto next; /* invalid entry, go to next */
goto delete; /* invalid entry, go to next */
}
fileblocks = VTOF(vp)->ff_blocks;
if ((blksmoved > 0) &&
Expand All @@ -1334,10 +1331,7 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)
#endif
hfs_unlock(VTOC(vp));
vnode_put(vp);
(void) BTDeleteRecord(filefork, iterator);
key->temperature = HFC_LOOKUPTAG;
(void) BTDeleteRecord(filefork, iterator);
goto next; /* go to next */
goto delete; /* stale entry, go to next */
}

/*
Expand All @@ -1348,6 +1342,7 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)
printf("hotfiles_evict: err %d relocating file %d\n", error, key->fileID);
hfs_unlock(VTOC(vp));
vnode_put(vp);
bt_op = kBTreeNextRecord;
goto next; /* go to next */
}

Expand All @@ -1367,20 +1362,20 @@ hotfiles_evict(struct hfsmount *hfsmp, struct proc *p)
listp->hfl_reclaimblks = 0;
blksmoved += fileblocks;
filesmoved++;

delete:
error = BTDeleteRecord(filefork, iterator);
if (error) {
printf("hotfiles_evict: BTDeleteRecord failed %d (fileid %d)\n", error, key->fileID);
error = MacToVFSError(error);
break;
}
savedtemp = key->temperature;
key->temperature = HFC_LOOKUPTAG;
error = BTDeleteRecord(filefork, iterator);
if (error) {
printf("hotfiles_evict: BTDeleteRecord thread failed %d (fileid %d)\n", error, key->fileID);
error = MacToVFSError(error);
break;
}
key->temperature = savedtemp;
next:
(void) BTFlushPath(filefork);

Expand Down
28 changes: 4 additions & 24 deletions bsd/hfs/hfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ static int hfs_vnop_setattr(struct vnop_setattr_args*);

int hfs_write_access(struct vnode *vp, kauth_cred_t cred, struct proc *p, Boolean considerFlags);

int hfs_chflags(struct vnode *vp, uint32_t flags, kauth_cred_t cred,
struct proc *p);
int hfs_chmod(struct vnode *vp, int mode, kauth_cred_t cred,
struct proc *p);
int hfs_chown(struct vnode *vp, uid_t uid, gid_t gid,
Expand Down Expand Up @@ -534,9 +532,10 @@ hfs_vnop_setattr(ap)
* current securelevel are being changed.
*/
VATTR_SET_SUPPORTED(vap, va_flags);
if (VATTR_IS_ACTIVE(vap, va_flags) &&
((error = hfs_chflags(vp, vap->va_flags, cred, p)) != 0))
goto out;
if (VATTR_IS_ACTIVE(vap, va_flags)) {
cp->c_flags = vap->va_flags;
cp->c_touch_chgtime = TRUE;
}

/*
* If the file's extended security data is being changed, we
Expand Down Expand Up @@ -705,25 +704,6 @@ hfs_write_access(struct vnode *vp, kauth_cred_t cred, struct proc *p, Boolean co
}



/*
* Change the flags on a file or directory.
* cnode must be locked before calling.
*/
__private_extern__
int
hfs_chflags(struct vnode *vp, uint32_t flags, __unused kauth_cred_t cred, __unused struct proc *p)
{
register struct cnode *cp = VTOC(vp);

cp->c_flags &= SF_SETTABLE;
cp->c_flags |= (flags & UF_SETTABLE);
cp->c_touch_chgtime = TRUE;

return (0);
}


/*
* Perform chown operation on cnode cp;
* code must be locked prior to call.
Expand Down
2 changes: 2 additions & 0 deletions bsd/kern/kern_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ ctl_ctloutput(struct socket *so, struct sockopt *sopt)
MALLOC(data, void *, sopt->sopt_valsize, M_TEMP, M_WAITOK);
if (data == NULL)
return(ENOMEM);
/* 4108337 - copy in data for get socket option */
error = sooptcopyin(sopt, data, sopt->sopt_valsize, sopt->sopt_valsize);
}
len = sopt->sopt_valsize;
socket_unlock(so, 0);
Expand Down
124 changes: 70 additions & 54 deletions bsd/kern/kern_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,8 @@ __private_extern__ void uio_calculateresid( uio_t a_uio )
* and increments the current iovec base address and offset value.
* If the current iovec length is 0 then advance to the next
* iovec (if any).
* If the a_count passed in is 0, than only do the advancement
* over any 0 length iovec's.
*/
void uio_update( uio_t a_uio, user_size_t a_count )
{
Expand All @@ -1108,71 +1110,85 @@ void uio_update( uio_t a_uio, user_size_t a_count )
}

if (UIO_IS_64_BIT_SPACE(a_uio)) {
if (a_count > a_uio->uio_iovs.uiovp->iov_len) {
a_uio->uio_iovs.uiovp->iov_base += a_uio->uio_iovs.uiovp->iov_len;
a_uio->uio_iovs.uiovp->iov_len = 0;
}
else {
a_uio->uio_iovs.uiovp->iov_base += a_count;
a_uio->uio_iovs.uiovp->iov_len -= a_count;
}
/*
* if a_count == 0, then we are asking to skip over
* any empty iovs
*/
if (a_count) {
if (a_count > a_uio->uio_iovs.uiovp->iov_len) {
a_uio->uio_iovs.uiovp->iov_base += a_uio->uio_iovs.uiovp->iov_len;
a_uio->uio_iovs.uiovp->iov_len = 0;
}
else {
a_uio->uio_iovs.uiovp->iov_base += a_count;
a_uio->uio_iovs.uiovp->iov_len -= a_count;
}
#if 1 // LP64todo - remove this temp workaround once we go live with uio KPI
if (a_uio->uio_resid < 0) {
a_uio->uio_resid = 0;
}
if (a_count > (user_size_t)a_uio->uio_resid) {
a_uio->uio_offset += a_uio->uio_resid;
a_uio->uio_resid = 0;
}
else {
a_uio->uio_offset += a_count;
a_uio->uio_resid -= a_count;
}
if (a_uio->uio_resid < 0) {
a_uio->uio_resid = 0;
}
if (a_count > (user_size_t)a_uio->uio_resid) {
a_uio->uio_offset += a_uio->uio_resid;
a_uio->uio_resid = 0;
}
else {
a_uio->uio_offset += a_count;
a_uio->uio_resid -= a_count;
}
#else
if (a_uio->uio_resid_64 < 0) {
a_uio->uio_resid_64 = 0;
}
if (a_count > (user_size_t)a_uio->uio_resid_64) {
a_uio->uio_offset += a_uio->uio_resid_64;
a_uio->uio_resid_64 = 0;
}
else {
a_uio->uio_offset += a_count;
a_uio->uio_resid_64 -= a_count;
}
if (a_uio->uio_resid_64 < 0) {
a_uio->uio_resid_64 = 0;
}
if (a_count > (user_size_t)a_uio->uio_resid_64) {
a_uio->uio_offset += a_uio->uio_resid_64;
a_uio->uio_resid_64 = 0;
}
else {
a_uio->uio_offset += a_count;
a_uio->uio_resid_64 -= a_count;
}
#endif // LP64todo

/* advance to next iovec if current one is totally consumed */
while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.uiovp->iov_len == 0) {
}
/*
* advance to next iovec if current one is totally consumed
*/
while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.uiovp->iov_len == 0) {
a_uio->uio_iovcnt--;
if (a_uio->uio_iovcnt > 0) {
a_uio->uio_iovs.uiovp++;
}
}
}
else {
if (a_count > a_uio->uio_iovs.kiovp->iov_len) {
a_uio->uio_iovs.kiovp->iov_base += a_uio->uio_iovs.kiovp->iov_len;
a_uio->uio_iovs.kiovp->iov_len = 0;
}
else {
a_uio->uio_iovs.kiovp->iov_base += a_count;
a_uio->uio_iovs.kiovp->iov_len -= a_count;
}
if (a_uio->uio_resid < 0) {
a_uio->uio_resid = 0;
}
if (a_count > (user_size_t)a_uio->uio_resid) {
a_uio->uio_offset += a_uio->uio_resid;
a_uio->uio_resid = 0;
}
else {
a_uio->uio_offset += a_count;
a_uio->uio_resid -= a_count;
/*
* if a_count == 0, then we are asking to skip over
* any empty iovs
*/
if (a_count) {
if (a_count > a_uio->uio_iovs.kiovp->iov_len) {
a_uio->uio_iovs.kiovp->iov_base += a_uio->uio_iovs.kiovp->iov_len;
a_uio->uio_iovs.kiovp->iov_len = 0;
}
else {
a_uio->uio_iovs.kiovp->iov_base += a_count;
a_uio->uio_iovs.kiovp->iov_len -= a_count;
}
if (a_uio->uio_resid < 0) {
a_uio->uio_resid = 0;
}
if (a_count > (user_size_t)a_uio->uio_resid) {
a_uio->uio_offset += a_uio->uio_resid;
a_uio->uio_resid = 0;
}
else {
a_uio->uio_offset += a_count;
a_uio->uio_resid -= a_count;
}
}

/* advance to next iovec if current one is totally consumed */
while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.kiovp->iov_len == 0) {
/*
* advance to next iovec if current one is totally consumed
*/
while (a_uio->uio_iovcnt > 0 && a_uio->uio_iovs.kiovp->iov_len == 0) {
a_uio->uio_iovcnt--;
if (a_uio->uio_iovcnt > 0) {
a_uio->uio_iovs.kiovp++;
Expand Down
15 changes: 10 additions & 5 deletions bsd/kern/kpi_socketfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,22 @@ sflt_data_in(
const struct sockaddr *from,
mbuf_t *data,
mbuf_t *control,
sflt_data_flag_t flags)
sflt_data_flag_t flags,
int *filtered)
{
struct socket_filter_entry *filter;
int filtered = 0;
int error = 0;
int filtered_storage;

if (filtered == NULL)
filtered = &filtered_storage;
*filtered = 0;

for (filter = so->so_filt; filter && (error == 0);
filter = filter->sfe_next_onsocket) {
if (filter->sfe_filter->sf_filter.sf_data_in) {
if (filtered == 0) {
filtered = 1;
if (*filtered == 0) {
*filtered = 1;
sflt_use(so);
socket_unlock(so, 0);
}
Expand All @@ -163,7 +168,7 @@ sflt_data_in(
}
}

if (filtered != 0) {
if (*filtered != 0) {
socket_lock(so, 0);
sflt_unuse(so);
}
Expand Down
4 changes: 4 additions & 0 deletions bsd/kern/uipc_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ sofreelastref(so, dealloc)
#ifdef __APPLE__
selthreadclear(&so->so_snd.sb_sel);
selthreadclear(&so->so_rcv.sb_sel);
so->so_rcv.sb_flags &= ~SB_UPCALL;
so->so_snd.sb_flags &= ~SB_UPCALL;
#endif
return;
}
Expand All @@ -664,6 +666,8 @@ sofreelastref(so, dealloc)
#ifdef __APPLE__
selthreadclear(&so->so_snd.sb_sel);
selthreadclear(&so->so_rcv.sb_sel);
so->so_rcv.sb_flags &= ~SB_UPCALL;
so->so_snd.sb_flags &= ~SB_UPCALL;
#endif
socket_unlock(head, 1);
return;
Expand Down
Loading

0 comments on commit 782d0a0

Please sign in to comment.