Skip to contentSkip to conversation

prctl: implement PR_GET_ENDIAN for all architectures

PATCH In review Helge Deller 7 participants 9 messages Jan 28, 2017 – Feb 15, 2017 ABI/API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 prctl: implement PR_GET_ENDIAN for all architectures

The prctl(PR_GET_ENDIAN) syscall was added to Kernel 2.6.18, but implemented for PowerPC only.
This trivial patch adds support for this syscall for all other architectures.

kernel/sys.c +6 -3
index 842914e..5818e5e 100644
@@ -79,9 +79,6 @@
 #ifndef GET_FPEXC_CTL
 # define GET_FPEXC_CTL(a, b)	(-EINVAL)
 #endif
-#ifndef GET_ENDIAN
-# define GET_ENDIAN(a, b)	(-EINVAL)
-#endif
 #ifndef SET_ENDIAN
 # define SET_ENDIAN(a, b)	(-EINVAL)
 #endif
@@ -2136,7 +2133,13 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EFAULT;
 		break;
 	case PR_GET_ENDIAN:
+#ifdef GET_ENDIAN
 		error = GET_ENDIAN(me, arg2);
+#elif defined(__BIG_ENDIAN)
+		error = put_user(PR_ENDIAN_BIG, (unsigned int __user *)arg2);
+#else
+		error = put_user(PR_ENDIAN_LITTLE, (unsigned int __user *)arg2);
+#endif
 		break;
 	case PR_SET_ENDIAN:
 		error = SET_ENDIAN(me, arg2);
#1 lore raw
Quoted 3 lines · On Sat, 28 Jan 2017 12:13:10 +0100 Helge Deller <[email protected]> wrote:

The prctl(PR_GET_ENDIAN) syscall was added to Kernel 2.6.18, but implemented for PowerPC only.
This trivial patch adds support for this syscall for all other architectures.

Seems reasonable. I guess. Why is this needed?

The man page will need updating. It says "PowerPC only".

Quoted 29 lines
kernel/sys.c +6 -3
index 842914e..5818e5e 100644
@@ -79,9 +79,6 @@
 #ifndef GET_FPEXC_CTL
 # define GET_FPEXC_CTL(a, b)	(-EINVAL)
 #endif
-#ifndef GET_ENDIAN
-# define GET_ENDIAN(a, b)	(-EINVAL)
-#endif
 #ifndef SET_ENDIAN
 # define SET_ENDIAN(a, b)	(-EINVAL)
 #endif
@@ -2136,7 +2133,13 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EFAULT;
 		break;
 	case PR_GET_ENDIAN:
+#ifdef GET_ENDIAN
 		error = GET_ENDIAN(me, arg2);
+#elif defined(__BIG_ENDIAN)
+		error = put_user(PR_ENDIAN_BIG, (unsigned int __user *)arg2);
+#else
+		error = put_user(PR_ENDIAN_LITTLE, (unsigned int __user *)arg2);
+#endif
 		break;
 	case PR_SET_ENDIAN:
 		error = SET_ENDIAN(me, arg2);
#2 lore raw

Hi Andrew,

Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Sat, 28 Jan 2017 12:13:10 +0100 Helge Deller…

The prctl(PR_GET_ENDIAN) syscall was added to Kernel 2.6.18, but implemented for PowerPC only.
This trivial patch adds support for this syscall for all other architectures.

Seems reasonable. I guess.

Heck, I did forgot but I submitted a similar patch 8 years ago:
http://www.serverphorums.com/read.php?12,51902

Quoted 1 line

Why is this needed?

It's not actually needed beside the trivial reason of providing an interface not just for one single architecture.

After reading the discussion from 2009 again, I'm fine if you would simply drop the patch. The decision up to you.

Quoted 1 line

The man page will need updating. It says "PowerPC only".

In case you would include the patch I'd send patches to update the manpage.

Thanks,
Helge

Quoted 28 lines
Quoted 28 lines
kernel/sys.c +6 -3
index 842914e..5818e5e 100644
@@ -79,9 +79,6 @@
 #ifndef GET_FPEXC_CTL
 # define GET_FPEXC_CTL(a, b)	(-EINVAL)
 #endif
-#ifndef GET_ENDIAN
-# define GET_ENDIAN(a, b)	(-EINVAL)
-#endif
 #ifndef SET_ENDIAN
 # define SET_ENDIAN(a, b)	(-EINVAL)
 #endif
@@ -2136,7 +2133,13 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EFAULT;
 		break;
 	case PR_GET_ENDIAN:
+#ifdef GET_ENDIAN
 		error = GET_ENDIAN(me, arg2);
+#elif defined(__BIG_ENDIAN)
+		error = put_user(PR_ENDIAN_BIG, (unsigned int __user *)arg2);
+#else
+		error = put_user(PR_ENDIAN_LITTLE, (unsigned int __user *)arg2);
+#endif
 		break;
 	case PR_SET_ENDIAN:
 		error = SET_ENDIAN(me, arg2);
