Commit Graph

904 Commits

Author SHA1 Message Date
maxv 1f8d4ff48b Add KASAN instrumentation for memmove. 2019-09-07 09:46:07 +00:00
thorpej 49da5e3bf1 clzdi2 and ctzdi2 are needed on alpha. (counting instructions are in the
optional CIX extension, and thus not used by the default compiler configuation).
2019-04-05 14:00:16 +00:00
mrg 7b8d5ea7c0 don't use -fnon-call-exceptions on arm. not needed and triggers eh_frame generation. 2019-02-07 10:44:54 +00:00
mrg 1143174b7d apply the previous to all GCC-7 platforms. it affects vax as well. 2019-02-07 05:22:09 +00:00
mrg 11d7172b93 for sh3 and GCC 7 pass -fnon-call-exceptions for udivmoddi4.c.
avoids it emitting a call to abort() for an explicit divide by zero.
2019-02-07 04:33:24 +00:00
rin e9ac1fc994 - Determine KERN_AS automatically depending on whether OPT_MODULAR is
set or not, in the same way as libcompat.

- Specify OPT_MODULAR in the port Makefile instead of KERN_AS.

Now, KERN_AS=library is used for kernels without module(7) for all ports.

OK christos
2018-09-22 12:24:01 +00:00
riastradh 8efd1f3e95 We have popcount; no need to reimplement it. 2018-09-03 18:52:33 +00:00
riastradh 82a15b88fc Rename min.c -> uimin.c, max.c -> uimax.c in libkern. 2018-09-03 16:54:54 +00:00
riastradh d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
maxv a0301d655f Add kasan interceptors for strcpy/strcmp/strlen. 2018-08-27 08:53:19 +00:00
maxv acb2576569 Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

	#makeoptions 	KASAN=1		# Kernel Address Sanitizer
	#options 	KASAN
	#no options	SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

	- global variables
	- kmem_alloc-ated areas
	- malloc-ated areas

More will come, but that's a good start.
2018-08-20 15:04:51 +00:00
christos 4231a89cbc provide memmem 2018-07-08 17:54:42 +00:00
christos de3955c3eb Use the standard build rules. 2018-06-05 00:57:47 +00:00
christos c50a4e606c - Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Revert :Q to work as before.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@
XXX: pullup 8
2018-05-27 01:14:50 +00:00
christos 87fd18f8e5 s/static inline/static __inline/g for consistency. 2018-04-19 21:50:06 +00:00
ryo e55e7ad672 use memmove.S 2018-03-16 07:56:50 +00:00
martin c9526096cc PR port-alpha/52520: provide float64 -> uint64 conversion and use
that when converting positive numbers.
2017-12-31 11:43:42 +00:00
christos 489063e9bc Even smaller and takes print function. 2017-12-09 00:51:52 +00:00
christos cbb79c448d don't ifdef _KERNEL 2017-12-08 23:57:57 +00:00
christos f0d31504f3 use a different, more readable approach. 2017-12-08 23:49:01 +00:00
christos 4a1f5c48a9 coalesce the two copies of hexdump into libkern 2017-12-08 21:51:07 +00:00
riastradh 969998948d Import SHA-3 code into libc and libkern.
No new public symbols in libc, but publishing the symbols is a simple
matter if/when we decide to do so.

Proposed on tech-kern and tech-userlevel with no objections:

