github.com/kidsbmilk/gofronted_all@v0.0.0-20220701224323-6479d5976c5d/libgo/mkrsysinfo.sh (about)

     1  #!/bin/sh
     2  
     3  # Copyright 2016 The Go Authors. All rights reserved.
     4  # Use of this source code is governed by a BSD-style
     5  # license that can be found in the LICENSE file.
     6  
     7  # Create runtime_sysinfo.go from gen-sysinfo.go and errno.i.
     8  
     9  OUT=tmp-runtime_sysinfo.go
    10  
    11  set -e
    12  
    13  echo 'package runtime' > ${OUT}
    14  
    15  # Get all the consts and types, skipping ones which could not be
    16  # represented in Go and ones which we need to rewrite.  We also skip
    17  # function declarations, as we don't need them here.  All the symbols
    18  # will all have a leading underscore.
    19  grep -v '^// ' gen-sysinfo.go | \
    20    grep -v '^func' | \
    21    grep -v '^var ' | \
    22    grep -v '^type _timeval ' | \
    23    grep -v '^type _timespec_t ' | \
    24    grep -v '^type _timespec ' | \
    25    grep -v '^type _epoll_' | \
    26    grep -v '^type _*locale[_ ]' | \
    27    grep -v '^type _in6_addr' | \
    28    grep -v 'sockaddr_in6' | \
    29    egrep -v '^const _*FLT(64|128)_(NORM_)?MAX' | \
    30    sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1timeval\2/g' \
    31        -e 's/\([^a-zA-Z0-9_]\)_timeval$/\1timeval/g' \
    32        -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
    33        -e 's/\([^a-zA-Z0-9_]\)_timespec_t$/\1timespec_t/g' \
    34        -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
    35        -e 's/\([^a-zA-Z0-9_]\)_timespec$/\1timespec/g' \
    36        -e 's/\([^a-zA-Z0-9_]\)_in6_addr\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
    37        -e 's/\([^a-zA-Z0-9_]\)_in6_addr$/\1[16]byte/g' \
    38        -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
    39        -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t$/\1[16]byte/g' \
    40      >> ${OUT}
    41  
    42  # The C long type, needed because that is the type that ptrace returns.
    43  sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
    44  if test "$sizeof_long" = "4"; then
    45    echo "type _C_long int32" >> ${OUT}
    46    echo "type _C_ulong uint32" >> ${OUT}
    47  elif test "$sizeof_long" = "8"; then
    48    echo "type _C_long int64" >> ${OUT}
    49    echo "type _C_ulong uint64" >> ${OUT}
    50  else
    51    echo 1>&2 "mkrsysinfo.sh: could not determine size of long (got $sizeof_long)"
    52    exit 1
    53  fi
    54  
    55  # The time structures need special handling: we need to name the
    56  # types, so that we can cast integers to the right types when
    57  # assigning to the structures.
    58  timeval=`grep '^type _timeval ' gen-sysinfo.go`
    59  timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
    60  timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
    61  echo "type timeval_sec_t $timeval_sec" >> ${OUT}
    62  echo "type timeval_usec_t $timeval_usec" >> ${OUT}
    63  echo $timeval | \
    64    sed -e 's/type _timeval /type timeval /' \
    65        -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timeval_sec_t/' \
    66        -e 's/tv_usec *[a-zA-Z0-9_]*/tv_usec timeval_usec_t/' >> ${OUT}
    67  echo >> ${OUT}
    68  echo "func (tv *timeval) set_usec(x int32) {" >> ${OUT}
    69  echo "	tv.tv_usec = timeval_usec_t(x)" >> ${OUT}
    70  echo "}" >> ${OUT}
    71  
    72  timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
    73  if test "$timespec" = ""; then
    74    # IRIX 6.5 has __timespec instead.
    75    timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
    76  fi
    77  timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
    78  timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
    79  echo "type timespec_sec_t $timespec_sec" >> ${OUT}
    80  echo "type timespec_nsec_t $timespec_nsec" >> ${OUT}
    81  echo $timespec | \
    82    sed -e 's/^type ___timespec /type timespec /' \
    83        -e 's/^type _timespec /type timespec /' \
    84        -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timespec_sec_t/' \
    85        -e 's/tv_nsec *[a-zA-Z0-9_]*/tv_nsec timespec_nsec_t/' >> ${OUT}
    86  echo >> ${OUT}
    87  echo "func (ts *timespec) setNsec(ns int64) {" >> ${OUT}
    88  echo "	ts.tv_sec = timespec_sec_t(ns / 1e9)" >> ${OUT}
    89  echo "	ts.tv_nsec = timespec_nsec_t(ns % 1e9)" >> ${OUT}
    90  echo "}" >> ${OUT}
    91  echo >> ${OUT}
    92  
    93  # Define the epollevent struct.  This needs special attention because
    94  # the C definition uses a union and is sometimes packed.
    95  if grep '^const _epoll_data_offset ' ${OUT} >/dev/null 2>&1; then
    96    val=`grep '^const _epoll_data_offset ' ${OUT} | sed -e 's/const _epoll_data_offset = \(.*\)$/\1/'`
    97    if test "$val" = "4"; then
    98        echo 'type epollevent struct { events uint32; data [8]byte }' >> ${OUT}
    99    elif test "$val" = "8"; then
   100        if test "$GOARCH" = "sparc64" -a "$GOOS" = "linux"; then
   101            echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte; _ [0]int64 }' >> ${OUT}
   102        else
   103            echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte }' >> ${OUT}
   104        fi
   105    else
   106        echo 1>&2 "unknown epoll data offset value ${val}"
   107        exit 1
   108    fi
   109  fi
   110  # Make sure EPOLLET is positive.
   111  if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go > /dev/null 2>&1; then
   112    echo "const _EPOLLETpos = _EPOLLET" >> ${OUT}
   113  else
   114    echo "const _EPOLLETpos = 0x80000000" >> ${OUT}
   115  fi
   116  # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
   117  if ! grep '^const _EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
   118    echo "const _EPOLLRDHUP = 0x2000" >> ${OUT}
   119  fi
   120  if ! grep '^const _EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
   121    echo "const _EPOLL_CLOEXEC = 02000000" >> ${OUT}
   122  fi
   123  
   124  # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
   125  # which leads to a constant overflow when using O_CLOEXEC in some
   126  # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
   127  # more present in 7.2 (_FCLOEXEC is a 32 bit value).
   128  if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
   129      sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
   130      mv ${OUT}-2 ${OUT}
   131  fi
   132  
   133  # Make sure _MAP_FAILED is defined.
   134  if ! grep '^const _MAP_FAILED =' gen-sysinfo.go > /dev/null 2>&1; then
   135    echo "const _MAP_FAILED = ^uintptr(0)" >> ${OUT}
   136  fi
   137  # Make sure _MAP_ANON is defined.
   138  if ! grep '^const _MAP_ANON =' gen-sysinfo.go > /dev/null 2>&1; then
   139    if grep '^const _MAP_ANONYMOUS ' gen-sysinfo.go > /dev/null 2>&1; then
   140      echo "const _MAP_ANON = _MAP_ANONYMOUS" >> ${OUT}
   141    else
   142      echo "const _MAP_ANON = 0" >> ${OUT}
   143    fi
   144  fi
   145  # Make sure _MADV_DONTNEED is defined.
   146  if ! grep '^const _MADV_DONTNEED =' gen-sysinfo.go > /dev/null 2>&1; then
   147    echo "const _MADV_DONTNEED = 0" >> ${OUT}
   148  fi
   149  # Make sure _MADV_FREE is defined.
   150  if ! grep '^const _MADV_FREE =' gen-sysinfo.go > /dev/null 2>&1; then
   151    echo "const _MADV_FREE = 0" >> ${OUT}
   152  fi
   153  # Make sure _MADV_HUGEPAGE is defined.
   154  if ! grep '^const _MADV_HUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
   155    echo "const _MADV_HUGEPAGE = 0" >> ${OUT}
   156  fi
   157  # Make sure _MADV_NOHUGEPAGE is defined.
   158  if ! grep '^const _MADV_NOHUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
   159    echo "const _MADV_NOHUGEPAGE = 0" >> ${OUT}
   160  fi
   161  
   162  # The semt structure, for Solaris.
   163  grep '^type _sem_t ' gen-sysinfo.go | \
   164      sed -e 's/_sem_t/semt/' >> ${OUT}
   165  
   166  # The Solaris port_event_t struct.
   167  grep '^type _port_event_t ' gen-sysinfo.go | \
   168      sed -e s'/_port_event_t/portevent/' \
   169      >> ${OUT}
   170  
   171  # The *BSD kevent struct.
   172  grep '^type _kevent ' gen-sysinfo.go | \
   173      sed -e s'/_kevent/keventt/' \
   174        -e 's/ udata [^;}]*/ udata *byte/' \
   175      >> ${OUT}
   176  
   177  # Type 'uint128' is needed in a couple of type definitions on arm64,such
   178  # as _user_fpsimd_struct, _elf_fpregset_t, etc.
   179  if ! grep '^type uint128' ${OUT} > /dev/null 2>&1; then
   180      echo "type uint128 [16]byte" >> ${OUT}
   181  fi