#3 lore raw
Quoted 14 lines · On Wed, 1 Feb 2017 20:47:06 +0100 Helge Deller…

Hi Andrew,

Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Sat, 28 Jan 2017 12:13:10 +0100 Helge Deller…

The prctl(PR_GET_ENDIAN) syscall was added to Kernel 2.6.18, but implemented for PowerPC only.
This trivial patch adds support for this syscall for all other architectures.

Seems reasonable. I guess.

Heck, I did forgot but I submitted a similar patch 8 years ago:
http://www.serverphorums.com/read.php?12,51902

Quoted 7 lines
Quoted 1 line

Why is this needed?

It's not actually needed beside the trivial reason of providing an interface not just for one single architecture.

After reading the discussion from 2009 again, I'm fine if you would simply drop the patch. The decision up to you.

Can't decide. I guess that moving it into the kernel will, over time, eliminate some irritating ifdefs from userspace code.

The implementation itself is a bit half-assed. The put_user() in arch/powerpc/kernel/process.c:get_endian() should be moved into kernel/sys.c. So the arch code only does the "what endianness am I" function and common code copies that out to userspace.

#4 lore raw
In reply to Andrew Morton
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Sat, 28 Jan 2017 12:13:10 +0100 Helge Deller <[email protected]> wrote:

The prctl(PR_GET_ENDIAN) syscall was added to Kernel 2.6.18, but implemented for PowerPC only. This trivial patch adds support for this syscall for all other architectures.

Seems reasonable. I guess. Why is this needed?

I don't think it is other than for PPC. If you're not variable endian (which is only PPC to date), then you should know a priori what endian you are from the #defines in userspace.

James

#5 lore raw
Quoted 8 lines · James Bottomley
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Sat, 28 Jan 2017 12:13:10 +0100 Helge Deller <[email protected]> wrote:

The prctl(PR_GET_ENDIAN) syscall was added to Kernel 2.6.18, but implemented for PowerPC only. This trivial patch adds support for this syscall for all other architectures.

Quoted 5 lines
Quoted 1 line

Seems reasonable. I guess. Why is this needed?

I don't think it is other than for PPC. If you're not variable endian (which is only PPC to date), then you should know a priori what endian you are from the #defines in userspace.

I find it vaguely odd even on PPC. Surely you can tell what your endianness is directly. (An API to query the endianness of another task would be useful, though.)

#6 lore raw
In reply to James Bottomley
Quoted 8 lines · James Bottomley
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Sat, 28 Jan 2017 12:13:10 +0100 Helge Deller <[email protected]> wrote:

The prctl(PR_GET_ENDIAN) syscall was added to Kernel 2.6.18, but implemented for PowerPC only. This trivial patch adds support for this syscall for all other architectures.

Quoted 5 lines
Quoted 1 line

Seems reasonable. I guess. Why is this needed?

I don't think it is other than for PPC. If you're not variable endian (which is only PPC to date), then you should know a priori what endian you are from the #defines in userspace.

MIPS as well, but it seems strange to require the kernel to tell you your endianness, when you can easily determine it yourself. Unless there's something about this I don't understand.

#7 lore raw
Quoted 7 lines · Matt Turner
Quoted 3 lines

I don't think it is other than for PPC. If you're not variable endian (which is only PPC to date), then you should know a priori what endian you are from the #defines in userspace.

MIPS as well, but it seems strange to require the kernel to tell you your endianness, when you can easily determine it yourself. Unless there's something about this I don't understand.

Many MIPS processors do have a reverse-endian control bit, which allows a
user process to execute in the endianness opposite to the endianness the kernel runs in. The feature has been around since 1991 and the R4000 CPU, however support is unlikely to be ever added to the MIPS/Linux port, due to the complexity required for byte-swapping all the data structures passed in memory between the kernel and the userland. Does the PPC/Linux port actually implement this swapping?

Maciej

#8 lore raw
Quoted 10 lines · Maciej W. Rozycki
Quoted 7 lines · Matt Turner
Quoted 3 lines

I don't think it is other than for PPC. If you're not variable endian (which is only PPC to date), then you should know a priori what endian you are from the #defines in userspace.

MIPS as well, but it seems strange to require the kernel to tell you your endianness, when you can easily determine it yourself. Unless there's something about this I don't understand.

Quoted 7 lines

Many MIPS processors do have a reverse-endian control bit, which allows a
user process to execute in the endianness opposite to the endianness the kernel runs in. The feature has been around since 1991 and the R4000 CPU, however support is unlikely to be ever added to the MIPS/Linux port, due to the complexity required for byte-swapping all the data structures passed in memory between the kernel and the userland. Does the PPC/Linux port actually implement this swapping?

No. Userspace can change endian, but it has to cope with the kernel being in the original endian.

cheers