https://mail-index.NetBSD.org/tech-kern/2017/11/11/msg022581.html
https://mail-index.NetBSD.org/tech-userlevel/2017/11/11/msg010968.html
2017-11-30 05:47:24 +00:00
maxv 2e01a9a26d Add END(). 2017-10-30 17:13:39 +00:00
riastradh d77a8e7afe Add garbage instructions at end of kern_assert after vpanic.
This avoids having the return address passed to vpanic confusingly
appear to be some other symbol.
2017-03-14 09:22:37 +00:00
jdolecek 3c404120db extract crc16 code from utoppy driver to a separate file in libkern, for use
by ext2fs; every usage gets their own copy of the table for now, as it's
fairly small, and too rare to be used to be useful pulling into every kernel
2016-08-20 19:44:46 +00:00
scole d3196bfdc3 PR port-ia64/51261
Use common/lib/libc/arch/ia64/string functions
2016-08-05 17:10:48 +00:00
msaitoh 8bc54e5be6 KNF. Remove extra spaces. No functional change. 2016-07-07 06:55:38 +00:00
rtr a44831a800 provide const versions of container_of macros.
discussed with riastradh@ by email
2016-05-11 03:17:22 +00:00
christos ee17f398d4 move scsipi_strvis -> libkern:strnvisx()
change the prototype to match userland
fix sizes of strings passed to it
2016-05-02 19:18:29 +00:00
riastradh 96b890b34c Fix relation in rngtest failure message to match reality. 2016-03-28 15:20:16 +00:00
mrg 65f5251eae remove a bunch of "@echo done" from the tail of rules. these messages
were vaguely useful back when we didn't run make -j, but now you end
up with a single line "done" every so often, with no idea what it is
for.  very few other targets claim they're done so just remove these.
2016-03-22 08:25:22 +00:00
mrg 091c49eab9 remove "@echo done" from 4 rules that don't need it and the random "done"
in my build logs don't help understanding.
2015-10-29 00:18:55 +00:00
uebayasi ea72de740f Order library object build. 2015-09-07 03:44:19 +00:00
uebayasi 9068ec741b Sprinkle more done messages. 2015-09-07 03:20:18 +00:00
uebayasi dd204a345e In kernel lib build, print message when things not only start bug also end. 2015-09-06 15:34:55 +00:00
uebayasi e7a049ec66 Include opt_diagnostic.h. 2015-08-30 07:55:45 +00:00
tsutsui f2142f537b Revert untested and unnecessary change in previous rev 1.36.
Our autobuild doesn't always reflect the latest fixes.
2015-07-30 15:29:52 +00:00
christos 7c7a7b43d2 add mulsi3, needed by inet_addr.o 2015-07-30 07:44:40 +00:00
matt c98065b9f6 If the platform support popcount as a __builtin, use that in preference
to the libc versions.
2015-05-29 19:38:59 +00:00
christos 925d349b50 tricks with sizeof() make coverity complain. 2015-05-09 18:49:36 +00:00
riastradh 7fd36dbc4a Add container_of to libkern.
Given x = &c->f, container_of(x, T, f) yields c, where T is the type
of c.

Discussed on tech-kern a while ago:

https://mail-index.netbsd.org/tech-kern/2013/03/21/msg015131.html
2015-04-20 15:22:17 +00:00
mrg 2603e0673f remove various HAVE_GCC=45 fragments. 2015-04-15 19:13:46 +00:00
christos d36e0de1e1 strtoi and strtou for the kernel 2015-01-16 18:36:31 +00:00
christos 96739e65c5 bcdtobin and bintobcd are now inlines in <dev/clock_subr.h> 2014-11-20 16:25:16 +00:00
matt 6cf6fe02a9 New files for Userland support of UCB RISC-V (both 32-bit and 64-bit) 2014-09-19 17:36:24 +00:00
joerg 35d69bab34 Revert 1.33 and 1.34 for now, until either .INVISIBLE is reinstanciated
or random.S dropped.
2014-09-08 12:12:19 +00:00
matt 27620987b8 New files for OR1K support 2014-09-03 19:34:25 +00:00
matt 905f9a1ab9 Make random.S invisible for coldfire too (e.g. anything not "m68k") 2014-09-01 07:32:35 +00:00
christos 2fac5fd5c7 use .INVISIBLE to hide random.S, instead of extra rules. 2014-08-27 08:51:37 +00:00
tls ea6af427bd Merge tls-earlyentropy branch into HEAD. 2014-08-10 16:44:32 +00:00
matt 547b3a3b01 Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only.  While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.
2014-08-10 05:56:36 +00:00
matt beb9c6d1b5 Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.
2014-08-10 05:47:35 +00:00
lneto 4ab4902eb2 lua: updated from 5.1 to 5.3 work3
* lua(1):
  - changed lua_Integer to intmax_t
  - updated distrib/sets/lists and etc/mtree
  - updated bsd.lua.mk
  - fixed bozohttpd (lua-bozo.c)
  - compatibilized bindings: gpio, sqlite
