sharing maximum errno symbol used in __syscall_return (i386)
PATCH 1/1 sharing maximum errno symbol used in __syscall_return (i386)
Hi,
__syscall_return in unistd.h is maintained?
In the macro the value returned from system call is
compared with the maximum error number defined in a header file to know the call is successful or not. However, the maximum error number is hard-coded and is not updated.
Here is an example(i386):
/*
* user-visible error numbers are in the range -1 - -128: see
* <asm-i386/errno.h>
*/
#define __syscall_return(type, res) \
do { \
if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \ errno = -(res); \
res = -1; \
} \
The comment says the maximum errno is 128.
However, the actual C code says 128 + 1. What does "+ 1" mean?
Look at <asm-i386/errno.h>:
#ifndef _I386_ERRNO_H
#define _I386_ERRNO_H
#include <asm-generic/errno.h>
#endifThe look at <asm-generic/errno.h>:
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED 129 /* Key was rejected by service */
/* for robust mutexes */
#define EOWNERDEAD 130 /* Owner died */
#define ENOTRECOVERABLE 131 /* State not recoverable */Here the maximum errno is 131.
In many architectures, <asm-foo/errno.h> just includes <asm-generic/errno.h>. So I think <asm-generic/errno.h> should exports the real maximum errno and the other headers can use it. So in many cases, we can just maintain
the real maximum errno in <asm-generic/errno.h>.
Here is the patch for i386. If this patch is approved, I will write patches for the other architectures. (However, it may be better to be done by each architecture's maintainer.)
include/asm-generic/errno.h +4 -0
@@ -106,4 +106,8 @@ #define EKEYREJECTED 129 /* Key was reje#define EOWNERDEAD 130/* Owner died */ #define ENOTRECOVERABLE 131/* State not recoverable */ +/* +* If you add a new error, Don't forget to update `GENERIC_ERRNO_MAX' +*/ +#define GENERIC_ERRNO_MAX ENOTRECOVERABLE#endif
include/asm-i386/errno.h +1 -1
@@ -2,5 +2,5 @@ #ifndef _I386_ERRNO_H#define _I386_ERRNO_H#include <asm-generic/errno.h> - +#define i386_ERRNO_MAX GENERIC_ERRNO_MAX#endif
include/asm-i386/unistd.h +4 -3
@@ -326,12 +326,13 @@ #define __NR_vmsplice 316#define NR_syscalls 317/* -* user-visible error numbers are in the range -1 - -128: see -* <asm-i386/errno.h> +* user-visible error numbers are in the range -1 - -i386_ERRNO_MAX */ +#include <asm-i386/errno.h> +#define __syscall_return (type, res) \ do { \ - if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \ + if ((unsigned long)(res) >= (unsigned long)(-(i386_ERRNO_MAX))) { \ errno = -(res); \ res = -1; \ } \
Quoted 8 lines · On Tue, 20 Jun 2006 18:40:10 +0900 (JST) Masatake YAMATO wrote:
Hi,
__syscall_returninunistd.his maintained?In the macro the value returned from system call is
compared with the maximum error number defined in a header file to know the call is successful or not. However, the maximum error number is hard-coded and is not updated.
Ack, this certainly needs some care & fixing.
Quoted 13 lines
Here is an example(i386):
/*
* user-visible error numbers are in the range -1 - -128: see
* <asm-i386/errno.h>
*/
#define__syscall_return(type, res)\do { \ if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \include/asm-i386/unistd.h +0
-0errno = -(res); \ res =-1 ; \ } \
Quoted 2 lines
The comment says the maximum errno is 128.
However, the actual C code says 128 + 1. What does "+ 1" mean?
I don't understand the -1 either. A few asm-*/unistd.h files use that, but most of them do not.
Quoted 27 lines
Look at <
asm-i386/errno.h>:#ifndef _I386_ERRNO_H #define _I386_ERRNO_H #include <asm-generic/errno.h> #endifThe look at <
asm-generic/errno.h>:#define EKEYREVOKED 128 /* Key has been revoked */ #define EKEYREJECTED 129 /* Key was rejected by service */ /* for robust mutexes */ #define EOWNERDEAD 130 /* Owner died */ #define ENOTRECOVERABLE 131 /* State not recoverable */Here the maximum errno is 131.
In many architectures, <
asm-foo/errno.h> just includes <asm-generic/errno.h>. So I think <asm-generic/errno.h> should exports the real maximum errno and the other headers can use it. So in many cases, we can just maintain
the real maximum errno in <asm-generic/errno.h>.
Quoted 3 lines
Here is the patch for i386. If this patch is approved, I will write patches for the other architectures. (However, it may be better to be done by each architecture's maintainer.)
I like the patch.
Quoted 38 lines
Signed-off-by Masatake YAMATO <[email protected]>include/asm-generic/errno.h +4
-0@@ -106,4 +106,8 @@ #define EKEYREJECTED 129 /* Key was reje#define EOWNERDEAD 130/* Owner died */ #define ENOTRECOVERABLE 131/* State not recoverable */ +/* +* If you add a new error, Don't forget to update `GENERIC_ERRNO_MAX' +*/ +#define GENERIC_ERRNO_MAX ENOTRECOVERABLE#endif include/asm-i386/errno.h +1
-1@@ -2,5 +2,5 @@ #ifndef _I386_ERRNO_H#define _I386_ERRNO_H#include <asm-generic/errno.h> - +#define i386_ERRNO_MAX GENERIC_ERRNO_MAX#endif include/asm-i386/unistd.h +1
-2@@ -326,12 +326,13 @@ #define __NR_vmsplice 316#define NR_syscalls 317/* -* user-visible error numbers are in the range -1 - -128: see -* <asm-i386/errno.h> +* user-visible error numbers are in the range -1 - -i386_ERRNO_MAX */
include/asm-i386/unistd.h #define __NR_vmsplice 316
Quoted 10 lines
include/asm-i386/unistd.h +3
-2+#include <asm-i386/errno.h> +#define __syscall_return (type, res) \ do { \ - if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \ + if ((unsigned long)(res) >= (unsigned long)(-(i386_ERRNO_MAX))) { \ errno = -(res); \ res = -1; \ } \ -
Thanks.
---
~Randy
Quoted 7 lines · Masatake YAMATO
Hi,
__syscall_returninunistd.his maintained?In the macro the value returned from system call is
compared with the maximum error number defined in a header file to know the call is successful or not. However, the maximum error number is hard-coded and is not updated.
And it's wrong, anyway. It has long been agreed that the maximum errno value, for any architecture, is 4095.
-hpa
Quoted 4 lines
Quoted 4 lines
Hi,
__syscall_returninunistd.his maintained?
Quoted 8 lines
Quoted 5 lines
In the macro the value returned from system call is
compared with the maximum error number defined in a header file to know the call is successful or not. However, the maximum error number is hard-coded and is not updated.And it's wrong, anyway. It has long been agreed that the maximum errno value, for any architecture, is 4095.
So we should do just:
#define GENERIC_ERRNO_MAX 4095
Here my patch is proved to be useful for maintaining __syscall_return:-P
Masatake YAMATO
Quoted 7 lines · Masatake YAMATO
Quoted 7 lines
Quoted 7 lines
Hi,
__syscall_returninunistd.his maintained?In the macro the value returned from system call is
compared with the maximum error number defined in a header file to know the call is successful or not. However, the maximum error number is hard-coded and is not updated.
Quoted 9 lines
Quoted 1 line
And it's wrong, anyway. It has long been agreed that the maximum errno value, for any architecture, is 4095.
So we should do just:
#define GENERIC_ERRNO_MAX 4095Here my patch is proved to be useful for maintaining __syscall_return:-P
Well, most of the various macros in unistd.h really should go too, since they're mostly underutilized and definitely ill-maintained.
The only one that I know of which is still used by the kernel itself is execve. If so, perhaps we should just have an open-coded execve.
-hpa