Bring forward the modern shiny scripts.
authorRonald G. Minnich <rminnich@google.com>
Thu, 16 Jan 2014 01:21:36 +0000 (17:21 -0800)
committerRonald G. Minnich <rminnich@google.com>
Thu, 16 Jan 2014 22:43:42 +0000 (14:43 -0800)
Signed-off-by: Ronald G. Minnich <rminnich@google.com>
33 files changed:
scripts/INFERNO [new file with mode: 0755]
scripts/PATCHPLAN9 [new file with mode: 0644]
scripts/RUN [new file with mode: 0644]
scripts/RUNTAP [new file with mode: 0644]
scripts/XRUN [new file with mode: 0644]
scripts/fixincludes [new file with mode: 0644]
scripts/linux.cocci [new file with mode: 0644]
scripts/pktdump [new file with mode: 0644]
scripts/plan9 [new file with mode: 0644]
scripts/plan9randomfixup [new file with mode: 0644]
scripts/plan9user/FIX [new file with mode: 0644]
scripts/plan9user/fixincludes [new file with mode: 0644]
scripts/plan9user/plan9.cocci [new file with mode: 0644]
scripts/plan9user/scalar.cocci [new file with mode: 0644]
scripts/plan9user/typedef.cocci [new file with mode: 0644]
scripts/scalar [new file with mode: 0644]
scripts/scalar.cocci [new file with mode: 0644]
scripts/spatch/kref.cocci [new file with mode: 0644]
scripts/spatch/locks.cocci [new file with mode: 0644]
scripts/spatch/malloc.cocci [new file with mode: 0644]
scripts/spatch/plan9.cocci [new file with mode: 0644]
scripts/spatch/rendez.cocci [new file with mode: 0644]
scripts/spatch/route.cocci [new file with mode: 0644]
scripts/spatch/scalar.cocci [new file with mode: 0644]
scripts/spatch/scalars.cocci [new file with mode: 0644]
scripts/spatch/typedef.cocci [new file with mode: 0644]
scripts/spatch/waserror.cocci [new file with mode: 0644]
scripts/tagging/MAKETAGS [new file with mode: 0644]
scripts/tagging/README [new file with mode: 0644]
scripts/tagging/bashrc-global [new file with mode: 0644]
scripts/tagging/global-subd.sh [new file with mode: 0755]
scripts/tagging/gtags-update.sh [new file with mode: 0755]
scripts/temporary_hack [new file with mode: 0644]