* lua(4):
  - removed floating-point and libc dependencies using '#ifndef _KERNEL'
  - fixed division by zero and exponentiation
  - libkern: added isalnum(), iscntrl(), isgraph(), isprint() and ispunct()
  - acpica: removed isprint() from acnetbsd.h
  - libc: moved strcspn.c, strpbrk.c and strspn.c to common
  - removed stub headers
  - compatibilized bindings: luapmf, luasystm
* reorganized luaconf.h
* updated doc/CHANGES and doc/RESPONSIBLE
2014-07-19 18:38:33 +00:00
jmcneill 65c6ea680a ${.PARSEDIR} not .${PARSEDIR} for Makefile.compiler-rt include 2014-07-04 16:44:26 +00:00
riastradh 6cb10275d0 Merge riastradh-drm2 to HEAD. 2014-03-18 18:20:35 +00:00
pooka bb154207c8 remove compiler-rt duplicates to fix build 2014-03-13 16:09:11 +00:00
pooka 1ee7f81f1b Do not include compiler-rt in librump. librump is not a toolchain support
library, and toolchain support belongs in the host libc or libgcc or
equivalent entity that is actually supposed to complement the toolchain.

Fixes librump build on (a) Linux ARM (collisions with libgcc)
2014-03-12 00:22:53 +00:00
nakayama 1b088eaae2 Align explicitly to make kernels compiled by clang generate
properly aligned code.
2014-03-07 20:23:09 +00:00
joerg 2ce54a14d1 Provide labs, llabs and imaxabs for kernel use. 2014-02-27 18:05:07 +00:00
joerg a48c968746 Update compiler-rt glue for the new source layout. 2014-02-26 22:37:55 +00:00
njoly 9d9871abbe Revert previous revision. It bkeaks profiling kernel builds.
LIBISPRIVATE unconditionnally set MKPROFILE to no, preventing
profiling kernel library.
2014-02-09 12:53:30 +00:00
joerg 720b2586bd Include compiler-rt in libc, libm and libkern. 2014-01-29 23:37:18 +00:00
joerg 9de82816fc For ARM EABI, includ divide-by-0 trap handlers. 2014-01-29 22:30:24 +00:00
joerg 329758262f This is not libc, so don't check the libc arch macro. 2014-01-17 00:49:55 +00:00
joerg 7a05a6aa88 For HAVE_LIBGCC=no, use compiler-rt for quad support. 2014-01-15 21:12:57 +00:00
christos 5e0bd251ff add strncat (for acpi) 2013-12-27 20:25:33 +00:00
pooka e546a6c273 Allow overriding CTASSERT. This helps with building NetBSD sources with
compilers that don't support __COUNTER__ -- shifting the CTASSERTs
around to avoid __LINE__ conflicts is a hopeless struggle.
2013-12-15 21:15:41 +00:00
joerg aceb213538 Allow kernel code to access constant databases by moving cdbr(3) and the
required mi_vector_hash(3) into src/common.
2013-12-11 01:24:08 +00:00
joerg ab0f68f9e6 libkern build glue for compiler-rt. 2013-12-03 16:15:22 +00:00
lneto c4a02e0a12 changed lua_Number to int64_t 2013-12-02 04:39:10 +00:00
christos ff19ecf77c For the purposes of static analysis, this never returns. 2013-11-19 16:56:21 +00:00
christos e382fdd226 mark some variables as unused, but keep them around as comments 2013-11-03 00:01:43 +00:00
joerg 4d12bfcd15 Pass PICFLAGS down to cc-as-as and use __PIC__ to decide if it is small
vs big PIC mode. Retire -DPIC and -DBIGPIC.
2013-09-12 15:36:14 +00:00
riastradh 04e877f3a1 Fix libkern's prototype for explicit_memset. 2013-08-28 16:20:38 +00:00
matt b3356a40df Thumbify 2013-08-21 08:30:18 +00:00
matt e1512a262a Simplify by using LIBISPRIVATE?= yes 2013-08-21 05:50:14 +00:00
matt 9a5bd26b35 Some assembly files need to compiled -marm since they are Thumb compatible. 2013-08-20 21:43:03 +00:00
matt 99a7d6ba8e Fix typos (prX not cpX) 2013-08-12 23:42:14 +00:00
matt 0009e83bf7 Add EHABI unwind stubs to libkern so prevent errors in linking if unwind
tables are present.
2013-08-12 23:22:12 +00:00
matt 015cebed78 Support thumb 2013-08-11 04:58:01 +00:00
skrll 0bdf107fbc Another codegen bug that fixes (in this case lots of) atf tests.
rump_server doesn't die so much now.
2013-07-23 14:52:07 +00:00
matt 516ab0fa43 Adjust for coldfire 2013-07-18 22:14:48 +00:00
matt 6b35aaa5b7 Fix typo. 2013-07-18 12:54:08 +00:00
matt 10fa00e357 Reorder a little to make clearer. 2013-07-18 12:53:09 +00:00
matt 0ad8b94ed8 Keep stack longword aligned.
Use longword ops for %d2.
2013-07-18 12:42:24 +00:00
matt 8d43a067dd Convert to motorola syntax 2013-07-18 12:40:42 +00:00
matt 6dedf03e19 Convert to morotola syntax 2013-07-18 12:29:30 +00:00
matt 547d5de4df Don't use %d2 (violates the ABI since it wasn't saved), use %a0 instead.
Use a pcrelative access for the local data avoiding the GOT.
2013-07-18 12:16:40 +00:00
rmind 7ae1c4ed1b libkern: add murmurhash module. 2013-06-29 16:02:01 +00:00
riastradh 82db4b9858 Replace consttime_bcmp/explicit_bzero by consttime_memequal/explicit_memset.
consttime_memequal is the same as the old consttime_bcmp.
explicit_memset is to memset as explicit_bzero was to bcmp.

