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 select() EBADF 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: Sat Jun 02, 2007 1:07 am    Post subject: newlib pipe.c implementation select() EBADF PATCH Reply with quote

hi,

me again ;)

- bad file descriptor handling is missing in select(). if we know that, system has no idea about 'fd' which was given in one of the sets 'read/write/except' we should return '-1' and set errno to 'EBADF'. we might increse the count and set exceptfd for that 'fd', but it is safe to obey select manual.
Code:
from manual;
On error, -1 is returned, and errno is set appropriately; the sets and timeout become undefined, so do not rely on their contents after an error.

- you can grab the path file for newlib - includes syscalls and select changes - from;
Code:
# wget http://gsulinux.org/~distch/pspdev/newlib-1.15.0-PSP-select.patch

- and also here is the changes only for select;
Code:
--- select.orig.c       2007-06-01 18:00:20.000000000 +0300
+++ select.c    2007-06-01 18:01:40.000000000 +0300
@@ -7,6 +7,9 @@
  *
  * Copyright (c) 2006 Rafael Cabezas <rafpsp@gmail.com>
  *
+ * - 20070701 Alper Akcan "anhanguera" <distchx@yahoo.com>
+ *            select EBADF fix
+ *
  */
 #include <fcntl.h>
 #include <errno.h>
@@ -43,6 +46,12 @@
                if ( (count > 0) || ((timeout != NULL) && ((clock() - start_time) >= time)) ) {
                        break;
                }
+               if (count < 0) {
+                       /* anhanguera - 20070701
+                        * error, lets let the caller to handle error state
+                        */
+                       break;
+               }
                else {
                        /* Nothing found, and not timed-out yet; let's yield for SELECT_POLLING_DELAY_IN_us, so we're not in a busy loop */
                        sceKernelDelayThread(SELECT_POLLING_DELAY_IN_us);
@@ -155,6 +164,24 @@
                                        }
                                        break;
                        }
+               } else {
+                       /* anhanguera - 20070701
+                        *
+                        * here we know that, system has no idea about 'fd'. if caller requested
+                        * information about 'fd', return '-1' and set errno to 'EBADF'. we should
+                        * increse the count and set exceptfd for fd, but it is safe to obey select
+                        * manual.
+                        *
+                        * from manual;
+                        * On error, -1 is returned, and errno is set appropriately; the sets and
+                        * timeout become undefined, so do not rely on their contents after an error.
+                        */
+                       if ((readfds && FD_ISSET(fd, readfds)) ||
+                           (writefds && FD_ISSET(fd, writefds)) ||
+                           (exceptfds && FD_ISSET(fd, exceptfds))) {
+                               errno = EBADF;
+                               return -1;
+                       }
                }
        }

cheers,
anhanguera
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Sat Jun 02, 2007 4:02 am    Post subject: Reply with quote

i'm starting to wonder what kind of demanding/huge project you are planning to port that you are fixing all that stuff ... :)
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
anhanguera



Joined: 26 Aug 2004
Posts: 31

PostPosted: Sat Jun 02, 2007 4:11 am    Post subject: Reply with quote

nothing special. i had ported one of my projects 'xynth windowing system' to pspsdk. xynth uses sockets for IPC. on PSP that was sockets emulated via pipes + pipe emulated via memory. now it is just sockets emulated via pipe. thats all ;)
there is information, sources and binaries of older releases on below urls.
url1: http://gsulinux.org/~distch/projects/xynth
url2: http://sf.net/projects/xynth
anhanguera.
Back to top
View user's profile Send private message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Sat Jun 02, 2007 4:46 am    Post subject: Reply with quote

Seems to build fine, and so was added to the repository.
Back to top
View user's profile Send private message Visit poster's website
raf



Joined: 13 Oct 2005
Posts: 57

PostPosted: Thu Jun 14, 2007 5:17 am    Post subject: Reply with quote

ooPo wrote:
Seems to build fine, and so was added to the repository.


Thanks, anhanguera!. ooPo, should't his changes also be applied to the newlib-psp/ modules in the trunk (i.e. not just to the .patch file)?

Raf.
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