kernel: Implement wait info count limit in wait_for_objects.
Since wait_for_objects can wait on sems, threads and ports in addition to FDs, limiting to RLIMIT_NOFILES as in the select/poll case does not work. Since space is allocated for the wait objects in kernel memory, limiting their number to a valid range is still desireable. The limit is now placed at the sum of max sem, thread and port count plus RLIMIT_NOFILES. This also fixes a signed vs. unsigned comparison warning in check_max_fds introduced in hrev51866.
This commit is contained in:
parent
80e9e5f3e7
commit
9c4845e767
@ -909,9 +909,12 @@ _kern_wait_for_objects(object_wait_info* infos, int numInfos, uint32 flags,
|
||||
static bool
|
||||
check_max_fds(int numFDs)
|
||||
{
|
||||
if (numFDs <= 0)
|
||||
return true;
|
||||
|
||||
struct io_context *context = get_current_io_context(false);
|
||||
MutexLocker(&context->io_mutex);
|
||||
return numFDs <= context->table_size;
|
||||
return (size_t)numFDs <= context->table_size;
|
||||
}
|
||||
|
||||
|
||||
@ -1060,8 +1063,11 @@ _user_wait_for_objects(object_wait_info* userInfos, int numInfos, uint32 flags,
|
||||
{
|
||||
syscall_restart_handle_timeout_pre(flags, timeout);
|
||||
|
||||
if (numInfos < 0)
|
||||
bigtime_t start = system_time();
|
||||
if (numInfos < 0 || !check_max_fds(numInfos - sem_max_sems()
|
||||
- port_max_ports() - thread_max_threads())) {
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
if (numInfos == 0) {
|
||||
// special case: no infos
|
||||
|
Loading…
x
Reference in New Issue
Block a user