newlib pipe.c implementation select() EBADF 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 select() EBADF PATCH

Post by anhanguera »

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: Select all

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: Select all

# wget http://gsulinux.org/~distch/pspdev/newlib-1.15.0-PSP-select.patch
- and also here is the changes only for select;

Code: Select all

--- 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 &#40;c&#41; 2006 Rafael Cabezas <[email protected]>
  *
+ * - 20070701 Alper Akcan "anhanguera" <[email protected]>
+ *            select EBADF fix
+ *
  */
 #include <fcntl.h>
 #include <errno.h>
@@ -43,6 +46,12 @@
                if &#40; &#40;count > 0&#41; || &#40;&#40;timeout != NULL&#41; && &#40;&#40;clock&#40;&#41; - start_time&#41; >= time&#41;&#41; &#41; &#123;
                        break;
                &#125;
+               if &#40;count < 0&#41; &#123;
+                       /* anhanguera - 20070701
+                        * error, lets let the caller to handle error state
+                        */
+                       break;
+               &#125;
                else &#123;
                        /* 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&#40;SELECT_POLLING_DELAY_IN_us&#41;;
@@ -155,6 +164,24 @@
                                        &#125;
                                        break;
                        &#125;
+               &#125; else &#123;
+                       /* 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 &#40;&#40;readfds && FD_ISSET&#40;fd, readfds&#41;&#41; ||
+                           &#40;writefds && FD_ISSET&#40;fd, writefds&#41;&#41; ||
+                           &#40;exceptfds && FD_ISSET&#40;fd, exceptfds&#41;&#41;&#41; &#123;
+                               errno = EBADF;
+                               return -1;
+                       &#125;
                &#125;
        &#125;
cheers,
anhanguera
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

i'm starting to wonder what kind of demanding/huge project you are planning to port that you are fixing all that stuff ... :)
anhanguera
Posts: 31
Joined: Thu Aug 26, 2004 4:20 pm

Post by anhanguera »

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.
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Seems to build fine, and so was added to the repository.
raf
Posts: 57
Joined: Thu Oct 13, 2005 7:38 am

Post by raf »

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.
Post Reply