--- sys/i386/i386/machdep.c 11 Sep 2006 18:41:31 -0000 1.616.2.8 +++ sys/i386/i386/machdep.c 25 Jun 2007 21:15:49 -0000 @@ -319,7 +319,7 @@ } else { /* Old FreeBSD-style arguments. */ sf.sf_arg2 = code; - sf.sf_addr = regs->tf_err; + sf.sf_addr = td->td_md.md_fault_addr; sf.sf_ahu.sf_handler = catcher; } mtx_unlock(&psp->ps_mtx); @@ -458,11 +458,11 @@ /* Fill in POSIX parts */ sf.sf_si.si_signo = sig; sf.sf_si.si_code = code; - sf.sf_si.si_addr = (void *)regs->tf_err; + sf.sf_si.si_addr = (void *)td->td_md.md_fault_addr; } else { /* Old FreeBSD-style arguments. */ sf.sf_siginfo = code; - sf.sf_addr = regs->tf_err; + sf.sf_addr = td->td_md.md_fault_addr; sf.sf_ahu.sf_handler = catcher; } mtx_unlock(&psp->ps_mtx); @@ -597,11 +597,11 @@ /* Fill in POSIX parts */ sf.sf_si.si_signo = sig; sf.sf_si.si_code = code; - sf.sf_si.si_addr = (void *)regs->tf_err; + sf.sf_si.si_addr = (void *)td->td_md.md_fault_addr; } else { /* Old FreeBSD-style arguments. */ sf.sf_siginfo = code; - sf.sf_addr = regs->tf_err; + sf.sf_addr = td->td_md.md_fault_addr; sf.sf_ahu.sf_handler = catcher; } mtx_unlock(&psp->ps_mtx); @@ -675,7 +675,7 @@ bzero(si, sizeof(*si)); si->si_signo = sig; si->si_code = code; - si->si_addr = (void *)td->td_frame->tf_err; + si->si_addr = (void *)td->td_md.md_fault_addr; /* XXXKSE fill other fields */ } --- sys/i386/i386/trap.c 2 Sep 2006 17:12:46 -0000 1.277.2.4 +++ sys/i386/i386/trap.c 25 Jun 2007 21:16:20 -0000 @@ -747,7 +747,7 @@ } /* kludge to pass faulting virtual address to sendsig */ - frame->tf_err = eva; + td->td_md.md_fault_addr = eva; return((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV); } --- sys/i386/include/proc.h 4 Apr 2005 21:53:54 -0000 1.25 +++ sys/i386/include/proc.h 25 Jun 2007 21:14:00 -0000 @@ -49,6 +49,7 @@ struct mdthread { int md_spinlock_count; /* (k) */ register_t md_saved_flags; /* (k) */ + register_t md_fault_addr; /* (k) */ }; struct mdproc { --- sys/i386/linux/linux_sysvec.c 15 Jun 2006 15:52:04 -0000 1.137.2.2 +++ sys/i386/linux/linux_sysvec.c 25 Jun 2007 21:16:33 -0000 @@ -324,7 +324,7 @@ /* Fill in POSIX parts */ frame.sf_si.lsi_signo = sig; frame.sf_si.lsi_code = code; - frame.sf_si.lsi_addr = (void *)regs->tf_err; + frame.sf_si.lsi_addr = (void *)td->td_md.md_fault_addr; /* * Build the signal context to be used by sigreturn. --- sys/sys/thr.h.orig 2005-04-23 04:36:07.000000000 +0200 +++ sys/sys/thr.h 2007-08-03 21:36:55.000000000 +0200 @@ -30,6 +30,13 @@ #ifndef _SYS_THR_H_ #define _SYS_THR_H_ +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + /* Create the thread in the suspended state. */ #define THR_SUSPENDED 0x0001 /* Create the system scope thread. */ @@ -52,12 +59,19 @@ * See pthread_* */ #ifndef _KERNEL +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif int thr_create(ucontext_t *ctx, long *id, int flags); int thr_new(struct thr_param *param, int param_size); int thr_self(long *id); void thr_exit(long *state); int thr_kill(long id, int sig); +int thr_kill2(pid_t pid, long id, int sig); int thr_suspend(const struct timespec *timeout); int thr_wake(long id); --- sys/kern/syscalls.master.orig 2006-10-10 15:19:47.000000000 +0200 +++ sys/kern/syscalls.master 2007-08-03 21:55:32.000000000 +0200 @@ -797,6 +797,32 @@ long id, void *uaddr, void *uaddr2); } 455 AUE_NULL MSTD { int thr_new(struct thr_param *param, \ int param_size); } +456 AUE_NULL UNIMPL sigqueue +457 AUE_NULL UNIMPL kmq_open +458 AUE_NULL UNIMPL kmq_setattr +459 AUE_NULL UNIMPL kmq_timedreceive +460 AUE_NULL UNIMPL kmq_timedsend +461 AUE_NULL UNIMPL kmq_notify +462 AUE_NULL UNIMPL kmq_unlink +463 AUE_NULL UNIMPL abort2 +464 AUE_NULL UNIMPL thr_set_name +465 AUE_NULL UNIMPL aio_fsync +466 AUE_NULL UNIMPL rtprio_thread +467 AUE_NULL UNIMPL nosys +468 AUE_NULL UNIMPL nosys +469 AUE_NULL UNIMPL __getpath_fromfd +470 AUE_NULL UNIMPL __getpath_fromaddr +471 AUE_NULL UNIMPL sctp_peeloff +472 AUE_NULL UNIMPL sctp_generic_sendmsg +473 AUE_NULL UNIMPL sctp_generic_sendmsg_iov +474 AUE_NULL UNIMPL sctp_generic_recvmsg +475 AUE_NULL UNIMPL pread +476 AUE_NULL UNIMPL pwrite +477 AUE_NULL UNIMPL mmap +478 AUE_NULL UNIMPL lseek +479 AUE_NULL UNIMPL truncate +480 AUE_NULL UNIMPL ftruncate +481 AUE_KILL MSTD { int thr_kill2(pid_t pid, long id, int sig); } ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master --- sys/compat/freebsd32/syscalls.master.orig 2007-08-03 21:58:19.000000000 +0200 +++ sys/compat/freebsd32/syscalls.master 2007-08-03 21:56:38.000000000 +0200 @@ -755,3 +755,30 @@ u_int length); } 453 AUE_AUDITCTL MNOPROTO { int auditctl(char *path); } 454 AUE_NULL UNIMPL _umtx_op +455 AUE_NULL UNIMPL thr_new +456 AUE_NULL UNIMPL sigqueue +457 AUE_NULL UNIMPL kmq_open +458 AUE_NULL UNIMPL kmq_setattr +459 AUE_NULL UNIMPL kmq_timedreceive +460 AUE_NULL UNIMPL kmq_timedsend +461 AUE_NULL UNIMPL kmq_notify +462 AUE_NULL UNIMPL kmq_unlink +463 AUE_NULL UNIMPL abort2 +464 AUE_NULL UNIMPL thr_set_name +465 AUE_NULL UNIMPL aio_fsync +466 AUE_NULL UNIMPL rtprio_thread +467 AUE_NULL UNIMPL nosys +468 AUE_NULL UNIMPL nosys +469 AUE_NULL UNIMPL __getpath_fromfd +470 AUE_NULL UNIMPL __getpath_fromaddr +471 AUE_NULL UNIMPL sctp_peeloff +472 AUE_NULL UNIMPL sctp_generic_sendmsg +473 AUE_NULL UNIMPL sctp_generic_sendmsg_iov +474 AUE_NULL UNIMPL sctp_generic_recvmsg +475 AUE_NULL UNIMPL freebsd32_pread +476 AUE_NULL UNIMPL freebsd32_pwrite +477 AUE_NULL UNIMPL freebsd32_mmap +478 AUE_NULL UNIMPL freebsd32_lseek +479 AUE_NULL UNIMPL freebsd32_truncate +480 AUE_NULL UNIMPL freebsd32_ftruncate +481 AUE_KILL MNOPROTO { int thr_kill2(pid_t pid, long id, int sig); } --- sys/kern/sys_process.c.orig 2007-08-03 22:23:50.000000000 +0200 +++ sys/kern/sys_process.c 2007-08-03 22:44:44.000000000 +0200 @@ -777,14 +777,14 @@ sx_xunlock(&proctree_lock); proctree_locked = 0; } - /* deliver or queue signal */ - mtx_lock_spin(&sched_lock); - td2->td_flags &= ~TDF_XSIG; - mtx_unlock_spin(&sched_lock); - td2->td_xsig = data; p->p_xstat = data; p->p_xthread = NULL; if ((p->p_flag & (P_STOPPED_SIG | P_STOPPED_TRACE)) != 0) { + /* deliver or queue signal */ + mtx_lock_spin(&sched_lock); + td2->td_flags &= ~TDF_XSIG; + mtx_unlock_spin(&sched_lock); + td2->td_xsig = data; mtx_lock_spin(&sched_lock); if (req == PT_DETACH) { struct thread *td3; @@ -802,11 +802,10 @@ mtx_lock_spin(&sched_lock); thread_unsuspend(p); mtx_unlock_spin(&sched_lock); + } else { + if (data) + psignal(p, data); } - - if (data) - psignal(p, data); - break; case PT_WRITE_I: --- sys/kern/kern_thr.c.orig 2006-06-17 00:11:55.000000000 +0200 +++ sys/kern/kern_thr.c 2007-08-12 16:02:42.000000000 +0200 @@ -46,6 +46,8 @@ __FBSDID("$FreeBSD: src/sys/kern/kern_th #include +#include + extern int max_threads_per_proc; extern int max_groups_per_proc; @@ -345,6 +347,62 @@ thr_kill(struct thread *td, struct thr_k } int +thr_kill2(struct thread *td, struct thr_kill2_args *uap) + /* pid_t pid, long id, int sig */ +{ + struct thread *ttd; + struct proc *p; + int error; + + AUDIT_ARG(signum, uap->sig); + + if (uap->pid == td->td_proc->p_pid) { + p = td->td_proc; + PROC_LOCK(p); + } else if ((p = pfind(uap->pid)) == NULL) { + return (ESRCH); + } + AUDIT_ARG(process, p); + + error = p_cansignal(td, p, uap->sig); + if (error == 0) { + if (uap->id == -1) { + if (uap->sig != 0 && !_SIG_VALID(uap->sig)) { + error = EINVAL; + } else { + error = ESRCH; + FOREACH_THREAD_IN_PROC(p, ttd) { + if (ttd != td) { + error = 0; + if (uap->sig == 0) + break; + tdsignal(ttd, uap->sig, SIGTARGET_TD); + } + } + } + } else { + if (uap->id != td->td_tid) { + FOREACH_THREAD_IN_PROC(p, ttd) { + if (ttd->td_tid == uap->id) + break; + } + } else + ttd = td; + if (ttd == NULL) + error = ESRCH; + else if (uap->sig == 0) + ; + else if (!_SIG_VALID(uap->sig)) + error = EINVAL; + else + tdsignal(ttd, uap->sig, SIGTARGET_TD); + } + } + PROC_UNLOCK(p); + return (error); +} + +int thr_suspend(struct thread *td, struct thr_suspend_args *uap) /* const struct timespec *timeout */ { Index: vm/vm_map.c =================================================================== RCS file: /usr/local/arch/ncvs/src/sys/vm/vm_map.c,v retrieving revision 1.366.2.5 diff -u -r1.366.2.5 vm_map.c --- sys/vm/vm_map.c 4 Sep 2007 22:40:40 -0000 1.366.2.5 +++ sys/vm/vm_map.c 8 Sep 2007 03:55:01 -0000 @@ -155,6 +155,22 @@ #define PROC_VMSPACE_LOCK(p) do { } while (0) #define PROC_VMSPACE_UNLOCK(p) do { } while (0) +/* + * VM_MAP_RANGE_CHECK: [ internal use only ] + * + * Asserts that the starting and ending region + * addresses fall within the valid range of the map. + */ +#define VM_MAP_RANGE_CHECK(map, start, end) \ + { \ + if (start < vm_map_min(map)) \ + start = vm_map_min(map); \ + if (end > vm_map_max(map)) \ + end = vm_map_max(map); \ + if (start > end) \ + start = end; \ + } + void vm_map_startup(void) { @@ -1151,6 +1167,25 @@ return (0); } +int +vm_map_fixed(vm_map_t map, vm_object_t object, vm_ooffset_t offset, + vm_offset_t *addr /* IN/OUT */, vm_size_t length, vm_prot_t prot, + vm_prot_t max, int cow) +{ + vm_offset_t start, end; + int result; + + start = *addr; + vm_map_lock(map); + end = start + length; + VM_MAP_RANGE_CHECK(map, start, end); + (void) vm_map_delete(map, start, end); + result = vm_map_insert(map, object, offset, start, end, prot, + max, cow); + vm_map_unlock(map); + return (result); +} + /* * vm_map_find finds an unallocated region in the target address * map with the given length. The search is defined to be @@ -1361,22 +1396,6 @@ } /* - * VM_MAP_RANGE_CHECK: [ internal use only ] - * - * Asserts that the starting and ending region - * addresses fall within the valid range of the map. - */ -#define VM_MAP_RANGE_CHECK(map, start, end) \ - { \ - if (start < vm_map_min(map)) \ - start = vm_map_min(map); \ - if (end > vm_map_max(map)) \ - end = vm_map_max(map); \ - if (start > end) \ - start = end; \ - } - -/* * vm_map_submap: [ kernel use only ] * * Mark the given range as handled by a subordinate map. Index: vm/vm_map.h =================================================================== RCS file: /usr/local/arch/ncvs/src/sys/vm/vm_map.h,v retrieving revision 1.117.2.1 diff -u -r1.117.2.1 vm_map.h --- sys/vm/vm_map.h 2 Jun 2006 00:26:27 -0000 1.117.2.1 +++ sys/vm/vm_map.h 8 Sep 2007 03:55:01 -0000 @@ -334,6 +334,7 @@ vm_map_t vm_map_create(pmap_t, vm_offset_t, vm_offset_t); int vm_map_delete (vm_map_t, vm_offset_t, vm_offset_t); int vm_map_find (vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, boolean_t, vm_prot_t, vm_prot_t, int); +int vm_map_fixed (vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, vm_prot_t, vm_prot_t, int); int vm_map_findspace (vm_map_t, vm_offset_t, vm_size_t, vm_offset_t *); int vm_map_inherit (vm_map_t, vm_offset_t, vm_offset_t, vm_inherit_t); void vm_map_init (struct vm_map *, vm_offset_t, vm_offset_t); Index: vm/vm_mmap.c =================================================================== RCS file: /usr/local/arch/ncvs/src/sys/vm/vm_mmap.c,v retrieving revision 1.200.2.3 diff -u -r1.200.2.3 vm_mmap.c --- sys/vm/vm_mmap.c 21 Jul 2006 05:54:24 -0000 1.200.2.3 +++ sys/vm/vm_mmap.c 8 Sep 2007 03:55:01 -0000 @@ -1284,7 +1284,6 @@ if (*addr != trunc_page(*addr)) return (EINVAL); fitit = FALSE; - (void) vm_map_remove(map, *addr, *addr + size); } /* * Lookup/allocate object. @@ -1342,8 +1341,11 @@ if (flags & MAP_STACK) rv = vm_map_stack(map, *addr, size, prot, maxprot, docow | MAP_STACK_GROWS_DOWN); + else if (fitit) + rv = vm_map_find(map, object, foff, addr, size, TRUE, + prot, maxprot, docow); else - rv = vm_map_find(map, object, foff, addr, size, fitit, + rv = vm_map_fixed(map, object, foff, addr, size, prot, maxprot, docow); if (rv != KERN_SUCCESS) {