Commit Graph

55 Commits

Author SHA1 Message Date
perry 477853c351 nuke trailing whitespace 2005-02-26 22:58:54 +00:00
jdolecek 74436be135 pass the fork flags down to the emulation fork hook, so that emulation
code can use the information for setup
2004-08-08 08:42:03 +00:00
drochner d19f706361 all ports define __HAVE_SIGINFO now, so remove the CPP conditionals 2004-03-26 17:34:18 +00:00
manu 996e659ce6 Try to do a better job at Mach port refcount. That's not perfect, though. 2004-01-01 22:48:54 +00:00
manu d1845c906c - Rework the Mach semaphore code to handle threads instead of processes
- Add 2 system calls: semaphore_signal_thread and sempaphore_signal_all (the
latter being untested)
- semaphore_signal_thread arguments list was wrong
2003-12-30 00:15:46 +00:00
manu 2c772b20d9 When the catcher of an exception dies before releasing the thread that
raised the exception, don't release the lock, this causes a crash (the lock
shall be released by the process that took it). Wakeup the thread instead,
it will release the lock itself.
2003-12-28 13:28:39 +00:00
manu 834aafd284 Rework Mach exception and Darwin's ptrace. gdb is now able to attach a
remote process. This new implementation also passes all the test programs
I've written so far.

- When exceptions come from traps, no UNIX signal should evet be sent.
- Add a lock to ensure a debugger handles only one exception at a time
- Use a structure to hold flavor and behavior in exception ports, instead
  of stuffing the two argument into an int.
- Implement new Mach services: thread_suspend, thread_resume and thread_abort
- Implement Darwin's ptrace PT_ATTACHEXC and PT_THUPDATE commands
- Handle NULL second argument correctly in sigprocmask.
- One mistake in the last commit (darwin_tracesig prototype)
2003-12-24 23:22:22 +00:00
manu 066436a916 Provide a kernel port for each thread. This makes the emulation of
Mach threads much more accurate: we do not confuse threads and tasks
anymore.
2003-12-20 19:43:17 +00:00
fvdl d99705e941 Put back Emmanuel's sigfilter hooks, as decided by Core. 2003-12-20 19:01:29 +00:00
manu b23b73b953 Introduce lwp_emuldata and the associated hooks. No hook is provided for the
exec case, as the emulation already has the ability to intercept that
with the e_proc_exec hook. It is the responsability of the emulation to
take appropriaye action about lwp_emuldata in e_proc_exec.

Patch reviewed by Christos.
2003-12-20 18:22:16 +00:00
grant 44ed233ab5 KNF, spelling and english fixes to some comments. remove trailing
whitespace.
2003-12-18 01:10:20 +00:00
manu 0951833f2e Remove the reference to struct proc in kernel and host port once the
process terminate, so that no stale pointer can be used if the port is
still referenced
2003-12-06 17:04:50 +00:00
manu 8f3ee36470 Fix some panics caused by incorrect Mach exceptions reference counts 2003-12-06 15:15:19 +00:00
jdolecek 0e253cf5f5 back the sigfilter emulation hook change off 2003-12-05 21:12:42 +00:00
manu 18e13eee35 Add a sigfilter emulation hook. It is used at the beginning of kpsignal2()
so that a specific emulation has the oportunity to filter out some signals.

if sigfilter returns 0, then no signal is sent by kpsignal2().

There is another place where signals can be generated: trapsignal. Since this
function is already an emulation hook, no call to the sigfilter hook was
introduced in trapsignal.

This is needed to emulate the softsignal feature in COMPAT_DARWIN (signals
sent as Mach exception messages)
2003-12-03 20:24:51 +00:00
manu 206a81affc Don't change process' special ports on exec(). If gdb attached the process,
it holds rights to the special ports, and it expects the rights to be valid
even after the process calls exec().
2003-11-25 13:22:38 +00:00
manu 43b8c2c38e Avoid re-allocations of darwin_emuldata structures by COMPAT_MACH. This
caused a memory leak, and as mach_emuldata is shorter than darwin_emuldata,
it caused memory corruption.
2003-11-20 22:05:25 +00:00
manu 28116d3012 Don't release the bootstrap port too much, as it is shared between
processes.
2003-11-18 15:57:13 +00:00
manu 74076749f8 Avoid leaking some Mach ports allocated in the kernel on fork, exec and
exit operations.
2003-11-18 14:11:33 +00:00
manu e04d06c9bb More work on exceptions. Once a task has raised an exception, it remains
blocked in the kernel. The task that catched the exception may unblock
it by sending a reply to the exception message (Of course it will have
to change something so that the exception is not immediatly raised again).

