forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
anhanguera



Joined: 26 Aug 2004
Posts: 31

PostPosted: Fri Jun 01, 2007 6:16 am    Post subject: newlib pipe.c implementation read/write() illegal size PATCH Reply with quote

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:
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(sceuid, buf, len, 0, 0);
++      ret = sceKernelTryReceiveMsgPipe(sceuid, buf, len, 0, 0);
 +
 +      if (ret == 0) {/* Success - Data */
 +              return len;
@@ -7601,8 +7601,8 @@
 +
 +#if 0
 +      /* we should block until there is some data (or maybe for enough data),
-+      * peeking the msg size should be only for nonblocking reads
-+      */
++       * peeking the msg size should be only for nonblocking reads
++       */
 +      size = __psp_pipe_peekmsgsize(fd);
 +      if (size > 0) {
 +              if (size < len) {
@@ -7614,6 +7614,13 @@
 +              return -1;
 +      }
 +#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 (len > PIPE_BUF) {
++              len = PIPE_BUF;
++      }
 +
 +      /**
 +      * Receive a message from a pipe
@@ -7650,6 +7657,14 @@
 +
 +      sceuid = __psp_descriptormap[fd]->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 (len > PIPE_BUF) {
++              len = PIPE_BUF;
++      }
++
 +      /**
 +      * Send a message to a pipe
 +      *
@@ -7664,7 +7679,6 @@
 +      */
 +      cbuf = (char *)buf;
 +      ret = sceKernelSendMsgPipe(sceuid, cbuf, len, 0, NULL, NULL);
-+
 +      if (ret == 0) {/* Success - Data */
 +              return len;
 +      }
@@ -7686,6 +7700,14 @@
 +
 +      sceuid = __psp_descriptormap[fd]->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 (len > PIPE_BUF) {
++              len = PIPE_BUF;
++      }
++
 +      cbuf = (char *)buf;
 +      ret = sceKernelTrySendMsgPipe(sceuid, cbuf, len, 0, 0);
 +
@@ -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:00:00.000000000 -0400
 +++ newlib-1.15.0/newlib/libc/sys/psp/pipe.c.orig      2007-05-29 15:00:50.000000000 -0300
-@@ -0,0 +1,280 @@
+@@ -0,0 +1,301 @@
 +/*
 + * PSP Software Development Kit - http://www.pspdev.org
 + * -----------------------------------------------------------------------
@@ -7861,7 +7883,7 @@
 +      *
 +      * @return 0 on success, < 0 on error
 +      */
-+    ret = sceKernelTryReceiveMsgPipe(sceuid, buf, len, 0, 0);
++      ret = sceKernelTryReceiveMsgPipe(sceuid, buf, len, 0, 0);
 +
 +      if (ret == 0) {/* Success - Data */
 +              return len;
@@ -7890,8 +7912,8 @@
 +
 +#if 0
 +      /* we should block until there is some data (or maybe for enough data),
-+      * peeking the msg size should be only for nonblocking reads
-+      */
++       * peeking the msg size should be only for nonblocking reads
++       */
 +      size = __psp_pipe_peekmsgsize(fd);
 +      if (size > 0) {
 +              if (size < len) {
@@ -7903,6 +7925,13 @@
 +              return -1;
 +      }
 +#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 (len > PIPE_BUF) {
++              len = PIPE_BUF;
++      }
 +
 +      /**
 +      * Receive a message from a pipe
@@ -7939,6 +7968,14 @@
 +
 +      sceuid = __psp_descriptormap[fd]->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 (len > PIPE_BUF) {
++              len = PIPE_BUF;
++      }
++
 +      /**
 +      * Send a message to a pipe
 +      *
@@ -7953,7 +7990,6 @@
 +      */
 +      cbuf = (char *)buf;
 +      ret = sceKernelSendMsgPipe(sceuid, cbuf, len, 0, NULL, NULL);
-+
 +      if (ret == 0) {/* Success - Data */
 +              return len;
 +      }
@@ -7975,6 +8011,14 @@
 +
 +      sceuid = __psp_descriptormap[fd]->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 (len > PIPE_BUF) {
++              len = PIPE_BUF;
++      }
++
 +      cbuf = (char *)buf;
 +      ret = sceKernelTrySendMsgPipe(sceuid, cbuf, len, 0, 0);
 +
@@ -7989,7 +8033,6 @@
 +              return __psp_set_errno(ret);
 +      }
 +}
-+
 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:00:00.000000000 -0400
 +++ newlib-1.15.0/newlib/libc/sys/psp/pspcwd.c 2007-05-29 15:00:50.000000000 -0300


cheers,
anhanguera.

ps: sorry for sending posts like spam.
Back to top
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Fri Jun 01, 2007 6:47 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
anhanguera



Joined: 26 Aug 2004
Posts: 31

PostPosted: Fri Jun 01, 2007 7:05 am    Post subject: Reply with quote

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:
# wget http://gsulinux.org/~distch/newlib-1.15.0-PSP.patch

anhanguera.

ps. i had added comment to the header, you can delete if it annoys. ;)
Back to top
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Fri Jun 01, 2007 7:37 am    Post subject: Reply with quote

I just completed a test compile and added it to the repository.
Back to top
View user's profile Send private message Visit poster's website
anhanguera



Joined: 26 Aug 2004
Posts: 31

PostPosted: Fri Jun 01, 2007 7:42 am    Post subject: Reply with quote

thanks. pipe() emul works fine ;)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group