2015-12-26 04:40:50 +03:00
/*
* Copyright ( c ) 2015 Dmitry V . Levin < ldv @ altlinux . org >
2018-06-14 14:00:00 +03:00
* Copyright ( c ) 2015 - 2018 The strace developers .
2015-12-26 04:40:50 +03:00
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : GPL - 2.0 - or - later
2015-12-26 04:40:50 +03:00
*/
2015-12-25 03:52:42 +03:00
# include <stdio.h>
# include <sys/personality.h>
2018-04-11 03:41:16 +03:00
# if XLAT_RAW
# define linux_type_str "0"
# define good_type_str "0x6"
# define bad_type_str "0x1f"
# define good_flags_str "0x7000000"
# define bad_flags_str "0x10000"
# define good_bad_flags_str "0x7010000"
# elif XLAT_VERBOSE
# define linux_type_str "0 / \\* PER_LINUX \\* / "
# define good_type_str "0x6 / \\* PER_BSD \\* / "
# define bad_type_str "0x1f / \\* PER_\\?\\?\\? \\* / "
# define good_flags_str \
" 0x7000000 / \\ * SHORT_INODE \\ |WHOLE_SECONDS \\ |STICKY_TIMEOUTS \\ */ "
# define bad_flags_str "0x10000"
# define good_bad_flags_str \
" 0x7010000 / \\ * SHORT_INODE \\ |WHOLE_SECONDS \\ |STICKY_TIMEOUTS " \
" \\ |0x10000 \\ */ "
# else
# define linux_type_str "PER_LINUX"
# define good_type_str "PER_BSD"
# define bad_type_str "0x1f / \\* PER_\\?\\?\\? \\* / "
# define good_flags_str "SHORT_INODE\\|WHOLE_SECONDS\\|STICKY_TIMEOUTS"
# define bad_flags_str "0x10000"
# define good_bad_flags_str \
" SHORT_INODE \\ |WHOLE_SECONDS \\ |STICKY_TIMEOUTS \\ |0x10000 "
# endif
2015-12-25 03:52:42 +03:00
int main ( void )
{
2015-12-26 04:40:50 +03:00
const unsigned int good_type = PER_BSD ;
const unsigned int bad_type = 0x1f ;
const unsigned int good_flags =
2015-12-25 03:52:42 +03:00
SHORT_INODE | WHOLE_SECONDS | STICKY_TIMEOUTS ;
2015-12-26 04:40:50 +03:00
const unsigned int bad_flags = 0x10000 ;
2015-12-25 23:56:06 +03:00
2015-12-26 04:40:50 +03:00
const unsigned int saved_pers = personality ( 0xffffffff ) ;
printf ( " personality \\ (0xffffffff \\ ) = %#x \\ ([^)]* \\ ) \n " , saved_pers ) ;
/* PER_LINUX */
personality ( PER_LINUX ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ ) = %#x \\ ([^)]* \\ ) \n " ,
linux_type_str , saved_pers ) ;
2015-12-25 23:56:06 +03:00
personality ( 0xffffffff ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (0xffffffff \\ ) = 0 \\ (%s \\ ) \n " , linux_type_str ) ;
2015-12-26 04:40:50 +03:00
personality ( good_flags ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ |%s \\ ) = 0 \\ (%s \\ ) \n " ,
linux_type_str , good_flags_str , linux_type_str ) ;
2015-12-26 04:40:50 +03:00
personality ( bad_flags ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ |%s \\ ) "
" = %#x \\ (%s \\ |%s \\ ) \n " ,
linux_type_str , bad_flags_str ,
good_flags , linux_type_str , good_flags_str ) ;
2015-12-26 04:40:50 +03:00
personality ( good_flags | bad_flags ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ |%s \\ ) "
" = %#x \\ (%s \\ |%s \\ ) \n " ,
linux_type_str , good_bad_flags_str ,
bad_flags , linux_type_str , bad_flags_str ) ;
2015-12-26 04:40:50 +03:00
/* another valid type */
personality ( good_type ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ ) = %#x \\ (%s \\ |%s \\ ) \n " ,
2015-12-26 04:40:50 +03:00
good_type_str , good_flags | bad_flags ,
2018-04-11 03:41:16 +03:00
linux_type_str , good_bad_flags_str ) ;
2015-12-26 04:40:50 +03:00
personality ( good_type | good_flags ) ;
printf ( " personality \\ (%s \\ |%s \\ ) = %#x \\ (%s \\ ) \n " ,
good_type_str , good_flags_str , good_type , good_type_str ) ;
personality ( good_type | bad_flags ) ;
printf ( " personality \\ (%s \\ |%s \\ ) = %#x \\ (%s \\ |%s \\ ) \n " ,
good_type_str , bad_flags_str , good_type | good_flags ,
good_type_str , good_flags_str ) ;
personality ( good_type | good_flags | bad_flags ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ |%s \\ ) = %#x \\ (%s \\ |%s \\ ) \n " ,
good_type_str , good_bad_flags_str ,
2015-12-26 04:40:50 +03:00
good_type | bad_flags ,
good_type_str , bad_flags_str ) ;
/* invalid type */
personality ( bad_type ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ ) = %#x \\ (%s \\ |%s \\ ) \n " ,
2015-12-26 04:40:50 +03:00
bad_type_str , good_type | good_flags | bad_flags ,
2018-04-11 03:41:16 +03:00
good_type_str , good_bad_flags_str ) ;
2015-12-26 04:40:50 +03:00
personality ( bad_type | good_flags ) ;
printf ( " personality \\ (%s \\ |%s \\ ) = %#x \\ (%s \\ ) \n " ,
bad_type_str , good_flags_str , bad_type , bad_type_str ) ;
personality ( bad_type | bad_flags ) ;
printf ( " personality \\ (%s \\ |%s \\ ) = %#x \\ (%s \\ |%s \\ ) \n " ,
bad_type_str , bad_flags_str , bad_type | good_flags ,
bad_type_str , good_flags_str ) ;
personality ( bad_type | good_flags | bad_flags ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ (%s \\ |%s \\ ) = %#x \\ (%s \\ |%s \\ ) \n " ,
bad_type_str , good_bad_flags_str ,
2015-12-26 04:40:50 +03:00
bad_type | bad_flags , bad_type_str , bad_flags_str ) ;
2015-12-25 23:56:06 +03:00
2015-12-25 03:52:42 +03:00
personality ( saved_pers ) ;
2018-04-11 03:41:16 +03:00
printf ( " personality \\ ([^)]* \\ ) = %#x \\ (%s \\ |%s \\ ) \n " ,
2015-12-26 04:40:50 +03:00
bad_type | good_flags | bad_flags ,
2018-04-11 03:41:16 +03:00
bad_type_str , good_bad_flags_str ) ;
2015-12-25 03:52:42 +03:00
return 0 ;
}