Handling of this reply is a bit complicated, as the kernel acts as the
client instead of the server. In this situation, we receive a message
but we will not send any reply (the message we receive is already a reply).
I have not found anything better than a special case in
mach_msg_overwrite_trap() to handle this.

A surprise: exceptions ports are preserved accross forks.

While we are there, use appropriate 64 bit types for make_memory_entry_64.
2003-11-18 01:40:18 +00:00
manu 144bfac97b First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.

TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.

While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 01:52:14 +00:00
christos e09c2a122c don't abuse the native sigcode. 2003-09-10 16:44:56 +00:00
chs 939df36e55 add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default.  the changes
fall into two basic catagories:

 - pmap and trap-handler changes.  these are all MD:
   = alpha: we already track per-page execute permission with the (software)
	PG_EXEC bit, so just have the trap handler pay attention to it.
   = i386: use a new GDT segment for %cs for processes that have no
	executable mappings above a certain threshold (currently the
	bottom of the stack).  track per-page execute permission with
	the last unused PTE bit.
   = powerpc/ibm4xx: just use the hardware exec bit.
   = powerpc/oea: we already track per-page exec bits, but the hardware only
	implements non-exec mappings at the segment level.  so track the
	number of executable mappings in each segment and turn on the no-exec
	segment bit iff the count is 0.  adjust the trap handler to deal.
   = sparc (sun4m): fix our use of the hardware protection bits.
	fix the trap handler to recognize text faults.
   = sparc64: split the existing unified TSB into data and instruction TSBs,
	and only load TTEs into the appropriate TSB(s) for the permissions.
	fix the trap handler to check for execute permission.
   = not yet implemented: amd64, hppa, sh5

 - changes in all the emulations that put a signal trampoline on the stack.
   instead, we now put the trampoline into a uvm_aobj and map that into
   the process separately.

originally from openbsd, adapted for netbsd by me.
2003-08-24 17:52:28 +00:00
fvdl d5aece61d6 Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
2003-06-29 22:28:00 +00:00
darrenr 960df3c8d1 Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records.  The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
2003-06-28 14:20:43 +00:00
martin d505b18964 Make sure to include opt_foo.h if a defflag option FOO is used. 2003-06-23 11:00:59 +00:00
manu 0479104b05 First attempt with task_suspend/task_resume, but we hit some bugs somewhere
else in our code.
2003-04-06 17:58:49 +00:00
manu fd94bf9486 First work on notifications. Not really working for now. 2003-03-29 11:04:08 +00:00
manu 2e73bb80fe More IOKit basics. Also introduced a mach_port flag to get a precise idea
of what port is sending a message to the kernel.
2003-02-05 23:58:09 +00:00
manu 2cd19ab0b2 - WindowServer wants io_master_port? Give it a port!
- introduce mach_port_destroy (badly emulated for now)
- on fork/exec, don't set l_private, as the process might be not mature
enough to survive a proc_representative_lwp call (-> kernel panic)

Once we give WindowServer the io_master_port, it sends a message to it:

   305 WindowServer MMSG  id 2804 [0x1310009 -> 0x131000e] -12016 bytes, flags 0
