Commit graph

367 commits

Author SHA1 Message Date
Pedro F. Giffuni b85f65af68 kern: for pointers replace 0 with NULL.
These are mostly cosmetical, no functional change.

Found with devel/coccinelle.
2016-04-15 16:10:11 +00:00
Conrad Meyer 65327c21ed libkern: ffs, fls: s/4/3/ the 3rd BSD clause
Approved by:	emaste
Sponsored by:	EMC / Isilon Storage Division
2015-10-22 21:04:47 +00:00
Conrad Meyer 3d3e385e75 Add libkern ffsll() for parity with flsll()
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D3962
2015-10-22 20:28:37 +00:00
Andrew Turner 756508c7f6 Add the __aeabi_memclr8 symbol, clang 3.7 uses this.
MFC after:	1 week
Sponsored by:	ABT Systems Lts
2015-09-21 18:35:32 +00:00
Andrew Turner 3303004f1a Remove checks for __ARM_EABI__, we only build for EABI now.
Sponsored by:	ABT Systems Ltd
2015-07-09 21:02:40 +00:00
Andrew Turner 6c50960be6 Add support for __aeabi_memclr4, clang 3.7 calls it.
Sponsored by:	ABT Systems Ltd
2015-07-09 20:54:38 +00:00
Mark Murray d1b06863fb Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
  neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
  random(4) device in the kernel, and the KERN_ARND sysctl will
  return nothing. With RANDOM_DUMMY there will be a random(4) that
  always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
  through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
  suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
  functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
  This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
  there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
  behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
  (direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
  weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
  weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
  when the dust settles.
- Use macros for locks.
- Fix comments.

* src/share/man/...
- Update the man pages.

* src/etc/...
- The startup/shutdown work is done in D2924.

* src/UPDATING
- Add UPDATING announcement.

* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.

* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.

* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.

* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
  selection is the way to go.

* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.

* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.

* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
  that instead. All that is needed here is N=0, N++, N==0, and some
  localised trickery is used to manufacture a 128-bit 0ULLL.

* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
  now the test will do a basic check of compressibility. Clairvoyant
  talent is still a good idea.
- This is still a long way off a proper unit test.

* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
  it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
  functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])

* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
  it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
  functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.

Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00
Andrew Turner 97f8390e7d Add more __aeabi_memcpy functions, later versions of clang generate calls
to these functions.
2015-05-31 07:31:20 +00:00
Craig Rodrigues d9db52256e Move zlib.c from net to libkern.
It is not network-specific code and would
be better as part of libkern instead.
Move zlib.h and zutil.h from net/ to sys/
Update includes to use sys/zlib.h and sys/zutil.h instead of net/

Submitted by:		Steve Kiernan stevek@juniper.net
Obtained from:		Juniper Networks, Inc.
GitHub Pull Request:	https://github.com/freebsd/freebsd/pull/28
Relnotes:		yes
2015-04-22 14:38:58 +00:00
Ryan Stone 3cd4533107 Implement asprintf in libkern
Differential Revision:		https://reviews.freebsd.org/D1877
Reviewed by:			pjd, jfv
MFC After:			1 month
Sponsored by:			Sandvine Inc.
2015-03-01 00:22:16 +00:00
Dimitry Andric 0b77a417c8 Similar to r277901, fix more -Wcast-qual warnings in libkern's strtoq(),
strtoul() and strtouq(), by using __DECONST.  No functional change.

MFC after:	3 days
2015-01-29 21:54:01 +00:00
Dimitry Andric b94d92e5c8 Fix a -Wcast-qual warning in libkern's strtol(), by using __DECONST. No
functional change.

MFC after:	3 days
2015-01-29 21:16:45 +00:00
John-Mark Gurney 08fca7a56b Add some new modes to OpenCrypto. These modes are AES-ICM (can be used
for counter mode), and AES-GCM.  Both of these modes have been added to
the aesni module.

Included is a set of tests to validate that the software and aesni
module calculate the correct values.  These use the NIST KAT test
vectors.  To run the test, you will need to install a soon to be
committed port, nist-kat that will install the vectors.  Using a port
is necessary as the test vectors are around 25MB.

All the man pages were updated.  I have added a new man page, crypto.7,
which includes a description of how to use each mode.  All the new modes
and some other AES modes are present.  It would be good for someone
else to go through and document the other modes.

A new ioctl was added to support AEAD modes which AES-GCM is one of them.
Without this ioctl, it is not possible to test AEAD modes from userland.

Add a timing safe bcmp for use to compare MACs.  Previously we were using
bcmp which could leak timing info and result in the ability to forge
messages.

Add a minor optimization to the aesni module so that single segment
mbufs don't get copied and instead are updated in place.  The aesni
module needs to be updated to support blocked IO so segmented mbufs
don't have to be copied.

We require that the IV be specified for all calls for both GCM and ICM.
This is to ensure proper use of these functions.

Obtained from:	p4: //depot/projects/opencrypto
Relnotes:	yes
Sponsored by:	FreeBSD Foundation
Sponsored by:	NetGate
2014-12-12 19:56:36 +00:00
Andrew Turner 524bca9008 Use the unified syntax in a few more assembly files
MFC after:	1 week
Sponsored by:	ABT Systems Ltd
2014-12-05 19:08:36 +00:00
Xin LI 4facd36ca0 Sync with userland variant.
MFC after:	2 weeks
2014-11-17 21:01:35 +00:00
Dag-Erling Smørgrav 99e9de871a Add a complete implementation of MurmurHash3. Tweak both implementations
so they match the established idiom.  Document them in hash(9).

