Skip to content

Commit

Permalink
xnu-2050.48.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Jun 4, 2017
1 parent 2b43307 commit c505eec
Show file tree
Hide file tree
Showing 91 changed files with 1,843 additions and 933 deletions.
28 changes: 27 additions & 1 deletion bsd/dev/i386/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
#include <i386/cpuid.h>
#include <i386/tsc.h>
#include <i386/machine_routines.h>
#include <i386/pal_routines.h>
#include <i386/ucode.h>
#include <kern/clock.h>
#include <libkern/libkern.h>
#include <i386/lapic.h>
#include <i386/pmCPU.h>


static int
_i386_cpu_info SYSCTL_HANDLER_ARGS
Expand Down Expand Up @@ -730,7 +733,30 @@ SYSCTL_QUAD(_machdep_memmap, OID_AUTO, Other, CTLFLAG_RD|CTLFLAG_LOCKED, &firmwa

SYSCTL_NODE(_machdep, OID_AUTO, tsc, CTLFLAG_RD|CTLFLAG_LOCKED, NULL, "Timestamp counter parameters");

SYSCTL_QUAD(_machdep_tsc, OID_AUTO, frequency, CTLFLAG_RD|CTLFLAG_LOCKED, &tscFreq, "");
SYSCTL_QUAD(_machdep_tsc, OID_AUTO, frequency,
CTLFLAG_RD|CTLFLAG_LOCKED, &tscFreq, "");

extern uint32_t deep_idle_rebase;
SYSCTL_UINT(_machdep_tsc, OID_AUTO, deep_idle_rebase,
CTLFLAG_RW|CTLFLAG_KERN|CTLFLAG_LOCKED, &deep_idle_rebase, 0, "");

SYSCTL_NODE(_machdep_tsc, OID_AUTO, nanotime,
CTLFLAG_RD|CTLFLAG_LOCKED, NULL, "TSC to ns conversion");
SYSCTL_QUAD(_machdep_tsc_nanotime, OID_AUTO, tsc_base,
CTLFLAG_RD | CTLFLAG_LOCKED,
(uint64_t *) &pal_rtc_nanotime_info.tsc_base, "");
SYSCTL_QUAD(_machdep_tsc_nanotime, OID_AUTO, ns_base,
CTLFLAG_RD | CTLFLAG_LOCKED,
(uint64_t *)&pal_rtc_nanotime_info.ns_base, "");
SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, scale,
CTLFLAG_RD | CTLFLAG_LOCKED,
(uint32_t *)&pal_rtc_nanotime_info.scale, 0, "");
SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, shift,
CTLFLAG_RD | CTLFLAG_LOCKED,
(uint32_t *)&pal_rtc_nanotime_info.shift, 0, "");
SYSCTL_UINT(_machdep_tsc_nanotime, OID_AUTO, generation,
CTLFLAG_RD | CTLFLAG_LOCKED,
(uint32_t *)&pal_rtc_nanotime_info.generation, 0, "");

SYSCTL_NODE(_machdep, OID_AUTO, misc, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
"Miscellaneous x86 kernel parameters");
Expand Down
47 changes: 38 additions & 9 deletions bsd/dev/random/randomdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <dev/random/YarrowCoreLib/include/yarrow.h>

#include <libkern/OSByteOrder.h>
#include <libkern/OSAtomic.h>

#include <mach/mach_time.h>
#include <machine/machine_routines.h>
Expand Down Expand Up @@ -101,13 +102,14 @@ static struct cdevsw random_cdevsw =


/* Used to detect whether we've already been initialized */
static int gRandomInstalled = 0;
static UInt8 gRandomInstalled = 0;
static PrngRef gPrngRef;
static int gRandomError = 1;
static lck_grp_t *gYarrowGrp;
static lck_attr_t *gYarrowAttr;
static lck_grp_attr_t *gYarrowGrpAttr;
static lck_mtx_t *gYarrowMutex = 0;
static UInt8 gYarrowInitializationLock = 0;

