newlib pipe.c implementation read/write() illegal size PATCH

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
anhanguera
Posts: 31
Joined: Thu Aug 26, 2004 4:20 pm

newlib pipe.c implementation read/write() illegal size PATCH

Post by anhanguera »

hi,

- the sceKernel[Send/TrySend/Receive]MsgPipe(...) functions return SCE_KERNEL_ERROR_ILLEGAL_SIZE if the given number of bytes param (size_t len) is greater than the initial size of MsgPipe. in our case the initial size is 'PIPE_BUF' which is declared as 512 bytes in syslimits.h - this is the normal value i guess -.
- MsgPipe functions should try to write at least PIPE_BUF bytes, and should return the number of bytes that has been read/written if there is no fd, or sys error. the patch below guarantiess this for '__psp_pipe_read(...), __psp_pipe_write(...), __psp_pipe_nonblocking_write(...)' functions. there is no need to do same in _psp_pipe_nonblocking_read(...) becouse __psp_pipe_peekmsgsize() handles for us.

the patch;

Code: Select all

Index: newlib-1.15.0-PSP.patch
===================================================================
--- newlib-1.15.0-PSP.patch     (revision 2236)
+++ newlib-1.15.0-PSP.patch     (working copy)
@@ -7420,7 +7420,7 @@
 diff -burN orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c newlib-1.15.0/newlib/libc/sys/psp/pipe.c
 --- orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c      1969-12-31 20:00:00.000000000 -0400
 +++ newlib-1.15.0/newlib/libc/sys/psp/pipe.c   2007-05-29 15:02:51.000000000 -0300
-@@ -0,0 +1,285 @@
+@@ -0,0 +1,307 @@
 +/*
 + * PSP Software Development Kit - http://www.pspdev.org
 + * -----------------------------------------------------------------------
@@ -7572,7 +7572,7 @@
 +      *
 +      * @return 0 on success, < 0 on error
 +      */
-+    ret = sceKernelTryReceiveMsgPipe&#40;sceuid, buf, len, 0, 0&#41;;
++      ret = sceKernelTryReceiveMsgPipe&#40;sceuid, buf, len, 0, 0&#41;;
 +
 +      if &#40;ret == 0&#41; &#123;/* Success - Data */
 +              return len;
@@ -7601,8 +7601,8 @@
 +
 +#if 0
 +      /* we should block until there is some data &#40;or maybe for enough data&#41;,
-+      * peeking the msg size should be only for nonblocking reads
-+      */
++       * peeking the msg size should be only for nonblocking reads
++       */
 +      size = __psp_pipe_peekmsgsize&#40;fd&#41;;
 +      if &#40;size > 0&#41; &#123;
 +              if &#40;size < len&#41; &#123;
@@ -7614,6 +7614,13 @@
 +              return -1;
 +      &#125;
 +#endif
++      /* if len is greater than PIPE_BUF then, MsgPipe functions returns
++       * SCE_KERNEL_ERROR_ILLEGAL_SIZE, but it should read at least
++       * PIPE_BUF bytes, and return the number of bytes read.
++       */
++      if &#40;len > PIPE_BUF&#41; &#123;
++              len = PIPE_BUF;
++      &#125;
 +
 +      /**
 +      * Receive a message from a pipe
@@ -7650,6 +7657,14 @@
 +
 +      sceuid = __psp_descriptormap&#91;fd&#93;->sce_descriptor;
 +
++      /* if len is greater than PIPE_BUF then, MsgPipe functions returns
++       * SCE_KERNEL_ERROR_ILLEGAL_SIZE, but it should write at least
++       * PIPE_BUF bytes, and return the number of bytes written.
++       */
++      if &#40;len > PIPE_BUF&#41; &#123;
++              len = PIPE_BUF;
++      &#125;
++
 +      /**
 +      * Send a message to a pipe
 +      *
@@ -7664,7 +7679,6 @@
 +      */
 +      cbuf = &#40;char *&#41;buf;
 +      ret = sceKernelSendMsgPipe&#40;sceuid, cbuf, len, 0, NULL, NULL&#41;;
-+
 +      if &#40;ret == 0&#41; &#123;/* Success - Data */
 +              return len;
 +      &#125;
@@ -7686,6 +7700,14 @@
 +
 +      sceuid = __psp_descriptormap&#91;fd&#93;->sce_descriptor;
 +
++      /* if len is greater than PIPE_BUF then, MsgPipe functions returns
++       * SCE_KERNEL_ERROR_ILLEGAL_SIZE, but it should write at least
++       * PIPE_BUF bytes, and return the number of bytes written.
++       */
++      if &#40;len > PIPE_BUF&#41; &#123;
++              len = PIPE_BUF;
++      &#125;
++
 +      cbuf = &#40;char *&#41;buf;
 +      ret = sceKernelTrySendMsgPipe&#40;sceuid, cbuf, len, 0, 0&#41;;
 +
@@ -7709,7 +7731,7 @@
 diff -burN orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig
 --- orig.newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig 1969-12-31 20&#58;00&#58;00.000000000 -0400
 +++ newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig      2007-05-29 15&#58;00&#58;50.000000000 -0300
