-/* $OpenBSD: gencode.c,v 1.64 2022/12/27 17:10:07 jmc Exp $ */
+/* $OpenBSD: gencode.c,v 1.65 2024/04/05 18:01:56 deraadt Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
* A strdup whose allocations are freed after code generation is over.
*/
char *
-sdup(s)
- const char *s;
+sdup(const char *s)
{
int n = strlen(s) + 1;
char *cp = newchunk(n);
}
static __inline struct block *
-new_block(code)
- int code;
+new_block(int code)
{
struct block *p;
}
static __inline struct slist *
-new_stmt(code)
- int code;
+new_stmt(int code)
{
struct slist *p;
}
static struct block *
-gen_retblk(v)
- int v;
+gen_retblk(int v)
{
struct block *b = new_block(BPF_RET|BPF_K);
* in each block is already resolved.
*/
static void
-backpatch(list, target)
- struct block *list, *target;
+backpatch(struct block *list, struct block *target)
{
struct block *next;
* which of jt and jf is the link.
*/
static void
-merge(b0, b1)
- struct block *b0, *b1;
+merge(struct block *b0, struct block *b1)
{
struct block **p = &b0;
}
void
-finish_parse(p)
- struct block *p;
+finish_parse(struct block *p)
{
backpatch(p, gen_retblk(snaplen));
p->sense = !p->sense;
}
void
-gen_and(b0, b1)
- struct block *b0, *b1;
+gen_and(struct block *b0, struct block *b1)
{
backpatch(b0, b1->head);
b0->sense = !b0->sense;
}
void
-gen_or(b0, b1)
- struct block *b0, *b1;
+gen_or(struct block *b0, struct block *b1)
{
b0->sense = !b0->sense;
backpatch(b0, b1->head);
}
void
-gen_not(b)
- struct block *b;
+gen_not(struct block *b)
{
b->sense = !b->sense;
}
static struct block *
-gen_cmp(offset, size, v)
- u_int offset, size;
- bpf_int32 v;
+gen_cmp(u_int offset, u_int size, bpf_int32 v)
{
struct slist *s;
struct block *b;
}
static struct block *
-gen_cmp_gt(offset, size, v)
- u_int offset, size;
- bpf_int32 v;
+gen_cmp_gt(u_int offset, u_int size, bpf_int32 v)
{
struct slist *s;
struct block *b;
}
static struct block *
-gen_mcmp(offset, size, v, mask)
- u_int offset, size;
- bpf_int32 v;
- bpf_u_int32 mask;
+gen_mcmp(u_int offset, u_int size, bpf_int32 v, bpf_u_int32 mask)
{
struct block *b = gen_cmp(offset, size, v);
struct slist *s;
/* Like gen_mcmp with 'dynamic off_nl' added to the offset */
static struct block *
-gen_mcmp_nl(offset, size, v, mask)
- u_int offset, size;
- bpf_int32 v;
- bpf_u_int32 mask;
+gen_mcmp_nl(u_int offset, u_int size, bpf_int32 v, bpf_u_int32 mask)
{
struct block *b = gen_cmp_nl(offset, size, v);
struct slist *s;
}
static struct block *
-gen_bcmp(offset, size, v)
- u_int offset, size;
- const u_char *v;
+gen_bcmp(u_int offset, u_int size, const u_char *v)
{
struct block *b, *tmp;
/* Like gen_cmp but adds the dynamic 'off_nl' to the offset */
static struct block *
-gen_cmp_nl(offset, size, v)
- u_int offset, size;
- bpf_int32 v;
+gen_cmp_nl(u_int offset, u_int size, bpf_int32 v)
{
struct slist *s, *tmp;
struct block *b;
}
static void
-init_linktype(type)
- int type;
+init_linktype(int type)
{
linktype = type;
init_code = NULL;
}
static struct block *
-gen_uncond(rsense)
- int rsense;
+gen_uncond(int rsense)
{
struct block *b;
struct slist *s;
}
static struct block *
-gen_linktype(proto)
- int proto;
+gen_linktype(int proto)
{
struct block *b0, *b1;
}
static struct block *
-gen_hostop(addr, mask, dir, proto, src_off, dst_off)
- bpf_u_int32 addr;
- bpf_u_int32 mask;
- int dir, proto;
- u_int src_off, dst_off;
+gen_hostop(bpf_u_int32 addr, bpf_u_int32 mask, int dir, int proto,
+ u_int src_off, u_int dst_off)
{
struct block *b0, *b1;
u_int offset;
#ifdef INET6
static struct block *
-gen_hostop6(addr, mask, dir, proto, src_off, dst_off)
- struct in6_addr *addr;
- struct in6_addr *mask;
- int dir, proto;
- u_int src_off, dst_off;
+gen_hostop6(struct in6_addr *addr, struct in6_addr *mask, int dir, int proto,
+ u_int src_off, u_int dst_off)
{
struct block *b0, *b1;
u_int offset;
#endif /*INET6*/
static struct block *
-gen_ehostop(eaddr, dir)
- const u_char *eaddr;
- int dir;
+gen_ehostop(const u_char *eaddr, int dir)
{
struct block *b0, *b1;
* Like gen_ehostop, but for DLT_FDDI
*/
static struct block *
-gen_fhostop(eaddr, dir)
- const u_char *eaddr;
- int dir;
+gen_fhostop(const u_char *eaddr, int dir)
{
struct block *b0, *b1;
* and not generate masking instructions if the mask is 0xFFFF.
*/
static struct block *
-gen_dnhostop(addr, dir, base_off)
- bpf_u_int32 addr;
- int dir;
- u_int base_off;
+gen_dnhostop(bpf_u_int32 addr, int dir, u_int base_off)
{
struct block *b0, *b1, *b2, *tmp;
u_int offset_lh; /* offset if long header is received */
}
static struct block *
-gen_host(addr, mask, proto, dir)
- bpf_u_int32 addr;
- bpf_u_int32 mask;
- int proto;
- int dir;
+gen_host(bpf_u_int32 addr, bpf_u_int32 mask, int proto, int dir)
{
struct block *b0, *b1;
#ifdef INET6
static struct block *
-gen_host6(addr, mask, proto, dir)
- struct in6_addr *addr;
- struct in6_addr *mask;
- int proto;
- int dir;
+gen_host6(struct in6_addr *addr, struct in6_addr *mask, int proto, int dir)
{
switch (proto) {
#endif /*INET6*/
struct block *
-gen_proto_abbrev(proto)
- int proto;
+gen_proto_abbrev(int proto)
{
struct block *b0 = NULL, *b1;
}
static struct block *
-gen_portatom(off, v)
- int off;
- bpf_int32 v;
+gen_portatom(int off, bpf_int32 v)
{
struct slist *s, *tmp;
struct block *b;
#ifdef INET6
static struct block *
-gen_portatom6(off, v)
- int off;
- bpf_int32 v;
+gen_portatom6(int off, bpf_int32 v)
{
return gen_cmp_nl(40 + off, BPF_H, v);
}
#endif/*INET6*/
struct block *
-gen_portop(port, proto, dir)
- int port, proto, dir;
+gen_portop(int port, int proto, int dir)
{
struct block *b0, *b1, *tmp;
}
static struct block *
-gen_port(port, ip_proto, dir)
- int port;
- int ip_proto;
- int dir;
+gen_port(int port, int ip_proto, int dir)
{
struct block *b0, *b1, *tmp;
#ifdef INET6
struct block *
-gen_portop6(port, proto, dir)
- int port, proto, dir;
+gen_portop6(int port, int proto, int dir)
{
struct block *b0, *b1, *tmp;
}
static struct block *
-gen_port6(port, ip_proto, dir)
- int port;
- int ip_proto;
- int dir;
+gen_port6(int port, int ip_proto, int dir)
{
struct block *b0, *b1, *tmp;
#endif /* INET6 */
static int
-lookup_proto(name, proto)
- const char *name;
- int proto;
+lookup_proto(const char *name, int proto)
{
int v;
}
static struct block *
-gen_protochain(v, proto, dir)
- int v;
- int proto;
- int dir;
+gen_protochain(int v, int proto, int dir)
{
struct block *b0, *b;
struct slist *s[100];
}
static struct block *
-gen_proto(v, proto, dir)
- int v;
- int proto;
- int dir;
+gen_proto(int v, int proto, int dir)
{
struct block *b0, *b1;
}
struct block *
-gen_scode(name, q)
- const char *name;
- struct qual q;
+gen_scode(const char *name, struct qual q)
{
int proto = q.proto;
int dir = q.dir;
}
struct block *
-gen_mcode(s1, s2, masklen, q)
- const char *s1, *s2;
- int masklen;
- struct qual q;
+gen_mcode(const char *s1, const char *s2, int masklen, struct qual q)
{
int nlen, mlen;
bpf_u_int32 n, m;
}
struct block *
-gen_ncode(s, v, q)
- const char *s;
- bpf_u_int32 v;
- struct qual q;
+gen_ncode(const char *s, bpf_u_int32 v, struct qual q)
{
bpf_u_int32 mask;
int proto = q.proto;
#ifdef INET6
struct block *
-gen_mcode6(s1, s2, masklen, q)
- const char *s1, *s2;
- int masklen;
- struct qual q;
+gen_mcode6(const char *s1, const char *s2, int masklen, struct qual q)
{
struct addrinfo *res;
struct in6_addr *addr;
#endif /*INET6*/
struct block *
-gen_ecode(eaddr, q)
- const u_char *eaddr;
- struct qual q;
+gen_ecode(const u_char *eaddr, struct qual q)
{
if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) {
if (linktype == DLT_EN10MB)
}
void
-sappend(s0, s1)
- struct slist *s0, *s1;
+sappend(struct slist *s0, struct slist *s1)
{
/*
* This is definitely not the best way to do this, but the
}
static struct slist *
-xfer_to_x(a)
- struct arth *a;
+xfer_to_x(struct arth *a)
{
struct slist *s;
}
static struct slist *
-xfer_to_a(a)
- struct arth *a;
+xfer_to_a(struct arth *a)
{
struct slist *s;
}
struct arth *
-gen_load(proto, index, size)
- int proto;
- struct arth *index;
- int size;
+gen_load(int proto, struct arth *index, int size)
{
struct slist *s, *tmp;
struct block *b;
}
struct block *
-gen_relation(code, a0, a1, reversed)
- int code;
- struct arth *a0, *a1;
- int reversed;
+gen_relation(int code, struct arth *a0, struct arth *a1, int reversed)
{
struct slist *s0, *s1, *s2;
struct block *b, *tmp;
}
struct arth *
-gen_loadi(val)
- int val;
+gen_loadi(int val)
{
struct arth *a;
struct slist *s;
}
struct arth *
-gen_neg(a)
- struct arth *a;
+gen_neg(struct arth *a)
{
struct slist *s;
}
struct arth *
-gen_arth(code, a0, a1)
- int code;
- struct arth *a0, *a1;
+gen_arth(int code, struct arth *a0, struct arth *a1)
{
struct slist *s0, *s1, *s2;
* be used later.
*/
static void
-free_reg(n)
- int n;
+free_reg(int n)
{
regused[n] = 0;
}
static struct block *
-gen_len(jmp, n)
- int jmp, n;
+gen_len(int jmp, int n)
{
struct slist *s;
struct block *b;
}
struct block *
-gen_greater(n)
- int n;
+gen_greater(int n)
{
return gen_len(BPF_JGE, n);
}
struct block *
-gen_less(n)
- int n;
+gen_less(int n)
{
struct block *b;
}
struct block *
-gen_byteop(op, idx, val)
- int op, idx, val;
+gen_byteop(int op, int idx, int val)
{
struct block *b;
struct slist *s;
}
struct block *
-gen_broadcast(proto)
- int proto;
+gen_broadcast(int proto)
{
bpf_u_int32 hostmask;
struct block *b0, *b1, *b2;
}
struct block *
-gen_multicast(proto)
- int proto;
+gen_multicast(int proto)
{
struct block *b0, *b1;
struct slist *s;
* = 1 implies "outbound".
*/
struct block *
-gen_inbound(dir)
- int dir;
+gen_inbound(int dir)
{
struct block *b0;
}
static struct block *
-gen_ahostop(eaddr, dir)
- const u_char *eaddr;
- int dir;
+gen_ahostop(const u_char *eaddr, int dir)
{
struct block *b0, *b1;
}
struct block *
-gen_acode(eaddr, q)
- const u_char *eaddr;
- struct qual q;
+gen_acode(const u_char *eaddr, struct qual q)
{
if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) {
if (linktype == DLT_ARCNET)
}
struct block *
-gen_mpls(label)
- int label;
+gen_mpls(int label)
{
struct block *b0;
* support IEEE 802.1Q VLAN trunk over ethernet
*/
struct block *
-gen_vlan(vlan_num)
- int vlan_num;
+gen_vlan(int vlan_num)
{
struct block *b0;
-/* $OpenBSD: optimize.c,v 1.21 2020/08/03 03:29:58 dlg Exp $ */
+/* $OpenBSD: optimize.c,v 1.22 2024/04/05 18:01:56 deraadt Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
#endif
static void
-find_levels_r(b)
- struct block *b;
+find_levels_r(struct block *b)
{
int level;
* with the 'link' field of the struct block.
*/
static void
-find_levels(root)
- struct block *root;
+find_levels(struct block *root)
{
memset((char *)levels, 0, n_blocks * sizeof(*levels));
unMarkAll();
* Assumes graph has been leveled.
*/
static void
-find_dom(root)
- struct block *root;
+find_dom(struct block *root)
{
int i;
struct block *b;
}
static void
-propedom(ep)
- struct edge *ep;
+propedom(struct edge *ep)
{
SET_INSERT(ep->edom, ep->id);
if (ep->succ) {
* Assumes graph has been leveled and predecessors established.
*/
static void
-find_edom(root)
- struct block *root;
+find_edom(struct block *root)
{
int i;
uset x;
* Assumes graph has been leveled.
*/
static void
-find_closure(root)
- struct block *root;
+find_closure(struct block *root)
{
int i;
struct block *b;
* The implementation should probably change to an array access.
*/
static int
-atomuse(s)
- struct stmt *s;
+atomuse(struct stmt *s)
{
int c = s->code;
* The implementation should probably change to an array access.
*/
static int
-atomdef(s)
- struct stmt *s;
+atomdef(struct stmt *s)
{
if (s->code == NOP)
return -1;
}
static void
-compute_local_ud(b)
- struct block *b;
+compute_local_ud(struct block *b)
{
struct slist *s;
atomset def = 0, use = 0, kill = 0;
* Assume graph is already leveled.
*/
static void
-find_ud(root)
- struct block *root;
+find_ud(struct block *root)
{
int i, maxlevel;
struct block *p;
/* Because we really don't have an IR, this stuff is a little messy. */
static int
-F(code, v0, v1)
- int code;
- int v0, v1;
+F(int code, int v0, int v1)
{
u_int hash;
int val;
}
static __inline void
-vstore(s, valp, newval, alter)
- struct stmt *s;
- int *valp;
- int newval;
- int alter;
+vstore(struct stmt *s, int *valp, int newval, int alter)
{
if (alter && *valp == newval)
s->code = NOP;
}
static void
-fold_op(s, v0, v1)
- struct stmt *s;
- int v0, v1;
+fold_op(struct stmt *s, int v0, int v1)
{
bpf_int32 a, b;
}
static __inline struct slist *
-this_op(s)
- struct slist *s;
+this_op(struct slist *s)
{
while (s != 0 && s->s.code == NOP)
s = s->next;
}
static void
-opt_not(b)
- struct block *b;
+opt_not(struct block *b)
{
struct block *tmp = JT(b);
}
static void
-opt_peep(b)
- struct block *b;
+opt_peep(struct block *b)
{
struct slist *s;
struct slist *next, *last;
* evaluation and code transformations weren't folded together.
*/
static void
-opt_stmt(s, val, alter)
- struct stmt *s;
- int val[];
- int alter;
+opt_stmt(struct stmt *s, int val[], int alter)
{
int op;
int v;
}
static void
-deadstmt(s, last)
- struct stmt *s;
- struct stmt *last[];
+deadstmt(struct stmt *s, struct stmt *last[])
{
int atom;
}
static void
-opt_deadstores(b)
- struct block *b;
+opt_deadstores(struct block *b)
{
struct slist *s;
int atom;
}
static void
-opt_blk(b, do_stmts)
- struct block *b;
- int do_stmts;
+opt_blk(struct block *b, int do_stmts)
{
struct slist *s;
struct edge *p;
* from 'b'.
*/
static int
-use_conflict(b, succ)
- struct block *b, *succ;
+use_conflict(struct block *b, struct block *succ)
{
int atom;
atomset use = succ->out_use;
}
static struct block *
-fold_edge(child, ep)
- struct block *child;
- struct edge *ep;
+fold_edge(struct block *child, struct edge *ep)
{
int sense;
int aval0, aval1, oval0, oval1;
}
static void
-opt_j(ep)
- struct edge *ep;
+opt_j(struct edge *ep)
{
int i, k;
struct block *target;
static void
-or_pullup(b)
- struct block *b;
+or_pullup(struct block *b)
{
int val, at_top;
struct block *pull;
}
static void
-and_pullup(b)
- struct block *b;
+and_pullup(struct block *b)
{
int val, at_top;
struct block *pull;
}
static void
-opt_blks(root, do_stmts)
- struct block *root;
- int do_stmts;
+opt_blks(struct block *root, int do_stmts)
{
int i, maxlevel;
struct block *p;
}
static __inline void
-link_inedge(parent, child)
- struct edge *parent;
- struct block *child;
+link_inedge(struct edge *parent, struct block *child)
{
parent->next = child->in_edges;
child->in_edges = parent;
}
static void
-find_inedges(root)
- struct block *root;
+find_inedges(struct block *root)
{
int i;
struct block *b;
}
static void
-opt_root(b)
- struct block **b;
+opt_root(struct block **b)
{
struct slist *tmp, *s;
}
static void
-opt_loop(root, do_stmts)
- struct block *root;
- int do_stmts;
+opt_loop(struct block *root, int do_stmts)
{
#ifdef BDEBUG
* Optimize the filter code in its dag representation.
*/
void
-bpf_optimize(rootp)
- struct block **rootp;
+bpf_optimize(struct block **rootp)
{
struct block *root;
}
static void
-make_marks(p)
- struct block *p;
+make_marks(struct block *p)
{
if (!isMarked(p)) {
Mark(p);
* only for nodes that are alive.
*/
static void
-mark_code(p)
- struct block *p;
+mark_code(struct block *p)
{
cur_mark += 1;
make_marks(p);
* the accumulator.
*/
static int
-eq_slist(x, y)
- struct slist *x, *y;
+eq_slist(struct slist *x, struct slist *y)
{
while (1) {
while (x && x->s.code == NOP)
}
static __inline int
-eq_blk(b0, b1)
- struct block *b0, *b1;
+eq_blk(struct block *b0, struct block *b1)
{
if (b0->s.code == b1->s.code &&
b0->s.k == b1->s.k &&
}
static void
-intern_blocks(root)
- struct block *root;
+intern_blocks(struct block *root)
{
struct block *p;
int i, j;
* Return the number of stmts in 's'.
*/
static int
-slength(s)
- struct slist *s;
+slength(struct slist *s)
{
int n = 0;
* All nodes should be initially unmarked.
*/
static int
-count_blocks(p)
- struct block *p;
+count_blocks(struct block *p)
{
if (p == 0 || isMarked(p))
return 0;
* the basic blocks, and entering them into the 'blocks' array.`
*/
static void
-number_blks_r(p)
- struct block *p;
+number_blks_r(struct block *p)
{
int n;
* The nodes should be unmarked before calling.
*/
static int
-count_stmts(p)
- struct block *p;
+count_stmts(struct block *p)
{
int n;
* from the total number of blocks and/or statements.
*/
static void
-opt_init(root)
- struct block *root;
+opt_init(struct block *root)
{
bpf_u_int32 *p;
int i, n, max_stmts;
* properly.
*/
static int
-convert_code_r(p)
- struct block *p;
+convert_code_r(struct block *p)
{
struct bpf_insn *dst;
struct slist *src;
* BPF array representation. Set *lenp to the number of instructions.
*/
struct bpf_insn *
-icode_to_fcode(root, lenp)
- struct block *root;
- int *lenp;
+icode_to_fcode(struct block *root, int *lenp)
{
int n;
struct bpf_insn *fp;