Commit Graph

3162 Commits

Author SHA1 Message Date
thorpej 438dc24855 Partially expose some of the kernel printf internals in the new
<sys/kprintf.h> header file.  This allows subsystems that need
printf semantics other than what are provided by the standard
kernel printf routines to implement exactly what they want.
2002-12-31 16:53:26 +00:00
thorpej 85c31b11c3 * Move the resched check from setrunnable() and resetpriority() to
a new inline, resched_proc().
* When performing the resched check, check the priority against the
  current priority on the CPU the process last ran on, not always the
  current CPU.
2002-12-29 17:40:26 +00:00
yamt 78d9abec0c sync comment for vflush with reality.
from FreeBSD.
2002-12-29 06:47:57 +00:00
thorpej 63ccfc36f6 Add a comment about affinity to awaken(). 2002-12-29 02:08:39 +00:00
gmcgarry f8f2c11fe0 Re-add yield(). Only used by compat code at the moment. 2002-12-21 23:52:05 +00:00
manu 4a06119a9d Pass the system call table to trace_enter() and ktrsys() so that it is
possible to use alternate system call tables. This is usefull for
displaying correctly the arguments in Mach binaries traces.

If NULL is given, then the regular systam call table for the process is used.
2002-12-21 16:23:56 +00:00
gmcgarry a5424a9df1 Remove yield() until the scheduler supports the sched_yield(2) system
call.
2002-12-20 05:43:09 +00:00
gmcgarry 74da856861 yield() -> preempt(). 2002-12-20 05:06:25 +00:00
thorpej 4c82425f5e Regen: reserved syscall slots for sigwaitinfo(2), sigtimedwait(2),
and sigqueue(2).
2002-12-19 23:53:42 +00:00
thorpej 39e4cd68c4 Reserve syscall slots for sigwaitinfo(2), sigtimedwait(2), and
sigqueue(2).
2002-12-19 23:51:00 +00:00
manu 5ba396cfb3 Added support for exchange of Mach messages between processes.
This does not buy us new functionnality for now, because we still have to
discover how mach_init (which acts as a name server, enabling processes to
discover each other's ports) is able to receive messages from other processes
(this is a bootstrap problem, and the bootstrap port might be the place to
search).

While we are there:
- removed a lot of debug which is now available using ktrace.
- reworked message handling to avoid mutliple copyin/copyout of the
same data. ktrace of Mach message now uses the in-kernel copy of the
message instead of copying it from userland.
- packed mach trap handlers arguments into a structure to avoid modifying
everything next time we have to add an argument.
2002-12-17 18:42:54 +00:00
jdolecek 94062cc04a add support for optional arch-specific restriction of valid value
for kern.maxproc
2002-12-16 18:15:18 +00:00
jdolecek 300acddf8c don't allow kern.maxproc bigger than PID_MAX - PID_SKIP; the pid allocation
code in fork1() would enter endless loop if all the allowed pids are taken
by running processes
2002-12-12 20:54:58 +00:00
jdolecek d18332248c replace magic number '500' in pid allocation code with a macro PID_SKIP,
defined in <sys/proc.h> (along PID_MAX, NO_PID)
2002-12-12 20:41:45 +00:00
christos 80564fa341 always compile in mach ktrace support; it is to small to bother. 2002-12-12 17:40:40 +00:00
abs 39387a63f4 Define nofile and maxuprc variables (set to NOFILE and MAXUPRC), so they can
be patched in a compiled kernel.
2002-12-11 23:23:45 +00:00
manu 4d607adf4f Load __OBJC and ____CGSERVER sections of Mach-O binaries as __TEXT. 2002-12-11 19:28:41 +00:00
jdolecek 5fd22809a5 Add kern.forkfsleep sysctl - set/get time (in miliseconds) for which
process would be forced to sleep in fork() if it hits either global
or user maxproc limit. Default is zero (no forced sleep).
Maximum is 20 seconds.
2002-12-11 19:14:34 +00:00
atatat 7ede0eeb03 Provide a ioctl called FIOGETBMAP (there are some who call
it...FIBMAP) that translates a logical block number to a physical
block number from the underlying device.  Via VOP_BMAP().
2002-12-11 18:25:03 +00:00
jdolecek f13ab92159 put back portion of fork-bomb protection removed in last commit,
and make the sleep length depend on value of variable forkfsleep;
it's set to zero by default (no sleep)
this is a preparation for making the sleep length settable via sysctl
2002-12-11 18:09:07 +00:00
scw 39a5a9dc76 Add two sysctls: kern.labelsector and kern.labeloffset.
These are of use to userland code which previously depended on the
hard-coded values of LABELSECTOR and LABELOFFSET to figure out the
location of the disklabel for a particular platform.

With the introduction of umbrella ports such as evbarm, evbmips, etc,
the location of the disklabel may vary between kernels for the same
MACHINE. This sysctl will allow userland programs to remain independent
of the particular flavour of MACHINE in such cases.
2002-12-11 12:59:29 +00:00
groo b9df764f32 Remove portion of fork-bomb protection that has unfortunate side effects. 2002-12-11 05:01:22 +00:00
thorpej e8cc3884de Rename __LDPGSZ to AOUT_LDPGSZ, to accurately reflect what it is. 2002-12-10 17:14:02 +00:00
thorpej 78ea2dd367 Use __LDPGSZ (which must be == USRTEXT) as the text address for a.out
executables, and eliminate the USRTEXT constant, which was only used
by the a.out exec code.
2002-12-10 05:14:24 +00:00
manu 6492e2171f Added support for dumping mach messages in ktrace/kdump. While we are
there, KNFify a few functions.
2002-12-09 21:29:20 +00:00
christos 0948705ad2 s/NOSYMLINK/O_NOFOLLOW/ 2002-12-06 22:44:49 +00:00
jdolecek 4c7e9f23da pipe_stat(): add S_IRUSR and S_IWUSR to mode; this is what Linux does,
and seems like generally sensible (more sensible than not doing so), so done
in generic code rather than compat glue only

Change proposed in PR kern/18767 by Emmanuel Dreyfus.
2002-12-05 16:30:55 +00:00
jdolecek 16e3e3cd55 Couple fork-bomb defense changes:
- leave 5 processes for root-only use, the previous value of 1
  was unsufficient to execute additional commands once logged, and
  perhaps also not enough to actually login remotely with recent (open)sshd
- protect the log of "proc: table full" with ratecheck(), so that
  the message is only logged once per 10 seconds; though syslogd normally
  doesn't pass the repeated messages through, this avoids flooding
  syslogd and potentially also screen/logs
- If the process hits either system limit of number of processes in system,
  or user's limit of same, force the process to sleep for 0.5 seconds
  before returning failure. This turns 2000 rampaging fork monsters into
  2000 harmlessly snoozing fork monsters.
  The sleep is intentionally uninterruptible by signals.

These are not intended as ultimate protection agains fork-bombs.
Determined attacker can eat CPU differently than via repeating
fork() calls. But this is good enough to help protect against
programming mistakes or simple-minded tests.

Based on FreeBSD kern_fork.c change in revision 1.132 by
Mike Silbersack <silby at FreeBSD org>

Change also discussed on tech-kern@NetBSD.org, thread
'Fork bomb protection patch'.
2002-12-05 16:24:46 +00:00
yamt 172a847692 initialize uvm.aiodoned_proc. 2002-12-05 10:30:00 +00:00
jdolecek 2c21ec9d61 Unfortunately, we can't really know if select collision is needed
until after wakeup event, so we can't clear the SI_COLL flag
in selrecord(). Thus, effectively back rev. 1.57 off.

Problem reported in PR kern/17517 by David Laight, program triggering
the problem is in regress/sys/kern/poll/poll3w.c.
2002-11-30 13:46:58 +00:00
jdolecek 555659c55c there is single emul_irix now
use irix_n32_setregs for the IRIX n32 execsw entry
2002-11-30 13:19:37 +00:00
manu 005949afda cosmetic fix 2002-11-30 11:20:51 +00:00
jdolecek 615f789e98 fix typo in comment. pointed out by David Sainty 2002-11-30 09:59:22 +00:00
jdolecek e0d29a5578 fix bug in previous - if child was traced and p_opptr == p_pptr,
need to reparent the process to initproc, so that child wouldn't
have its p_pptr pointer still pointing on the exited parent

pointed out by Dave Sainty in private mail (the patch in kern/14443
didn't have this bug)
2002-11-30 09:54:43 +00:00
jdolecek a45e0497c5 selwakeup(): don't bother with pfind() in SI_COLL case; sel_pid is always zero
in this case, and even if not, the process would be already woken up by the
wakeup() call
change sent as part of kern/17517 by David Laight

XXX perhaps should KASSERT() sel_pid is zero in the SI_COLL case
2002-11-29 19:48:22 +00:00
manu 39b522c107 back out the previous change, which is useless. Darwin loads the libraries
that are required by the binary, not the libraries required by the libraries
required by the binary.

Hopefully, binaries should load again on i386.
2002-11-29 15:49:09 +00:00
manu b36d0c1bf6 Maitain a chainedlist of already loaded Mach-O objects, to avoid loading
the same file multiple times because of recursive loading (ie: libx require
liby and libz and liby require libz, so libz would be loaded twice)

This is probably suboptimal, but it enable /bin/sh to load on the PowerPC,
so it's a good interim solution until we figure precisely how things should
work.

I'm not sure whether this makes the excessive recursive check useless or not.
2002-11-29 11:31:11 +00:00
jdolecek b439ca6951 exit1(): make sure that, if orphaned child is being traced, it's
reparented back to original parent before it's killed.
This makes the original parent aware that the child has exited if
the debugger failed to wait() on the debugged zombie before exiting.
Since we clear tracing flags before killing the child, the reparenting
logic in wait4() wouldn't be triggered, so it's necessary to do it here.

Problem reported and fix provided in kern/14443 by David Sainty.
2002-11-28 21:41:29 +00:00
jdolecek dc55168cb6 issignal(): put apparently long-forgotten (at least since 4.4BSD)
debug printf inside #ifdef DEBUG_ISSIGNAL

This adresses kern/16760 by Love.
2002-11-28 21:00:27 +00:00
itojun ae1b88aa21 "tv->tv_sec * hz" could overflow a long. millert@openbsd 2002-11-27 04:07:42 +00:00
itojun dfd721e53e small SO_RCVTIMEO values are mistakenly taken to be zero. FreeBSD PR kern/32827. 2002-11-27 03:36:04 +00:00
christos e22906f6d0 si_ -> sel_ to avoid conflicts with siginfo. 2002-11-26 18:44:34 +00:00
itojun f81516ac1f 1.8 committed by mistake 2002-11-25 08:50:07 +00:00
itojun a1a2fcda1e no need for error check after MEXTMALLOC - jdolecek 2002-11-25 08:31:58 +00:00
itojun 387ba53bc6 MEXTMALLOC() can fail even if M_WAITOK, if arg is too big for malloc(). 2002-11-25 06:32:37 +00:00
manu 589ff87f68 Rewrite the excessive recursive loading protection by actually counting the
recursions instead of the total function calls. We limit to 6 recursion,
which is what Darwin does.
2002-11-24 21:59:43 +00:00
thorpej 3d64e26035 Add an EVCNT_ATTACH_STATIC() macro which gathers static evcnts
into a link set, which are added to the list of event counters
at boot time.
2002-11-24 17:33:43 +00:00
scw 0f91ed3dfa Quell uninitialised variable warnings. 2002-11-24 11:37:54 +00:00
manu 0e734a6755 Libraries do not use relative addresses, they are absolute and should be
treated as such if we want the same mapping as in Darwin.

While we are there KNFify function names
2002-11-22 23:09:46 +00:00
manu f528c56f39 Check for excessive recursive Mach-O loading 2002-11-21 22:30:32 +00:00
manu ae6b5562b1 Remove a debug message that has been committed by mistake. 2002-11-21 22:01:45 +00:00
manu af59b63bbd We now have the exact stack initial stack layout of Darwin:
macho_hdr, argc, *argv, NULL, *envp, NULL, progname, NULL,
*progname, **argv, **envp

Where progname is a pointer to the program name as given in the first
argument to execve(), and macho_hdr a pointer to the Mach-O header at
the beginning of the executable file.
2002-11-21 19:53:40 +00:00
simonb 928196073c White-space nits. 2002-11-20 04:29:31 +00:00
chs ab17ec89d1 add support for __MACHINE_STACK_GROWS_UP platforms. from fredette@ 2002-11-17 22:53:46 +00:00
chs ab08c3ab73 support a variant of the "member" keyword where the symbol defined
is different from the actual member name.
2002-11-17 19:24:50 +00:00
chs 4b2625143d change uvm_uarea_alloc() to indicate whether the returned uarea is already
backed by physical pages (ie. because it reused a previously-freed one),
so that we can skip a bunch of useless work in that case.
this fixes the underlying problem behind PR 18543, and also speeds up fork()
quite a bit (eg. 7% on my pc, 1% on my ultra2) when we get a cache hit.
2002-11-17 08:32:43 +00:00
uebayasi c041971257 Fix compilation errors introduced by recent trace_enter()/ktrsyscall() changes.
Provided by FUKAUMI Naoki <naoki at fukaumi dot org> in kern/19070.
2002-11-16 07:40:38 +00:00
manu d584ed9598 Add a realcode argument to trace_enter and ktrsyscall. realcode is the
original system call number, which can be negative for a Mach trap.
We cannot just replace code by realcode, because ktrsyscall uses it as
an index in the system call table, thus crashing the kernel when the
value is negative.
2002-11-15 20:06:00 +00:00
jdolecek cedc87712e ELF copyargs: at the time this is executed, process's ucred doesn't
contain the new uid/gid for suid/sgid binaries yet; determine AT_EUID
and AT_EGID by checking executed program vnode attributes in this case
2002-11-13 15:49:44 +00:00
jdolecek cee43b67cc add generic linux compat ELF copyargs function
this gives:
* linux sysconf(_SC_CLK_TCK) gives correct value for linux binaries (hz)
  even if hz != 100
* glibc gets proper information on real/effective uid and enables
  secure mode for suid binaries

g/c LINUX_COPYARGS_FUNCTION, replaced by linux ELF copyargs function
g/c alpha-specific linux ELF copyargs function and linux ELF defines
2002-11-13 15:16:27 +00:00
provos a5883f1616 fix systrace panic that was introduced when postponing pid number allocation
approved itojun
2002-11-13 00:51:02 +00:00
manu 530968e795 The kernel now builds with COMPAT_DARWIN. 2002-11-12 23:40:19 +00:00
blymn c4774e1260 * Don't keep evaluating fingerprint if there is no fingerprints for the
device.  Should help performance when no fingerprints are loaded.
* Back down the securelevel, now securelevel of 2 will make lack of
  fingerprint or fingerprint mismatch a fatal error.  Previously this
  was done at securelevel 3 or greater.
2002-11-12 12:54:36 +00:00
jdolecek c771eafacf add comments for trace_enter()/trace_exit(); particularily comment
expected value of 'code'
2002-11-11 10:43:54 +00:00
fvdl d0e6437e6d Back out previous, it caused compile errors in kern_fork.c. ISSET
and friends should either be made first-class citizens and moved
to an include file (systm.h perhaps), or nuked completely, but
not be redefined in a lot of files.
2002-11-10 14:01:57 +00:00
jdolecek 0a0804119d move definitions of custom SET()/ISSET()/CLR() macros from
sys/systrace.h to kern/kern_systrace.c
2002-11-10 10:01:03 +00:00
thorpej e0fb587e4e Avoid signed/unsigned comparison and strict alias warnings. 2002-11-10 03:35:31 +00:00
thorpej dccc71f1fe Fix signed/unsigned comparison warnings. 2002-11-10 03:28:59 +00:00
thorpej ff114c4a59 Fix signed/unsigned comparison warnings. 2002-11-09 20:06:07 +00:00
manu 99bc517790 Added sysctl to change all IRIX kernel values reported by uname and systeminfo:
OS name, hw name, kernel version, and so forth.
2002-11-09 09:03:56 +00:00
jdolecek 1e0e4766d3 kevent(2): if the specified timeout is >=1ns and <1us, perform a poll
rather than waiting forever due to TIMESPEC_TO_TIMEVAL() conversion
2002-11-08 20:26:50 +00:00
enami c07ab7ce9f Parse the modifier of ddb command as documented. 2002-11-08 02:08:57 +00:00
manu 9a4dfe85fa Added two sysctl-able flags: proc.curproc.stopfork and proc.curproc.stopexec
that can be used to block a process after fork(2) or exec(2) calls. The
new process is created in the SSTOP state and is never scheduled for running.

This feature is designed so that it is esay to attach the process using gdb
before it has done anything.

It works also with sproc, kthread_create, clone...
2002-11-07 00:22:28 +00:00
enami 8f82ec28ee Factor out the COMPAT_16 code. 2002-11-06 02:31:34 +00:00
mrg 3e8df71794 - do the COMPAT_16 dance in sysctl_diskstats() for the where == NULL case
as well.  pointed out by enami@.
- defflag COMPAT_16.
2002-11-05 13:22:32 +00:00
thorpej 80f8dbe30a Add a new VM map, lkm_map, which machine-dependent code can provide
in the event that it needs to use a special VM range (x86_64 falls
into this category).  We fall back onto kernel_map if machine-dependent
code doesn't create a special map.
2002-11-05 01:24:35 +00:00
mrg 5cad86b3ea repair backwards compatibility with netbsd 1.6 - if we are not given the
wanted sizeof(struct disk_sysctl), use the old size.  for non-COMPAT_16,
however, we return EINVAL so that all future programs are forced into
passing the wanted size.  1.6 iostat(8) works with -current kernel again.

as seen on tech-kern.
2002-11-04 03:50:07 +00:00
nisimura da22f42379 Add some informative comments about setrunqueue and remrunqueue. 2002-11-03 13:59:12 +00:00
perry 6858187df6 /*CONTCOND*/ while (0)'ed macros 2002-11-02 07:20:42 +00:00
kristerw 85b746f61a ISO C requires a statement after a label. 2002-11-01 21:46:51 +00:00
jdolecek 6a40f5edcb pipe_read(): initialize ocnt before pipelock() call; it might have been
used unitialized when the pipelock() call would fail
bug found by Krister Walfridsson
2002-11-01 21:34:30 +00:00
jdolecek 2a9e0afa92 set emul_netbsd's e_nsysent to SYS_NSYSENT, not SYS_MAXSYSCALL 2002-11-01 19:27:05 +00:00
simonb 307ae1b2e5 When calculating the space needed for the data, use the supplied
userland structure size (if passed in).
Use the supplied userland structure size (if passed in) to check if
there is enough room to copyout the next structure.
2002-11-01 15:20:03 +00:00
mrg 603098b9b5 implement separate read/write disk statistics:
- disk_unbusy() gets a new parameter to tell the IO direction.
	- struct disk_sysctl gets 4 new members for read/write bytes/transfers.
	when processing hw.diskstats, add the read&write bytes/transfers for
	the old combined stats to attempt to keep backwards compatibility.

unfortunately, due to multiple bugs, this will cause new kernels and old
vmstat/iostat/systat programs to fail.  however, the next time this is
change it will not fail again.

this is just the kernel portion.
2002-11-01 11:31:50 +00:00
enami fc1c4219ef Make this works with QUEUEDEBUG defined; don't use queue pointer after
removing an element from queue.
2002-11-01 03:34:07 +00:00
enami 5eec77bccd Cosmetic changes. 2002-11-01 03:32:21 +00:00
fvdl 4244ef3b22 For INTERLOCK_ACQUIRE, s/splsched/spllock/. 2002-11-01 01:13:32 +00:00
christos e6535bf628 XXX: be32toh on powerpc does not cast to int32_t so passing u_long to
be32toh produces an unsigned long result, causing a printf argument
mismatch. This is the wrong fix, but I am not going to change the
powerpc macros; fix the powerpc macros and revert my change.
2002-10-31 02:40:41 +00:00
manu 293419f314 int format long arg problems 2002-10-30 23:08:00 +00:00
kleink 0917926472 Revert rev. 1.147, as per PR kern/17411.
While a hard link to a symbolic link is not ruled out by POSIX-2001,
the link(2) interface is to perform normal pathname resolution,
which includes the resolution of symbolic links.
2002-10-30 22:36:46 +00:00
christos 74e8fc3424 fix fat binary architecture choosing code. mach binaries now execute as
poorly as before the x86 MP merge.
2002-10-30 15:21:01 +00:00
christos dc5aff13e6 make this compile again. 2002-10-30 15:04:47 +00:00
manu 9b4f3b0464 Introduce an array of supported CPU types by a given arch for Mach-O 2002-10-29 22:22:30 +00:00
manu b57515f2c4 If the magic number is 0xfeedface instead of 0xcafebabe, this means that
the executable is not fat. The binary starts with an object header instead
of a mach fat header.
2002-10-29 19:28:19 +00:00
blymn 29b7b4241f Added support for fingerprinted executables aka verified exec 2002-10-29 12:31:20 +00:00
jdolecek 25f6d9c389 regen: kqueue branch merge, addition of kqueue(2), kevent(2) 2002-10-23 09:18:16 +00:00
jdolecek 25cfe9dabd regen: kqueue branch merge, addition of VOP_KQFILTER() 2002-10-23 09:16:46 +00:00
jdolecek e0cc03a09b merge kqueue branch into -current
kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
2002-10-23 09:10:23 +00:00
gmcgarry 3dae1c4857 vclean() isn't part of the interface so make it local.
Sort prototypes by the interface they belong to.
2002-10-23 06:45:49 +00:00
perry 4235f246f8 Gah. I meant Empty. EMPTY!!! 2002-10-23 00:11:00 +00:00