History log of /haiku/headers/private/kernel/syscall_restart.h
Revision Date Author Comments
# f27a660a 27-Aug-2021 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Style fixup.


# 9c91c3b5 27-Aug-2021 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Adjust timeout computation for syscall_restart.

If the timeout is already >= B_INFINITE_TIMEOUT, we do not need
to do any of the following math (which would usually overflow anyway)
and can leave the timeout alone.

Spotted by kernel undefined behavior sanitizer.


# 547cd462 02-Nov-2013 Axel Dörfler <axeld@pinc-software.de>

trim: Added is_called_via_syscall() function.

* And use it in get_trim_data_from_user(), formerly known as copy_*().
* This fixes differentiating between user and kernel buffers.


# 4535495d 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f13ba039 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed SyscallRestartWrapper comparison operators. They are not
needed, since we've got a cast operator.
* Reverted r24927-r24929. There's no potential ambiguity anymore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24949 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 43d5590c 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Yep, first clear THREAD_FLAGS_SYSCALL, then check whether it is set.
That would explain why syscall restarts were broken. In fact there's no
reason to check the flag at all, since we know we set it.

ftp appears to work again.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24918 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75015ff5 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed THREAD_FLAGS_IOCTL_SYSCALL to THREAD_FLAGS_SYSCALL,
syscall_restart_ioctl_is_restarted() to syscall_restart_is_restarted,
IoctlSyscallFlagUnsetter to SyscallFlagUnsetter, and
IoctlSyscallRestartWrapper to SyscallRestartWrapper, as they are no
longer only used for ioctl().
* Removed unused syscall_restart_ioctl_handle_post().
* Made SyscallRestartWrapper a lot fancier. Instead of storing a
reference to the result value, it stores the value itself, and it
features all the interesting operators that make it appear like that
value. This simplifies the use of the class quite a bit.
* THREAD_FLAGS_SYSCALL is now set for all socket function and the
read[v](), write[v]() syscalls.
* Added is_syscall() function and net_stack hook to the net stack.
* Removed "kernel" parameter from all net_stack_interface and net_socket
module hooks. They aren't need any longer, since is_syscall() can be
used instead.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24914 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 89df64c5 10-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added two helper classes for dealing with restarts of ioctl() like
syscalls.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24903 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7dc065bd 23-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* syscall_restart_handle_timeout_pre(uint32&, bigtime_t&): A huge
negative relative timeout would be converted to B_INFINITE_TIMEOUT.
For some reason the ScreenSaver preflet is snooze()ing with such
a value.
* Some more comments.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24080 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c72d22a5 17-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Converting relative timeouts into absolute ones is fine in principle,
but there's a special handling for 0 us relative timeouts. Syscalls
usually return B_WOULD_BLOCK instead of B_TIMED_OUT in this case, and
callers might explicitely check for it. Hence we don't convert 0 us
timeouts anymore. gdb works again.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23989 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4048494c 17-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

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


# 547cd462f843df15db02ed0dd7a35528221b66bc 02-Nov-2013 Axel Dörfler <axeld@pinc-software.de>

trim: Added is_called_via_syscall() function.

* And use it in get_trim_data_from_user(), formerly known as copy_*().
* This fixes differentiating between user and kernel buffers.


# 4535495d80c86e19e2610e7444a4fcefe3e0f8e6 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f13ba03959f6227a75ff8c2e129058215dea380f 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed SyscallRestartWrapper comparison operators. They are not
needed, since we've got a cast operator.
* Reverted r24927-r24929. There's no potential ambiguity anymore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24949 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 43d5590ce13da8a9a962b119748258419959f125 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Yep, first clear THREAD_FLAGS_SYSCALL, then check whether it is set.
That would explain why syscall restarts were broken. In fact there's no
reason to check the flag at all, since we know we set it.

ftp appears to work again.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24918 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75015ff525050d1d716f499732c566956c6078ad 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed THREAD_FLAGS_IOCTL_SYSCALL to THREAD_FLAGS_SYSCALL,
syscall_restart_ioctl_is_restarted() to syscall_restart_is_restarted,
IoctlSyscallFlagUnsetter to SyscallFlagUnsetter, and
IoctlSyscallRestartWrapper to SyscallRestartWrapper, as they are no
longer only used for ioctl().
* Removed unused syscall_restart_ioctl_handle_post().
* Made SyscallRestartWrapper a lot fancier. Instead of storing a
reference to the result value, it stores the value itself, and it
features all the interesting operators that make it appear like that
value. This simplifies the use of the class quite a bit.
* THREAD_FLAGS_SYSCALL is now set for all socket function and the
read[v](), write[v]() syscalls.
* Added is_syscall() function and net_stack hook to the net stack.
* Removed "kernel" parameter from all net_stack_interface and net_socket
module hooks. They aren't need any longer, since is_syscall() can be
used instead.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24914 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 89df64c56e54842e2194cff74c413d81e5716989 10-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added two helper classes for dealing with restarts of ioctl() like
syscalls.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24903 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7dc065bdb0cedc86ef41c16fb242a80647b9e173 23-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* syscall_restart_handle_timeout_pre(uint32&, bigtime_t&): A huge
negative relative timeout would be converted to B_INFINITE_TIMEOUT.
For some reason the ScreenSaver preflet is snooze()ing with such
a value.
* Some more comments.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24080 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c72d22a5e897f54592734173f93d21cff5d2cb2d 17-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Converting relative timeouts into absolute ones is fine in principle,
but there's a special handling for 0 us relative timeouts. Syscalls
usually return B_WOULD_BLOCK instead of B_TIMED_OUT in this case, and
callers might explicitely check for it. Hence we don't convert 0 us
timeouts anymore. gdb works again.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23989 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4048494ce44a925d3d1e40e4ffb9abe670b4b827 17-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

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