-@@ -0,0 +1,280 @@
+@@ -0,0 +1,301 @@
 +/*
 + * PSP Software Development Kit - http&#58;//www.pspdev.org
 + * -----------------------------------------------------------------------
@@ -7861,7 +7883,7 @@
 +      *
 +      * @return 0 on success, < 0 on error
 +      */
-+    ret = sceKernelTryReceiveMsgPipe&#40;sceuid, buf, len, 0, 0&#41;;
++      ret = sceKernelTryReceiveMsgPipe&#40;sceuid, buf, len, 0, 0&#41;;
 +
 +      if &#40;ret == 0&#41; &#123;/* Success - Data */
 +              return len;
@@ -7890,8 +7912,8 @@
 +
 +#if 0
 +      /* we should block until there is some data &#40;or maybe for enough data&#41;,
-+      * peeking the msg size should be only for nonblocking reads
-+      */
++       * peeking the msg size should be only for nonblocking reads
++       */
 +      size = __psp_pipe_peekmsgsize&#40;fd&#41;;
 +      if &#40;size > 0&#41; &#123;
 +              if &#40;size < len&#41; &#123;
@@ -7903,6 +7925,13 @@
 +              return -1;
 +      &#125;
 +#endif
++      /* if len is greater than PIPE_BUF then, MsgPipe functions returns
++       * SCE_KERNEL_ERROR_ILLEGAL_SIZE, but it should read at least
++       * PIPE_BUF bytes, and return the number of bytes read.
++       */
++      if &#40;len > PIPE_BUF&#41; &#123;
++              len = PIPE_BUF;
++      &#125;
 +
 +      /**
 +      * Receive a message from a pipe
@@ -7939,6 +7968,14 @@
 +
 +      sceuid = __psp_descriptormap&#91;fd&#93;->sce_descriptor;
 +
++      /* if len is greater than PIPE_BUF then, MsgPipe functions returns
++       * SCE_KERNEL_ERROR_ILLEGAL_SIZE, but it should write at least
++       * PIPE_BUF bytes, and return the number of bytes written.
++       */
++      if &#40;len > PIPE_BUF&#41; &#123;
++              len = PIPE_BUF;
++      &#125;
++
 +      /**
 +      * Send a message to a pipe
 +      *
@@ -7953,7 +7990,6 @@
 +      */
 +      cbuf = &#40;char *&#41;buf;
 +      ret = sceKernelSendMsgPipe&#40;sceuid, cbuf, len, 0, NULL, NULL&#41;;
-+
 +      if &#40;ret == 0&#41; &#123;/* Success - Data */
 +              return len;
 +      &#125;
@@ -7975,6 +8011,14 @@
 +
 +      sceuid = __psp_descriptormap&#91;fd&#93;->sce_descriptor;
 +
++      /* if len is greater than PIPE_BUF then, MsgPipe functions returns
++       * SCE_KERNEL_ERROR_ILLEGAL_SIZE, but it should write at least
++       * PIPE_BUF bytes, and return the number of bytes written.
++       */
++      if &#40;len > PIPE_BUF&#41; &#123;
++              len = PIPE_BUF;
++      &#125;
++
 +      cbuf = &#40;char *&#41;buf;
 +      ret = sceKernelTrySendMsgPipe&#40;sceuid, cbuf, len, 0, 0&#41;;
 +
@@ -7989,7 +8033,6 @@
 +              return __psp_set_errno&#40;ret&#41;;
 +      &#125;
 +&#125;
-+
 diff -burN orig.newlib-1.15.0/newlib/libc/sys/psp/pspcwd.c newlib-1.15.0/newlib/libc/sys/psp/pspcwd.c
 --- orig.newlib-1.15.0/newlib/libc/sys/psp/pspcwd.c    1969-12-31 20&#58;00&#58;00.000000000 -0400
 +++ newlib-1.15.0/newlib/libc/sys/psp/pspcwd.c 2007-05-29 15&#58;00&#58;50.000000000 -0300
cheers,
anhanguera.

ps: sorry for sending posts like spam.
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

I'm having a lot of problems trying to merge this patch. It appears that the forum munges tabs into spaces when you make a post. Is there any chance you could upload this patch somewhere so I can grab it in its true form?

Keep up the good work, btw.
anhanguera
Posts: 31
Joined: Thu Aug 26, 2004 4:20 pm

Post by anhanguera »

hi,

thanks. it was a while i have last played with pspsdk - almost one year- it is superb that pspdev grow so much. thank you all for providing us such good dev kit. you can grab the patch from;

Code: Select all

# wget http&#58;//gsulinux.org/~distch/newlib-1.15.0-PSP.patch
anhanguera.

ps. i had added comment to the header, you can delete if it annoys. ;)
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

I just completed a test compile and added it to the repository.
anhanguera
Posts: 31
Joined: Thu Aug 26, 2004 4:20 pm

Post by anhanguera »

thanks. pipe() emul works fine ;)
Post Reply