MFC after:	1 month
MFC with:	r272906
2014-10-18 22:15:11 +00:00
Xin LI d427f43c25 Remove duplicated code.
Suggested by:	jmg
2014-10-16 22:04:07 +00:00
George V. Neville-Neil 1d2baefc13 Change the PF hash from Jenkins to Murmur3. In forwarding tests
this showed a conservative 3% incrase in PPS.

Differential Revision:	https://reviews.freebsd.org/D461
Submitted by:	des
Reviewed by:	emaste
MFC after:	1 month
2014-10-10 19:26:26 +00:00
Xin LI 78b59024b5 Add explicit_bzero(3) and its kernel counterpart.
Obtained from:	OpenBSD
MFC after:	2 weeks
2014-10-07 04:54:11 +00:00
Bjoern A. Zeeb afa0a6efe0 Use __DECONST to avoid compiler warnings (and thus build failures)
with gcc on sparc64, mips, and powerpc after r271173.
2014-09-08 08:12:09 +00:00
Benno Rice 27ecc2adbc Add support for gdb's memory searching capabilities to our in-kernel gdb
server.

Submitted by:	Daniel O'Connor <daniel.oconnor@isilon.com>
Reviewed by:	jhb
Sponsored by:	EMC Isilon Storage Division
2014-09-05 16:40:47 +00:00
Edward Tomasz Napierala 3914ddf8a7 Bring in the new automounter, similar to what's provided in most other
UNIX systems, eg. MacOS X and Solaris.  It uses Sun-compatible map format,
has proper kernel support, and LDAP integration.

There are still a few outstanding problems; they will be fixed shortly.

Reviewed by:	allanjude@, emaste@, kib@, wblock@ (earlier versions)
Phabric:	D523
MFC after:	2 weeks
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
2014-08-17 09:44:42 +00:00
Ian Lepore 25166187e3 Fix unwind-info errors in our hand-written arm assembler code.
We have functions nested within functions, and places where we start a
function then never end it, we just jump to the middle of something else.
We tried to express this with nested ENTRY()/END() macros (which result
in .fnstart and .fnend directives), but it turns out there's no way to
express that nesting in ARM EHABI unwind info, and newer tools treat
multiple .fnstart directives without an intervening .fnend as an error.

These changes introduce two new macros, EENTRY() and EEND().  EENTRY()
creates a global label you can call/jump to just like ENTRY(), but it
doesn't emit a .fnstart.  EEND() is a no-op that just documents the
conceptual endpoint that matches up with the same-named EENTRY().

This is based on patches submitted by Stepan Dyatkovskiy, but I made some
changes and added the EEND() stuff, so blame any problems on me.

Submitted by:	Stepan Dyatkovskiy <stpworld@narod.ru>
2014-08-01 18:24:44 +00:00
Marcel Moolenaar e7d939bda2 Remove ia64.
This includes:
o   All directories named *ia64*
o   All files named *ia64*
o   All ia64-specific code guarded by __ia64__
o   All ia64-specific makefile logic
o   Mention of ia64 in comments and documentation

This excludes:
o   Everything under contrib/
o   Everything under crypto/
o   sys/xen/interface
o   sys/sys/elf_common.h

Discussed at: BSDcan
2014-07-07 00:27:09 +00:00
John Baldwin 0cbce0671e Use strcasecmp() instead of strcmp() when checking user-supplied encoding
names so that encoding names are treated as case-insensitive.  This allows
the use of 'utf-8' instead of 'UTF-8' for example and matches the behavior
of iconv(1).

PR:		167977
Submitted by:	buganini@gmail.com
MFC after:	1 week
2014-06-09 19:27:47 +00:00
Eitan Adler 04660ed15f Fix typo
Reported by:	emaste
2013-11-29 20:14:26 +00:00
Eitan Adler 5c41c9d246 Fix typo
Reported by:	swildner@DragonFlyBSD.org
2013-11-29 20:12:02 +00:00
Andrew Turner ca49624410 Fix ixp425 boot2 with ARM EABI:
- libkern is missing __aeabi_llsl, implement this by calling __ashldi3.
 - Because of how the asm entry macros are defined the boot2 code
   requires the unwind symbols to exist, include them in boot2.

Approved by:	re (marius)
2013-09-29 15:19:34 +00:00
Alfred Perlstein 3d30404f83 Fix watchdog pretimeout.
The original API calls for pow2ns, however the new APIs from
Linux call for seconds.

We need to be able to convert to/from 2^Nns to seconds in both
userland and kernel to fix this and properly compare units.
2013-07-27 20:47:01 +00:00
Andrey A. Chernov 2b50ce65be Attempt to mitigate poor initialization of arc4 by one-shot
reinitialization from yarrow right after good entropy is harvested.

Approved by:    secteam (delphij)
MFC after:      1 week
2013-04-19 00:30:52 +00:00
Andrew Turner 69d758b4b8 Add __aeabi_memset to libkern, implemented using memset, as clang may
generate calls to it.
2013-03-16 23:11:55 +00:00
Andrew Turner a2dee2ad37 Add END to ARM libkern assembly functions 2013-03-16 04:08:01 +00:00
Andrew Turner 5cc8d54ca0 Move the __aeabi_unwind_cpp_pr{0,1,2} functions to libkern so they can be
referenced in a non-debug kernel.
2013-03-16 04:06:49 +00:00
Andrew Turner 530bff3f19 Add __aeabi_memcpy to libkern as clang may generate calls to it. 2013-03-10 07:55:40 +00:00
Andrew Turner 31735bf308 Add __aeabi_ulcmp to allow building of the LINT kernel. 2013-01-23 09:18:18 +00:00
Andrew Turner 46d741dc7f Add the required __aeabi_* functions the kernel uses when built for ARM EABI 2013-01-17 09:37:42 +00:00
Xin LI 299ff0d7cc Sync strlcpy with userland version.
MFC after:	1 month
2012-11-03 04:29:24 +00:00
Xin LI 6afdae4139 Sync strlen with userland implementation.
MFC after:	1 month
2012-11-03 04:28:53 +00:00
Eitan Adler 0af1b47258 s/ is is / is /g
s/ a a / a /g

