personality(2) broken

Mathias Krause <[email protected]>
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
Hi,

personality(2) seams to have no users since it was added back in  
version 0.10 because it won't work. Take the following example:

cat >pers.c<<EOF
#include <sys/personality.h>
#include <stdio.h>

int main(void) {
	printf("0x%08lx\n", (unsigned long) personality(0xffffffff));
	return 0;
}
EOF

Compiling this program and starting it with strace gives me:

mk@vbox:~/tmp/pers$ diet gcc -o pers pers.c && strace ./pers > /dev/null
/usr/lib/diet/lib-i386/libc.a(vprintf.o): In function `vprintf':
vprintf.c:(.text+0x20): warning: warning: the printf functions add  
several kilobytes of bloat.
execve("./pers", ["./pers"], [/* 20 vars */]) = 0
write(1, "0x"..., 2)                    = 2
write(1, "000000"..., 6)                = 6
write(1, "ff"..., 2)                    = 2
write(1, "\n"..., 1)                    = 1
_exit(0)                                = ?
mk@vbox:~/tmp/pers$

No personality(2) called here, just printing 0xff. Looking at the  
header file gives us a clue why:

mk@vbox:~/tmp/pers$ grep -w personality /usr/include/diet/sys/ 
personality.h
         unsigned char           pers_low;       /* lowest  
personality */
         unsigned char           pers_high;      /* highest  
personality */
  * Return the base personality without flags.
#define personality(pers)       (pers & PER_MASK)
#define get_personality         (current->personality)
  * Change personality of the currently running process.
         ((current->personality == pers) ? 0 : __set_personality(pers))
mk@vbox:~/tmp/pers$

So personality() is just wrong here. It's the macro the kernel may  
use but this definition is useless for userland. Don't know who is  
wrong here, the kernel in falsely exporting the header or dietlibc in  
not checking what it actually uses as header. Anyway, the header  
needs to be fixed. I would say strip it down and just leave in the  
enums and add an 'extern int personality(unsigned long persona)'.  
That should do it.

Greets,
Mathias
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.