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 

errno & libc

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



Joined: 15 Oct 2005
Posts: 6
Location: Maribor

PostPosted: Sun Oct 16, 2005 12:20 am    Post subject: errno & libc Reply with quote

Hi everybody,

first i would like to say hello as i'm new here (been lurking for some time).

Recently i started to mess with Python port and noticed that functions in libc do not set
errno when sce* functions fail. I think this is not ok as it may break programs that expect
non zero value in errno when function fails (it also helps to debug).

I implemented a naive approach to solve this problem in libcglue.c.
I implemented this function:

Code:

#define __PSP_FACILITY_ERRNO (0x80010000)

static int psp_set_errno(int code)
{
        if (code & 0x80000000)
        {
                if (code & __PSP_FACILITY_ERRNO)
                {
                        code &= 0x0000FFFF;
                        switch(code)
                        {
                                case 0x24:
                                        code = ENAMETOOLONG;
                                        break;
                                case 0x62:
                                        code = EADDRINUSE;
                                        break;
                                case 0x67:
                                        code = ECONNABORTED;
                                        break;
                                case 0x6E:
                                        code = ETIMEDOUT;
                                        break;
                                case 0x7B:
                                        code = ENOMEDIUM;
                                        break;
                                       
                        }
                                               
                }
                errno = code;
                return -1;
        }
        else
        {
                return code;
        }
}


then wrapped most sce* calls like that:

Code:

int mkdir(const char *pathname, mode_t mode)
{
        char dest[MAXPATHLEN + 1];

        if(__psp_path_absolute(pathname, dest, MAXPATHLEN) < 0) {
                errno = ENAMETOOLONG;
                return -1;
        }

        return psp_set_errno(sceIoMkdir(dest, mode));
}



I tested this with Python and it seems to work fine.
Would that be acceptable approach, or is there another way?

BR,
Robert
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Sun Oct 16, 2005 4:29 am    Post subject: Re: errno & libc Reply with quote

I'd rather see something without a lookup:
Code:
static int psp_set_errno(int code)
{
                if (code & 0x80010000) {
                        errno = code & 0xFFFF;
                        return -1;
                }
                return code;
}
and then modify our newlib errno.h to use errno codes that match up with Sony's. I think most of the errno codes match up anyway; changing those that don't shouldn't hurt anything.

BTW, the errno variable in pspsdk isn't thread-local. I'm not sure of the best way to fix that.
Back to top
View user's profile Send private message
robif



Joined: 15 Oct 2005
Posts: 6
Location: Maribor

PostPosted: Sun Oct 16, 2005 5:18 am    Post subject: Re: Lookup Reply with quote

I agree that it would be better to change newlib's error codes than to perform lookup, as there
are only few values (that i know of) that differ.

Regarding thread safety i'm not sure either. Currently when i compile thread code into Python
PSP seems to freeze. This could be for many reasons...
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Tue Oct 25, 2005 8:01 pm    Post subject: Reply with quote

OK, I've cleaned up the errno handling in r1223. It should be more or less correct now, except that the actual errno values still need to get fixed up.
Back to top
View user's profile Send private message
robif



Joined: 15 Oct 2005
Posts: 6
Location: Maribor

PostPosted: Wed Oct 26, 2005 4:08 am    Post subject: Reply with quote

Thanks Jim,
this looks great.

Robert
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