[CRIU] Re: [PATCH 13/13] syscalls: Change syscalls generating script to shell one

Pavel Emelyanov xemul at parallels.com
Wed Apr 18 04:37:15 EDT 2012


On 04/18/2012 01:55 AM, Cyrill Gorcunov wrote:
> I would appreciate if someone will help to simplify
> it more.
> 
> In particular this script doesn't allow the syscalls
> template file to have only two rows but require four
> rows to present.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  Makefile.syscall   |    4 ++--
>  syscalls-x86-64.pl |   51 ---------------------------------------------------
>  syscalls-x86-64.sh |   46 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 48 insertions(+), 53 deletions(-)
>  delete mode 100644 syscalls-x86-64.pl
>  create mode 100644 syscalls-x86-64.sh
> 
> diff --git a/Makefile.syscall b/Makefile.syscall
> index ac180da..42fbae7 100644
> --- a/Makefile.syscall
> +++ b/Makefile.syscall
> @@ -6,7 +6,7 @@ SYS-CODES	:= include/syscall-codes.h
>  SYS-PROTO	:= include/syscall.h
>  
>  SYS-ASM		:= syscall-x86-64.S
> -SYS-GEN		:= syscalls-x86-64.pl
> +SYS-GEN		:= syscalls-x86-64.sh
>  
>  SYS-OBJ		:= $(patsubst %.S,%.o,$(SYS-ASM))
>  
> @@ -14,7 +14,7 @@ SYS-FLAGS	:= -pie -Wstrict-prototypes -D__ASSEMBLY__ -nostdlib -fomit-frame-poin
>  
>  $(SYS-ASM): $(SYS-GEN) $(SYS-DEF) $(SYS-ASM-COMMON) $(SYS-TYPES)
>  	$(E) "  GEN     " $@
> -	$(Q) $(PERL)			\
> +	$(Q) $(SH)			\

Just wire the shell version into the patch #12.

>  		$(SYS-GEN)		\
>  		$(SYS-DEF)		\
>  		$(SYS-CODES)		\
> diff --git a/syscalls-x86-64.pl b/syscalls-x86-64.pl
> deleted file mode 100644
> index f751869..0000000
> --- a/syscalls-x86-64.pl
> +++ /dev/null
> @@ -1,51 +0,0 @@
> -#!/usr/bin/perl -w
> -
> -my($in, $codes, $protos, $asm, $asmcommon, $proto_types) = @ARGV;
> -
> -open(IN, "< $in") or die "$0: cannot open: $in\n";
> -open(CODES, "> $codes") or die "$0: cannot open: $codes\n";
> -open(PROTOS, "> $protos") or die "$0: cannot open: $protos\n";
> -open(ASM, "> $asm") or die "$0: cannot open: $asm\n";
> -
> -$codes =~ s/include\///g;
> -$protos =~ s/include\///g;
> -$proto_types =~ s/include\///g;
> -
> -print ASM "/* Autogenerated, don't edit */\n";
> -print ASM "#include \"$codes\"\n\n";
> -print ASM "#include \"$asmcommon\"\n";
> -
> -my($codes_def, $protos_def) = ($codes, $protos);
> -
> -$codes_def =~ s/[\s|\t|\-|\.|\/]/_/g;
> -$protos_def =~ s/[\s|\t|\-|\.|\/]/_/g;
> -
> -print CODES  "/* Autogenerated, don't edit */\n#ifndef $codes_def\n#define $codes_def\n";
> -print PROTOS "/* Autogenerated, don't edit */\n#ifndef $protos_def\n#define $protos_def\n";
> -print PROTOS "#include \"$proto_types\"\n";
> -print PROTOS "#include \"$codes\"\n";
> -
> -while (defined($line = <IN>)) {
> -	chomp $line;
> -	$line =~ s/^\s+//;
> -	$line =~ s/\s*\#.*$//;
> -	next if ($line eq '');
> -
> -	my(@field) = split(/\t+/, $line);
> -
> -	if ($#field >= 1) {
> -		print CODES "#define $field[0] $field[1]\n";
> -	}
> -
> -	if ($#field >= 2) {
> -		print PROTOS "extern long $field[2]$field[3];\n";
> -		print ASM "SYSCALL($field[2], $field[0])\n";
> -	}
> -}
> -
> -print CODES "#endif /* $codes_def */\n";
> -print PROTOS "#endif /* $protos_def */\n";
> -
> -close(IN);
> -close(CODES);
> -close(PROTOS);
> diff --git a/syscalls-x86-64.sh b/syscalls-x86-64.sh
> new file mode 100644
> index 0000000..cc1be0d
> --- /dev/null
> +++ b/syscalls-x86-64.sh
> @@ -0,0 +1,46 @@
> +#!/bin/sh
> +
> +in=$1
> +codesout=$2
> +codes=`echo $2 | sed -e 's/include\///g'`
> +protosout=$3
> +protos=`echo $3 | sed -e 's/include\///g'`
> +asmout=$4
> +asmcommon=$5
> +prototypes=`echo $6 | sed -e 's/include\///g'`
> +
> +codesdef=`echo $codes | tr "[[:space:]].-" _`
> +protosdef=`echo $protos | tr "[[:space:]].-" _`
> +
> +echo "/* Autogenerated, don't edit */"	>  $codesout

Look at how gen-offsets.h works. It uses the

cat << EOF
bla-bla-bla
EOF

notation to dump big chink of data into a file

> +echo "#ifndef $codesdef"		>> $codesout
> +echo "#define $codesdef"		>> $codesout
> +
> +echo "/* Autogenerated, don't edit */"	>  $protosout
> +echo "#ifndef $protosdef"		>> $protosout
> +echo "#define $protosdef"		>> $protosout
> +echo "#include \"$prototypes\""		>> $protosout
> +echo "#include \"$codes\""		>> $protosout
> +
> +echo "/* Autogenerated, don't edit */"	>  $asmout
> +echo "#include \"$codes\""		>> $asmout
> +echo "#include \"$asmcommon\""		>> $asmout
> +
> +(
> +while read line
> +do
> +	line=`echo $line | sed -e 's/^ *//g' | sed -e '/^\#/d' | sed -e 's/\t\{1,\}/|/g'`
> +	if [ -z "$line" ]; then
> +		continue
> +	fi
> +	num=`echo $line | cut -f 1 -d ' '`
> +	lv=`echo $line | cut -f 3 -d ' '`
> +	rv=`echo $line | cut -f 2 -d '('`

O_o  Just make \t be awk delimiter and rewrite the below as

cat $in | egrep -v '^#' | awk '{print "#define", $1, $2}' > $codesout
cat $in | egrep -v '^#' | awk '{print "extern unsigned long $3 $2"} > $protosout
cat $in | egrep -v '^#' | awk '{print "SYSCALL($3, $2)"} > $asmout

or smth like this.

> +	echo $line | awk '{ print "#define " $1 " " $2};'	>> $codesout
> +	echo "extern unsigned long $lv ($rv;"			>> $protosout
> +	echo "SYSCALL($lv,$num)"				>> $asmout


More information about the CRIU mailing list