OS APIs without error codes

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: OS APIs without error codes

Post by gravaera »

Yo:
Cognition wrote:Wouldn't it be easier to simply use a bitmask to return multiple error conditions? It seems like it'd work under most scenarios pretty well, perhaps there are some scenarios were you would have to worry about handling more than 32 or 64 error conditions but I can't imagine there would be many. At any rate in such scenarios calling several syscalls to resolve the error would definitely be a huge performance hit as well.
In practice, no: if a syscall passes through several "hurdles" at which an error can occur, it normally stops and returns error at the first one, because proceeding with a shaky state into the second hurdle is just likely to cause another error, or produce suboptimal results.

If the syscall is of such a nature that it can be completed sanely with one or more unusual flags occuring then the API would normally just provide a "FORCE_OPERATION" flag that the app explicitly passes to bypass a certain hurdle if it has knowledge of the ramifications. In practice, since continuing with unstable state into a syscall past an error point would produce more errors, and possibly corrupt system state, the kernel usually just returns an error code for the first encountered error and then leaves the onus on the application to rectify it and call in again, etc.

An error bitfield would end up unintentionally just becoming a single-error value since it will rarely ever have more than one bit set on return.

--Peace out
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: OS APIs without error codes

Post by Solar »

rdos wrote:I like your idea. Especially since that would define the possible error returns per API, not in a huge list that is specific for each OS and version.

And for showing error reasons to users, I think returning a text string is quite adequate, and only requires a printf or similar to decode.
That's just too much. How can anyone take this guy seriously? If that's not either trolling or complete retardedness, what is?

PS: For those wondering why I throw up my hands in exasperation... given the C standard library's "errno" mechanism, the list of possible error returns is well-defined per API call, and the the perror() and strerror() functions turn an errno value into a (localized!) error description.

Not that the "errno" mechanism is perfect; it has a couple of problems itself (especially in the realm of multithreading).
Last edited by Solar on Tue Apr 24, 2012 12:14 am, edited 1 time in total.
Every good solution is obvious once you've found it.
Cognition
Member
Member
Posts: 191
Joined: Tue Apr 15, 2008 6:37 pm
Location: Gotham, Batmanistan

Re: OS APIs without error codes

Post by Cognition »

gravaera wrote:Yo:

In practice, no: if a syscall passes through several "hurdles" at which an error can occur, it normally stops and returns error at the first one, because proceeding with a shaky state into the second hurdle is just likely to cause another error, or produce suboptimal results.

If the syscall is of such a nature that it can be completed sanely with one or more unusual flags occuring then the API would normally just provide a "FORCE_OPERATION" flag that the app explicitly passes to bypass a certain hurdle if it has knowledge of the ramifications. In practice, since continuing with unstable state into a syscall past an error point would produce more errors, and possibly corrupt system state, the kernel usually just returns an error code for the first encountered error and then leaves the onus on the application to rectify it and call in again, etc.

An error bitfield would end up unintentionally just becoming a single-error value since it will rarely ever have more than one bit set on return.

--Peace out
gravaera
I'm not suggesting the whole multiple return value thing is necessarily a great thing to go after in the first place. Just that if you wanted to do it, this would be one of the simplest ways to return a number of error conditions without querying the kernel multiple times or having to form a list somewhere.
Reserved for OEM use.
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

Solar wrote:PS: For those wondering why I throw up my hands in exasperation... given the C standard library's "errno" mechanism, the list of possible error returns is well-defined per API call, and the the perror() and strerror() functions turn an errno value into a (localized!) error description.
FYI, the standard C errno mechanism can be implemented with a syscall API that doesn't return error code information. I know because I've done it. :mrgreen:
Solar wrote: Not that the "errno" mechanism is perfect; it has a couple of problems itself (especially in the realm of multithreading).
Yes, the multithreaded errno implementation have to rely on things like thread local storage.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: OS APIs without error codes

Post by Yoda »

rdos wrote:FYI, the standard C errno mechanism can be implemented with a syscall API that doesn't return error code information. I know because I've done it. :mrgreen:
There is a Russian joke about a priority in surgery. A professor claimed that he made a unique surgical operation: tonsillectomy. Others wondered, - this surgical procedure is 3 thousands years old! But not via rectum!! - he replied :D
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: OS APIs without error codes

Post by piranha »

FYI, the standard C errno mechanism can be implemented with a syscall API that doesn't return error code information. I know because I've done it.
Uh huh. It doesn't return any error information? So, how do you know what the error is? Do you guess? :lol:

I believe that you're talking about using your superfluous kernel-polling error info API (which I just don't understand why you would do such a thing. Even if you're the only one who is writing programs for your OS, it just seems silly. Please, provide us with a real example, discuss exactly why it is better in an objective way. So far, I haven't seen that. If you want to post your design decisions here, expect people to respond critically to them, and if this many people disagree that it is a good idea, maybe you're wrong? Or is that even possible?) :roll:

Anyway, given a function (say, open) that can return the following errors (of course there are more, this is simplified):
  • access denied
    no such file
    invalid argument
    bad path
    interrupted by signal
    IO error
Go ahead, write the user space error handling API for this exactly how you envision to be "perfect".

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: OS APIs without error codes

Post by bluemoon »

Code: Select all

int syscall_get_errorno() {
  return FeatureNotSupported;
}
:mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen:
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: OS APIs without error codes

Post by qw »

:D Looks a lot like the Epimenides paradox.
User avatar
miker00lz
Member
Member
Posts: 144
Joined: Wed Dec 08, 2010 3:16 am
Location: St. Louis, MO USA

Re: OS APIs without error codes

Post by miker00lz »

i try to keep an open mind, but this whole thread is kind of stupid. why would you ever possibly want to do that? if you're just returning a boolean, you ALREADY are returning a value anyway so it might as well be a specific value telling the application what the problem was!

and about checking various printer states before making a print call, what if something changes between the time you asked and the time you print, resulting in a failed print call without you knowing why.

brilliant! =D>
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: OS APIs without error codes

Post by Brendan »

Hi,
berkus wrote:Best kernel syscall ever is in BeOS anyway.

Code: Select all

// Returns:
//   0 = computer has been sent "wake on LAN" packet
//   1 = computer is booting
//   2 = computer is on
//   3 = computer is preparing for shut down
//   4 = computer is in the "soft off" state (waiting for "wake on LAN")
//   5 = computer is off (unable to respond to "wake on LAN")

int _kern_is_computer_on(machine_ID)
{
   return state_of_each_computer_in_the_cluster[machine_ID];
}
Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

piranha wrote:
FYI, the standard C errno mechanism can be implemented with a syscall API that doesn't return error code information. I know because I've done it.
Uh huh. It doesn't return any error information? So, how do you know what the error is? Do you guess? :lol:

I believe that you're talking about using your superfluous kernel-polling error info API (which I just don't understand why you would do such a thing. Even if you're the only one who is writing programs for your OS, it just seems silly. Please, provide us with a real example, discuss exactly why it is better in an objective way. So far, I haven't seen that. If you want to post your design decisions here, expect people to respond critically to them, and if this many people disagree that it is a good idea, maybe you're wrong? Or is that even possible?) :roll:

Anyway, given a function (say, open) that can return the following errors (of course there are more, this is simplified):
  • access denied
    no such file
    invalid argument
    bad path
    interrupted by signal
    IO error
Go ahead, write the user space error handling API for this exactly how you envision to be "perfect".

-JL

Code: Select all


    int handle;

   handle = RdosOpenFile(path);
   if (handle == 0)
       setterrno(FILE_NOT_FOUND);

Works just fine. There is no other relevant return status.

1. Syscalls cannot be interrupted (interrupted by signal not relevant)
2. IO-errors are not returned to application (they are fatal)
3. Invalid parameter doesn't exist (other than at the C level)
4. Access denied cannot be returned as RDOS doesn't support access control
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: OS APIs without error codes

Post by piranha »

Trouble is, you started this thread with:
Traditional APIs (like DOS, Windows and *nix) are cluttered with error-codes, but is this really necesary? Isn't error-codes just a bagage from non-object oriented designs that are not really necesary?
Your OS may be perfect and you may be a perfect programmer and make it impossible for someone to supply an input that is a bad path (part of the path isn't a directory, etc, any other errors of which there will be a multitude for a lot of syscalls). But since you started this thread talking about API's in general, all the arguments you just made that discarded the error codes that I set forth in my challenge are then invalid. The point was to write error code handling for that challenge for a general OS, where all those errors are not fatal, can happen, and need to be handled by the application.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

piranha wrote: Your OS may be perfect and you may be a perfect programmer and make it impossible for someone to supply an input that is a bad path (part of the path isn't a directory, etc, any other errors of which there will be a multitude for a lot of syscalls).
FILE_NOT_FOUND covers a bad path as well. Naturally, the FS traversing code will notice that there is no match for part of the pathname and abort the search, but it won't set an error code. It would just abort with CY set. There is no reason to separate bad path from file not found, as they are essentially the same thing.
piranha wrote:But since you started this thread talking about API's in general, all the arguments you just made that discarded the error codes that I set forth in my challenge are then invalid.
I don't discard error codes. I never produce them, since I don't think lists of error codes are compatible with an object oriented design. They violate the encapsulation requirement, because as soon as you add a new global error code, all your error code processing code might become broken since you don't handle that case. That's why I don't support error codes.
piranha wrote:The point was to write error code handling for that challenge for a general OS, where all those errors are not fatal, can happen, and need to be handled by the application.
Applications shouldn't handle OS issues. The OS should do it's best to perform syscalls, and when this fails, these failures are fatal and there is nothing the application can do about it provided that the application checked relevant preconditions. That is my design concept in regard to this issue. So if an application passes an invalid path or non-existent file to openfile, it has violated the preconditions and should be rewritten to make sure it produces valid paths and checks that files it assume to exist also exists.

My error handling philosophy is that error handling should be localized, and not globalized, which means that errors should be handled where they are produced, and not propagated for ever to higher levels to be handled by a monster error handler. With localized error handling, there is no need for global error codes.
rdos
Member
Member
Posts: 3276
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

berkus wrote:@rdos
How do you go from carry flag to int handle again?
Pseudocode for RdosOpenFile:

Code: Select all


; file handle is returned in ebx for 32-bit memory model

RdosOpenFile    Macro
    DoSyscall ; returns handle in bx
    jc failed

ok:
    movzx ebx,bx
    jmp done

failed:
    xor ebx,ebx

done:
                     Endm
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: OS APIs without error codes

Post by Solar »

rdos wrote:I don't discard error codes. I never produce them, since I don't think lists of error codes are compatible with an object oriented design.
rdos wrote:My error handling philosophy is that error handling should be localized, and not globalized, which means that errors should be handled where they are produced, and not propagated for ever to higher levels to be handled by a monster error handler.
To wit: Every OO language I know uses exceptions, for the very reason that errors should not be handled at the point they occur (e.g. the filesystem), but at the point where something can be done about them (the application).
rdos wrote:Applications shouldn't handle OS issues. The OS should do it's best to perform syscalls, and when this fails, these failures are fatal and there is nothing the application can do about it provided that the application checked relevant preconditions.
That is your opinion. It might even work for RDOS. In the general case, you'd want to have multitasking, and in such an environment the above design is BS.

Can we close this?
Last edited by Solar on Wed Apr 25, 2012 2:51 am, edited 1 time in total.
Every good solution is obvious once you've found it.
Locked