[haiku-commits] r42273 - haiku/trunk/src/system/kernel

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 21 Jun 2011 03:13:43 +0200 (CEST)

Author: mmlr
Date: 2011-06-21 03:13:43 +0200 (Tue, 21 Jun 2011)
New Revision: 42273
Changeset: https://dev.haiku-os.org/changeset/42273

Modified:
   haiku/trunk/src/system/kernel/port.cpp
Log:
* Actually include an offset to write to in writev_port_etc(). It would
  previously just always write over the beginning of the buffer for each vector.
  Since the writev version isn't exposed to userland by means of a syscall and
  kernel internally nobody used it, nobody noticed so far.
* Merge the two loops for user and kernel copy to remove the code duplication.


Modified: haiku/trunk/src/system/kernel/port.cpp
===================================================================
--- haiku/trunk/src/system/kernel/port.cpp      2011-06-21 00:56:20 UTC (rev 
42272)
+++ haiku/trunk/src/system/kernel/port.cpp      2011-06-21 01:13:43 UTC (rev 
42273)
@@ -1434,38 +1434,27 @@
        message->sender_team = team_get_current_team_id();
 
        if (bufferSize > 0) {
-               uint32 i;
-               if (userCopy) {
-                       // copy from user memory
-                       for (i = 0; i < vecCount; i++) {
-                               size_t bytes = msgVecs[i].iov_len;
-                               if (bytes > bufferSize)
-                                       bytes = bufferSize;
+               size_t offset = 0;
+               for (uint32 i = 0; i < vecCount; i++) {
+                       size_t bytes = msgVecs[i].iov_len;
+                       if (bytes > bufferSize)
+                               bytes = bufferSize;
 
-                               status_t status = user_memcpy(message->buffer,
+                       if (userCopy) {
+                               status_t status = user_memcpy(message->buffer + 
offset,
                                        msgVecs[i].iov_base, bytes);
                                if (status != B_OK) {
                                        put_port_message(message);
                                        goto error;
                                }
+                       } else
+                               memcpy(message->buffer + offset, 
msgVecs[i].iov_base, bytes);
 
-                               bufferSize -= bytes;
-                               if (bufferSize == 0)
-                                       break;
-                       }
-               } else {
-                       // copy from kernel memory
-                       for (i = 0; i < vecCount; i++) {
-                               size_t bytes = msgVecs[i].iov_len;
-                               if (bytes > bufferSize)
-                                       bytes = bufferSize;
+                       bufferSize -= bytes;
+                       if (bufferSize == 0)
+                               break;
 
-                               memcpy(message->buffer, msgVecs[i].iov_base, 
bytes);
-
-                               bufferSize -= bytes;
-                               if (bufferSize == 0)
-                                       break;
-                       }
+                       offset += bytes;
                }
        }
 


Other related posts:

  • » [haiku-commits] r42273 - haiku/trunk/src/system/kernel - mmlr