1#!/usr/bin/env bash 2 3# Copyright 2017 The Fuchsia Authors 4# 5# Use of this source code is governed by a MIT-style 6# license that can be found in the LICENSE file or at 7# https://opensource.org/licenses/MIT 8 9header() { 10 echo "// This file is generated by $0. DO NOT EDIT." 11 echo 12 echo '#include <stdint.h>' 13 echo '#include "vdso-code.h"' 14 echo 15 echo "\ 16struct VDso::ValidSyscallPC { 17" 18} 19 20footer() { 21 echo '};' 22} 23 24scan() { 25 local define symbol rest syscall caller 26 local syscalls='' 27 28 while read define symbol rest; do 29 case "$symbol" in 30 VDSO_CODE_SYSRET_*) ;; 31 *) continue ;; 32 esac 33 34 syscall="${symbol#VDSO_CODE_SYSRET_zx_}" 35 caller="${syscall#*_VIA_}" 36 syscall="${syscall%_VIA_*}" 37 if eval "test -z \"\$syscall_callers_${syscall}\""; then 38 syscalls+=" $syscall" 39 eval "local syscall_callers_${syscall}=\$caller" 40 else 41 eval "syscall_callers_${syscall}+=\" \$caller\"" 42 fi 43 done 44 45 for syscall in $syscalls; do 46 echo "\ 47 static bool ${syscall}(uintptr_t offset) { 48 switch (offset) {\ 49" 50 eval "local callers=\$syscall_callers_$syscall" 51 for caller in $callers; do 52 echo "\ 53 case VDSO_CODE_SYSRET_zx_${syscall}_VIA_${caller} - VDSO_CODE_START: 54 return true;\ 55" 56 done 57 echo "\ 58 } 59 return false; 60 } 61" 62 done 63} 64 65set -e 66header 67scan < "$1" 68footer 69