x1513
   0x0000  0x00001513 0xffffd110 0x0131000e 0x01310009   .........1...1..
   0x0010  0xffffcfd0 0x00000af4 0x00000000 0x00000000   ................
   0x0020  0xffffcf60 0x00000052 0x3c646963 0x74204944   ...`...R<dict ID
   0x0030  0x3d223022 0x3e3c6b65 0x793e494f 0x50726f76   ="0"><key>IOProv
   0x0040  0x69646572 0x436c6173 0x733c2f6b 0x65793e3c   iderClass</key><
   0x0050  0x73747269 0x6e672049 0x443d2231 0x223e494f   string ID="1">IO
   0x0060  0x48494453 0x79737465 0x6d3c2f73 0x7472696e   HIDSystem</strin
   0x0070  0x673e3c2f 0x64696374 0x3e0047cc              g></dict>.G.

Did you ever dreamt about system call arguments in XML?
2003-02-02 19:06:31 +00:00
manu 34a458238c For cproc_t, use a per thread value instead of a per process value. ifdef
out l_emuldata in struct lwp until we actually use it.
2003-01-30 19:14:18 +00:00
manu 80d406d8fe FIxed the way rights are recycled: the refcount makes only sense for
send, send once, and dead names, not for port sets and receive rights.
This make vi and telnet able to work again.

Also removed the all process right list and its lock, which got useless. The
all process lock is replaced by a per process lock, located in struct
mach_emuldata.

Also one bug fix: we did not correctly called Mach hooks for struct emuldata
initialization and release for Darwin processes.
2003-01-03 13:40:04 +00:00
manu 2c04ce0604 A better implementation of right carried by messages. We now correctly create
the right in the destination process.

This is a small step backward for functionnality: vi does not work anymore
because our right checks cause some spurious errors, but this will be fixed
later.
2003-01-02 12:46:06 +00:00
manu 0d5c4544d1 The first int on the stack is not the page size, it's the address of the
mach-O header. This is a guess based on what we have on Darwin, we need
to check other Mach systems to see if this value is Darwin specific or not.
Also updated copyright and removed useless debug
2003-01-01 15:18:25 +00:00
manu f3e11e72e9 Introduce port names, deallocate mach ressources at Darwin process exit 2002-12-31 15:47:37 +00:00
manu 874517b438 - When MACH_MSG_RCV_LARGE is set, we must return a message with just a header
and a body.
- If mach_init is not availabkle for boostrap requests, try to handle them
in the kernel (we don't really handle them, we just try to avoid hanging there)
- minor tweaks.
2002-12-27 19:57:47 +00:00
manu f464631d66 Several things:
1) rights should be shared by the threads within a process. While it would
be easier to handle this with the struct proc/struct lwp split, we attempt to
do this now by sharing the right lists. Because each right holds a reference
to struct proc, this might cause some problems later.
2) in pthread_exit, really exit the thread. Also reintialize the righ tlist to
make sure we will not destroy the parent's right list
3) rights can hold multiple permissions on a port (ie: send and receive). Fix th
is.
4) first attempt on right carried by messages. We still have to do rights carrie
d in the message body (complex messages).
2002-12-27 09:59:24 +00:00
manu 2894c4a53f Handle the kernel clock service by the kernel. 2002-12-26 13:45:17 +00:00
manu 3b71b464b2 First attempt on mach ports sets. Also maitian only one list of rights
per process, as segregating recv, send and send_once did not buy anything.
2002-12-19 22:23:06 +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
manu b8a9df5e21 FIrst attempt at mach ports and rights, which are needed if we ever want
to implement messages between kernel and userland.
While we are there, cleanup some debug messages.
2002-12-15 00:40:24 +00:00
manu 530e1a6b60 Added thread_switch and some bits of Mach semaphores 2002-12-12 23:18:20 +00:00
manu 9b84721494 Added implementation for cthread_self() and cthread_set_self(). Theses are
used to get and set the thread user value, which is an opaque pointer to
a per thread structure stored in userland. cthread_self() is used by Darwin
as an implementation for pthread_self(), which return the thread id.

We use the p_emuldata field of struct proc in order to keep track of the
thread user value. For now the value is per-process, but we will make it
per-thread when we will take care of threading.

While we are there, do some KNF
2002-12-07 15:33:01 +00:00
manu 0f239dc026 Check for alternate receive buffer for mach_msg_overwrite_trap
Check for target buffer length, and fail if it is too short
Move mach_msg_trap and mach_msg_overwrite_trap to their own file
Remove some useless debug messages now we have ktrace
Remove __P()
2002-11-28 21:21:32 +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
christos 645fa8d600 remove stack adjustment. 2002-11-19 16:29:32 +00:00
manu 114cae0e54 Fix the stack layout on program startup. This should be:
(8 bytes boundary) PAGE_SIZE   argc    argv  .... envp
2002-11-12 19:01:18 +00:00
jdolecek 1524c4bf08 set struct emul's nsysent to compat SYS_NSYSENT, not SYS_MAXSYSCALL 2002-11-01 19:26:21 +00:00
manu 80ee637534 - Introduce a e_fault field in struct proc to provide emulation specific
memory fault handler. IRIX uses irix_vm_fault, and all other emulation
use NULL, which means to use uvm_fault.

- While we are there, explicitely set to NULL the uninitialized fields in
struct emul: e_fault and e_sysctl on most ports

- e_fault is used by the trap handler, for now only on mips. In order to avoid
intrusive modifications in UVM, the function pointed by e_fault does not
has exactly the same protoype as uvm_fault:
int uvm_fault __P((struct vm_map *, vaddr_t, vm_fault_t, vm_prot_t));
int e_fault __P((struct proc *, vaddr_t, vm_fault_t, vm_prot_t));

- In IRIX share groups, all the VM space is shared, except one page.
This bounds us to have different VM spaces and synchronize modifications
to the VM space accross share group members. We need an IRIX specific hook
to the page fault handler in order to propagate VM space modifications
caused by page faults.
2002-09-21 21:14:54 +00:00
christos 830c5c171a Implement passing AT_{E,R}{U,G}ID in the elf aux vector, like solaris.
- pass struct proc to copyargs.
- eliminate svr4_copyargs, since it is the same as ours now.
2002-08-26 21:05:59 +00:00