Passes amd64 release and i386/ALL, but I'm sure I missed some spots,
so please let me know.
2013-06-24 04:21:19 +00:00
riastradh bfb8ca3f2e Account bytes drawn from initial call to libkern arc4random.
XXX This unlocked initialization looks rather bogus...
2013-06-23 02:38:22 +00:00
riastradh 6290b0987e Rework rndsink(9) abstraction and adapt arc4random(9) and cprng(9).
rndsink(9):
- Simplify API.
- Simplify locking scheme.
- Add a man page.
- Avoid races in destruction.
- Avoid races in requesting entropy now and scheduling entropy later.

Periodic distribution of entropy to sinks reduces the need for the
last one, but this way we don't need to rely on periodic distribution
(e.g., in a future tickless NetBSD).

rndsinks_lock should probably eventually merge with the rndpool lock,
but we'll put that off for now.

cprng(9):
- Make struct cprng_strong opaque.
- Move rndpseudo.c parts that futz with cprng guts to subr_cprng.c.
- Fix kevent locking.  (Is kevent locking documented anywhere?)
- Stub out rump cprng further until we can rumpify rndsink instead.
- Strip code to grovel through struct cprng_strong in fstat.
2013-06-23 02:35:23 +00:00
matt 47a6ce0396 Add back {,u}modsi3 for libkern since if we are building standalone tools
we might be using the old ABI and might need them.
2013-06-21 05:06:24 +00:00
matt 7213984b98 modsi3/umodsi3 are only needed !EABI arm 2013-06-20 07:29:50 +00:00
matt 5f058922b3 This change arm, armeb, earm, earmeb, earmhf, earmhfeb so all builds that
share a MACHINE_ARCH for userland so that except for etc, will produce
identical sets.

usr/include/machine now points to usr/include/arm
2013-05-02 03:56:38 +00:00
nakayama 99b8f1ddbf Remove duplicate source files. 2013-03-17 04:47:16 +00:00
nakayama e923193871 Revert previous. christos fixed the root cause. 2013-03-17 04:45:46 +00:00
christos ab495c9f87 undo sparc64 kludge 2013-03-17 00:47:13 +00:00
nakayama 809b806d54 Make sparc64 32-bit kernel buildable. 2013-03-14 11:53:33 +00:00
christos d3a58d87a8 amend previous sparc64 fix: rump does not know about memcpyset.s 2013-03-11 11:44:48 +00:00