diff --git a/scripts/INFERNO b/scripts/INFERNO
new file mode 100755 (executable)
index 0000000..9e25b1d
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+ed $1 << EOF
+1i
+// INFERNO
+.
+w
+q
+EOF
diff --git a/scripts/PATCHPLAN9 b/scripts/PATCHPLAN9
new file mode 100644 (file)
index 0000000..7cd8770
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/sh
+set -e
+#Plan 9 source can be converted for akaros via a set of scripts.
+#This is a WIP. 
+# At this point, we take it just so far and do the rest
+# by hand. Cocci has its issues, and we're not here to debug
+# and fix them all. Also, we may create some post-conversion
+# scripts as well. We'll see.
+#
+#We preserve the waserror/poperror style, which adds complications
+#but leaves the source relatively clean.
+#
+#To convert plan 9 source, we have to do several things.
+#We use spatch, the semantic patch tool. BUT, that tool can be
+#painful for some stuff, so we also use sed. And in some cases
+#we clean up things that we do with spatch with a sed pass.
+#Ugly but effective. Some scripts are idempotent, so we mark
+#them as such. 
+#
+# waserror/poperror fixing, via script/spatch/waserror.cocci
+# N.B. Need r18 or later.
+spatch --sp-file scripts/spatch/waserror.cocci --in-place $1
+# General Plan 9 fixing, via script/spatch/waserror.cocci
+spatch --sp-file scripts/spatch/plan9.cocci --in-place $1
+spatch --sp-file scripts/spatch/scalar.cocci --in-place $1
+spatch --sp-file scripts/spatch/typedef.cocci --in-place $1
+spatch --sp-file scripts/spatch/locks.cocci --in-place $1
+# include fixing. Idempotent. 
+sh scripts/fixincludes $1
+# Scalars. Idempotent.
+sh scripts/scalar $1
+# Stuff we might want to think about later. Idempotent
+sh scripts/temporary_hack $1
+# malloc. Idempotent.
+spatch --sp-file scripts/spatch/malloc.cocci --in-place $1
+# type names, via scripts/plan9. NOT idempotent.
+# in fact, we almost certainly don't want it.
+sh scripts/plan9 $1
+# kref. Idempotent.
+spatch --sp-file scripts/spatch/kref.cocci --in-place $1
+ed $1 << EOF
+1i
+// INFERNO
+.
+w
+q
+EOF
+
diff --git a/scripts/RUN b/scripts/RUN
new file mode 100644 (file)
index 0000000..7344386
--- /dev/null
@@ -0,0 +1,23 @@
+sudo qemu-system-x86_64 -s -cpu qemu64 -smp 4 -m 2048 -nographic  \
+-net nic,model=rtl8139 \
+-net user,hostfwd=tcp::5555-:23 \
+-kernel obj/kern/akaros-kernel $*
+
+#-kernel mnt/hdd/kernel $*
+
+# if you need the dump.
+#-net dump,file=/tmp/vm0.pcap \
+
+# from Kevin, how to run without the hdd
+#sudo qemu-system-x86_64 -s -enable-kvm  -net nic,model=e1000 -net user,hostfwd=tcp::5555-:23 -monitor /dev/pts/29 -cpu phenom -smp 8 -m 4096 -kernel obj/kern/akaros-kernel -nographic
+
+#sudo qemu-system-x86_64 -s -cpu phenom -smp 8 -m 4096 -nographic  \
+#-net nic,model=rtl8139 mnt/hdd268mb.img \
+#-net user,hostfwd=tcp::5555-:23 \
+#-net dump,file=/tmp/vm0.pcap \
+#-kernel mnt/hdd/kernel $*
+#
+#sudo qemu-system-x86_64 -s -cpu phenom -smp 8 -m 6024 -nographic  -net nic,model=rtl8139 mnt/hdd268mb.img -netdev user,id=mynet0 -kernel mnt/hdd/kernel $*
+#sudo qemu-system-x86_64 -s -cpu phenom -smp 8 -m 6024 -nographic  -net nic,model=rtl8139 mnt/hdd268mb.img -netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9 -kernel mnt/hdd/kernel $*
+
+# -S -s -gdb tcp::1234
diff --git a/scripts/RUNTAP b/scripts/RUNTAP
new file mode 100644 (file)
index 0000000..2faff8f
--- /dev/null
@@ -0,0 +1,13 @@
+brctl addbr br0
+tunctl -u rminnich -t tap0
+ifconfig tap0 0.0.0.0 up
+brctl addif br0 tap0
+#    need to rebuild tap0 and br0 each time, ifconfig tap0 up, or give
+#it an /etc/init (and config_tap0("null")) init.d br0, dnsmasq, iptables
+#(currently in default RL) iptables is set to masq to either eth0 or
+#wlan0. if you ever add wlan0 to br0, this probably needs changing echo
+#1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/ip_dynaddr
+
+sudo qemu-system-x86_64 -s -cpu phenom -smp 8 -m 6024 -nographic  -net nic,model=rtl8139 -netdev tap,id=mynet0 mnt/hdd268mb.img -kernel mnt/hdd/kernel $*
+
+# -S -s -gdb tcp::1234
diff --git a/scripts/XRUN b/scripts/XRUN
new file mode 100644 (file)
index 0000000..9e9c25c
--- /dev/null
@@ -0,0 +1 @@
+sudo qemu-system-x86_64 -s -cpu phenom -smp 8 -m 6024  -monitor /dev/pts/$1 -net nic,model=e1000 mnt/hdd268mb.img -kernel mnt/hdd/kernel
diff --git a/scripts/fixincludes b/scripts/fixincludes
new file mode 100644 (file)
index 0000000..413216c
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+# N.B. Preserve blank line we match against so this is idempotent.
+sed -i '/^#include/,/^$/c\
+#include <vfs.h>\
+#include <kfs.h>\
+#include <slab.h>\
+#include <kmalloc.h>\
+#include <kref.h>\
+#include <string.h>\
+#include <stdio.h>\
+#include <assert.h>\
+#include <error.h>\
+#include <cpio.h>\
+#include <pmap.h>\
+#include <smp.h>\
+#include <fcall.h>\
+' $1
diff --git a/scripts/linux.cocci b/scripts/linux.cocci
new file mode 100644 (file)
index 0000000..a665a10
--- /dev/null
@@ -0,0 +1,6 @@
+@@
+expression E;
+@@
+- __va(
++KADDR(
+ E);
diff --git a/scripts/pktdump b/scripts/pktdump
new file mode 100644 (file)
index 0000000..c9459f3
--- /dev/null
@@ -0,0 +1,2 @@
+tail -c10000 -f /tmp/vm0.pcap | tcpdump -n -r -
+
diff --git a/scripts/plan9 b/scripts/plan9
new file mode 100644 (file)
index 0000000..01242e0
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+sed -i 's/nil/NULL/g' $1
+sed -i 's/KERN_WAIT/KMALLOC_WAIT/g' $1
+sed -i 's/nelem/ARRAY_SIZE/g' $1
+
+# stuff I'm not smart enough to do with spatch
+sed -i '/strcpy.*(\(.*\),\(.*\));/s//strncpy(\1, \2, sizeof(\1));/' $1
+sed -i '/snprint(/s//snprintf(/' $1
+sed -i '/seprint(/s//seprintf(/' $1
+sed -i 's/[ \t][ \t]*QLock;/   qlock_t qlock;/' $1
+
+# spatch can't do this yet -- we've talked to them.
+sed -i 's/struct ipifc\*,/struct ipifc *unused_ipifc,/' $1
+sed -i 's/(struct ipifc\*)/(struct ipifc *unused_ipifc)/' $1
+sed -i 's/ *uint8_t,/ uint8_t unused_uint8_t,/' $1
+sed -i 's/ *uint8_t\*,/ uint8_t *unused_uint8_p_t,/' $1
+sed -i 's/ *uint8_t)/ uint8_t unused_uint8_t)/' $1
+sed -i 's/ *uint8_t\*)/ uint8_t *unused_uint8_p_t)/' $1
+sed -i 's/ *char\*\([,)]\)/ char *unused_char_p_t\1/' $1
+sed -i 's/ *char\*\*\([,)]\)/ char **unused_char_pp_t\1/' $1
+sed -i 's/ *int,/ int unused_int,/' $1
+sed -i '/USED(.*);/d' $1
+
diff --git a/scripts/plan9randomfixup b/scripts/plan9randomfixup
new file mode 100644 (file)
index 0000000..5879ba8
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+sed -i 's/qunlock(&(&ip->fraglock4)->qlock)/qunlock(\&ip->fraglock4)/' $1
+sed -i 's/qlock(&(&ip->fraglock4)->qlock)/qlock(\&ip->fraglock4)/' $1
+sed -i 's/kref_get(&(&ip->id4)->ref/kref_get(\&ip->id4/' $1
+
+sed -i 's/qunlock(&(&ip->fraglock6)->qlock)/qunlock(\&ip->fraglock6)/' $1
+sed -i 's/qlock(&(&ip->fraglock6)->qlock)/qlock(\&ip->fraglock6)/' $1
+sed -i 's/kref_get(&(&ip->id6)->ref/kref_get(\&ip->id6/' $1
+
diff --git a/scripts/plan9user/FIX b/scripts/plan9user/FIX
new file mode 100644 (file)
index 0000000..bf6c659
--- /dev/null
@@ -0,0 +1,8 @@
+spatch --in-place --sp-file ~/akaros/scripts/plan9user/scalar.cocci $1
+spatch --in-place --sp-file ~/akaros/scripts/plan9user/typedef.cocci $1
+spatch --in-place --sp-file ~/akaros/scripts/plan9user/plan9.cocci $1
+sh ~/akaros/scripts/plan9user/fixincludes $1
+sed -i 's/= nil/= NULL/' $1
+sed -i 's/ OREAD/ O_RDONLY/' $1
+sed -i 's/ ORDWR/ O_RDWR/' $1
+sed -i 's/return nil/return NULL/' $1
diff --git a/scripts/plan9user/fixincludes b/scripts/plan9user/fixincludes
new file mode 100644 (file)
index 0000000..cf07a0c
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+# N.B. Preserve blank line we match against so this is idempotent.
+sed -i '/^#include/,/^$/c\
+#include <stdlib.h>\
+#include <stdio.h>\
+#include <parlib.h>\
+#include <unistd.h>\
+#include <signal.h>\
+#include <fcntl.h>\
+#include <error.h>
+#include <nixip.h>\
+#include <ndb.h>\
+#include <fcall.h>\
+' $1
diff --git a/scripts/plan9user/plan9.cocci b/scripts/plan9user/plan9.cocci
new file mode 100644 (file)
index 0000000..4a93ffe
--- /dev/null
@@ -0,0 +1,204 @@
+@ seek@
+@@
+-Bseek(
++fseek(
+...)
+
+@ Boffset@
+@@
+-Boffset(
++ftell(
+...)
+
+@ print@
+@@
+-print(
++printf(
+...)
+
+@ sprint@
+@@
+-sprint(
++sprintf(
+...)
+
+@ fprint@
+expression E;
+@@
+-fprint(E,
++fprintf(stderr,
+...)
+
+@ mallocz@
+expression E;
+expression yes;
+@@
+-mallocz(
++calloc(1, 
+E
+-, yes
+ )
+
+@USED@
+@@
+-USED(...);
+
+@NOTED@
+expression E;
+@@
+-noted(E);
++ignore(E);fprintf(stderr, "noted\n"); exit(1);
+
+@exits@
+expression E;
+@@
+-exits(E);
++fprintf(stderr, E); exit(1);
+
+@ channel @
+identifier d;
+@@
+-Chan
++struct chan
+d;
+
+@ channelstar @
+identifier d;
+@@
+-Chan *
++struct chan *
+d;
+
+@mount@
+identifier d;
+@@
+-Mount
++struct mount
+d;
+
+@ mountstar @
+identifier d;
+@@
+-Chan *
++struct mount *
+d;
+
+@uvlong@
+identifier d;
+@@
+-uvlong
++uint64_t
+d;
+@vlong@
+identifier d;
+@@
+-vlong
++int64_t
+d;
+@ulong@
+identifier d;
+@@
+-ulong
++uint32_t
+d;
+@ushort@
+identifier d;
+@@
+-ushort
++uint16_t
+d;
+
+@ rulesm @
+identifier t;
+identifier f;
+expression E1;
+type T;
+@@
+T f(...){<...
+t = smalloc(E1);
+...>}
+@@
+identifier rulesm.f;
+expression E1;
+@@
+
+- smalloc(E1
++ calloc(E1, 1
+   )
+
+@ rulem @
+identifier t;
+identifier f;
+expression E1;
+type T;
+@@
+T f(...){<...
+t = malloc(E1);
+...>}
+@@
+identifier rulem.f;
+expression E1;
+@@
+
+- malloc(E1
++ calloc(E1, 1
+   )
+
+@@
+@@
+-getcallerpc(...);
+@@
+@@
+-setmalloctag(...);
+
+@@
+type T;
+@@
+-T validname0(...){...}
+
+@@
+type T;
+@@
+-T kstrcpy(...){...}
+
+@@
+@@
+-if (up){
++if (current){
+...  } else {...}
+
+@@
+@@
+-snprint(
++snprintf(
+...)
+
+@@
+@@
+-seek(
++lseek(
+...)
+
+@@
+expression E;
+@@
+-strcpy(up->errstr,
++set_errstr(
+E)
+@@
+@@
+-saveregisters(...);
+@@
+@@
+-saveregisters(...){...}
+@@
+@@
++//
+muxclose(...);
+
+@@
+@@
+-sysfatal(
++error(1, 0, 
+...)
+
diff --git a/scripts/plan9user/scalar.cocci b/scripts/plan9user/scalar.cocci
new file mode 100644 (file)
index 0000000..f7a07ca
--- /dev/null
@@ -0,0 +1,61 @@
+@@
+typedef uint;
+@@
+-uint
++unsigned int
+
+@@
+typedef uvlong;
+typedef uint64_t;
+@@
+-uvlong
++uint64_t
+
+@@
+typedef vlong;
+typedef int64_t;
+@@
+-vlong
++int64_t
+
+@@
+typedef ulong;
+typedef uint32_t;
+@@
+-ulong
++uint32_t
+
+@@
+typedef usize;
+@@
+-usize
++unsigned long
+
+@@
+typedef u32int;
+@@
+-u32int
++uint32_t
+
+@@
+typedef ushort;
+typedef uint16_t;
+@@
+-ushort
++uint16_t
+
+@@
+typedef uchar;
+typedef uint8_t;
+@@
+-uchar
++uint8_t
+
+@@
+typedef uintptr;
+typedef uintptr_t;
+@@
+-uintptr
++uintptr_t
+
+
diff --git a/scripts/plan9user/typedef.cocci b/scripts/plan9user/typedef.cocci
new file mode 100644 (file)
index 0000000..2f5acfd
--- /dev/null
@@ -0,0 +1,435 @@
+@@
+typedef Ipifc;
+@@
+-Ipifc
++struct ipifc
+
+@@
+typedef Ndbcache;
+@@
+-Ndbcache
++struct ndbcache
+
+@@
+typedef Ndbtuple;
+@@
+-Ndbtuple
++struct ndbtuple
+
+@@
+typedef Iplifc;
+@@
+-Iplifc
++struct iplifc
+
+@@
+typedef Ipv6rp;
+@@
+-Ipv6rp
++struct ipv6rp
+
+@@
+typedef Ip6hdr;
+@@
+-Ip6hdr
++struct ip6hdr
+
+@@
+typedef Icmp6hdr;
+@@
+-Icmp6hdr
++struct icmp6hdr
+
+@@
+typedef Udphdr;
+@@
+-Udphdr
++struct udphdr
+
+@@
+typedef Conv;
+@@
+-Conv
++struct conv
+
+@@
+typedef Fragment4;
+@@
+-Fragment4
++struct fragment4
+
+@@
+typedef Fragment6;
+@@
+-Fragment6
++struct fragment6
+
+@@
+typedef Fraghdr6;
+@@
+-Fraghdr6
++struct fraghdr6
+
+@@
+typedef Fs;
+@@
+-Fs
++struct fs
+
+@@
+typedef Hwaddr;
+@@
+-Hwaddr
++struct hwaddr
+
+@@
+typedef IP;
+@@
+-IP
++struct IP
+
+@@
+typedef IPaux;
+@@
+-IPaux
++struct IPaux
+
+@@
+typedef Ip4hdr;
+@@
+-Ip4hdr
++struct Ip4hdr
+
+@@
+typedef Ipfrag;
+@@
+-Ipfrag
++struct Ipfrag
+
+@@
+typedef Ipself;
+@@
+-Ipself
++struct Ipself
+
+@@
+typedef Ipselftab;
+@@
+-Ipselftab
++struct Ipselftab
+
+@@
+typedef Iplink;
+@@
+-Iplink
++struct Iplink
+
+@@
+typedef Ipmulti;
+@@
+-Ipmulti
++struct Ipmulti
+
+@@
+typedef Iphash;
+@@
+-Iphash
++struct iphash
+
+@@
+typedef Ipht;
+@@
+-Ipht
++struct Ipht
+
+@@
+typedef Netlog;
+@@
+-Netlog
++struct netlog
+
+@@
+typedef Medium;
+@@
+-Medium
++struct medium
+
+@@
+typedef Proto;
+@@
+-Proto
++struct proto
+
+@@
+typedef Arpent;
+@@
+-Arpent
++struct arpent
+
+@@
+typedef Arp;
+@@
+-Arp
++struct arp
+
+@@
+typedef Route;
+@@
+-Route
++struct route
+
+@@
+typedef Routerparams;
+@@
+-Routerparams
++struct routerparams
+
+@@
+typedef Hostparams;
+@@
+-Hostparams
++struct hostparams
+
+@@
+typedef v6router;
+@@
+-v6router
++struct v6router
+
+@@
+typedef v6params;
+@@
+-v6params
++struct v6params
+
+@@
+typedef RouteTree;
+@@
+-RouteTree
++struct RouteTree
+
+@@
+typedef Routewalk;
+@@
+-Routewalk
++struct routewalk
+
+@@
+typedef Queue;
+@@
+-Queue
++struct queue
+
+@@
+typedef V4route;
+@@
+-V4route
++struct V4route
+
+@@
+typedef V6route;
+@@
+-V6route
++struct V6route
+
+
+@@
+typedef Block;
+@@
+-Block
++struct block
+
+@@
+typedef Ctlr;
+@@
+-Ctlr
++struct ctlr
+
+@@
+typedef Ether;
+@@
+-Ether
++struct ether
+
+@@
+typedef Etherpkt;
+@@
+-Etherpkt
++struct etherpkt
+
+@@
+typedef Chan;
+@@
+-Chan
++struct chan
+
+@@
+typedef Dirtab;
+@@
+-Dirtab
++struct dirtab
+
+@@
+typedef Dirlist;
+@@
+-Dirlist
++struct dirlist
+
+@@
+typedef Dir;
+@@
+-Dir
++struct dir
+
+@@
+typedef Fgrp;
+@@
+-Fgrp
++struct fgrp
+
+@@
+typedef Qid;
+@@
+-Qid
++struct qid
+
+@@
+typedef Waitqid;
+@@
+-Waitqid
++struct waitqid
+
+@@
+typedef Mount;
+@@
+-Mount
++struct mount
+
+@@
+typedef Mhead;
+@@
+-Mhead
++struct mhead
+
+@@
+typedef Path;
+@@
+-Path
++struct path
+
+@@
+typedef Proc;
+@@
+-Proc
++struct proc
+
+@@
+typedef Pgrp;
+@@
+-Pgrp
++struct pgrp
+
+@@
+typedef Dev;
+@@
+-Dev
++struct dev
+
+@@
+typedef QLock;
+typedef qlock_t;
+@@
+-QLock
++qlock_t 
+
+@@
+typedef RWLock;
+typedef rwlock_t;
+@@
+-RWLock
++rwlock_t 
+
+@@
+typedef Lock;
+typedef spinlock_t;
+@@
+-Lock
++spinlock_t 
+
+@@
+typedef Ref;
+@@
+-Ref
++struct kref
+
+@@
+typedef Walkqid;
+@@
+-Walkqid
++struct walkqid
+
+@@
+typedef Cmdbuf;
+@@
+-Cmdbuf
++struct cmdbuf
+
+@@
+typedef Cmdtab;
+@@
+-Cmdtab
++struct cmdtab
+
+@@
+typedef Tcppriv;
+@@
+-Tcppriv
++struct tcppriv
+
+@@
+typedef Mnt;
+@@
+-Mnt
++struct mnt
+
+@@
+typedef Mntwalk;
+@@
+-Mntwalk
++struct mntwalk
+
+@@
+typedef Mntrpc;
+@@
+-Mntrpc
++struct mntrpc
+
+@@
+typedef Fcall;
+@@
+-Fcall
++struct fcall
+
+@@
+typedef Srv;
+@@
+-Srv
++struct srv
+
+@@
+typedef Ndb;
+@@
+-Ndb
++struct ndb
+
+@@
+typedef Ndbs;
+@@
+-Ndbs
++struct ndbs
+
+@@
+typedef Ndbhf;
+@@
+-Ndbhf
++struct ndbhf
diff --git a/scripts/scalar b/scripts/scalar
new file mode 100644 (file)
index 0000000..314ef5f
--- /dev/null
@@ -0,0 +1,6 @@
+sed -i 's,uvlong,uint64_t,g' $1
+sed -i 's,vlong,int64_t,g' $1
+sed -i 's,ulong,uint32_t,g' $1
+sed -i 's,ushort,uint16_t,g' $1
+sed -i 's,uchar,uint8_t,g' $1
+sed -i 's,uintptr,uintptr_t,g' $1
diff --git a/scripts/scalar.cocci b/scripts/scalar.cocci
new file mode 100644 (file)
index 0000000..a8468f3
--- /dev/null
@@ -0,0 +1,62 @@
+@@
+typedef uint;
+@@
+-uint
++unsigned int
+
+@@
+typedef u64;
+typedef uint64_t;
+@@
+-u64
++uint64_t
+
+@@
+typedef s64;
+typedef int64_t;
+@@
+-s64
++int64_t
+
+@@
+typedef u32;
+typedef uint32_t;
+@@
+-u32
++uint32_t
+
+@@
+typedef usize;
+@@
+-usize
++unsigned long
+
+@@
+typedef s32;
+typedef int32_t;
+@@
+- s32
++ int32_t
+
+@@
+typedef u16;
+typedef uint16_t;
+@@
+-u16
++uint16_t
+
+@@
+typedef u8;
+typedef uint8_t;
+@@
+-u8
++uint8_t
+
+@@
+typedef uintptr;
+typedef uintptr_t;
+@@
+-uintptr
++uintptr_t
+
+
diff --git a/scripts/spatch/kref.cocci b/scripts/spatch/kref.cocci
new file mode 100644 (file)
index 0000000..822e28d
--- /dev/null
@@ -0,0 +1,19 @@
+@  @
+type kref;
+identifier f;
+expression E;
+@@
+-f->ref = E
++kref_init(&f->ref, fake_release, E)
+
+@  @
+expression E;
+@@
+-incref(E)
++kref_get(&E->ref, 1)
+
+@  @
+expression E;
+@@
+-decref(E)
++kref_put(&E->ref)
diff --git a/scripts/spatch/locks.cocci b/scripts/spatch/locks.cocci
new file mode 100644 (file)
index 0000000..6f6ba9e
--- /dev/null
@@ -0,0 +1,75 @@
+@@
+expression E;
+@@
+-lock(
++spin_lock(
+-E
++&E->lock
+ )
+@@
+expression E;
+@@
+-unlock(
++spin_unlock(
+-E
++&E->lock
+ )
+
+@@
+expression E;
+@@
+wlock(
+-E
++&E->rwlock
+ )
+@@
+expression E;
+@@
+wunlock(
+-E
++&E->rwlock
+ )
+
+@@
+expression E;
+@@
+rlock(
+-E
++&E->rwlock
+ )
+@@
+expression E;
+@@
+canrlock(
+-E
++&E->rwlock
+ )
+@@
+expression E;
+@@
+runlock(
+-E
++&E->rwlock
+ )
+@@
+
+expression E;
+@@
+qlock(
+-E
++&E->qlock
+ )
+@@
+expression E;
+@@
+qunlock(
+-E
++&E->qlock
+ )
+@@
+expression E;
+@@
+canqlock(
+-E
++&E->qlock
+ )
diff --git a/scripts/spatch/malloc.cocci b/scripts/spatch/malloc.cocci
new file mode 100644 (file)
index 0000000..9a9dabc
--- /dev/null
@@ -0,0 +1,49 @@
+@ rulesm @
+identifier t;
+identifier f;
+expression E1;
+type T;
+@@
+T f(...){<...
+t = smalloc(E1);
+...>}
+@@
+identifier rulesm.f;
+expression E1;
+@@
+
+- smalloc(E1
++ kzmalloc(E1, KERN_WAIT
+   )
+
+@ rulem @
+identifier t;
+identifier f;
+expression E1;
+type T;
+@@
+T f(...){<...
+t = malloc(E1);
+...>}
+@@
+identifier rulem.f;
+expression E1;
+@@
+
+- malloc(E1
++ kzmalloc(E1, KERN_WAIT
+   )
+
+@@
+@@
+-getcallerpc(...);
+
+@@
+@@
+-setmalloctag(...);
+
+@@
+@@
+-free(
++kfree(
+...);
\ No newline at end of file
diff --git a/scripts/spatch/plan9.cocci b/scripts/spatch/plan9.cocci
new file mode 100644 (file)
index 0000000..ceeb979
--- /dev/null
@@ -0,0 +1,134 @@
+@ print@
+@@
+-print(
++printd(
+...)
+
+@ channel @
+identifier d;
+@@
+-Chan
++struct chan
+d;
+
+@ channelstar @
+identifier d;
+@@
+-Chan *
++struct chan *
+d;
+
+@mount@
+identifier d;
+@@
+-Mount
++struct mount
+d;
+
+@ mountstar @
+identifier d;
+@@
+-Chan *
++struct mount *
+d;
+
+@uvlong@
+identifier d;
+@@
+-uvlong
++uint64_t
+d;
+@vlong@
+identifier d;
+@@
+-vlong
++int64_t
+d;
+@ulong@
+identifier d;
+@@
+-ulong
++uint32_t
+d;
+@ushort@
+identifier d;
+@@
+-ushort
++uint16_t
+d;
+
+@ rulesm @
+identifier t;
+identifier f;
+expression E1;
+type T;
+@@
+T f(...){<...
+t = smalloc(E1);
+...>}
+@@
+identifier rulesm.f;
+expression E1;
+@@
+
+- smalloc(E1
++ kzmalloc(E1, 0
+   )
+
+@ rulem @
+identifier t;
+identifier f;
+expression E1;
+type T;
+@@
+T f(...){<...
+t = malloc(E1);
+...>}
+@@
+identifier rulem.f;
+expression E1;
+@@
+
+- malloc(E1
++ kzmalloc(E1, 0
+   )
+
+@@
+@@
+-getcallerpc(...);
+@@
+@@
+-setmalloctag(...);
+
+@@
+type T;
+@@
+-T validname0(...){...}
+
+@@
+type T;
+@@
+-T kstrcpy(...){...}
+
+@@
+@@
+-if (up){
++if (current){
+...  } else {...}
+
+@@
+expression E;
+@@
+-strcpy(up->errstr,
++set_errstr(
+E)
+@@
+@@
+-saveregisters(...);
+@@
+@@
+-saveregisters(...){...}
+@@
+@@
++//
+muxclose(...);
diff --git a/scripts/spatch/rendez.cocci b/scripts/spatch/rendez.cocci
new file mode 100644 (file)
index 0000000..be646bd
--- /dev/null
@@ -0,0 +1,32 @@
+@@
+expression RV;
+expression RVF;
+expression RVFA;
+@@
+-sleep(RV, RVF, RVFA);
++rendez_sleep(RV, RVF, RVFA);
+
+// i'm assuming this one runs first, matches all the return0s, which really
+// just want to delay in place (I think).
+@@
+expression RV;
+expression RVTO;
+@@
+-tsleep(RV, return0, 0, RVTO);
++udelay_sched(RVTO * 1000);
+
+// and then this one catches all real usage of rendez_sleep_timeout
+@@
+expression RV;
+expression RVF;
+expression RVFA;
+expression RVTO;
+@@
+-tsleep(RV, RVF, RVFA, RVTO);
++rendez_sleep_timeout(RV, RVF, RVFA, RVTO);
+
+@@
+expression RV;
+@@
+-wakeup(RV);
++rendez_wakeup(RV);
diff --git a/scripts/spatch/route.cocci b/scripts/spatch/route.cocci
new file mode 100644 (file)
index 0000000..c02737b
--- /dev/null
@@ -0,0 +1,90 @@
+@@
+identifier route;
+@@
+route
+- ->ifcid
++->routeTree.ifcid
+
+@@
+identifier route;
+@@
+route
+- ->tag
++->routeTree.tag
+
+@@
+identifier route;
+@@
+route
+- ->ipifc
++->routeTree.ipifc
+
+@@
+identifier route;
+@@
+route
+- ->type
++->routeTree.type
+
+@@
+identifier route;
+@@
+route
+- ->ifc
++->routeTree.ifc
+
+@@
+identifier route;
+@@
+route
+- ->left
++->routeTree.left
+
+@@
+identifier route;
+@@
+route
+- ->right
++->routeTree.right
+
+@@
+identifier route;
+@@
+route
+- ->mid
++->routeTree.mid
+
+@@
+identifier route;
+@@
+route
+- ->depth
++->routeTree.depth
+
+@@
+identifier route;
+@@
+route
+- ->ref
++->routeTree.ref
+
+@@
+typedef RouteTree;
+@@
+-RouteTree
++struct routeTree
+
+@@
+typedef V4route;
+@@
+-V4route
++struct V4route
+
+@@
+typedef V6route;
+@@
+-V6route
++struct V6route
+
+
+
diff --git a/scripts/spatch/scalar.cocci b/scripts/spatch/scalar.cocci
new file mode 100644 (file)
index 0000000..fed0fc6
--- /dev/null
@@ -0,0 +1,60 @@
+@@
+typedef uint;
+@@
+-uint
++unsigned int
+
+@@
+typedef uvlong;
+typedef uint64_t;
+@@
+-uvlong
++uint64_t
+
+@@
+typedef vlong;
+typedef int64_t;
+@@
+-vlong
++int64_t
+
+@@
+typedef ulong;
+typedef uint32_t;
+@@
+-ulong
++uint32_t
+
+@@
+typedef usize;
+@@
+-usize
++unsigned long
+
+@@
+typedef u32int;
+@@
+-u32int
++uint32_t
+
+@@
+typedef ushort;
+typedef uint16_t;
+@@
+-ushort
++uint16_t
+
+@@
+typedef uchar;
+typedef uint8_t;
+@@
+-uchar
++uint8_t
+
+@@
+typedef uintptr;
+typedef uintptr_t;
+@@
+-uintptr
++uintptr_t
+
diff --git a/scripts/spatch/scalars.cocci b/scripts/spatch/scalars.cocci
new file mode 100644 (file)
index 0000000..e6effa9
--- /dev/null
@@ -0,0 +1,25 @@
+
+@uvlong@
+identifier d;
+@@
+-uvlong
++uint64_t
+d;
+@vlong@
+identifier d;
+@@
+-vlong
++int64_t
+d;
+@ulong@
+identifier d;
+@@
+-ulong
++uint32_t
+d;
+@ushort@
+identifier d;
+@@
+-ushort
++uint16_t
+d;
diff --git a/scripts/spatch/typedef.cocci b/scripts/spatch/typedef.cocci
new file mode 100644 (file)
index 0000000..4bf5cb8
--- /dev/null
@@ -0,0 +1,461 @@
+@@
+typedef Ipifc;
+@@
+-Ipifc
++struct ipifc
+
+@@
+typedef Iplifc;
+@@
+-Iplifc
++struct iplifc
+
+@@
+typedef Ipv6rp;
+@@
+-Ipv6rp
++struct ipv6rp
+
+@@
+typedef Ip6hdr;
+@@
+-Ip6hdr
++struct ip6hdr
+
+@@
+typedef Icmp6hdr;
+@@
+-Icmp6hdr
++struct icmp6hdr
+
+@@
+typedef Udphdr;
+@@
+-Udphdr
++struct udphdr
+
+@@
+typedef Conv;
+@@
+-Conv
++struct conv
+
+@@
+typedef Fragment4;
+@@
+-Fragment4
++struct fragment4
+
+@@
+typedef Fragment6;
+@@
+-Fragment6
++struct fragment6
+
+@@
+typedef Fraghdr6;
+@@
+-Fraghdr6
++struct fraghdr6
+
+@@
+typedef Fs;
+@@
+-Fs
++struct fs
+
+@@
+typedef Hwaddr;
+@@
+-Hwaddr
++struct hwaddr
+
+@@
+typedef IP;
+@@
+-IP
++struct IP
+
+@@
+typedef IPaux;
+@@
+-IPaux
++struct IPaux
+
+@@
+typedef Ip4hdr;
+@@
+-Ip4hdr
++struct Ip4hdr
+
+@@
+typedef Ipfrag;
+@@
+-Ipfrag
++struct Ipfrag
+
+@@
+typedef Ipself;
+@@
+-Ipself
++struct Ipself
+
+@@
+typedef Ipselftab;
+@@
+-Ipselftab
++struct Ipselftab
+
+@@
+typedef Iplink;
+@@
+-Iplink
++struct Iplink
+
+@@
+typedef Ipmulti;
+@@
+-Ipmulti
++struct Ipmulti
+
+@@
+typedef Iphash;
+@@
+-Iphash
++struct iphash
+
+@@
+typedef Ipht;
+@@
+-Ipht
++struct Ipht
+
+@@
+typedef Netlog;
+@@
+-Netlog
++struct netlog
+
+@@
+typedef Medium;
+@@
+-Medium
++struct medium
+
+@@
+typedef Proto;
+@@
+-Proto
++struct proto
+
+@@
+typedef Arpent;
+@@
+-Arpent
++struct arpent
+
+@@
+typedef Arp;
+@@
+-Arp
++struct arp
+
+@@
+typedef Route;
+@@
+-Route
++struct route
+
+@@
+typedef Routerparams;
+@@
+-Routerparams
++struct routerparams
+
+@@
+typedef Hostparams;
+@@
+-Hostparams
++struct hostparams
+
+@@
+typedef v6router;
+@@
+-v6router
++struct v6router
+
+@@
+typedef v6params;
+@@
+-v6params
++struct v6params
+
+@@
+typedef RouteTree;
+@@
+-RouteTree
++struct RouteTree
+
+@@
+typedef Routewalk;
+@@
+-Routewalk
++struct routewalk
+
+@@
+typedef Queue;
+@@
+-Queue
++struct queue
+
+@@
+typedef V4route;
+@@
+-V4route
++struct V4route
+
+@@
+typedef V6route;
+@@
+-V6route
++struct V6route
+
+
+@@
+typedef Block;
+@@
+-Block
++struct block
+
+@@
+typedef Ctlr;
+@@
+-Ctlr
++struct ctlr
+
+@@
+typedef Ether;
+@@
+-Ether
++struct ether
+
+@@
+typedef Etherpkt;
+@@
+-Etherpkt
++struct etherpkt
+
+@@
+typedef Chan;
+@@
+-Chan
++struct chan
+
+@@
+typedef Dirtab;
+@@
+-Dirtab
++struct dirtab
+
+@@
+typedef Dirlist;
+@@
+-Dirlist
++struct dirlist
+
+@@
+typedef Dir;
+@@
+-Dir
++struct dir
+
+@@
+typedef Fgrp;
+@@
+-Fgrp
++struct fgrp
+
+@@
+typedef Qid;
+@@
+-Qid
++struct qid
+
+@@
+typedef Waitqid;
+@@
+-Waitqid
++struct waitqid
+
+@@
+typedef Mount;
+@@
+-Mount
++struct mount
+
+@@
+typedef Mhead;
+@@
+-Mhead
++struct mhead
+
+@@
+typedef Path;
+@@
+-Path
++struct path
+
+@@
+typedef Proc;
+@@
+-Proc
++struct proc
+
+@@
+typedef Pgrp;
+@@
+-Pgrp
++struct pgrp
+
+@@
+typedef Dev;
+@@
+-Dev
++struct dev
+
+@@
+typedef QLock;
+typedef qlock_t;
+@@
+-QLock
++qlock_t 
+
+@@
+typedef RWLock;
+typedef rwlock_t;
+@@
+-RWLock
++rwlock_t 
+
+@@
+typedef Lock;
+typedef spinlock_t;
+@@
+-Lock
++spinlock_t 
+
+@@
+typedef Ref;
+@@
+-Ref
++struct kref
+
+@@
+typedef Walkqid;
+@@
+-Walkqid
++struct walkqid
+
+@@
+typedef Cmdbuf;
+@@
+-Cmdbuf
++struct cmdbuf
+
+@@
+typedef Cmdtab;
+@@
+-Cmdtab
++struct cmdtab
+
+@@
+typedef Tcppriv;
+@@
+-Tcppriv
++struct tcppriv
+
+@@
+typedef Mnt;
+@@
+-Mnt
++struct mnt
+
+@@
+typedef Mntwalk;
+@@
+-Mntwalk
++struct mntwalk
+
+@@
+typedef Mntrpc;
+@@
+-Mntrpc
++struct mntrpc
+
+@@
+typedef Fcall;
+@@
+-Fcall
++struct fcall
+
+@@
+typedef Srv;
+@@
+-Srv
++struct srv
+
+@@
+typedef Mii;
+@@
+-Mii
++struct mii
+
+@@
+typedef MiiPhy;
+@@
+-MiiPhy
++struct miiphy
+
+@@
+typedef Rendez;
+@@
+-Rendez
++struct rendez
+
+@@
+typedef SDunit;
+@@
+-SDunit
++struct sdunit
+
+@@
+typedef SDev;
+@@
+-SDev
++struct sdev
+
+@@
+typedef SDifc;
+@@
+-SDifc
++struct sdifc
+
+@@
+typedef SDpart;
+@@
+-SDpart
++struct sdpart
+
+@@
+typedef SDperm;
+@@
+-SDperm
++struct sdperm
+
+@@
+typedef SDreq;
+@@
+-SDreq
++struct sdreq
+
+
diff --git a/scripts/spatch/waserror.cocci b/scripts/spatch/waserror.cocci
new file mode 100644 (file)
index 0000000..408dbd1
--- /dev/null
@@ -0,0 +1,11 @@
+@@
+type T;
+identifier f;
+@@
+T f(...)
+{
++ERRSTACK(2);
+... 
+waserror() ...}
+
+
diff --git a/scripts/tagging/MAKETAGS b/scripts/tagging/MAKETAGS
new file mode 100644 (file)
index 0000000..fe1a395
--- /dev/null
@@ -0,0 +1,6 @@
+ctags `du -a  \
+kern/drivers \
+kern/include \
+kern/kfs \
+kern/src \
+kern/arch/x86 | awk '/\.[ch]$/{print $2}'`
diff --git a/scripts/tagging/README b/scripts/tagging/README
new file mode 100644 (file)
index 0000000..2b3a9b4
--- /dev/null
@@ -0,0 +1,39 @@
+scripts/tagging holds a few utilities for code tagging.
+
+MAKETAGS is Ron's script for ctags.
+
+The other stuff is for brho's Gnu Global setup.  If you want to use it, add the
+bashrc chunk to your bashrc, and put the scripts in your path.  I put them in
+~/scripts.
+
+The global scripts are made to work similar to git grep, allowing you to run
+global on a subdirectory.  For instance, you can run gl (the bash alias for
+global) on kern/ to limit your search to only kernel files.
+
+I commonly run something like:
+$ gl functi(TAB TAB) (uses the tab complete)
+$ gl function
+
+To see info about 'function'.  Add -x for "explicit" info, and -r for
+"references" (who calls function).  Check out
+http://www.gnu.org/software/global/ for more info.
+
+Whenever you change files, you need to update the GTAGS database, otherwise the
+system will be out of date.  It's not a huge deal, but you'll be off by a
+couple lines.  This hurts more when integrated with your editor.
+
+To update, run 'gtu' (my alias for scripts/tagging/gtags-update.sh)
+
+Global integrates nicely with vi (and other editors).  For instance, in my
+vimrc, I have:
+
+noremap <c-k> :GtagsCursor<CR>
+
+Which binds the global command to Ctrl-K.
+
+I also use:
+
+noremap <c-h> :nohlsearch<CR> :ccl<CR>
+
+to clear my highlighted search and to close the little search window opened by
+global.
diff --git a/scripts/tagging/bashrc-global b/scripts/tagging/bashrc-global
new file mode 100644 (file)
index 0000000..9277b9a
--- /dev/null
@@ -0,0 +1,26 @@
+# GNU global stuff
+
+# optional aliases
+alias gl="~/scripts/global-subd.sh"
+alias gtu="~/scripts/gtags-update.sh"
+
+# for global autocomplete
+_global_subd_comp()
+{
+    local cur="${COMP_WORDS[COMP_CWORD]}"
+    # bail if it is an option (-x, -l, etc)
+    if [[ $cur == -* ]]
+    then
+        return 0
+    fi
+    local DIRS=`compgen -S/ -d $cur`
+    # if our tab complete matches a directory (not null) , go with that
+    if [[ -n "$DIRS" ]]
+    then
+        COMPREPLY=( $DIRS )
+        return 0
+    fi
+    # otherwise, use global's autocomplete
+    COMPREPLY=(`global -c $cur`)
+}
+complete -o nospace -F _global_subd_comp gl
diff --git a/scripts/tagging/global-subd.sh b/scripts/tagging/global-subd.sh
new file mode 100755 (executable)
index 0000000..499f07f
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/bash
+# global-subd.sh
+# barret rhoden 2012-03-07
+
+# this is a wrapper for 'global' that allows limiting the search to a
+# subdirectory of the pwd.  set the last argument to be the subdirectory, like
+# with git grep.  due to some limitations with global's formatting options, we
+# don't have the output sorted (by whatever mechanism they use), but it does
+# still retain its relative path.
+#
+# one nice side effect of the directory argument is that you can use this
+# script from outside of a gtags-managed directory, since we cd into the path.
+# for example, you can be in ~you/ and call global-subd.sh PATH_TO_REPO
+# ARGUMENTS, and it will run global within that directory.  not a big deal one
+# way or another.
+#
+# as a side note, if you call global with a wildcard, you need to quote-escape
+# it (single or double), to prevent the bash expansion.  e.g., cd user/parlib,
+# global vcore* isn't what you want, you want global "vcore*" (or 'vcore*').  
+# we still need to "" the args we pass to global (even for plain old global),
+# so that the caller's quotes make it through.  also note that if there is bash
+# expansion, it happens at the calling dir, not the cd'd dir
+
+FIRST_ARG=$1
+LAST_ARG=${BASH_ARGV[0]}
+
+# Helper: we needed to drop our dir's trailing /, if there was one, and escape
+# all intermediate ones for sed later.  This will make whatever path you send
+# in correct for sed later.
+set_sed_arg()
+{
+       SED_ARG="$1"
+       # remove trailing /
+       SED_ARG=`echo "$SED_ARG" | sed 's/\/$//'`
+       # need 4 \ to get two \ in the sed, which outputs one \ (something to do
+       # with the nested shell calls (``).  just need \/ to output \
+       SED_ARG=`echo "$SED_ARG" | sed 's/\//\\\\\//g'`
+}
+
+# We try for the first arg being the dir, and then the last arg.  In either
+# case, we call global with -l for local (this dir and children), and -n to
+# stop stripping paths.  unfortunately, -n also stops the (decent?) sorting of
+# the results...  sed finds our path and strips the leading "./".
+# Note, we need the quotes on input, o/w the test will pass for empty input...
+if [ -d "$FIRST_ARG" ]
+then
+       cd "$FIRST_ARG"
+       set_sed_arg $FIRST_ARG
+       # call global with the first arg taken off
+       shift # have $@ forget arg1
+       global -ln "$@" | sed "s/\.\/\($SED_ARG\)/\1/g"
+elif [ -d "$LAST_ARG" ]
+then
+       cd "$LAST_ARG"
+       set_sed_arg $LAST_ARG
+       # call global with the last arg taken off.  need to do it in one line,
+       # since bash sucks and it won't keep any quoted wildcards intact otherwise
+       # (or will still muck with the arguments in some weird way).  this is
+       # similar to doing NEW_ARGS=${@:1:$LAST_MINUS_ONE}, and passing NEW_ARGS
+       LAST_MINUS_ONE=$(($#-1))
+       global -ln "${@:1:$LAST_MINUS_ONE}" | sed "s/\.\/\($SED_ARG\)/\1/g"
+else # plain old global
+       global "$@"
+fi
diff --git a/scripts/tagging/gtags-update.sh b/scripts/tagging/gtags-update.sh
new file mode 100755 (executable)
index 0000000..28780d8
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+# Barret Rhoden 2012-03-07
+
+# Builds/updates a gtags database for all directories/paths listed in GTAGS_INC_FILE
+# (.gtagsinclude).  If you are in a gtags-managed directory (subdir), it will
+# update from the rootdir.  If not, it will attempt to build a new gtags
+# database, if you have the whitelist file.
+#
+# This will also do the incremental update, so run this when you have new files
+# in the system.  Don't run global -u, since it takes forever, and is probably
+# doing something I don't like.
+
+GTAGS_INC_FILE=.gtagsinclude
+# If we're already in a gtags-managed directory, cd into the root
+ROOTDIR=`global -p 2> /dev/null`
+RETVAL=$?
+if [ $RETVAL == 0 ]
+then
+       cd $ROOTDIR
+# otherwise, we assume we're in the (new) root
+fi
+# Find our include file (the whitelist)
+if [ ! -f "$GTAGS_INC_FILE" ]
+then
+       echo "Could not find gtags include file, aborting"
+       exit -1
+fi
+# get our directory list, send the list of all files in those paths to gtags
+DIRS=`cat $GTAGS_INC_FILE`
+find $DIRS -type f | gtags -f - -i
diff --git a/scripts/temporary_hack b/scripts/temporary_hack
new file mode 100644 (file)
index 0000000..d287e1d
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Hacks to build, but we might not want long term
+sed -i 's/DBGFLG/2/' $1
+sed -i 's/DBG/printk/' $1