#define RESEED_TICKS 50 /* how long a reseed operation can take */

Expand Down Expand Up @@ -307,6 +309,27 @@ PreliminarySetup(void)
{
prng_error_status perr;

/* Multiple threads can enter this as a result of an earlier
* check of gYarrowMutex. We make sure that only one of them
* can enter at a time. If one of them enters and discovers
* that gYarrowMutex is no longer NULL, we know that another
* thread has initialized the Yarrow state and we can exit.
*/

/* The first thread that enters this function will find
* gYarrowInitializationLock set to 0. It will atomically
* set the value to 1 and, seeing that it was zero, drop
* out of the loop. Other threads will see that the value is
* 1 and continue to loop until we are initialized.
*/

while (OSTestAndSet(0, &gYarrowInitializationLock)); /* serialize access to this function */

if (gYarrowMutex) {
/* we've already been initialized, clear and get out */
goto function_exit;
}

/* create a Yarrow object */
perr = prngInitialize(&gPrngRef);
if (perr != 0) {
Expand All @@ -321,6 +344,8 @@ PreliminarySetup(void)
char buffer [16];

/* get a little non-deterministic data as an initial seed. */
/* On OSX, securityd will add much more entropy as soon as it */
/* comes up. On iOS, entropy is added with each system interrupt. */
microtime(&tt);

/*
Expand All @@ -334,7 +359,7 @@ PreliminarySetup(void)
if (perr != 0) {
/* an error, complain */
printf ("Couldn't seed Yarrow.\n");
return;
goto function_exit;
}

/* turn the data around */
Expand All @@ -350,6 +375,10 @@ PreliminarySetup(void)
gYarrowMutex = lck_mtx_alloc_init(gYarrowGrp, gYarrowAttr);

fips_initialize ();

function_exit:
/* allow other threads to figure out whether or not we have been initialized. */
gYarrowInitializationLock = 0;
}

