michael@0: /*- michael@0: * Copyright (c) 2009-2010 Brad Penoff michael@0: * Copyright (c) 2009-2010 Humaira Kamal michael@0: * Copyright (c) 2011-2012 Irene Ruengeler michael@0: * Copyright (c) 2011-2012 Michael Tuexen michael@0: * michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND michael@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE michael@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL michael@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS michael@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT michael@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY michael@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@0: * SUCH DAMAGE. michael@0: */ michael@0: michael@0: /* __Userspace__ */ michael@0: michael@0: #include michael@0: #if !defined (__Userspace_os_Windows) michael@0: #include michael@0: #include michael@0: #endif michael@0: #include michael@0: #include michael@0: /* #include defines MIN */ michael@0: #if !defined(MIN) michael@0: #define MIN(arg1,arg2) ((arg1) < (arg2) ? (arg1) : (arg2)) michael@0: #endif michael@0: #include michael@0: michael@0: #define uHZ 1000 michael@0: michael@0: /* See user_include/user_environment.h for comments about these variables */ michael@0: int maxsockets = 25600; michael@0: int hz = uHZ; michael@0: int ip_defttl = 64; michael@0: int ipport_firstauto = 49152, ipport_lastauto = 65535; michael@0: int nmbclusters = 65536; michael@0: michael@0: /* Source ip_output.c. extern'd in ip_var.h */ michael@0: u_short ip_id = 0; /*__Userspace__ TODO Should it be initialized to zero? */ michael@0: michael@0: /* used in user_include/user_atomic.h in order to make the operations michael@0: * defined there truly atomic michael@0: */ michael@0: userland_mutex_t atomic_mtx; michael@0: michael@0: /* Source: /usr/src/sys/dev/random/harvest.c */ michael@0: static int read_random_phony(void *, int); michael@0: michael@0: static int (*read_func)(void *, int) = read_random_phony; michael@0: michael@0: /* Userland-visible version of read_random */ michael@0: int michael@0: read_random(void *buf, int count) michael@0: { michael@0: return ((*read_func)(buf, count)); michael@0: } michael@0: michael@0: /* If the entropy device is not loaded, make a token effort to michael@0: * provide _some_ kind of randomness. This should only be used michael@0: * inside other RNG's, like arc4random(9). michael@0: */ michael@0: static int michael@0: read_random_phony(void *buf, int count) michael@0: { michael@0: uint32_t randval; michael@0: int size, i; michael@0: michael@0: /* srandom() is called in kern/init_main.c:proc0_post() */ michael@0: michael@0: /* Fill buf[] with random(9) output */ michael@0: for (i = 0; i < count; i+= (int)sizeof(uint32_t)) { michael@0: randval = random(); michael@0: size = MIN(count - i, (int)sizeof(uint32_t)); michael@0: memcpy(&((char *)buf)[i], &randval, (size_t)size); michael@0: } michael@0: michael@0: return (count); michael@0: } michael@0: