Question

When developing a module (device driver, middleware, etc...) that will run in the kernel space, we would like to have some way to capture the reason an operation might fail.

In VxWorks, The errno mechanism seems to be a good way to do this.

Is it possible to define my own errno values?

Was it helpful?

Solution

In the context of VxWorks errno is defined as two 16-bit:

  • The upper 16-bit identifies the "module" where the error occured.
  • The lower 16-bit represent the particular error for that module.

The official vxWorks module values (for errno) are located in the ../h/vwModNum.h file. They are currently using a few hundred numbers. These module numbers all have the form

#define M_something   (nn <<  16)

It is strongly discouraged to modify this (or any) vxWorks header file.

What you could do is create your own module header file and start at a large enough number to not cause conflicts.

/* myModNum.h */
#define M_MyModule     (10000 << 16)
#define M_MyNextModule (10001 << 16)
...

The in the individual module header files, create the individual errno values.

/* myModule.h */
#define S_MyModule_OutOfResources (M_MyModule | 1)
#define S_MyModule_InvalidHandle  (M_MyModule | 2)
...

In your code, you can then set errno to your defined macro.

OTHER TIPS

Errno is just a number and functions like strerror() return a describing text. If you want to extend it just provide an own function similar to strerror() that looks into your error list or delegates to strerror().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top