axeld + bonefish:

* Implemented automatic syscall restarts:
  - A syscall can indicate that it has been interrupted and can be
    restarted by setting a respective bit in thread::flags. It can
    store parameters it wants to be preserved for the restart in
    thread::syscall_restart::parameters. Another thread::flags bit
    indicates whether it has been restarted.
  - handle_signals() clears the restart flag, if the handled signal
    has a handler function installed and SA_RESTART is not set. Another
    thread flag (THREAD_FLAGS_DONT_RESTART_SYSCALL) can prevent syscalls
    from being restarted, even if they could be (not used yet, but we
    might want to use it in resume_thread(), so that we stay
    behaviorally compatible with BeOS).
  - The architecture specific syscall handler restarts the syscall, if
    the restart flag is set. Implemented for x86 only.
  - Added some support functions in the private <syscall_restart.h> to
    simplify the syscall restart code in the syscalls.
  - Adjusted all syscalls that can potentially be restarted accordingly.
  - _user_ioctl() sets new thread flag THREAD_FLAGS_IOCTL_SYSCALL while
    calling the underlying FS's/driver's hook, so that syscall restarts
    can also be supported there.
* thread_at_kernel_exit() invokes handle_signals() in a loop now, as
  long as the latter indicates that the thread shall be suspended, so
  that after waking up signals received in the meantime will be handled
  before the thread returns to userland. Adjusted handle_signals()
  accordingly -- when encountering a suspending signal we don't check
  for further signals.
* Fixed sigsuspend(): Suspending the thread and rescheduling doesn't
  result in the correct behavior. Instead we employ a temporary
  condition variable and interruptably wait on it. The POSIX test
  suite test passes, now.
* Made the switch_sem[_etc]() behavior on interruption consistent.
  Depending on when the signal arrived (before the call or when already
  waiting) the first semaphore would or wouldn't be released. Now we
  consistently release it.
* Refactored _user_{read,write}[v]() syscalls. Use a common function for
  either pair. The iovec version doesn't fail anymore, if anything could
  be read/written at all. It also checks whether a complete vector
  could be read/written, so that we won't skip data, if the underlying
  FS/driver couldn't read/write more ATM.
* Some refactoring in the x86 syscall handler: The int 99 and sysenter
  handlers use a common subroutine to avoid code duplication.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23983 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-02-17 15:48:30 +00:00
parent 4af8877673
commit 4048494ce4
15 changed files with 561 additions and 432 deletions
+15 -14
View File
@@ -30,6 +30,7 @@
#include <ksignal.h>
#include <smp.h>
#include <syscalls.h>
#include <syscall_restart.h>
#include <team.h>
#include <tls.h>
#include <user_runtime.h>
@@ -1490,26 +1491,20 @@ void
thread_at_kernel_exit(void)
{
struct thread *thread = thread_get_current_thread();
cpu_status state;
bigtime_t now;
TRACE(("thread_at_kernel_exit: exit thread %ld\n", thread->id));
if (handle_signals(thread)) {
state = disable_interrupts();
GRAB_THREAD_LOCK();
// was: smp_send_broadcast_ici(SMP_MSG_RESCHEDULE, 0, 0, 0, NULL, SMP_MSG_FLAG_SYNC);
while (handle_signals(thread)) {
InterruptsSpinLocker _(thread_spinlock);
scheduler_reschedule();
}
RELEASE_THREAD_LOCK();
} else
state = disable_interrupts();
cpu_status state = disable_interrupts();
thread->in_kernel = false;
// track kernel time
now = system_time();
bigtime_t now = system_time();
thread->kernel_time += now - thread->last_time;
thread->last_time = now;
@@ -2472,7 +2467,12 @@ _user_spawn_thread(int32 (*entry)(thread_func, void *), const char *userName,
status_t
_user_snooze_etc(bigtime_t timeout, int timebase, uint32 flags)
{
return snooze_etc(timeout, timebase, flags | B_CAN_INTERRUPT);
// NOTE: We only know the system timebase at the moment.
syscall_restart_handle_timeout_pre(flags, timeout);
status_t error = snooze_etc(timeout, timebase, flags | B_CAN_INTERRUPT);
return syscall_restart_handle_timeout_post(error, timeout);
}
@@ -2554,10 +2554,11 @@ _user_wait_for_thread(thread_id id, status_t *userReturnCode)
status = wait_for_thread_etc(id, B_CAN_INTERRUPT, 0, &returnCode);
if (status == B_OK && userReturnCode != NULL
&& user_memcpy(userReturnCode, &returnCode, sizeof(status_t)) < B_OK)
&& user_memcpy(userReturnCode, &returnCode, sizeof(status_t)) < B_OK) {
return B_BAD_ADDRESS;
}
return status;
return syscall_restart_handle_post(status);
}