Approved by:	cperciva
MFC after:	3 days
2012-09-14 22:00:03 +00:00
Gleb Smirnoff 62208ca5d2 - Move jenkins.h to jenkins_hash.c
- Provide missing function that can do hashing of arbitrary sized buffer.
- Refetch lookup3.c and do only minimal edits to it, so that diff between
  our jenkins_hash.c and lookup3.c is minimal.
- Add declarations for jenkins_hash(), jenkins_hash32() to sys/hash.h.
- Document these functions in hash(9)

Obtained from:	http://burtleburtle.net/bob/c/lookup3.c
2012-09-04 12:07:33 +00:00
Mateusz Guzik 414d9b2ed0 Fix unloading of libiconv module.
Previously it would either loop infinitely or exit with error leaking a lock.

Reported by:	Will DeVries
Approved by:	trasz (mentor)
MFC after:	1 week
2012-06-11 17:42:39 +00:00
Kevin Lo fa27760e2e Use strcmp that I replaced by accident. 2012-05-21 02:45:47 +00:00
Kevin Lo 040b0e4eda Fix broken ref count
Submitted by:	gcooper
2012-05-21 02:41:15 +00:00
Kevin Lo f529372e8a Fix improper handling of variadic args with ICDEBUG
PR:	kern/168095
Submitted by:	gcooper
2012-05-21 02:30:22 +00:00
Kevin Lo bc6f23e0ad Remove dead code 2012-05-21 02:23:20 +00:00
Marius Strobl f7b9ae0882 Remove second consts in r233288 in order to appease C++ compilers.
While at it, remove some style(9) bugs in libkern.h.

Submitted by:	kan
2012-03-26 18:22:04 +00:00
Marius Strobl cc0c154ffb Declare the CRC lookup-tables const as they hardly should change at
run-time.
2012-03-21 20:55:21 +00:00
Ed Schouten 22fec34a57 Implement extensions on top of standards instead of the other way around.
Now that index() and rindex() have become unused, simply turn them into
wrappers around strchr() and strrchr(), respectively.
2012-01-03 07:05:30 +00:00
Ed Schouten dc15eac046 Use strchr() and strrchr().
It seems strchr() and strrchr() are used more often than index() and
rindex(). Therefore, simply migrate all kernel code to use it.

For the XFS code, remove an empty line to make the code identical to
the code in the Linux kernel.
2012-01-02 12:12:10 +00:00
Ed Schouten 41adcfa1d0 Remove the now unused skpc() function.
It was only used by ufs and ext2 and I have really strong doubts that
there are other pieces of code that also use this function. If it turns
out that external drivers use this code as well, I'd be happy to migrate
or revert.

