Skip to content

Commit

Permalink
xnu-2422.110.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Jun 4, 2017
1 parent d48495c commit 2a67609
Show file tree
Hide file tree
Showing 16 changed files with 284 additions and 110 deletions.
1 change: 1 addition & 0 deletions bsd/hfs/hfs_fsctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct hfs_journal_info {
#define HFSIOC_GET_WRITE_GEN_COUNTER _IOR('h', 30, u_int32_t)
#define HFS_GET_WRITE_GEN_COUNTER IOCBASECMD(HFSIOC_GET_WRITE_GEN_COUNTER)

/* revisiond uses this to allocate a doc-id for files from Cab and earlier systems that are marked tracked but don't have a doc-id */
#define HFS_DOCUMENT_ID_ALLOCATE 0x1

#define HFSIOC_GET_DOCUMENT_ID _IOR('h', 31, u_int32_t)
Expand Down
1 change: 1 addition & 0 deletions bsd/kern/kern_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ kqueue_body(struct proc *p, fp_allocfn_t fp_zalloc, void *cra, int32_t *retval)
fp->f_data = kq;

proc_fdlock(p);
*fdflags(p, fd) |= UF_EXCLOSE;
procfdtbl_releasefd(p, fd, NULL);
fp_drop(p, fd, fp, 1);
proc_fdunlock(p);
Expand Down
19 changes: 19 additions & 0 deletions bsd/kern/kern_kpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <kern/kpc.h>

#include <pexpert/pexpert.h>
#include <kperf/kperf.h>

/* Various sysctl requests */
#define REQ_CLASSES (1)
Expand Down Expand Up @@ -387,6 +388,24 @@ kpc_sysctl SYSCTL_HANDLER_ARGS
if( !kpc_initted )
panic("kpc_init not called");

// Most sysctls require an access check, but a few are public.
switch( (uintptr_t) arg1 ) {
case REQ_CLASSES:
case REQ_CONFIG_COUNT:
case REQ_COUNTER_COUNT:
// These read-only sysctls are public.
break;

default:
// Require kperf access to read or write anything else.
// This is either root or the blessed pid.
ret = kperf_access_check();
if (ret) {
return ret;
}
break;
}

lck_mtx_lock(&sysctl_buffer_lock);

/* which request */
Expand Down
15 changes: 14 additions & 1 deletion bsd/netinet/tcp_input.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2013 Apple Inc. All rights reserved.
* Copyright (c) 2000-2014 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -3367,6 +3367,19 @@ tcp_input(m, off0)
*/
if (SEQ_LEQ(th->th_ack, tp->snd_una)) {
if (tlen == 0 && tiwin == tp->snd_wnd) {
/*
* If both ends send FIN at the same time,
* then the ack will be a duplicate ack
* but we have to process the FIN. Check
* for this condition and process the FIN
* instead of the dupack
*/
if ((thflags & TH_FIN) &&
(tp->t_flags & TF_SENTFIN) &&
!TCPS_HAVERCVDFIN(tp->t_state) &&
(th->th_ack + 1) == tp->snd_max) {
break;
}
process_dupack:
#if MPTCP
/*
Expand Down
16 changes: 10 additions & 6 deletions bsd/netinet/tcp_output.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2013 Apple Inc. All rights reserved.
* Copyright (c) 2000-2014 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -854,6 +854,7 @@ tcp_output(struct tcpcb *tp)

recwin = tcp_sbspace(tp);


/*
* If the socket is capable of doing unordered send,
* pull the amount of data that can be sent from the
Expand Down Expand Up @@ -992,8 +993,8 @@ tcp_output(struct tcpcb *tp)
* If our state indicates that FIN should be sent
* and we have not yet done so, then we need to send.
*/
if (flags & TH_FIN &&
((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
if ((flags & TH_FIN) &&
(!(tp->t_flags & TF_SENTFIN) || tp->snd_nxt == tp->snd_una))
goto send;
/*
* In SACK, it is possible for tcp_output to fail to send a segment
Expand Down Expand Up @@ -1800,7 +1801,8 @@ tcp_output(struct tcpcb *tp)
if (flags & (TH_SYN|TH_FIN)) {
if (flags & TH_SYN)
tp->snd_nxt++;
if (flags & TH_FIN) {
if ((flags & TH_FIN) &&
!(tp->t_flags & TF_SENTFIN)) {
tp->snd_nxt++;
tp->t_flags |= TF_SENTFIN;
}
Expand Down Expand Up @@ -1832,7 +1834,8 @@ tcp_output(struct tcpcb *tp)
timer:
if (tp->t_timer[TCPT_REXMT] == 0 &&
((sack_rxmit && tp->snd_nxt != tp->snd_max) ||
tp->snd_nxt != tp->snd_una)) {
tp->snd_nxt != tp->snd_una ||
(flags & TH_FIN))) {
if (tp->t_timer[TCPT_PERSIST]) {
tp->t_timer[TCPT_PERSIST] = 0;
tp->t_rxtshift = 0;
Expand All @@ -1849,7 +1852,8 @@ tcp_output(struct tcpcb *tp)
int xlen = len;
if (flags & TH_SYN)
++xlen;
if (flags & TH_FIN) {
if ((flags & TH_FIN) &&
!(tp->t_flags & TF_SENTFIN)) {
++xlen;
tp->t_flags |= TF_SENTFIN;
}
Expand Down
75 changes: 49 additions & 26 deletions bsd/netinet/tcp_timer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2013 Apple Inc. All rights reserved.
* Copyright (c) 2000-2014 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -282,6 +282,8 @@ timer_diff(uint32_t t1, uint32_t toff1, uint32_t t2, uint32_t toff2) {
/* Returns true if the timer is on the timer list */
#define TIMER_IS_ON_LIST(tp) ((tp)->t_flags & TF_TIMER_ONLIST)

/* Run the TCP timerlist atleast once every hour */
#define TCP_TIMERLIST_MAX_OFFSET (60 * 60 * TCP_RETRANSHZ)

static void add_to_time_wait_locked(struct tcpcb *tp, uint32_t delay);
void add_to_time_wait(struct tcpcb *tp, uint32_t delay) ;
Expand Down Expand Up @@ -1107,16 +1109,18 @@ need_to_resched_timerlist(uint32_t runtime, uint16_t index) {
int32_t diff;
boolean_t is_fast;

if (runtime == 0 || index == TCPT_NONE)
if (index == TCPT_NONE)
return FALSE;
is_fast = !(IS_TIMER_SLOW(index));

/* If the list is being processed then the state of the list is in flux.
* In this case always acquire the lock and set the state correctly.
*/
if (listp->running) {
if (listp->running)
return TRUE;
}

if (!listp->scheduled)
return (TRUE);

diff = timer_diff(listp->runtime, 0, runtime, 0);
if (diff <= 0) {
Expand All @@ -1143,12 +1147,16 @@ tcp_sched_timerlist(uint32_t offset)

lck_mtx_assert(listp->mtx, LCK_MTX_ASSERT_OWNED);

offset = min(offset, TCP_TIMERLIST_MAX_OFFSET);
listp->runtime = tcp_now + offset;
if (listp->runtime == 0)
listp->runtime++;

clock_interval_to_deadline(offset, NSEC_PER_SEC / TCP_RETRANSHZ,
&deadline);

thread_call_enter_delayed(listp->call, deadline);
listp->scheduled = TRUE;
}

/* Function to run the timers for a connection.
Expand Down Expand Up @@ -1188,11 +1196,9 @@ tcp_run_conn_timer(struct tcpcb *tp, uint16_t *next_index) {
* with another thread that can cancel or reschedule the timer that is
* about to run. Check if we need to run anything.
*/
index = tp->tentry.index;
timer_val = tp->t_timer[index];

if (index == TCPT_NONE || tp->tentry.runtime == 0)
if ((index = tp->tentry.index) == TCPT_NONE)
goto done;
timer_val = tp->t_timer[index];

diff = timer_diff(tp->tentry.runtime, 0, tcp_now, 0);
if (diff > 0) {
Expand Down Expand Up @@ -1235,8 +1241,8 @@ tcp_run_conn_timer(struct tcpcb *tp, uint16_t *next_index) {
tp->tentry.index = lo_index;
if (lo_index != TCPT_NONE) {
tp->tentry.runtime = tp->tentry.timer_start + tp->t_timer[lo_index];
} else {
tp->tentry.runtime = 0;
if (tp->tentry.runtime == 0)
tp->tentry.runtime++;
}

if (count > 0) {
Expand All @@ -1245,8 +1251,11 @@ tcp_run_conn_timer(struct tcpcb *tp, uint16_t *next_index) {
if (needtorun[i]) {
tp->t_timer[i] = 0;
tp = tcp_timers(tp, i);
if (tp == NULL)
if (tp == NULL) {
offset = 0;
*(next_index) = TCPT_NONE;
goto done;
}
}
}
tcp_set_lotimer_index(tp);
Expand All @@ -1260,6 +1269,7 @@ tcp_run_conn_timer(struct tcpcb *tp, uint16_t *next_index) {
done:
if (tp != NULL && tp->tentry.index == TCPT_NONE) {
tcp_remove_timer(tp);
offset = 0;
}
tcp_unlock(so, 1, 0);
return offset;
Expand Down Expand Up @@ -1288,7 +1298,7 @@ tcp_run_timerlist(void * arg1, void * arg2) {
LIST_FOREACH_SAFE(te, &listp->lhead, le, next_te) {
uint32_t offset = 0;
uint32_t runtime = te->runtime;
if (TSTMP_GT(runtime, tcp_now)) {
if (te->index < TCPT_NONE && TSTMP_GT(runtime, tcp_now)) {
offset = timer_diff(runtime, 0, tcp_now, 0);
if (next_timer == 0 || offset < next_timer) {
next_timer = offset;
Expand Down Expand Up @@ -1384,8 +1394,11 @@ tcp_run_timerlist(void * arg1, void * arg2) {

tcp_sched_timerlist(next_timer);
} else {
/* No need to reschedule this timer */
listp->runtime = 0;
/*
* No need to reschedule this timer, but always run
* periodically at a much higher granularity.
*/
tcp_sched_timerlist(TCP_TIMERLIST_MAX_OFFSET);
}

listp->running = FALSE;
Expand All @@ -1402,7 +1415,7 @@ tcp_sched_timers(struct tcpcb *tp)
struct tcptimerentry *te = &tp->tentry;
uint16_t index = te->index;
struct tcptimerlist *listp = &tcp_timer_list;
uint32_t offset = 0;
int32_t offset = 0;
boolean_t is_fast;
int list_locked = 0;

Expand All @@ -1420,8 +1433,8 @@ tcp_sched_timers(struct tcpcb *tp)
}

is_fast = !(IS_TIMER_SLOW(index));
offset = te->runtime - tcp_now;
if (offset == 0) {
offset = timer_diff(te->runtime, 0, tcp_now, 0);
if (offset <= 0) {
offset = 1;
tcp_timer_advanced++;
}
Expand All @@ -1442,7 +1455,7 @@ tcp_sched_timers(struct tcpcb *tp)
listp->maxentries = listp->entries;

/* if the list is not scheduled, just schedule it */
if (listp->runtime == 0)
if (!listp->scheduled)
goto schedule;

}
Expand All @@ -1464,15 +1477,22 @@ tcp_sched_timers(struct tcpcb *tp)
if (is_fast) {
listp->pref_mode = TCP_TIMERLIST_FASTMODE;
} else if (listp->pref_offset == 0 ||
((int)offset) < listp->pref_offset) {
offset < listp->pref_offset) {
listp->pref_offset = offset;
}
} else {
int32_t diff;
diff = timer_diff(listp->runtime, 0, tcp_now, offset);
if (diff <= 0) {
/* The list is going to run before this timer */
goto done;
/*
* The list could have got scheduled while this
* thread was waiting for the lock
*/
if (listp->scheduled) {
int32_t diff;
diff = timer_diff(listp->runtime, 0,
tcp_now, offset);
if (diff <= 0)
goto done;
else
goto schedule;
} else {
goto schedule;
}
Expand Down Expand Up @@ -1508,8 +1528,8 @@ tcp_set_lotimer_index(struct tcpcb *tp) {
tp->tentry.index = lo_index;
if (lo_index != TCPT_NONE) {
tp->tentry.runtime = tp->tentry.timer_start + tp->t_timer[lo_index];
} else {
tp->tentry.runtime = 0;
if (tp->tentry.runtime == 0)
tp->tentry.runtime++;
}
}

Expand All @@ -1518,6 +1538,9 @@ tcp_check_timer_state(struct tcpcb *tp) {

lck_mtx_assert(&tp->t_inpcb->inpcb_mtx, LCK_MTX_ASSERT_OWNED);

if (tp->t_inpcb->inp_flags2 & INP2_TIMEWAIT)
return;

tcp_set_lotimer_index(tp);

tcp_sched_timers(tp);
Expand Down
3 changes: 2 additions & 1 deletion bsd/netinet/tcp_timer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2010 Apple Computer, Inc. All rights reserved.
* Copyright (c) 2000-2014 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -208,6 +208,7 @@ struct tcptimerlist {

/* Set desired mode when timer list running */
boolean_t running; /* Set when timer list is being processed */
boolean_t scheduled; /* Set when timer is scheduled */
#define TCP_TIMERLIST_FASTMODE 0x1
#define TCP_TIMERLIST_SLOWMODE 0x2
uint32_t mode; /* Current mode, fast or slow */
Expand Down
2 changes: 1 addition & 1 deletion config/MasterVersion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
13.2.0
13.3.0

# The first line of this file contains the master version number for the kernel.
# All other instances of the kernel version in xnu are derived from this file.
Expand Down
3 changes: 3 additions & 0 deletions iokit/IOKit/IOHibernatePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref,
off_t discard_offset, off_t discard_end);
#endif /* _SYS_CONF_H_ */

void
vm_compressor_do_warmup(void);

hibernate_page_list_t *
hibernate_page_list_allocate(boolean_t log);

Expand Down
Loading

0 comments on commit 2a67609

Please sign in to comment.