const Block kKnownAnswer = {0x92, 0xb4, 0x04, 0xe5, 0x56, 0x58, 0x8c, 0xed, 0x6c, 0x1a, 0xcd, 0x4e, 0xbf, 0x05, 0x3f, 0x68, 0x09, 0xf7, 0x3a, 0x93};
Expand Down Expand Up @@ -384,14 +413,11 @@ random_init(void)
{
int ret;

if (gRandomInstalled)
if (OSTestAndSet(0, &gRandomInstalled)) {
/* do this atomically so that it works correctly with
multiple threads */
return;

/* install us in the file system */
gRandomInstalled = 1;

/* setup yarrow and the mutex */
PreliminarySetup();
}

ret = cdevsw_add(RANDOM_MAJOR, &random_cdevsw);
if (ret < 0) {
Expand All @@ -409,6 +435,9 @@ random_init(void)
*/
devfs_make_node(makedev (ret, 1), DEVFS_CHAR,
UID_ROOT, GID_WHEEL, 0666, "urandom", 0);

/* setup yarrow and the mutex if needed*/
PreliminarySetup();
}

int
Expand Down
58 changes: 34 additions & 24 deletions bsd/hfs/hfs_cnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,31 @@ int hfs_cnode_teardown (struct vnode *vp, vfs_context_t ctx, int reclaim) {
(cp->c_flag & C_DELETED) &&
((forkcount == 1) || (!VNODE_IS_RSRC(vp)))) {

/* Start a transaction here. We're about to change file sizes */
if (started_tr == 0) {
if (hfs_start_transaction(hfsmp) != 0) {
error = EINVAL;
goto out;
}
else {
started_tr = 1;
}
}

/* Truncate away our own fork data. (Case A, B, C above) */
if (VTOF(vp)->ff_blocks != 0) {


/*
* SYMLINKS only:
*
* Encapsulate the entire change (including truncating the link) in
* nested transactions if we are modifying a symlink, because we know that its
* file length will be at most 4k, and we can fit both the truncation and
* any relevant bitmap changes into a single journal transaction. We also want
* the kill_block code to execute in the same transaction so that any dirty symlink
* blocks will not be written. Otherwise, rely on
* hfs_truncate doing its own transactions to ensure that we don't blow up
* the journal.
*/
if ((started_tr == 0) && (v_type == VLNK)) {
if (hfs_start_transaction(hfsmp) != 0) {
error = EINVAL;
goto out;
}
else {
started_tr = 1;
}
}

/*
* At this point, we have decided that this cnode is
* suitable for full removal. We are about to deallocate
Expand All @@ -348,28 +359,33 @@ int hfs_cnode_teardown (struct vnode *vp, vfs_context_t ctx, int reclaim) {
if (hfsmp->jnl && vnode_islnk(vp)) {
buf_iterate(vp, hfs_removefile_callback, BUF_SKIP_NONLOCKED, (void *)hfsmp);
}

/*
* Since we're already inside a transaction,
* tell hfs_truncate to skip the ubc_setsize.
*
* This truncate call (and the one below) is fine from VNOP_RECLAIM's
* context because we're only removing blocks, not zero-filling new
* ones. The C_DELETED check above makes things much simpler.
*/
error = hfs_truncate(vp, (off_t)0, IO_NDELAY, 1, 0, ctx);
error = hfs_truncate(vp, (off_t)0, IO_NDELAY, 0, 0, ctx);
if (error) {
goto out;
}
truncated = 1;

/* (SYMLINKS ONLY): Close/End our transaction after truncating the file record */
if (started_tr) {
hfs_end_transaction(hfsmp);
started_tr = 0;
}
}

/*
* Truncate away the resource fork, if we represent the data fork and
* it is the last fork. That means, by definition, the rsrc fork is not in
* core. To avoid bringing a vnode into core for the sole purpose of deleting the
* data in the resource fork, we call cat_lookup directly, then hfs_release_storage
* to get rid of the resource fork's data.
* to get rid of the resource fork's data. Note that because we are holding the
* cnode lock, it is impossible for a competing thread to create the resource fork
* vnode from underneath us while we do this.
*
* This is invoked via case A above only.
*/
Expand Down Expand Up @@ -441,12 +457,6 @@ int hfs_cnode_teardown (struct vnode *vp, vfs_context_t ctx, int reclaim) {
*/
cp->c_blocks = 0;
}

/* End the transaction from the start of the file truncation segment */
if (started_tr) {
hfs_end_transaction(hfsmp);
started_tr = 0;
}
}

/*
Expand Down
20 changes: 13 additions & 7 deletions bsd/hfs/hfs_hotfiles.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2008 Apple Inc. All rights reserved.
* Copyright (c) 2003-2013 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -207,8 +207,8 @@ hfs_recording_start(struct hfsmount *hfsmp)
(SWAP_BE32 (hotfileinfo.timeleft) > 0) &&
(SWAP_BE32 (hotfileinfo.timebase) > 0)) {
hfsmp->hfc_maxfiles = SWAP_BE32 (hotfileinfo.maxfilecnt);
hfsmp->hfc_timeout = SWAP_BE32 (hotfileinfo.timeleft) + tv.tv_sec ;
hfsmp->hfc_timebase = SWAP_BE32 (hotfileinfo.timebase);
hfsmp->hfc_timeout = SWAP_BE32 (hotfileinfo.timeleft) + tv.tv_sec ;
/* Fix up any bogus timebase values. */
if (hfsmp->hfc_timebase < HFC_MIN_BASE_TIME) {
hfsmp->hfc_timebase = hfsmp->hfc_timeout - HFC_DEFAULT_DURATION;
Expand Down Expand Up @@ -792,7 +792,8 @@ hfs_addhotfile_internal(struct vnode *vp)
if (hfsmp->hfc_stage != HFC_RECORDING)
return (0);

if ((!vnode_isreg(vp) && !vnode_islnk(vp)) || vnode_issystem(vp)) {
/* Only regular files are allowed for hotfile inclusion ; symlinks disallowed */
if ((!vnode_isreg(vp)) || vnode_issystem(vp)) {
return (0);
}
/* Skip resource forks for now. */
Expand Down Expand Up @@ -862,7 +863,8 @@ hfs_removehotfile(struct vnode *vp)
if (hfsmp->hfc_stage != HFC_RECORDING)
return (0);

if ((!vnode_isreg(vp) && !vnode_islnk(vp)) || vnode_issystem(vp)) {
/* Only regular files can move out of hotfiles */
if ((!vnode_isreg(vp)) || vnode_issystem(vp)) {
return (0);
}

Expand Down Expand Up @@ -904,7 +906,7 @@ hfs_removehotfile(struct vnode *vp)
static int
hotfiles_collect_callback(struct vnode *vp, __unused void *cargs)
{
if ((vnode_isreg(vp) || vnode_islnk(vp)) && !vnode_issystem(vp))
if ((vnode_isreg(vp)) && !vnode_issystem(vp))
(void) hfs_addhotfile_internal(vp);

return (VNODE_RETURNED);
Expand Down Expand Up @@ -1138,7 +1140,9 @@ hotfiles_adopt(struct hfsmount *hfsmp)
}
break;
}
if (!vnode_isreg(vp) && !vnode_islnk(vp)) {

/* only regular files are eligible */
if (!vnode_isreg(vp)) {
printf("hfs: hotfiles_adopt: huh, not a file %d (%d)\n", listp->hfl_hotfile[i].hf_fileid, VTOC(vp)->c_cnid);
hfs_unlock(VTOC(vp));
vnode_put(vp);
Expand Down Expand Up @@ -1361,7 +1365,9 @@ hotfiles_evict(struct hfsmount *hfsmp, vfs_context_t ctx)
}
break;
}
if (!vnode_isreg(vp) && !vnode_islnk(vp)) {

/* only regular files are eligible */
if (!vnode_isreg(vp)) {
printf("hfs: hotfiles_evict: huh, not a file %d\n", key->fileID);
hfs_unlock(VTOC(vp));
vnode_put(vp);
Expand Down
8 changes: 4 additions & 4 deletions bsd/hfs/hfs_readwrite.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2012 Apple Inc. All rights reserved.
* Copyright (c) 2000-2013 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
Expand Down Expand Up @@ -4391,7 +4391,8 @@ hfs_relocate(struct vnode *vp, u_int32_t blockHint, kauth_cred_t cred,
enum vtype vnodetype;

vnodetype = vnode_vtype(vp);
if (vnodetype != VREG && vnodetype != VLNK) {
if (vnodetype != VREG) {
/* Note symlinks are not allowed to be relocated */
return (EPERM);
}

Expand Down Expand Up @@ -4424,8 +4425,7 @@ hfs_relocate(struct vnode *vp, u_int32_t blockHint, kauth_cred_t cred,
if (blockHint == 0)
blockHint = hfsmp->nextAllocation;

if ((fp->ff_size > 0x7fffffff) ||
((fp->ff_size > blksize) && vnodetype == VLNK)) {
if ((fp->ff_size > 0x7fffffff)) {
return (EFBIG);
}

Expand Down
4 changes: 3 additions & 1 deletion bsd/kern/kdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2459,13 +2459,15 @@ stack_snapshot2(pid_t pid, user_addr_t tracebuf, uint32_t tracebuf_size, uint32_
}

void
start_kern_tracing(unsigned int new_nkdbufs) {
start_kern_tracing(unsigned int new_nkdbufs, boolean_t need_map) {

if (!new_nkdbufs)
return;
nkdbufs = kdbg_set_nkdbufs(new_nkdbufs);
kdbg_lock_init();
kdbg_reinit(TRUE);
if (need_map == TRUE)
kdbg_mapinit();
kdbg_set_tracing_enabled(TRUE, KDEBUG_ENABLE_TRACE);

#if defined(__i386__) || defined(__x86_64__)
Expand Down
Loading

0 comments on commit c505eec

Please sign in to comment.