Bump __FreeBSD_version while there.
2012-01-01 20:54:44 +00:00
Ed Schouten de85bfc508 Introducing memcchr(3).
It seems two of the file system drivers we have in the tree, namely ufs
and ext3, use a function called `skpc()'. The meaning of this function
does not seem to be documented in FreeBSD, but it turns out one needs to
be a VAX programmer to understand what it does.

SPKC is an instruction on the VAX that does the opposite of memchr(). It
searches for the non-equal character. Add a new function called
memcchr() to the tree that has the following advantages over skpc():

- It has a name that makes more sense than skpc(). Just like strcspn()
  matches the complement of strspn(), memcchr() is the complement of
  memchr().

- It is faster than skpc(). Similar to our strlen() in libc, it compares
  entire words, instead of single bytes. It seems that for this routine
  this yields a sixfold performance increase on amd64.

- It has a man page.
2012-01-01 20:26:11 +00:00
Andriy Gapon 6aa40c0146 retire libkern gets
Inspired by:	bde
MFC after:	2 months
X-MFC-Note:	if deemed a part of KPI, just call cngets internally
2011-12-17 15:48:55 +00:00
Kevin Lo 41f1dccceb Add unicode support to msdosfs and smbfs; original pathes from imura,
bug fixes by Kuan-Chung Chiu <buganini at gmail dot com>.

Tested by me in production for several days at work.
2011-11-18 03:05:20 +00:00
Ed Schouten d745c852be Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.
This means that their use is restricted to a single C file.
2011-11-07 06:44:47 +00:00
Jung-uk Kim f359758c4e Add strnlen() to libkern. 2011-10-04 23:53:47 +00:00
Rebecca Cran 974206cf70 Fix typos - remove duplicate "is".
PR:		docs/154934
Submitted by:	Eitan Adler <lists at eitanadler.com>
MFC after:	3 days
2011-02-23 09:22:33 +00:00
Ed Schouten eb4c31fd41 Add support for asterisk characters when filling in the GELI password
during boot.

Change the last argument of gets() to indicate a visibility flag and add
definitions for the numerical constants. Except for the value 2, gets()
will behave exactly the same, so existing consumers shouldn't break. We
only use it in two places, though.

Submitted by:	lme (older version)
2010-11-14 14:12:43 +00:00
Attilio Rao 109c1de8ba Make the RPC specific __rpc_inet_ntop() and __rpc_inet_pton() general
in the kernel (just as inet_ntoa() and inet_aton()) are and sync their
prototype accordingly with already mentioned functions.

Sponsored by:	Sandvine Incorporated
Reviewed by:	emaste, rstone
Approved by:	dfr
MFC after:	2 weeks
2010-09-24 15:01:45 +00:00
Rafal Jaworowski 1b1270176e Provide memchr() in the libkern.
This is required by libfdt and will be compiled in conditionally only for
FDT-enabled platforms.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
2010-06-02 17:27:23 +00:00
Joel Dahl d122d78412 Switch to our preferred 2-clause BSD license.
Approved by:	bp
2010-04-07 16:50:38 +00:00
Joel Dahl c0587701ad Start copyright notice with /*- 2010-04-07 16:29:10 +00:00
Attilio Rao 758801232c Move inet_aton() (specular to inet_ntoa(), already present in libkern)
into libkern in order to made it usable by other modules than alias_proxy.

Obtained from:	Sandvine Incorporated
Sponsored by:	Sandvine Incorporated
MFC:		1 week
2009-11-12 00:46:28 +00:00
Xin LI 0622974ab2 done method is supposed to return int. 2009-06-22 22:09:18 +00:00
Xin LI 6ac937c89c Split tolower/toupper code from usual xlat16 kiconv table, and make it
possible to do tolower/toupper independently without code conversion.

Submitted by:	imura (but bugs are mine)
Obtained from:	http://people.freebsd.org/~imura/kiconv/
		(1_kiconv_wctype_kern.diff, 1_kiconv_wctype_user.diff)
2009-06-22 17:09:46 +00:00
Kip Macy ea2ecf4f10 add explanatory header license 2009-06-09 21:29:16 +00:00
Kip Macy ee117d034c move jenkins hash to its own header in libkern 2009-06-09 20:21:40 +00:00
Ed Schouten 802cb57e34 Add memmove() to the kernel, making the kernel compile with Clang.
When copying big structures, LLVM generates calls to memmove(), because
it may not be able to figure out whether structures overlap. This caused
linker errors to occur. memmove() is now implemented using bcopy().
Ideally it would be the other way around, but that can be solved in the
future. On ARM we don't do add anything, because it already has
memmove().

Discussed on:	arch@
Reviewed by:	rdivacky
2009-02-28 16:21:25 +00:00
Ed Schouten 64b0a21bf8 Remove redundant assignment of `s'.
The variable is already initialized to `nptr'.

Found by:	LLVM's scan-build
2009-02-26 12:06:46 +00:00
Randall Stewart eef9e53e55 This commit fixes the issue with alias_sctp.c. No
longer do we require SCTP to be in the kernel for the
lib to be able to handle SCTP. We do this by moving
the CRC32c checksum into libkern/crc32.c and then adjusting
all routines to use the common methods. Note that this
will improve the performance of iSCSI since they were
using the old single 256 bit table lookup versus the
slicing 8 algorithm (which gives a 4x speed up in
CRC32c calculation :-D)

Reviewed by:rwatson, gnn, scottl, paolo
MFC after:	4 week? (assuming we MFC the alias_sctp changes)
2009-02-14 11:34:57 +00:00
John Baldwin ee03ef72e3 Add simple locking for the in-kernel iconv code. Translation operations
do not need any locking.  Opening and closing translators is serialized
using an sx lock.

Note: This depends on the earlier fix to kern_module.c to properly order
MOD_UNLOAD events.

MFC after:	2 months
2008-12-05 21:19:24 +00:00
Andrew Thompson 6ff5e8a6e2 Prefix the static shl function with '__' like its parent function __qdivrem to
avoid being picked up by the DTrace fbt provider.

This is called by __udivdi3() for doing 64bit division on a 32bit arch and may
be called from within the dtrace context causing a double fault.
2008-10-09 20:43:42 +00:00
David E. O'Brien ae72afe0f2 The kernel implemented 'memcmp' is an alias for 'bcmp'. However, memcmp
and bcmp are not the same thing.  'man bcmp' states that the return is
"non-zero" if the two byte strings are not identical.  Where as,
'man memcmp' states that the return is the "difference between the
first two differing bytes (treated as unsigned char values" if the
two byte strings are not identical.

So provide a proper memcmp(9), but it is a C implementation not a tuned
assembly implementation.  Therefore bcmp(9) should be preferred over memcmp(9).
2008-09-23 14:45:10 +00:00
Kip Macy bbbc5bc1ee Add strcspn to libkern for use by xenbus routines. Will add to build
in separate commit.
2008-08-15 04:07:22 +00:00
Andrey A. Chernov b834665cd5 Return arc4_i = arc4_j = 0; line from previous backing out since
just found it in OpenBSD, see their sys/crypto/arc4.c, function
rc4_keysetup, line ctx->x = ctx->y = 0;

Obtained from:  OpenBSD
2008-07-26 16:42:45 +00:00
Andrey A. Chernov fff6495ea6 Per rwatson's request:
"If you don't get a review within a day or two, I would firmly recommend
backing out the changes"

back out all my changes as unreviewed by secteam@ yet.
2008-07-25 15:53:32 +00:00
Andrey A. Chernov d16863efa6 1) Initialize arc4_i and arc4_j to 0 after key mixing as recommended in
draft-kaukonen-cipher-arcfour-03.txt (3.1.5)

2) Drop first 768 bytes as standard RC4-drop(768)
2008-07-22 16:16:51 +00:00
David E. O'Brien 1989184838 Match the implementation of the inline function from libkern.h. 2008-07-14 21:36:02 +00:00
Marcel Moolenaar c2602b5b06 Add prototype for __cmpd2(). 2008-02-23 22:40:05 +00:00
Marcel Moolenaar f7355c360b Bring back (without advertising clause) cmpdi2.c. It's needed on PowerPC
when the FP emulator is compiled-in.
2008-02-23 20:10:49 +00:00
Olivier Houchard def35d2ca7 Do not use __XSCALE__ to detect if clz is available, use _ARM_ARCH_5 instead.
MFC After:	3 days
2007-10-13 12:05:36 +00:00
Bruce Evans 7df7fc34a3 Unbreak high resolution profiling a little: use dummy asms to prevent
timing loops being optimized away.

Once apon a time, gcc promised not to optimize away timing loops, but
gcc started optimizing away the call to a null function in the timing
loop here some time between gcc-3.3.3 and gcc-3.4.6, and it started
optimizing away the timing loop itself some time between gcc-3.4.6
and gcc-4.2.
2007-06-13 06:17:48 +00:00
Wojciech A. Koszek f7caeade24 strchr() and strrchr() are already present in the kernel, but with less
popular names. Hence:

- comment current index() and rindex() functions, as these serve the same
  functionality as, respectively, strchr() and strrchr() from userland;
- add inlined version of strchr() and strrchr(), as we tend to use them more
  often;
- remove str[r]chr() definitions from ZFS code;

Reviewed by:	pjd
Approved by:	cognet (mentor)
2007-04-10 21:42:12 +00:00
Alexander Kabaev c8c0ba192e Add local ptototype for memset function. 2007-04-06 00:06:26 +00:00
Alexander Kabaev 616db5f04c Add trivial MI memset function implementation. GCC mandates the
existence of this function as a linkable symbol in standalone
configurations and existing inline memcpy from libkern.h fails
this requirement.
2007-04-05 22:02:39 +00:00
Pawel Jakub Dawidek 73c0c41140 Add strstr() function to the libkern. 2006-08-12 15:28:39 +00:00
John Baldwin 67ab9fd759 First pass at removing Alpha kernel support. 2006-05-11 22:25:28 +00:00
Robert Watson b059cbd3eb Convert function declarations to ANSI C.
MFC after:	1 week
2006-01-22 00:46:40 +00:00
Ruslan Ermilov 90ee1f3a04 Ignore spurious '\0' first character read on a serial console.
This allows me to "boot -a" over a serial console.  Tested on
several machines.
2006-01-14 20:45:02 +00:00
Robert Watson 5bb84bc84b Normalize a significant number of kernel malloc type names:
- Prefer '_' to ' ', as it results in more easily parsed results in
  memory monitoring tools such as vmstat.

- Remove punctuation that is incompatible with using memory type names
  as file names, such as '/' characters.

- Disambiguate some collisions by adding subsystem prefixes to some
  memory types.

- Generally prefer lower case to upper case.

- If the same type is defined in multiple architecture directories,
  attempt to use the same name in additional cases.

Not all instances were caught in this change, so more work is required to
finish this conversion.  Similar changes are required for UMA zone names.
2005-10-31 15:41:29 +00:00
Pawel Jakub Dawidek 24f8c87b41 Backout strtok() addition to libkern, strsep() is enough and strtok()
is not safe.

Discussed with:	stefanf, njl
2005-10-06 19:06:07 +00:00
Pawel Jakub Dawidek 5e66cbaeaf Add strtok() and strtok_r() function to libkern.
MFC after:	2 weeks
2005-10-06 11:10:09 +00:00
R. Imura f373a82454 - Fix checking range of strings of struct iconv_add_in in libsmb and libkiconv,
- Add checking range of strings to iconv_sysctl_add().

Submitted by:	Rudolf Cejka
2005-08-24 12:38:26 +00:00
Pawel Jakub Dawidek 57169160b0 Ha! This is a very interesting bug.
I copied strcasecmp() from userland to the kernel and it didn't worked!
I started to debug the problem and I find out that this line:

	while (tolower(*us1) == tolower(*us2++)) {

was adding _3_ bytes to 'us2' pointer. Am I loosing my minds here?!...
No, in-kernel tolower() is a macro which uses its argument three times.
Bad tolower(9), no cookie.
2005-08-08 19:38:00 +00:00
Pawel Jakub Dawidek c812ca43bd Add strcasecmp() and strncasecmp() to libkern and connect to the build. 2005-08-08 18:31:13 +00:00
R. Imura 8fa523fb95 Temporary restore a part of rev 1.6.
We must not increase a capability of buffer size here,
because codes which call these functions expect that dst and src
are the same size.
This will cause problem when someone convert a character whose
length is different between charsets on smbfs which was changed
to use xlat16 converter.
2005-07-23 16:52:57 +00:00
R. Imura bf8ba9ab3a Fix kiconv on the 64bit plathomes.
- Correct idxp pointer to point the properly address of the
  each array of the kiconv character conversion tables,
  so that character conversion work properly when file
  systems are mounted with kiconv options.

- The definition of ICONV_CSMAXDATALEN was also bogus
  because it was defined as if all machines were 32bit
  computers.

Tested on:	amd64
MFC after:	1 month
2005-05-24 15:38:08 +00:00
Marcel Moolenaar 61d596a8ff Update comment to direct the reader to libkern.h instead of systm.h.
The functions were moved.

Pointed out by: johan@
2005-04-28 05:50:18 +00:00
Marcel Moolenaar ee6bcf1223 Refactor the CRC-32 code to enhance its usability. Move the actual
CRC logic to a new function: crc32_raw() that obtains the initial
CRC value as well as leaves any post-processing to the caller. As
such, it can be used when the initial CRC value is not ~0U or when
the final CRC value does need to be inverted (bitwise). It also
means that crc32_raw() can be called repeatedly when the data is
not available as a single block, such as for scatter/gather lists
and the likes.

Avoid the additional call overhead incured by the refactoring by
moving the implementation off crc32() to sys/systm.h and making it
inlinable. Since crc32_raw() is itself trivial and since it may
be used in loops that iterate over fragments, having it available
for inlining can be beneficial. Hence, move its implementation
to sys/systm.h as well.

Keep the original implementation of crc32() in libkern/crc32.c for
documentation purposes (as a comment of course).

Triggered by: Jose M Rodriguez (josemi at freebsd dot jazztel dot es)
Discussed on: current@
Tested on: amd64, ia64 (BVO having GPT partitions)
Jargon file candidate: BVO = By Virtue Of :-)
2005-04-27 22:26:45 +00:00
David Schultz f0ceb98f93 Replace the current strspn() and strcspn() with significantly faster
implementations inspired by the ones in DragonFly.  Unlike the
DragonFly versions, these have a small data cache footprint, and my
tests show that they're never slower than the old code except when the
charset or the span is 0 or 1 characters.  This implementation is
generally faster than DragonFly until either the charset or the span
gets in the ballpark of 32 to 64 characters.
2005-04-02 18:52:44 +00:00
Gleb Smirnoff 75737f3423 Add strspn() to libkern.
Ok'ed by:	rwatson
2005-02-10 20:39:39 +00:00
Ruslan Ermilov 27667f5821 MFlibc: Remove extra closing parenthesis. 2005-02-03 15:51:39 +00:00
Pawel Jakub Dawidek f3830f0482 We do want to print '\n'/'\r'.
Pointed out by:	stefanf
2005-02-03 15:47:30 +00:00
Pawel Jakub Dawidek 6513f57682 'c' cannot be -1.
Submitted by:	stefanf
2005-02-03 15:23:27 +00:00
Pawel Jakub Dawidek f627315f1e - Move gets() function to libkern (I want to use it outside vfs_mount.c).
- Add buffer size limitations (overflow will not be possible anymore).
- Add 'visible' option, which will allow for passphrase reading in the
  future.
- Remove special treatment of '@' and '#', those two are only confusing.

Discussed with:	rwatson
MFC after:	2 weeks
2005-02-03 15:10:58 +00:00
Robert Watson dc66c5fe6f Because the argument to strvalid() is a size_t, use a size_t to iterate
over the array.

Submitted by:	stefanf
2005-01-29 13:34:22 +00:00
Robert Watson debb2f87b6 Per permission from McAfee, remove clause 3 of the BSD license on
strvalid.c.
2005-01-29 13:04:04 +00:00
Warner Losh d6ea02625f /* -> /*- for copyright notices, minor format tweaks as necessary 2005-01-07 00:24:33 +00:00
Olivier Houchard 2fd21813b0 Use the RET macro. 2004-11-09 16:47:47 +00:00
Olivier Houchard ec98ae75da Implement ffs with clz for Xscale.
Idea taken from:	NetBSD
2004-11-07 16:53:29 +00:00
Olivier Houchard fbaa643e9a Don't attempt to profile __udivsi3() and friends, as mcount() uses them. 2004-10-01 16:44:08 +00:00
Marcel Moolenaar 0f2fe153bc Move the kernel-specific logic to adjust frompc from MI to MD. For
these two reasons:
1. On ia64 a function pointer does not hold the address of the first
   instruction of a functions implementation. It holds the address
   of a function descriptor. Hence the user(), btrap(), eintr() and
   bintr() prototypes are wrong for getting the actual code address.
2. The logic forces interrupt, trap and exception entry points to
   be layed-out contiguously. This can not be achieved on ia64 and is
   generally just bad programming.

The MCOUNT_FROMPC_USER macro is used to set the frompc argument to
some kernel address which represents any frompc that falls outside
the kernel text range. The macro can expand to ~0U to bail out in
that case.
The MCOUNT_FROMPC_INTR macro is used to set the frompc argument to
some kernel address to represent a call to a trap or interrupt
handler. This to avoid that the trap or interrupt handler appear to
be called from everywhere in the call graph. The macro can expand
to ~0U to prevent adjusting frompc. Note that the argument is selfpc,
not frompc.

This commit defines the macros on all architectures equivalently to
the original code in sys/libkern/mcount.c. People can take it from
here...

Compile-tested on: alpha, amd64, i386, ia64 and sparc64
Boot-tested on: i386
2004-08-27 19:42:35 +00:00
Poul-Henning Kamp 3dfe213e61 Convert the vfsconf list to a TAILQ.
Introduce vfs_byname() function to find things on it.

Staticize vfs_nmount() function under the name vfs_donmount().

Various cleanups.
2004-07-27 22:32:01 +00:00
Gleb Smirnoff b1e34c44ef Copy qsort_r(3) from libc to libkern.
Reviewed by:	phk
Approved by:	julian (mentor)
2004-07-15 23:58:23 +00:00
Olivier Houchard 03f110294b Import libkern arm specific bits. 2004-05-14 12:28:31 +00:00
Bruce Evans c7e459ed6c Fixed some style bugs (unsorting of prototypes in previous commit, and
messes involving the idempotency guard).
2004-05-05 15:12:55 +00:00
Olivier Houchard 967f542177 Prototype __ashldi3(), __ashrdi3() and __lshrdi3(). 2004-05-04 22:15:54 +00:00
Warner Losh f36cfd49ad Remove advertising clause from University of California Regent's
license, per letter dated July 22, 1999 and email from Peter Wemm,
Alan Cox and Robert Watson.

Approved by: core, peter, alc, rwatson
2004-04-07 20:46:16 +00:00
Robert Drehmel 9fbb80baff Bring these files closer to style(9) conformance by comparing a
dereferenced character pointer to '\0' instead of using the ! operator.
2004-03-29 21:15:41 +00:00
Tom Rhodes a122cca953 These are changes to allow to use the Intel C/C++ compiler (lang/icc)
to build the kernel. It doesn't affect the operation if gcc.

Most of the changes are just adding __INTEL_COMPILER to #ifdef's, as
icc v8 may define __GNUC__ some parts may look strange but are
necessary.

Additional changes:
 - in_cksum.[ch]:
   * use a generic C version instead of the assembly version in the !gcc
     case (ASM code breaks with the optimizations icc does)
     -> no bad checksums with an icc compiled kernel
     Help from:		andre, grehan, das
     Stolen from: 	alpha version via ppc version
     The entire checksum code should IMHO be replaced with the DragonFly
     version (because it isn't guaranteed future revisions of gcc will
     include similar optimizations) as in:
        ---snip---
          Revision  Changes    Path
          1.12      +1 -0      src/sys/conf/files.i386
          1.4       +142 -558  src/sys/i386/i386/in_cksum.c
          1.5       +33 -69    src/sys/i386/include/in_cksum.h
          1.5       +2 -0      src/sys/netinet/igmp.c
          1.6       +0 -1      src/sys/netinet/in.h
          1.6       +2 -0      src/sys/netinet/ip_icmp.c

          1.4       +3 -4      src/contrib/ipfilter/ip_compat.h
          1.3       +1 -2      src/sbin/natd/icmp.c
          1.4       +0 -1      src/sbin/natd/natd.c
          1.48      +1 -0      src/sys/conf/files
          1.2       +0 -1      src/sys/conf/files.amd64
          1.13      +0 -1      src/sys/conf/files.i386
          1.5       +0 -1      src/sys/conf/files.pc98
          1.7       +1 -1      src/sys/contrib/ipfilter/netinet/fil.c
          1.10      +2 -3      src/sys/contrib/ipfilter/netinet/ip_compat.h
          1.10      +1 -1      src/sys/contrib/ipfilter/netinet/ip_fil.c
          1.7       +1 -1      src/sys/dev/netif/txp/if_txp.c
          1.7       +1 -1      src/sys/net/ip_mroute/ip_mroute.c
          1.7       +1 -2      src/sys/net/ipfw/ip_fw2.c
          1.6       +1 -2      src/sys/netinet/igmp.c
          1.4       +158 -116  src/sys/netinet/in_cksum.c
          1.6       +1 -1      src/sys/netinet/ip_gre.c
          1.7       +1 -2      src/sys/netinet/ip_icmp.c
          1.10      +1 -1      src/sys/netinet/ip_input.c
          1.10      +1 -2      src/sys/netinet/ip_output.c
          1.13      +1 -2      src/sys/netinet/tcp_input.c
          1.9       +1 -2      src/sys/netinet/tcp_output.c
          1.10      +1 -1      src/sys/netinet/tcp_subr.c
          1.10      +1 -1      src/sys/netinet/tcp_syncache.c
          1.9       +1 -2      src/sys/netinet/udp_usrreq.c

          1.5       +1 -2      src/sys/netinet6/ipsec.c
          1.5       +1 -2      src/sys/netproto/ipsec/ipsec.c
          1.5       +1 -1      src/sys/netproto/ipsec/ipsec_input.c
          1.4       +1 -2      src/sys/netproto/ipsec/ipsec_output.c

          and finally remove
            sys/i386/i386        in_cksum.c
            sys/i386/include     in_cksum.h
        ---snip---
 - endian.h:
   * DTRT in C++ mode
 - quad.h:
   * we don't use gcc v1 anymore, remove support for it
   Suggested by:	bde (long ago)
 - assym.h:
   * avoid zero-length arrays (remove dependency on a gcc specific
     feature)
     This change changes the contents of the object file, but as it's
     only used to generate some values for a header, and the generator
     knows how to handle this, there's no impact in the gcc case.
   Explained by:	bde
   Submitted by:	Marius Strobl <marius@alchemy.franken.de>
 - aicasm.c:
   * minor change to teach it about the way icc spells "-nostdinc"
   Not approved by:	gibbs (no reply to my mail)
 - bump __FreeBSD_version (lang/icc needs to know about the changes)

Incarnations of this patch survive gcc compiles since a loooong time,
I use it on my desktop. An icc compiled kernel works since Nov. 2003
(exceptions: snd_* if used as modules), it survives a build of the
entire ports collection with icc.

Parts of this commit contains suggestions or submissions from
Marius Strobl <marius@alchemy.franken.de>.

Reviewed by:	-arch
Submitted by:	netchild
2004-03-12 21:45:33 +00:00
Peter Grehan 9a580b5e18 Remove register keyword and constify tmp values. This fixes
PPC compile warning - PPC is the only consumer of this code
path.
2004-02-12 03:23:13 +00:00
Dag-Erling Smørgrav 29554ea51a Translate from GNU C to ISO C. 2004-01-14 07:47:10 +00:00
Dag-Erling Smørgrav 8746a69a28 Cast to unsigned to avoid sign-extension problems. 2004-01-13 16:02:20 +00:00
Dag-Erling Smørgrav f04ecda547 Add C implementations of ffsl(), fls() and flsl(). 2004-01-13 15:36:34 +00:00
Dag-Erling Smørgrav 53546cd058 ANSIfy, de-register, replace VAX reference with actual description. 2004-01-13 15:35:22 +00:00
Max Khon 0f4e4130e1 Make msdosfs long filenames matching case insensitive again.
PR:		59765
Submitted by:	Ryuichiro Imura <imura@ryu16.org>
2003-12-08 08:32:20 +00:00
Max Khon c4f02a891f - Support for multibyte charsets in LIBICONV.
- CD9660_ICONV, NTFS_ICONV and MSDOSFS_ICONV kernel options
(with corresponding modules).
- kiconv(3) for loadable charset conversion tables support.

Submitted by:	Ryuichiro Imura <imura@ryu16.org>
2003-09-26 20:26:25 +00:00
Mike Silbersack 2f823fa326 Lock down arc4random so it can be safely called w/o Giant.
Minor code reorganization was required, but the only functional
change was that the first 1024 bytes of output are thrown out
after each reseed, rather than just the initial seed.
2003-08-15 06:34:47 +00:00
Andrey A. Chernov 696fe9ddcd Lower initial drop value to 50, it is enough to hide linearity 2003-08-10 17:56:58 +00:00
Bruce Evans 4066649d5a Backed out the micro-optimization in 1.4. It was to help gcc-2.6.3
on i486's (and probably i386's), but it has had very little effect
since gcc-2.7 or gcc-2.95.  With gcc-3.3, it gave a small
pessimization for at least i386's, athlon-xp's and pentium4's, a
small optimization (I think) for pentium1's, and made no difference
for i386's.  (movzbl is best for all the later processors, and the
micro-optimization was to stop it being used on i486's.)
2003-07-25 15:54:23 +00:00
David E. O'Brien ab0de15baf Use __FBSDID(). 2003-06-11 05:37:42 +00:00
Alexander Kabaev 104a9b7e3e Deprecate machine/limits.h in favor of new sys/limits.h.
Change all in-tree consumers to include <sys/limits.h>

Discussed on:	standards@
Partially submitted by: Craig Rodrigues <rodrigc@attbi.com>
2003-04-29 13:36:06 +00:00
Robert Watson 05c06d15e8 Further GC of M_STRING, missed previously. 2003-02-26 01:00:29 +00:00
Robert Watson ae4f61f0d7 Replace license with two-clause BSD; an old license template with three
clauses was used by mistake.
2003-02-26 00:59:53 +00:00
Robert Watson 354d43abf3 Pass a malloc type into the libkern strdup() implementation explicitly,
so that callers can specify what malloc pool the resulting memory
should come from.

Requested by:	phk
2003-02-25 22:11:39 +00:00
Robert Watson 96c4266cb3 Add an implementation of strdup() to libkern. Allocated memory is of
type M_STRING, now defined in malloc.h.  Useful when string parsing
must occur using the kernel strsep() and we want to avoid toasting
the source string.

Obtained from:	TrustedBSD Project
Sponsored by:	DARPA, Network Associates Laboratories
2003-02-23 14:30:17 +00:00
Warner Losh a163d034fa Back out M_* changes, per decision of the TRB.
Approved by: trb
2003-02-19 05:47:46 +00:00
Jens Schweikhardt 00ad14c702 Improve a comment and undo a bogus s/a/an/ in a comment. An asm guru
should add more comments explaining which registers hold which variables.

Spotted by:	bde
2003-02-11 20:15:11 +00:00
Jeffrey Hsu 93eb73aa48 Add restrict keyword to string functions.
Reviewed by:	bde
2003-02-10 00:36:27 +00:00
Andrey A. Chernov dba8967550 Since we drop NSHUFF values now, set default seed to what it becomes
after srandom(1)
2003-02-05 21:28:52 +00:00
Andrey A. Chernov a36d6a59f0 Drop NSHUFF values right after srandom() to remove part of seed -> 1st
value correlation. Correlation still remains because of algorithm limits.
2003-02-04 11:33:09 +00:00
Andrey A. Chernov b413a2949e Park & Miller PRNG can be safely initialized with any value but 0 and stuck
at 0 as designed. Its BSD adaptation tries to fight it by mapping 0 to
2147483647 after calculation, but this method not works since 2147483647
seed returns to 0 again on the next interation. Instead of after calculation
mapping, map 0 to another value _before_ calculation, so it never stucks.
2003-02-03 10:29:47 +00:00
Alfred Perlstein 44956c9863 Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.
Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.
2003-01-21 08:56:16 +00:00
Jens Schweikhardt 9d5abbddbf Correct typos, mostly s/ a / an / where appropriate. Some whitespace cleanup,
especially in troff files.
2003-01-01 18:49:04 +00:00
Alfred Perlstein 29f194457c Fix instances of macros with improperly parenthasized arguments.
Verified by: md5
2002-11-09 12:55:07 +00:00
Poul-Henning Kamp 2c38619b52 Slight overhaul of arc4random() and friends.
One bug fixed:  Use getmicrouptime() to trigger reseeds so that we
cannot be tricked by a clock being stepped backwards.

Express parameters in natural units and with natural names.

Don't use struct timeval more than we need to.

Various stylistic and readability polishing.

Introduce arc4rand(void *ptr, u_int len, int reseed) function which
returns a stream of pseudo-random bytes, observing the automatic
reseed criteria as well as allowing forced reseeds.

Rewrite arc4random() in terms of arc4rand().

Sponsored by:   DARPA & NAI Labs.
2002-10-11 13:13:08 +00:00
Robert Watson 469fda7e25 Hook up strsep(3) to libkern following a repo-copy by Peter. This will
allow us to avoid nasty by-hand string parsing stuff in a number of
places in the kernel, reducing the risk of unexpected consequences
for kernel correctness.
2002-10-10 17:02:11 +00:00
Poul-Henning Kamp 943e5db958 Allow for multiple #includes of this file. 2002-10-08 07:24:19 +00:00
Dima Dorfman 20a6cb8cb8 Import the libc fnmatch() into the kernel. This will be used by,
among other things, the DEVFS rule subsystem to match nodes against a
path pattern supplied by the user.

fnmatch.c was repo-copied from src/lib/libc/gen/fnmatch.c, and the
only changes to it are those necessary to make it compile in the
kernel.  The relevant parts of fnmatch.h were imported into libkern.h.

Approved by:	-arch
2002-10-08 04:15:55 +00:00
Maxime Henrion 5ff9562781 Fix a bunch of s/int */size_t */. 2002-10-06 12:20:09 +00:00
Peter Wemm 105d189b78 Use sys/libkern.h not /usr/include/string.h 2002-09-06 06:04:36 +00:00