[haiku-commits] haiku: hrev51871 - src/system/kernel

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 6 Apr 2018 15:24:13 -0400 (EDT)

hrev51871 adds 1 changeset to branch 'master'
old head: 80e9e5f3e772ea3c7d3d3478a3c70c2c86745954
new head: 9c4845e7678a4b508212e6adbb57084a4cd9a2a5
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=9c4845e7678a+%5E80e9e5f3e772

----------------------------------------------------------------------------

9c4845e7678a: 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.

                                            [ Michael Lotz <mmlr@xxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51871
Commit:      9c4845e7678a4b508212e6adbb57084a4cd9a2a5
URL:         http://cgit.haiku-os.org/haiku/commit/?id=9c4845e7678a
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Fri Apr  6 19:05:45 2018 UTC

----------------------------------------------------------------------------

1 file changed, 8 insertions(+), 2 deletions(-)
src/system/kernel/wait_for_objects.cpp | 10 ++++++++--

----------------------------------------------------------------------------

diff --git a/src/system/kernel/wait_for_objects.cpp 
b/src/system/kernel/wait_for_objects.cpp
index edc3b8a286..737a85130e 100644
--- a/src/system/kernel/wait_for_objects.cpp
+++ b/src/system/kernel/wait_for_objects.cpp
@@ -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


Other related posts:

  • » [haiku-commits] haiku: hrev51871 - src/system/kernel - mmlr