CVS commit: src/sys/net

2015-02-12 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Feb 12 23:09:55 UTC 2015

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Fix bugs found by afl fuzzer http://lcamtuf.coredump.cx/afl/.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.38 src/sys/net/bpfjit.c:1.39
--- src/sys/net/bpfjit.c:1.38	Thu Jan 15 16:31:05 2015
+++ src/sys/net/bpfjit.c	Thu Feb 12 23:09:55 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.38 2015/01/15 16:31:05 christos Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.39 2015/02/12 23:09:55 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.38 2015/01/15 16:31:05 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.39 2015/02/12 23:09:55 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.38 2015/01/15 16:31:05 christos Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.39 2015/02/12 23:09:55 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -290,15 +290,10 @@ read_width(const struct bpf_insn *pc)
 {
 
 	switch (BPF_SIZE(pc-code)) {
-	case BPF_W:
-		return 4;
-	case BPF_H:
-		return 2;
-	case BPF_B:
-		return 1;
-	default:
-		BJ_ASSERT(false);
-		return 0;
+	case BPF_W: return 4;
+	case BPF_H: return 2;
+	case BPF_B: return 1;
+	default:return 0;
 	}
 }
 
@@ -839,6 +834,8 @@ emit_pkt_read(struct sljit_compiler *com
 
 	ld_reg = BJ_BUF;
 	width = read_width(pc);
+	if (width == 0)
+		return SLJIT_ERR_ALLOC_FAILED;
 
 	if (BPF_MODE(pc-code) == BPF_IND) {
 		/* tmp1 = buflen - (pc-k + width); */
@@ -1235,12 +1232,15 @@ read_pkt_insn(const struct bpf_insn *pc,
 	case BPF_LD:
 		rv = BPF_MODE(pc-code) == BPF_ABS ||
 		 BPF_MODE(pc-code) == BPF_IND;
-		if (rv)
+		if (rv) {
 			width = read_width(pc);
+			rv = (width != 0);
+		}
 		break;
 
 	case BPF_LDX:
-		rv = pc-code == (BPF_LDX|BPF_B|BPF_MSH);
+		rv = BPF_MODE(pc-code) == BPF_MSH 
+		 BPF_SIZE(pc-code) == BPF_B;
 		width = 1;
 		break;
 	}
@@ -1412,6 +1412,9 @@ optimize_pass1(const bpf_ctx_t *bc, cons
 			/* Initialize abc_length for ABC pass. */
 			insn_dat[i].u.jdata.abc_length = MAX_ABC_LENGTH;
 
+			if (BPF_SRC(insns[i].code) == BPF_X)
+*hints |= BJ_HINT_XREG;
+
 			if (BPF_OP(insns[i].code) == BPF_JA) {
 jt = jf = insns[i].k;
 			} else {
@@ -1590,6 +1593,7 @@ optimize(const bpf_ctx_t *bc, const stru
 static int
 bpf_alu_to_sljit_op(const struct bpf_insn *pc)
 {
+	const int bad = SLJIT_UNUSED;
 
 	/*
 	 * Note: all supported 64bit arches have 32bit multiply
@@ -1602,11 +1606,10 @@ bpf_alu_to_sljit_op(const struct bpf_ins
 	case BPF_OR:  return SLJIT_OR;
 	case BPF_XOR: return SLJIT_XOR;
 	case BPF_AND: return SLJIT_AND;
-	case BPF_LSH: return SLJIT_SHL;
-	case BPF_RSH: return SLJIT_LSHR|SLJIT_INT_OP;
+	case BPF_LSH: return (pc-k  31) ? bad : SLJIT_SHL;
+	case BPF_RSH: return (pc-k  31) ? bad : SLJIT_LSHR|SLJIT_INT_OP;
 	default:
-		BJ_ASSERT(false);
-		return 0;
+		return bad;
 	}
 }
 
@@ -1927,10 +1930,12 @@ generate_insn_code(struct sljit_compiler
 
 			op = BPF_OP(pc-code);
 			if (op != BPF_DIV  op != BPF_MOD) {
+const int op2 = bpf_alu_to_sljit_op(pc);
+
+if (op2 == SLJIT_UNUSED)
+	goto fail;
 status = sljit_emit_op2(compiler,
-bpf_alu_to_sljit_op(pc),
-BJ_AREG, 0,
-BJ_AREG, 0,
+op2, BJ_AREG, 0, BJ_AREG, 0,
 kx_to_reg(pc), kx_to_reg_arg(pc));
 if (status != SLJIT_SUCCESS)
 	goto fail;



CVS commit: src/tests/net/bpfilter

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 19:37:37 UTC 2015

Modified Files:
src/tests/net/bpfilter: t_bpfilter.c

Log Message:
Add bpfilterbadjmp and bpfilterbadret tests.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/net/bpfilter/t_bpfilter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfilter/t_bpfilter.c
diff -u src/tests/net/bpfilter/t_bpfilter.c:1.8 src/tests/net/bpfilter/t_bpfilter.c:1.9
--- src/tests/net/bpfilter/t_bpfilter.c:1.8	Tue Jun 24 11:32:36 2014
+++ src/tests/net/bpfilter/t_bpfilter.c	Wed Feb 11 19:37:37 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfilter.c,v 1.8 2014/06/24 11:32:36 alnsn Exp $	*/
+/*	$NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfilter.c,v 1.8 2014/06/24 11:32:36 alnsn Exp $);
+__RCSID($NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 alnsn Exp $);
 
 #include sys/param.h
 #include sys/ioctl.h
@@ -115,6 +115,15 @@ static struct bpf_insn noinitX_prog[] = 
 	BPF_STMT(BPF_RET+BPF_A, 0),
 };
 
+static struct bpf_insn badjmp_prog[] = {
+	BPF_STMT(BPF_JMP+BPF_JA, 5),
+	BPF_STMT(BPF_RET+BPF_A, 0),
+};
+
+static struct bpf_insn badret_prog[] = {
+	BPF_STMT(BPF_RET+BPF_A+0x8000, 0),
+};
+
 static uint16_t
 in_cksum(void *data, size_t len)
 {
@@ -387,6 +396,52 @@ ATF_TC_BODY(bpfilternoinitX, tc)
 	RL(send_bpf_prog(bpfilternoinitX, prog));
 }
 
+ATF_TC(bpfilterbadjmp);
+ATF_TC_HEAD(bpfilterbadjmp, tc)
+{
+
+	atf_tc_set_md_var(tc, descr, Checks that bpf program that 
+	jumps to invalid destination is rejected by the kernel);
+	atf_tc_set_md_var(tc, timeout, 30);
+}
+
+ATF_TC_BODY(bpfilterbadjmp, tc)
+{
+	struct bpf_program prog;
+
+	prog.bf_len = __arraycount(badjmp_prog);
+	prog.bf_insns = badjmp_prog;
+	ATF_CHECK_ERRNO(EINVAL, send_bpf_prog(bpfilterbadjmp, prog) == -1);
+}
+
+ATF_TC(bpfilterbadret);
+ATF_TC_HEAD(bpfilterbadret, tc)
+{
+
+	atf_tc_set_md_var(tc, descr, Checks that bpf program that 
+	ends with invalid BPF_RET instruction is rejected by the kernel);
+	atf_tc_set_md_var(tc, timeout, 30);
+}
+
+ATF_TC_BODY(bpfilterbadret, tc)
+{
+	struct bpf_program prog;
+	struct bpf_insn *last;
+
+	prog.bf_len = __arraycount(badret_prog);
+	prog.bf_insns = badret_prog;
+
+	/*
+	 * The point of this test is checking a bad instruction of
+	 * a valid class and with a valid BPF_RVAL data.
+	 */
+	last = prog.bf_insns[prog.bf_len - 1];
+	ATF_CHECK(BPF_CLASS(last-code) == BPF_RET 
+	(BPF_RVAL(last-code) == BPF_K || BPF_RVAL(last-code) == BPF_A));
+
+	ATF_CHECK_ERRNO(EINVAL, send_bpf_prog(bpfilterbadret, prog) == -1);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -395,6 +450,8 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, bpfilterbadmem);
 	ATF_TP_ADD_TC(tp, bpfilternoinitA);
 	ATF_TP_ADD_TC(tp, bpfilternoinitX);
+	ATF_TP_ADD_TC(tp, bpfilterbadjmp);
+	ATF_TP_ADD_TC(tp, bpfilterbadret);
 
 	return atf_no_error();
 }



CVS commit: src/tests/net/bpfjit

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 23:29:48 UTC 2015

Modified Files:
src/tests/net/bpfjit: t_bpfjit.c

Log Message:
Add bpfjit_jmp_ja_overflow test.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/net/bpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfjit/t_bpfjit.c
diff -u src/tests/net/bpfjit/t_bpfjit.c:1.5 src/tests/net/bpfjit/t_bpfjit.c:1.6
--- src/tests/net/bpfjit/t_bpfjit.c:1.5	Wed Feb 11 22:37:55 2015
+++ src/tests/net/bpfjit/t_bpfjit.c	Wed Feb 11 23:29:48 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.5 2015/02/11 22:37:55 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.6 2015/02/11 23:29:48 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.5 2015/02/11 22:37:55 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.6 2015/02/11 23:29:48 alnsn Exp $);
 
 #include sys/param.h
 #include sys/mbuf.h
@@ -1700,6 +1700,36 @@ ATF_TC_BODY(bpfjit_jmp_ja_invalid, tc)
 	ATF_CHECK(code == NULL);
 }
 
+ATF_TC(bpfjit_jmp_ja_overflow);
+ATF_TC_HEAD(bpfjit_jmp_ja_overflow, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test BPF_JMP+BPF_JA with negative offset);
+}
+
+ATF_TC_BODY(bpfjit_jmp_ja_overflow, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_JMP+BPF_JA, 1),
+		BPF_STMT(BPF_RET+BPF_K, 777),
+		BPF_STMT(BPF_JMP+BPF_JA, UINT32_MAX - 1), // -2
+		BPF_STMT(BPF_RET+BPF_K, 0)
+	};
+
+	bpfjit_func_t code;
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	/* Jumps with negative offsets work only in userspace. */
+	ATF_CHECK(!prog_validate(insns, insn_count));
+
+	rump_schedule();
+	code = rumpns_bpfjit_generate_code(NULL, insns, insn_count);
+	rump_unschedule();
+	ATF_CHECK(code == NULL);
+}
+
 ATF_TC(bpfjit_jmp_jgt_k);
 ATF_TC_HEAD(bpfjit_jmp_jgt_k, tc)
 {
@@ -4491,6 +4521,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, bpfjit_alu_neg);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_ja);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_ja_invalid);
+	ATF_TP_ADD_TC(tp, bpfjit_jmp_ja_overflow);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_jgt_k);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_jge_k);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_jeq_k);



CVS commit: src/tests/lib/libbpfjit

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 23:00:41 UTC 2015

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Add libbpfjit_ret_k and libbpfjit_bad_ret_k tests.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.8 src/tests/lib/libbpfjit/t_bpfjit.c:1.9
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.8	Thu Nov 20 11:08:29 2014
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Wed Feb 11 23:00:41 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.8 2014/11/20 11:08:29 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.9 2015/02/11 23:00:41 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.8 2014/11/20 11:08:29 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.9 2015/02/11 23:00:41 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -70,6 +70,71 @@ ATF_TC_BODY(libbpfjit_empty, tc)
 	ATF_CHECK(bpfjit_generate_code(NULL, dummy, 0) == NULL);
 }
 
+ATF_TC(libbpfjit_ret_k);
+ATF_TC_HEAD(libbpfjit_ret_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of a trivial bpf program);
+}
+
+ATF_TC_BODY(libbpfjit_ret_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_RET+BPF_K, 17)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 17);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_bad_ret_k);
+ATF_TC_HEAD(libbpfjit_bad_ret_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test that JIT compilation of a program with bad BPF_RET fails);
+}
+
+ATF_TC_BODY(libbpfjit_bad_ret_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_RET+BPF_K+0x8000, 13)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	/*
+	 * The point of this test is checking a bad instruction of
+	 * a valid class and with a valid BPF_RVAL data.
+	 */
+	const uint16_t rcode = insns[0].code;
+	ATF_CHECK(BPF_CLASS(rcode) == BPF_RET 
+	(BPF_RVAL(rcode) == BPF_K || BPF_RVAL(rcode) == BPF_A));
+
+	ATF_CHECK(!bpf_validate(insns, insn_count));
+
+	/* Current implementation generates code. */
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 13);
+
+	bpfjit_free_code(code);
+}
+
 ATF_TC(libbpfjit_alu_add_k);
 ATF_TC_HEAD(libbpfjit_alu_add_k, tc)
 {
@@ -4430,6 +4495,8 @@ ATF_TP_ADD_TCS(tp)
 	 * to ../../net/bpfjit/t_bpfjit.c
 	 */
 	ATF_TP_ADD_TC(tp, libbpfjit_empty);
+	ATF_TP_ADD_TC(tp, libbpfjit_ret_k);
+	ATF_TP_ADD_TC(tp, libbpfjit_bad_ret_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_add_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_sub_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_mul_k);



CVS commit: src/tests/lib/libbpfjit

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 23:33:16 UTC 2015

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Add libbpfjit_jmp_ja_overflow test.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.10 src/tests/lib/libbpfjit/t_bpfjit.c:1.11
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.10	Wed Feb 11 23:17:16 2015
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Wed Feb 11 23:33:16 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.10 2015/02/11 23:17:16 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.11 2015/02/11 23:33:16 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.10 2015/02/11 23:17:16 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.11 2015/02/11 23:33:16 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -1941,6 +1941,31 @@ ATF_TC_BODY(libbpfjit_jmp_ja_invalid, tc
 	ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
 }
 
+ATF_TC(libbpfjit_jmp_ja_overflow);
+ATF_TC_HEAD(libbpfjit_jmp_ja_overflow, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test BPF_JMP+BPF_JA with negative offset);
+}
+
+ATF_TC_BODY(libbpfjit_jmp_ja_overflow, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_JMP+BPF_JA, 1),
+		BPF_STMT(BPF_RET+BPF_K, 777),
+		BPF_STMT(BPF_JMP+BPF_JA, UINT32_MAX - 1), // -2
+		BPF_STMT(BPF_RET+BPF_K, 0)
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	/* Jumps with negative offsets work in userspace ... */
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	/* .. but not for bpfjit. */
+	ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
+}
+
 ATF_TC(libbpfjit_jmp_jgt_k);
 ATF_TC_HEAD(libbpfjit_jmp_jgt_k, tc)
 {
@@ -4578,6 +4603,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_neg);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_invalid);
+	ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_overflow);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_jgt_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_k);



CVS commit: src/tests/lib/libbpfjit

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 23:17:16 UTC 2015

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Add libbpfjit_jmp_ja_invalid test.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.9 src/tests/lib/libbpfjit/t_bpfjit.c:1.10
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.9	Wed Feb 11 23:00:41 2015
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Wed Feb 11 23:17:16 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.9 2015/02/11 23:00:41 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.10 2015/02/11 23:17:16 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.9 2015/02/11 23:00:41 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.10 2015/02/11 23:17:16 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -67,6 +67,7 @@ ATF_TC_BODY(libbpfjit_empty, tc)
 {
 	struct bpf_insn dummy;
 
+	ATF_CHECK(!bpf_validate(dummy, 0));
 	ATF_CHECK(bpfjit_generate_code(NULL, dummy, 0) == NULL);
 }
 
@@ -1917,6 +1918,29 @@ ATF_TC_BODY(libbpfjit_jmp_ja, tc)
 	bpfjit_free_code(code);
 }
 
+ATF_TC(libbpfjit_jmp_ja_invalid);
+ATF_TC_HEAD(libbpfjit_jmp_ja_invalid, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test BPF_JMP+BPF_JA to invalid destination);
+}
+
+ATF_TC_BODY(libbpfjit_jmp_ja_invalid, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_JMP+BPF_JA, 4),
+		BPF_STMT(BPF_RET+BPF_K, 0),
+		BPF_STMT(BPF_RET+BPF_K, 1),
+		BPF_STMT(BPF_RET+BPF_K, 2),
+		BPF_STMT(BPF_RET+BPF_K, 3),
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(!bpf_validate(insns, insn_count));
+	ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
+}
+
 ATF_TC(libbpfjit_jmp_jgt_k);
 ATF_TC_HEAD(libbpfjit_jmp_jgt_k, tc)
 {
@@ -4553,6 +4577,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_modulo_x);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_neg);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja);
+	ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_invalid);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_jgt_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_k);



CVS commit: src/tests/net/bpfilter

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 23:39:07 UTC 2015

Modified Files:
src/tests/net/bpfilter: t_bpfilter.c

Log Message:
Add bpfilternegjmp test.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/net/bpfilter/t_bpfilter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfilter/t_bpfilter.c
diff -u src/tests/net/bpfilter/t_bpfilter.c:1.9 src/tests/net/bpfilter/t_bpfilter.c:1.10
--- src/tests/net/bpfilter/t_bpfilter.c:1.9	Wed Feb 11 19:37:37 2015
+++ src/tests/net/bpfilter/t_bpfilter.c	Wed Feb 11 23:39:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 alnsn Exp $	*/
+/*	$NetBSD: t_bpfilter.c,v 1.10 2015/02/11 23:39:07 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfilter.c,v 1.9 2015/02/11 19:37:37 alnsn Exp $);
+__RCSID($NetBSD: t_bpfilter.c,v 1.10 2015/02/11 23:39:07 alnsn Exp $);
 
 #include sys/param.h
 #include sys/ioctl.h
@@ -120,6 +120,12 @@ static struct bpf_insn badjmp_prog[] = {
 	BPF_STMT(BPF_RET+BPF_A, 0),
 };
 
+static struct bpf_insn negjmp_prog[] = {
+	BPF_STMT(BPF_JMP+BPF_JA, 0),
+	BPF_STMT(BPF_JMP+BPF_JA, UINT32_MAX - 1), // -2
+	BPF_STMT(BPF_RET+BPF_A, 0),
+};
+
 static struct bpf_insn badret_prog[] = {
 	BPF_STMT(BPF_RET+BPF_A+0x8000, 0),
 };
@@ -414,6 +420,24 @@ ATF_TC_BODY(bpfilterbadjmp, tc)
 	ATF_CHECK_ERRNO(EINVAL, send_bpf_prog(bpfilterbadjmp, prog) == -1);
 }
 
+ATF_TC(bpfilternegjmp);
+ATF_TC_HEAD(bpfilternegjmp, tc)
+{
+
+	atf_tc_set_md_var(tc, descr, Checks that bpf program that 
+	jumps backwards is rejected by the kernel);
+	atf_tc_set_md_var(tc, timeout, 30);
+}
+
+ATF_TC_BODY(bpfilternegjmp, tc)
+{
+	struct bpf_program prog;
+
+	prog.bf_len = __arraycount(negjmp_prog);
+	prog.bf_insns = negjmp_prog;
+	ATF_CHECK_ERRNO(EINVAL, send_bpf_prog(bpfilternegjmp, prog) == -1);
+}
+
 ATF_TC(bpfilterbadret);
 ATF_TC_HEAD(bpfilterbadret, tc)
 {
@@ -451,6 +475,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, bpfilternoinitA);
 	ATF_TP_ADD_TC(tp, bpfilternoinitX);
 	ATF_TP_ADD_TC(tp, bpfilterbadjmp);
+	ATF_TP_ADD_TC(tp, bpfilternegjmp);
 	ATF_TP_ADD_TC(tp, bpfilterbadret);
 
 	return atf_no_error();



CVS commit: src/tests/net/bpfjit

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 22:37:55 UTC 2015

Modified Files:
src/tests/net/bpfjit: t_bpfjit.c

Log Message:
Add bpfjit_ret_k, bpfjit_bad_ret_k, bpfjit_jmp_ja_invalid tests.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/net/bpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfjit/t_bpfjit.c
diff -u src/tests/net/bpfjit/t_bpfjit.c:1.4 src/tests/net/bpfjit/t_bpfjit.c:1.5
--- src/tests/net/bpfjit/t_bpfjit.c:1.4	Thu Nov 20 11:36:13 2014
+++ src/tests/net/bpfjit/t_bpfjit.c	Wed Feb 11 22:37:55 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.4 2014/11/20 11:36:13 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.5 2015/02/11 22:37:55 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.4 2014/11/20 11:36:13 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.5 2015/02/11 22:37:55 alnsn Exp $);
 
 #include sys/param.h
 #include sys/mbuf.h
@@ -79,15 +79,73 @@ ATF_TC_HEAD(bpfjit_empty, tc)
 ATF_TC_BODY(bpfjit_empty, tc)
 {
 	struct bpf_insn dummy;
-	bpfjit_func_t fn;
+	bpfjit_func_t code;
 
 	RZ(rump_init());
 
+	ATF_CHECK(!prog_validate(dummy, 0));
+
 	rump_schedule();
-	fn = rumpns_bpfjit_generate_code(NULL, dummy, 0);
+	code = rumpns_bpfjit_generate_code(NULL, dummy, 0);
 	rump_unschedule();
 
-	ATF_CHECK(fn == NULL);
+	ATF_CHECK(code == NULL);
+}
+
+ATF_TC(bpfjit_ret_k);
+ATF_TC_HEAD(bpfjit_ret_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of a trivial bpf program);
+}
+
+ATF_TC_BODY(bpfjit_ret_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_RET+BPF_K, 17)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 17);
+}
+
+ATF_TC(bpfjit_bad_ret_k);
+ATF_TC_HEAD(bpfjit_bad_ret_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test that JIT compilation of a program with bad BPF_RET fails);
+}
+
+ATF_TC_BODY(bpfjit_bad_ret_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_RET+BPF_K+0x8000, 13)
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	/*
+	 * The point of this test is checking a bad instruction of
+	 * a valid class and with a valid BPF_RVAL data.
+	 */
+	const uint16_t rcode = insns[0].code;
+	ATF_CHECK(BPF_CLASS(rcode) == BPF_RET 
+	(BPF_RVAL(rcode) == BPF_K || BPF_RVAL(rcode) == BPF_A));
+
+	RZ(rump_init());
+
+	ATF_CHECK(!prog_validate(insns, insn_count));
+
+	/* Current implementation generates code. */
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 13);
 }
 
 ATF_TC(bpfjit_alu_add_k);
@@ -1612,6 +1670,36 @@ ATF_TC_BODY(bpfjit_jmp_ja, tc)
 	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == UINT32_MAX);
 }
 
+ATF_TC(bpfjit_jmp_ja_invalid);
+ATF_TC_HEAD(bpfjit_jmp_ja_invalid, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test BPF_JMP+BPF_JA to invalid destination);
+}
+
+ATF_TC_BODY(bpfjit_jmp_ja_invalid, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_JMP+BPF_JA, 4),
+		BPF_STMT(BPF_RET+BPF_K, 0),
+		BPF_STMT(BPF_RET+BPF_K, 1),
+		BPF_STMT(BPF_RET+BPF_K, 2),
+		BPF_STMT(BPF_RET+BPF_K, 3),
+	};
+
+	bpfjit_func_t code;
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(!prog_validate(insns, insn_count));
+
+	rump_schedule();
+	code = rumpns_bpfjit_generate_code(NULL, insns, insn_count);
+	rump_unschedule();
+	ATF_CHECK(code == NULL);
+}
+
 ATF_TC(bpfjit_jmp_jgt_k);
 ATF_TC_HEAD(bpfjit_jmp_jgt_k, tc)
 {
@@ -4344,6 +4432,8 @@ ATF_TP_ADD_TCS(tp)
 	 * to ../../lib/libbpfjit/t_bpfjit.c
 	 */
 	ATF_TP_ADD_TC(tp, bpfjit_empty);
+	ATF_TP_ADD_TC(tp, bpfjit_ret_k);
+	ATF_TP_ADD_TC(tp, bpfjit_bad_ret_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_add_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_sub_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_mul_k);
@@ -4400,6 +4490,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, bpfjit_alu_modulo_x);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_neg);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_ja);
+	ATF_TP_ADD_TC(tp, bpfjit_jmp_ja_invalid);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_jgt_k);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_jge_k);
 	ATF_TP_ADD_TC(tp, bpfjit_jmp_jeq_k);



CVS commit: src/sys/net

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 12:03:30 UTC 2015

Modified Files:
src/sys/net: bpf_filter.c

Log Message:
It's not enough to check that a class of the last instruction is BPF_RET.
The opcodes in bpf_validate() must match opcodes understood by bpf_filter().

Found by afl-fuzz http://lcamtuf.coredump.cx/afl/.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/net/bpf_filter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf_filter.c
diff -u src/sys/net/bpf_filter.c:1.68 src/sys/net/bpf_filter.c:1.69
--- src/sys/net/bpf_filter.c:1.68	Wed Nov 19 19:35:21 2014
+++ src/sys/net/bpf_filter.c	Wed Feb 11 12:03:30 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf_filter.c,v 1.68 2014/11/19 19:35:21 christos Exp $	*/
+/*	$NetBSD: bpf_filter.c,v 1.69 2015/02/11 12:03:30 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.68 2014/11/19 19:35:21 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.69 2015/02/11 12:03:30 alnsn Exp $);
 
 #if 0
 #if !(defined(lint) || defined(KERNEL))
@@ -628,8 +628,10 @@ bpf_validate(const struct bpf_insn *f, i
 	if (len  BPF_MAXINSNS)
 		return 0;
 #endif
-	if (BPF_CLASS(f[len - 1].code) != BPF_RET)
+	if (f[len - 1].code != BPF_RET|BPF_K 
+	f[len - 1].code != BPF_RET|BPF_A) {
 		return 0;
+	}
 
 #if defined(KERNEL) || defined(_KERNEL)
 	/* Note: only the pre-initialised is valid on startup */



CVS commit: src/sys/net

2015-02-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Feb 11 12:53:15 UTC 2015

Modified Files:
src/sys/net: bpf_filter.c

Log Message:
Fix the build.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/net/bpf_filter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf_filter.c
diff -u src/sys/net/bpf_filter.c:1.69 src/sys/net/bpf_filter.c:1.70
--- src/sys/net/bpf_filter.c:1.69	Wed Feb 11 12:03:30 2015
+++ src/sys/net/bpf_filter.c	Wed Feb 11 12:53:15 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf_filter.c,v 1.69 2015/02/11 12:03:30 alnsn Exp $	*/
+/*	$NetBSD: bpf_filter.c,v 1.70 2015/02/11 12:53:15 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.69 2015/02/11 12:03:30 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.70 2015/02/11 12:53:15 alnsn Exp $);
 
 #if 0
 #if !(defined(lint) || defined(KERNEL))
@@ -628,8 +628,8 @@ bpf_validate(const struct bpf_insn *f, i
 	if (len  BPF_MAXINSNS)
 		return 0;
 #endif
-	if (f[len - 1].code != BPF_RET|BPF_K 
-	f[len - 1].code != BPF_RET|BPF_A) {
+	if (f[len - 1].code != (BPF_RET|BPF_K) 
+	f[len - 1].code != (BPF_RET|BPF_A)) {
 		return 0;
 	}
 



CVS commit: src/tests/lib/libbpfjit

2014-11-20 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Nov 20 11:08:29 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Add BPF_MOD tests. Plus one tiny change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.7 src/tests/lib/libbpfjit/t_bpfjit.c:1.8
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.7	Wed Nov 19 22:56:35 2014
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Thu Nov 20 11:08:29 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.8 2014/11/20 11:08:29 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.8 2014/11/20 11:08:29 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -399,6 +399,245 @@ ATF_TC_BODY(libbpfjit_alu_div8000_k,
 	bpfjit_free_code(code);
 }
 
+ATF_TC(libbpfjit_alu_mod0_k);
+ATF_TC_HEAD(libbpfjit_alu_mod0_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0);
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod0_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 0),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	//ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod1_k);
+ATF_TC_HEAD(libbpfjit_alu_mod1_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=1);
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod1_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 7),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 1),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 0);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod2_k);
+ATF_TC_HEAD(libbpfjit_alu_mod2_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=2);
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod2_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 7),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 2),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 1);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod4_k);
+ATF_TC_HEAD(libbpfjit_alu_mod4_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=4);
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod4_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x)),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 4),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 3);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod10_k);
+ATF_TC_HEAD(libbpfjit_alu_mod10_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10);
+}
+
+ATF_TC_BODY(libbpfjit_alu_mod10_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 9);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod1_k);
+ATF_TC_HEAD(libbpfjit_alu_mod1_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=1);
+}
+
+ATF_TC_BODY

CVS commit: src/tests/net/bpfjit

2014-11-20 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Nov 20 11:36:13 UTC 2014

Modified Files:
src/tests/net/bpfjit: t_bpfjit.c

Log Message:
Add BPF_MOD tests. Plus one tiny change.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/net/bpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfjit/t_bpfjit.c
diff -u src/tests/net/bpfjit/t_bpfjit.c:1.3 src/tests/net/bpfjit/t_bpfjit.c:1.4
--- src/tests/net/bpfjit/t_bpfjit.c:1.3	Wed Nov 19 23:00:12 2014
+++ src/tests/net/bpfjit/t_bpfjit.c	Thu Nov 20 11:36:13 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.4 2014/11/20 11:36:13 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.4 2014/11/20 11:36:13 alnsn Exp $);
 
 #include sys/param.h
 #include sys/mbuf.h
@@ -364,6 +364,205 @@ ATF_TC_BODY(bpfjit_alu_div8000_k, tc
 	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 1);
 }
 
+ATF_TC(bpfjit_alu_mod0_k);
+ATF_TC_HEAD(bpfjit_alu_mod0_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0);
+}
+
+ATF_TC_BODY(bpfjit_alu_mod0_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 0),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	//ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0);
+}
+
+ATF_TC(bpfjit_alu_mod1_k);
+ATF_TC_HEAD(bpfjit_alu_mod1_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=1);
+}
+
+ATF_TC_BODY(bpfjit_alu_mod1_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 7),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 1),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0);
+}
+
+ATF_TC(bpfjit_alu_mod2_k);
+ATF_TC_HEAD(bpfjit_alu_mod2_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=2);
+}
+
+ATF_TC_BODY(bpfjit_alu_mod2_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 7),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 2),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 1);
+}
+
+ATF_TC(bpfjit_alu_mod4_k);
+ATF_TC_HEAD(bpfjit_alu_mod4_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=4);
+}
+
+ATF_TC_BODY(bpfjit_alu_mod4_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x)),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 4),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 3);
+}
+
+ATF_TC(bpfjit_alu_mod10_k);
+ATF_TC_HEAD(bpfjit_alu_mod10_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10);
+}
+
+ATF_TC_BODY(bpfjit_alu_mod10_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 9);
+}
+
+ATF_TC(bpfjit_alu_mod1_k);
+ATF_TC_HEAD(bpfjit_alu_mod1_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=1);
+}
+
+ATF_TC_BODY(bpfjit_alu_mod1_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+		BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 1),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 3849);
+}
+
+ATF_TC(bpfjit_alu_mod7609801_k);
+ATF_TC_HEAD(bpfjit_alu_mod7609801_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT

CVS commit: src/sys/net

2014-11-20 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Nov 20 14:35:01 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Follow argument convension of other emit_xxx() functions.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.33 src/sys/net/bpfjit.c:1.34
--- src/sys/net/bpfjit.c:1.33	Wed Nov 19 19:34:43 2014
+++ src/sys/net/bpfjit.c	Thu Nov 20 14:35:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.33 2014/11/19 19:34:43 christos Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.34 2014/11/20 14:35:01 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.33 2014/11/19 19:34:43 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.34 2014/11/20 14:35:01 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.33 2014/11/19 19:34:43 christos Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.34 2014/11/20 14:35:01 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -1132,9 +1132,11 @@ modulus(sljit_uw x, sljit_uw y)
  * divt,divw are either SLJIT_IMM,pc-k or BJ_XREG,0.
  */
 static int
-emit_moddiv(bool div, struct sljit_compiler *compiler, int divt, sljit_sw divw)
+emit_moddiv(struct sljit_compiler *compiler,
+const struct bpf_insn *pc, int divt, sljit_sw divw)
 {
 	int status;
+	const bool div = BPF_OP(pc-code) == BPF_DIV;
 
 #if BJ_XREG == SLJIT_RETURN_REG   || \
 BJ_XREG == SLJIT_SCRATCH_REG1 || \
@@ -1938,15 +1940,14 @@ generate_insn_code(struct sljit_compiler
 			}
 
 			if (src == BPF_X) {
-status = emit_moddiv(op == BPF_DIV,
-compiler, BJ_XREG, 0);
+status = emit_moddiv(compiler, pc, BJ_XREG, 0);
 if (status != SLJIT_SUCCESS)
 	goto fail;
 			} else if (pc-k != 0) {
 /* XXX: We can do better here for MOD */
 if ((pc-k  (pc-k - 1)) || op == BPF_MOD) {
-status = emit_moddiv(op == BPF_DIV,
-	compiler, SLJIT_IMM, (uint32_t)pc-k);
+	status = emit_moddiv(compiler, pc,
+	SLJIT_IMM, (uint32_t)pc-k);
 } else {
 status = emit_pow2_division(compiler,
 (uint32_t)pc-k);



CVS commit: src/sys/net

2014-11-20 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Nov 20 19:18:52 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Implement BPF_ALU+BPF_MOD-BPF_K when pc-k is a power of 2. Get rid of divt
and divw arguments in emit_moddiv(), they're accessible via the pc argument.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.34 src/sys/net/bpfjit.c:1.35
--- src/sys/net/bpfjit.c:1.34	Thu Nov 20 14:35:01 2014
+++ src/sys/net/bpfjit.c	Thu Nov 20 19:18:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.34 2014/11/20 14:35:01 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.35 2014/11/20 19:18:52 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.34 2014/11/20 14:35:01 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.35 2014/11/20 19:18:52 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.34 2014/11/20 14:35:01 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.35 2014/11/20 19:18:52 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -1087,25 +1087,43 @@ emit_msh(struct sljit_compiler *compiler
 	return SLJIT_SUCCESS;
 }
 
+/*
+ * Emit code for A = A / k or A = A % k when k is a power of 2.
+ * @pc BPF_DIV or BPF_MOD instruction.
+ */
 static int
-emit_pow2_division(struct sljit_compiler *compiler, uint32_t k)
+emit_pow2_moddiv(struct sljit_compiler *compiler, const struct bpf_insn *pc)
 {
-	int shift = 0;
+	uint32_t k = pc-k;
 	int status = SLJIT_SUCCESS;
 
-	while (k  1) {
-		k = 1;
-		shift++;
-	}
-
-	BJ_ASSERT(k == 1  shift  32);
+	BJ_ASSERT(k != 0  (k  (k - 1)) == 0);
 
-	if (shift != 0) {
+	if (BPF_OP(pc-code) == BPF_MOD) {
 		status = sljit_emit_op2(compiler,
-		SLJIT_LSHR|SLJIT_INT_OP,
+		SLJIT_AND,
 		BJ_AREG, 0,
 		BJ_AREG, 0,
-		SLJIT_IMM, shift);
+		SLJIT_IMM, k - 1);
+	} else {
+		int shift = 0;
+
+		/*
+		 * Do shift = __builtin_ctz(k).
+		 * The loop is slower, but that's ok.
+		 */
+		while (k  1) {
+			k = 1;
+			shift++;
+		}
+
+		if (shift != 0) {
+			status = sljit_emit_op2(compiler,
+			SLJIT_LSHR|SLJIT_INT_OP,
+			BJ_AREG, 0,
+			BJ_AREG, 0,
+			SLJIT_IMM, shift);
+		}
 	}
 
 	return status;
@@ -1128,15 +1146,15 @@ modulus(sljit_uw x, sljit_uw y)
 #endif
 
 /*
- * Emit code for A = A / div or A = A % div
- * divt,divw are either SLJIT_IMM,pc-k or BJ_XREG,0.
+ * Emit code for A = A / div or A = A % div.
+ * @pc BPF_DIV or BPF_MOD instruction.
  */
 static int
-emit_moddiv(struct sljit_compiler *compiler,
-const struct bpf_insn *pc, int divt, sljit_sw divw)
+emit_moddiv(struct sljit_compiler *compiler, const struct bpf_insn *pc)
 {
 	int status;
 	const bool div = BPF_OP(pc-code) == BPF_DIV;
+	const bool xreg = BPF_SRC(pc-code) == BPF_X;
 
 #if BJ_XREG == SLJIT_RETURN_REG   || \
 BJ_XREG == SLJIT_SCRATCH_REG1 || \
@@ -1157,7 +1175,8 @@ emit_moddiv(struct sljit_compiler *compi
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV,
 	SLJIT_SCRATCH_REG2, 0,
-	divt, divw);
+	xreg ? BJ_XREG : SLJIT_IMM,
+	xreg ? 0 : (uint32_t)pc-k);
 	if (status != SLJIT_SUCCESS)
 		return status;
 
@@ -1940,17 +1959,14 @@ generate_insn_code(struct sljit_compiler
 			}
 
 			if (src == BPF_X) {
-status = emit_moddiv(compiler, pc, BJ_XREG, 0);
+status = emit_moddiv(compiler, pc);
 if (status != SLJIT_SUCCESS)
 	goto fail;
 			} else if (pc-k != 0) {
-/* XXX: We can do better here for MOD */
-if ((pc-k  (pc-k - 1)) || op == BPF_MOD) {
-	status = emit_moddiv(compiler, pc,
-	SLJIT_IMM, (uint32_t)pc-k);
+if (pc-k  (pc-k - 1)) {
+	status = emit_moddiv(compiler, pc);
 } else {
-status = emit_pow2_division(compiler,
-(uint32_t)pc-k);
+	status = emit_pow2_moddiv(compiler, pc);
 }
 if (status != SLJIT_SUCCESS)
 	goto fail;



CVS commit: src/sys/net

2014-11-20 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Nov 20 20:31:22 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Implement BPF_MOD.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.35 src/sys/net/bpfjit.c:1.36
--- src/sys/net/bpfjit.c:1.35	Thu Nov 20 19:18:52 2014
+++ src/sys/net/bpfjit.c	Thu Nov 20 20:31:22 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.35 2014/11/20 19:18:52 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.36 2014/11/20 20:31:22 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.35 2014/11/20 19:18:52 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.36 2014/11/20 20:31:22 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.35 2014/11/20 19:18:52 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.36 2014/11/20 20:31:22 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -76,11 +76,6 @@ __RCSID($NetBSD: bpfjit.c,v 1.35 2014/1
 #endif
 
 /*
- * XXX: Until we support SLJIT_UMOD properly
- */
-#undef BPFJIT_USE_UDIV
-
-/*
  * Arguments of generated bpfjit_func_t.
  * The first argument is reassigned upon entry
  * to a more frequently used buf argument.
@@ -1183,14 +1178,25 @@ emit_moddiv(struct sljit_compiler *compi
 #if defined(BPFJIT_USE_UDIV)
 	status = sljit_emit_op0(compiler, SLJIT_UDIV|SLJIT_INT_OP);
 
+	if (BPF_OP(pc-code) == BPF_DIV) {
 #if BJ_AREG != SLJIT_SCRATCH_REG1
-	status = sljit_emit_op1(compiler,
-	SLJIT_MOV,
-	BJ_AREG, 0,
-	SLJIT_SCRATCH_REG1, 0);
+		status = sljit_emit_op1(compiler,
+		SLJIT_MOV,
+		BJ_AREG, 0,
+		SLJIT_SCRATCH_REG1, 0);
+#endif
+	} else {
+#if BJ_AREG != SLJIT_SCRATCH_REG2
+		/* Remainder is in SLJIT_SCRATCH_REG2. */
+		status = sljit_emit_op1(compiler,
+		SLJIT_MOV,
+		BJ_AREG, 0,
+		SLJIT_SCRATCH_REG2, 0);
+#endif
+	}
+
 	if (status != SLJIT_SUCCESS)
 		return status;
-#endif
 #else
 	status = sljit_emit_ijump(compiler,
 	SLJIT_CALL2,



CVS commit: src/tests/lib/libbpfjit

2014-11-19 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Nov 19 22:56:35 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Add BPF_XOR tests.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.6 src/tests/lib/libbpfjit/t_bpfjit.c:1.7
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.6	Tue Jul  8 21:07:52 2014
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Wed Nov 19 22:56:35 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -459,6 +459,36 @@ ATF_TC_BODY(libbpfjit_alu_or_k, tc)
 	bpfjit_free_code(code);
 }
 
+ATF_TC(libbpfjit_alu_xor_k);
+ATF_TC_HEAD(libbpfjit_alu_xor_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_XOR+BPF_K);
+}
+
+ATF_TC_BODY(libbpfjit_alu_xor_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+		BPF_STMT(BPF_ALU+BPF_XOR+BPF_K, 0xb1e0),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 0xdeadbeef);
+
+	bpfjit_free_code(code);
+}
+
 ATF_TC(libbpfjit_alu_lsh_k);
 ATF_TC_HEAD(libbpfjit_alu_lsh_k, tc)
 {
@@ -1045,6 +1075,37 @@ ATF_TC_BODY(libbpfjit_alu_or_x, tc)
 	bpfjit_free_code(code);
 }
 
+ATF_TC(libbpfjit_alu_xor_x);
+ATF_TC_HEAD(libbpfjit_alu_xor_x, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_XOR+BPF_X);
+}
+
+ATF_TC_BODY(libbpfjit_alu_xor_x, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0xb1e0),
+		BPF_STMT(BPF_ALU+BPF_XOR+BPF_X, 0),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(jitcall(code, pkt, 1, 1) == 0xdeadbeef);
+
+	bpfjit_free_code(code);
+}
+
 ATF_TC(libbpfjit_alu_lsh_x);
 ATF_TC_HEAD(libbpfjit_alu_lsh_x, tc)
 {
@@ -3896,6 +3957,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_div8000_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_and_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_or_k);
+	ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_k);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_k);
@@ -3914,6 +3976,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_div8000_x);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_and_x);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_or_x);
+	ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_x);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_x);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_x);
 	ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_x);



CVS commit: src/tests/net/bpfjit

2014-11-19 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Nov 19 23:00:12 UTC 2014

Modified Files:
src/tests/net/bpfjit: t_bpfjit.c

Log Message:
Add BPF_XOR tests.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/bpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfjit/t_bpfjit.c
diff -u src/tests/net/bpfjit/t_bpfjit.c:1.2 src/tests/net/bpfjit/t_bpfjit.c:1.3
--- src/tests/net/bpfjit/t_bpfjit.c:1.2	Tue Jul  8 21:44:26 2014
+++ src/tests/net/bpfjit/t_bpfjit.c	Wed Nov 19 23:00:12 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $);
 
 #include sys/param.h
 #include sys/mbuf.h
@@ -414,6 +414,31 @@ ATF_TC_BODY(bpfjit_alu_or_k, tc)
 	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0xdeadbeef);
 }
 
+ATF_TC(bpfjit_alu_xor_k);
+ATF_TC_HEAD(bpfjit_alu_xor_k, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_XOR+BPF_K);
+}
+
+ATF_TC_BODY(bpfjit_alu_xor_k, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+		BPF_STMT(BPF_ALU+BPF_XOR+BPF_K, 0xb1e0),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0xdeadbeef);
+}
+
 ATF_TC(bpfjit_alu_lsh_k);
 ATF_TC_HEAD(bpfjit_alu_lsh_k, tc)
 {
@@ -920,6 +945,32 @@ ATF_TC_BODY(bpfjit_alu_or_x, tc)
 	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0xdeadbeef);
 }
 
+ATF_TC(bpfjit_alu_xor_x);
+ATF_TC_HEAD(bpfjit_alu_xor_x, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test JIT compilation of BPF_ALU+BPF_XOR+BPF_X);
+}
+
+ATF_TC_BODY(bpfjit_alu_xor_x, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0xb1e0),
+		BPF_STMT(BPF_ALU+BPF_XOR+BPF_X, 0),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(prog_validate(insns, insn_count));
+	ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0xdeadbeef);
+}
+
 ATF_TC(bpfjit_alu_lsh_x);
 ATF_TC_HEAD(bpfjit_alu_lsh_x, tc)
 {
@@ -3900,6 +3951,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, bpfjit_alu_div8000_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_and_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_or_k);
+	ATF_TP_ADD_TC(tp, bpfjit_alu_xor_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_lsh_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_lsh0_k);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_rsh_k);
@@ -3918,6 +3970,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, bpfjit_alu_div8000_x);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_and_x);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_or_x);
+	ATF_TP_ADD_TC(tp, bpfjit_alu_xor_x);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_lsh_x);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_lsh0_x);
 	ATF_TP_ADD_TC(tp, bpfjit_alu_rsh_x);



CVS commit: src/sys/net

2014-07-28 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jul 28 07:32:46 UTC 2014

Modified Files:
src/sys/net: bpf.c

Log Message:
Enable net.bpf.jit only if MODULAR and BPFJIT. Tweak a warning about postponed
jit activation.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/net/bpf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf.c
diff -u src/sys/net/bpf.c:1.185 src/sys/net/bpf.c:1.186
--- src/sys/net/bpf.c:1.185	Fri Jul 25 08:10:40 2014
+++ src/sys/net/bpf.c	Mon Jul 28 07:32:46 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.185 2014/07/25 08:10:40 dholland Exp $	*/
+/*	$NetBSD: bpf.c,v 1.186 2014/07/28 07:32:46 alnsn Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: bpf.c,v 1.185 2014/07/25 08:10:40 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpf.c,v 1.186 2014/07/28 07:32:46 alnsn Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_bpf.h
@@ -1928,6 +1928,7 @@ sysctl_net_bpf_maxbufsize(SYSCTLFN_ARGS)
 	return (0);
 }
 
+#if defined(MODULAR) || defined(BPFJIT)
 static int
 sysctl_net_bpf_jit(SYSCTLFN_ARGS)
 {
@@ -1951,12 +1952,13 @@ sysctl_net_bpf_jit(SYSCTLFN_ARGS)
 	membar_sync();
 
 	if (newval  bpfjit_module_ops.bj_generate_code == NULL) {
-		printf(WARNING jit activation is postponed 
+		printf(JIT compilation is postponed 
 		until after bpfjit module is loaded\n);
 	}
 
 	return 0;
 }
+#endif
 
 static int
 sysctl_net_bpf_peers(SYSCTLFN_ARGS)
@@ -2042,12 +2044,14 @@ sysctl_net_bpf_setup(void)
 		   NULL, 0, NULL, 0,
 		   CTL_NET, CTL_CREATE, CTL_EOL);
 	if (node != NULL) {
+#if defined(MODULAR) || defined(BPFJIT)
 		sysctl_createv(bpf_sysctllog, 0, NULL, NULL,
 			CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 			CTLTYPE_BOOL, jit,
 			SYSCTL_DESCR(Toggle Just-In-Time compilation),
 			sysctl_net_bpf_jit, 0, bpf_jit, 0,
 			CTL_NET, node-sysctl_num, CTL_CREATE, CTL_EOL);
+#endif
 		sysctl_createv(bpf_sysctllog, 0, NULL, NULL,
 			CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 			CTLTYPE_INT, maxbufsize,



CVS commit: src/sys/net

2014-07-26 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul 26 11:23:46 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Don't use saved EREG registers because sljit 0.91 can generate
bogus code on amd64. The A and X registers are saved on the stack.

The most recent version of sljit fixes bogus code generation but
it's not backward compatible with sljit 0.91.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.31 src/sys/net/bpfjit.c:1.32
--- src/sys/net/bpfjit.c:1.31	Thu Jul 24 22:54:38 2014
+++ src/sys/net/bpfjit.c	Sat Jul 26 11:23:46 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.31 2014/07/24 22:54:38 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.32 2014/07/26 11:23:46 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.31 2014/07/24 22:54:38 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.32 2014/07/26 11:23:46 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.31 2014/07/24 22:54:38 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.32 2014/07/26 11:23:46 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -89,12 +89,11 @@ __RCSID($NetBSD: bpfjit.c,v 1.31 2014/0
 #define BJ_BUF		SLJIT_SAVED_REG1
 //#define BJ_ARGS	SLJIT_SAVED_REG2
 #define BJ_BUFLEN	SLJIT_SAVED_REG3
-#define BJ_XREG		SLJIT_SAVED_EREG1
-#define BJ_ASAVE	SLJIT_SAVED_EREG2
 #define BJ_AREG		SLJIT_SCRATCH_REG1
 #define BJ_TMP1REG	SLJIT_SCRATCH_REG2
 #define BJ_TMP2REG	SLJIT_SCRATCH_REG3
-#define BJ_TMP3REG	SLJIT_TEMPORARY_EREG1
+#define BJ_XREG		SLJIT_TEMPORARY_EREG1
+#define BJ_TMP3REG	SLJIT_TEMPORARY_EREG2
 
 #ifdef _KERNEL
 #define MAX_MEMWORDS BPF_MAX_MEMWORDS
@@ -136,6 +135,7 @@ struct bpfjit_stack
 {
 	bpf_ctx_t *ctx;
 	uint32_t *extmem; /* pointer to external memory store */
+	uint32_t reg; /* saved A or X register */
 #ifdef _KERNEL
 	int err; /* 3rd argument for m_xword/m_xhalf/m_xbyte function call */
 #endif
@@ -259,8 +259,16 @@ nscratches(bpfjit_hint_t hints)
 	if (hints  BJ_HINT_COP)
 		rv = 3; /* calls copfunc with three arguments */
 
+	if (hints  BJ_HINT_XREG)
+		rv = 4; /* uses BJ_XREG */
+
+#ifdef _KERNEL
+	if (hints  BJ_HINT_LDX)
+		rv = 5; /* uses BJ_TMP3REG */
+#endif
+
 	if (hints  BJ_HINT_COPX)
-		rv = 4; /* uses BJ_TMP3REG */
+		rv = 5; /* uses BJ_TMP3REG */
 
 	return rv;
 }
@@ -274,14 +282,6 @@ nsaveds(bpfjit_hint_t hints)
 {
 	sljit_si rv = 3;
 
-	if (hints  BJ_HINT_XREG)
-		rv = 4; /* uses BJ_XREG */
-
-#ifdef _KERNEL
-	if (hints  BJ_HINT_LDX)
-		rv = 5; /* uses BJ_ASAVE */
-#endif
-
 	return rv;
 }
 
@@ -528,21 +528,30 @@ emit_read32(struct sljit_compiler *compi
  * BPF_LDX+BPF_B+BPF_MSH   X - 4*(P[k:1]0xf)
  */
 static int
-emit_xcall(struct sljit_compiler *compiler, const struct bpf_insn *pc,
-int dst, struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize,
+emit_xcall(struct sljit_compiler *compiler, bpfjit_hint_t hints,
+const struct bpf_insn *pc, int dst, struct sljit_jump ***ret0,
+size_t *ret0_size, size_t *ret0_maxsize,
 uint32_t (*fn)(const struct mbuf *, uint32_t, int *))
 {
+#if BJ_XREG == SLJIT_RETURN_REG   || \
+BJ_XREG == SLJIT_SCRATCH_REG1 || \
+BJ_XREG == SLJIT_SCRATCH_REG2 || \
+BJ_XREG == SLJIT_SCRATCH_REG3
+#error Not supported assignment of registers.
+#endif
 	struct sljit_jump *jump;
+	sljit_si save_reg;
 	int status;
 
-	BJ_ASSERT(dst != BJ_ASAVE);
+	save_reg = (BPF_CLASS(pc-code) == BPF_LDX) ? BJ_AREG : BJ_XREG;
 
-	if (BPF_CLASS(pc-code) == BPF_LDX) {
-		/* save A */
+	if (save_reg == BJ_AREG || (hints  BJ_HINT_XREG)) {
+		/* save A or X */
 		status = sljit_emit_op1(compiler,
-		SLJIT_MOV,
-		BJ_ASAVE, 0,
-		BJ_AREG, 0);
+		SLJIT_MOV_UI, /* uint32_t destination */
+		SLJIT_MEM1(SLJIT_LOCALS_REG),
+		offsetof(struct bpfjit_stack, reg),
+		save_reg, 0);
 		if (status != SLJIT_SUCCESS)
 			return status;
 	}
@@ -634,12 +643,13 @@ emit_xcall(struct sljit_compiler *compil
 	if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
 		return SLJIT_ERR_ALLOC_FAILED;
 
-	if (BPF_CLASS(pc-code) == BPF_LDX) {
-		/* restore A */
+	if (save_reg == BJ_AREG || (hints  BJ_HINT_XREG)) {
+		/* restore A or X */
 		status = sljit_emit_op1(compiler,
-		SLJIT_MOV,
-		BJ_AREG, 0,
-		BJ_ASAVE, 0);
+		SLJIT_MOV_UI, /* uint32_t source */
+		save_reg, 0,
+		SLJIT_MEM1(SLJIT_LOCALS_REG),
+		offsetof(struct bpfjit_stack, reg));
 		if (status != SLJIT_SUCCESS)
 			return status;
 	}
@@ -652,11 +662,15 @@ emit_xcall(struct sljit_compiler *compil
  * Emit code for BPF_COP and BPF_COPX instructions.
  */
 static int
-emit_cop(struct sljit_compiler *compiler,
+emit_cop(struct sljit_compiler *compiler, bpfjit_hint_t hints,
 const bpf_ctx_t *bc, const struct

CVS commit: src/sys/external/bsd/sljit/sljit

2014-07-26 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul 26 21:07:45 UTC 2014

Modified Files:
src/sys/external/bsd/sljit/sljit: sljit_mod.c

Log Message:
Don't destroy mutexes because the module can't be unload.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/sljit/sljit/sljit_mod.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/sljit/sljit/sljit_mod.c
diff -u src/sys/external/bsd/sljit/sljit/sljit_mod.c:1.2 src/sys/external/bsd/sljit/sljit/sljit_mod.c:1.3
--- src/sys/external/bsd/sljit/sljit/sljit_mod.c:1.2	Tue Dec 17 22:39:23 2013
+++ src/sys/external/bsd/sljit/sljit/sljit_mod.c	Sat Jul 26 21:07:45 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sljit_mod.c,v 1.2 2013/12/17 22:39:23 alnsn Exp $	*/
+/*	$NetBSD: sljit_mod.c,v 1.3 2014/07/26 21:07:45 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: sljit_mod.c,v 1.2 2013/12/17 22:39:23 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: sljit_mod.c,v 1.3 2014/07/26 21:07:45 alnsn Exp $);
 
 #include sys/param.h
 #include sys/kernel.h
@@ -51,8 +51,6 @@ sljit_modcmd(modcmd_t cmd, void *arg)
 		return 0;
 
 	case MODULE_CMD_FINI:
-		mutex_destroy(sljit_global_mutex);
-		mutex_destroy(sljit_allocator_mutex);
 		return EOPNOTSUPP;
 
 	default:



CVS commit: src

2014-07-24 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Jul 24 21:08:50 UTC 2014

Modified Files:
src/distrib/sets/lists/man: mi
src/share/man/man4: Makefile
Added Files:
src/share/man/man4: bpfjit.4

Log Message:
man 4 bpfjit


To generate a diff of this commit:
cvs rdiff -u -r1.1479 -r1.1480 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.615 -r1.616 src/share/man/man4/Makefile
cvs rdiff -u -r0 -r1.1 src/share/man/man4/bpfjit.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1479 src/distrib/sets/lists/man/mi:1.1480
--- src/distrib/sets/lists/man/mi:1.1479	Sun Jul 13 08:37:13 2014
+++ src/distrib/sets/lists/man/mi	Thu Jul 24 21:08:50 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1479 2014/07/13 08:37:13 mbalmer Exp $
+# $NetBSD: mi,v 1.1480 2014/07/24 21:08:50 alnsn Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -916,6 +916,7 @@
 ./usr/share/man/cat4/bnx.0			man-sys-catman		.cat
 ./usr/share/man/cat4/boca.0			man-sys-catman		.cat
 ./usr/share/man/cat4/bpf.0			man-sys-catman		.cat
+./usr/share/man/cat4/bpfjit.0			man-sys-catman		.cat
 ./usr/share/man/cat4/brgphy.0			man-sys-catman		.cat
 ./usr/share/man/cat4/bridge.0			man-sys-catman		.cat
 ./usr/share/man/cat4/bt.0			man-sys-catman		.cat
@@ -3962,6 +3963,7 @@
 ./usr/share/man/html4/bnx.html			man-sys-htmlman		html
 ./usr/share/man/html4/boca.html			man-sys-htmlman		html
 ./usr/share/man/html4/bpf.html			man-sys-htmlman		html
+./usr/share/man/html4/bpfjit.html		man-sys-htmlman		html
 ./usr/share/man/html4/brgphy.html		man-sys-htmlman		html
 ./usr/share/man/html4/bridge.html		man-sys-htmlman		html
 ./usr/share/man/html4/bt.html			man-sys-htmlman		html
@@ -6773,6 +6775,7 @@
 ./usr/share/man/man4/bnx.4			man-sys-man		.man
 ./usr/share/man/man4/boca.4			man-sys-man		.man
 ./usr/share/man/man4/bpf.4			man-sys-man		.man
+./usr/share/man/man4/bpfjit.4			man-sys-man		.man
 ./usr/share/man/man4/brgphy.4			man-sys-man		.man
 ./usr/share/man/man4/bridge.4			man-sys-man		.man
 ./usr/share/man/man4/bt.4			man-sys-man		.man

Index: src/share/man/man4/Makefile
diff -u src/share/man/man4/Makefile:1.615 src/share/man/man4/Makefile:1.616
--- src/share/man/man4/Makefile:1.615	Sun Jul 13 08:37:13 2014
+++ src/share/man/man4/Makefile	Thu Jul 24 21:08:50 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.615 2014/07/13 08:37:13 mbalmer Exp $
+#	$NetBSD: Makefile,v 1.616 2014/07/24 21:08:50 alnsn Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 MAN=	aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -12,7 +12,7 @@ MAN=	aac.4 ac97.4 acardide.4 aceride.4 a
 	auacer.4 audio.4 audiocs.4 auich.4 \
 	auixp.4 autri.4 auvia.4 awi.4 azalia.4 \
 	battery_pmu.4 bba.4 bce.4 bcsp.4 be.4 bge.4 bnx.4 bha.4 \
-	bio.4 bktr.4 bluetooth.4 bmtphy.4 bpf.4 \
+	bio.4 bktr.4 bluetooth.4 bmtphy.4 bpf.4 bpfjit.4 \
 	brgphy.4 bridge.4 bthidev.4 bthub.4 btkbd.4 \
 	btmagic.4 btms.4 btsco.4 btuart.4 \
 	bwi.4 \

Added files:

Index: src/share/man/man4/bpfjit.4
diff -u /dev/null src/share/man/man4/bpfjit.4:1.1
--- /dev/null	Thu Jul 24 21:08:50 2014
+++ src/share/man/man4/bpfjit.4	Thu Jul 24 21:08:50 2014
@@ -0,0 +1,117 @@
+.\ -*- nroff -*-
+.\
+.\	$NetBSD: bpfjit.4,v 1.1 2014/07/24 21:08:50 alnsn Exp $
+.\
+.\ Copyright (c) 2014 Alexander Nasonov.
+.\ All rights reserved.
+.\
+.\ Redistribution and use in source and binary forms, with or without
+.\ modification, are permitted provided that the following conditions
+.\ are met:
+.\
+.\ 1. Redistributions of source code must retain the above copyright
+.\notice, this list of conditions and the following disclaimer.
+.\ 2. Redistributions in binary form must reproduce the above copyright
+.\notice, this list of conditions and the following disclaimer in
+.\the documentation and/or other materials provided with the
+.\distribution.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+.\ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+.\ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+.\ FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+.\ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\ INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+.\ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+.\ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+.\ AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+.\ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+.\ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\ SUCH DAMAGE.
+.\
+.Dd July 24, 2014
+.Dt BPFJIT 4
+.Os
+.Sh NAME
+.Nm bpfjit
+.Nd Just-In-Time compiler for Berkeley Packet Filter
+.Sh SYNOPSIS
+.Cd options BPFJIT
+.Cd options SLJIT
+.Sh DESCRIPTION
+The
+.Nm
+kernel

CVS commit: src/share/man/man4

2014-07-24 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Jul 24 21:10:26 UTC 2014

Modified Files:
src/share/man/man4: bpf.4

Log Message:
Use .Sy for 'Just-In-Time', add a reference to bpfjit(4).


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/share/man/man4/bpf.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/bpf.4
diff -u src/share/man/man4/bpf.4:1.53 src/share/man/man4/bpf.4:1.54
--- src/share/man/man4/bpf.4:1.53	Thu Aug 29 20:02:35 2013
+++ src/share/man/man4/bpf.4	Thu Jul 24 21:10:26 2014
@@ -1,6 +1,6 @@
 .\ -*- nroff -*-
 .\
-.\	$NetBSD: bpf.4,v 1.53 2013/08/29 20:02:35 wiz Exp $
+.\	$NetBSD: bpf.4,v 1.54 2014/07/24 21:10:26 alnsn Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1992, 1993, 1994
 .\	The Regents of the University of California.  All rights reserved.
@@ -682,7 +682,7 @@ support, the additional sysctl is availa
 .Bl -tag -width XnetXbpfXjitXX
 .It Li net.bpf.jit
 Toggle
-.Nm Just-In-Time
+.Sy Just-In-Time
 compilation of new filter programs.
 In order to enable Just-In-Time compilation,
 the bpfjit kernel module must be loaded.
@@ -748,6 +748,7 @@ struct bpf_insn insns[] = {
 };
 .Ed
 .Sh SEE ALSO
+.Xr bpfjit 4 ,
 .Xr ioctl 2 ,
 .Xr read 2 ,
 .Xr select 2 ,



CVS commit: src/sys/net

2014-07-24 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Jul 24 22:54:38 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
For P[X+0] load, don't emit wrap around check and copy X intead of emitting X+0.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.30 src/sys/net/bpfjit.c:1.31
--- src/sys/net/bpfjit.c:1.30	Tue Jul 22 08:29:51 2014
+++ src/sys/net/bpfjit.c	Thu Jul 24 22:54:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.30 2014/07/22 08:29:51 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.31 2014/07/24 22:54:38 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.30 2014/07/22 08:29:51 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.31 2014/07/24 22:54:38 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.30 2014/07/22 08:29:51 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.31 2014/07/24 22:54:38 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -558,24 +558,34 @@ emit_xcall(struct sljit_compiler *compil
 		return status;
 
 	if (BPF_CLASS(pc-code) == BPF_LD  BPF_MODE(pc-code) == BPF_IND) {
-		/* if (X  UINT32_MAX - pc-k) return 0; */
-		jump = sljit_emit_cmp(compiler,
-		SLJIT_C_GREATER,
-		BJ_XREG, 0,
-		SLJIT_IMM, UINT32_MAX - pc-k);
-		if (jump == NULL)
-			return SLJIT_ERR_ALLOC_FAILED;
-		if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
-			return SLJIT_ERR_ALLOC_FAILED;
-
-		/* k = X + pc-k; */
-		status = sljit_emit_op2(compiler,
-		SLJIT_ADD,
-		SLJIT_SCRATCH_REG2, 0,
-		BJ_XREG, 0,
-		SLJIT_IMM, (uint32_t)pc-k);
-		if (status != SLJIT_SUCCESS)
-			return status;
+		if (pc-k == 0) {
+			/* k = X; */
+			status = sljit_emit_op1(compiler,
+			SLJIT_MOV,
+			SLJIT_SCRATCH_REG2, 0,
+			BJ_XREG, 0);
+			if (status != SLJIT_SUCCESS)
+return status;
+		} else {
+			/* if (X  UINT32_MAX - pc-k) return 0; */
+			jump = sljit_emit_cmp(compiler,
+			SLJIT_C_GREATER,
+			BJ_XREG, 0,
+			SLJIT_IMM, UINT32_MAX - pc-k);
+			if (jump == NULL)
+return SLJIT_ERR_ALLOC_FAILED;
+			if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
+return SLJIT_ERR_ALLOC_FAILED;
+
+			/* k = X + pc-k; */
+			status = sljit_emit_op2(compiler,
+			SLJIT_ADD,
+			SLJIT_SCRATCH_REG2, 0,
+			BJ_XREG, 0,
+			SLJIT_IMM, (uint32_t)pc-k);
+			if (status != SLJIT_SUCCESS)
+return status;
+		}
 	} else {
 		/* k = pc-k */
 		status = sljit_emit_op1(compiler,



CVS commit: src

2014-07-23 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jul 23 07:16:14 UTC 2014

Modified Files:
src/external/bsd/sljit: Makefile.inc
src/sys/rump/kern/lib/libsljit: Makefile
Added Files:
src/sys/rump/kern/lib/libsljit/arch/arm: cpufunc.c sljit_rump.c

Log Message:
Implement rumpcomp_sync_icache() hyprecall for arm and add
a barebone implementation of arm cache ops to librumpkern_sljit.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/external/bsd/sljit/Makefile.inc
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/kern/lib/libsljit/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/rump/kern/lib/libsljit/arch/arm/cpufunc.c \
src/sys/rump/kern/lib/libsljit/arch/arm/sljit_rump.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/sljit/Makefile.inc
diff -u src/external/bsd/sljit/Makefile.inc:1.1 src/external/bsd/sljit/Makefile.inc:1.2
--- src/external/bsd/sljit/Makefile.inc:1.1	Mon Nov  5 00:23:18 2012
+++ src/external/bsd/sljit/Makefile.inc	Wed Jul 23 07:16:14 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.1 2012/11/05 00:23:18 alnsn Exp $
+# $NetBSD: Makefile.inc,v 1.2 2014/07/23 07:16:14 alnsn Exp $
 
 .include bsd.own.mk
 
@@ -6,3 +6,9 @@ SLJITDIST=	${NETBSDSRCDIR}/sys/external/
 LIBSLJITDIR!=	cd ${NETBSDSRCDIR}/external/bsd/sljit/lib  ${PRINTOBJDIR}
 
 CPPFLAGS+=	-I${SLJITDIST}/sljit_src
+
+# Link to libarm to get arm_sync_icache(2), for mips it's not
+# required because _cacheflush() is in libc.
+.if !empty(MACHINE_ARCH:Marm*) || !empty(MACHINE_ARCH:Mearm*)
+LDADD+=	-larm
+.endif

Index: src/sys/rump/kern/lib/libsljit/Makefile
diff -u src/sys/rump/kern/lib/libsljit/Makefile:1.2 src/sys/rump/kern/lib/libsljit/Makefile:1.3
--- src/sys/rump/kern/lib/libsljit/Makefile:1.2	Tue Jul 22 20:25:13 2014
+++ src/sys/rump/kern/lib/libsljit/Makefile	Wed Jul 23 07:16:14 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.2 2014/07/22 20:25:13 alnsn Exp $
+#	$NetBSD: Makefile,v 1.3 2014/07/23 07:16:14 alnsn Exp $
 #
 # Public Domain.
 #
@@ -23,5 +23,17 @@ RUMPCOMP_INCS_DIR:=	${.PARSEDIR}
 RUMPCOMP_USER_CPPFLAGS=-I${RUMPCOMP_INCS_DIR}
 .endif
 
+.if !empty(MACHINE_ARCH:Marm*) || !empty(MACHINE_ARCH:Mearm*)
+SRCS+=			cpufunc.c
+RUMPCOMP_USER_SRCS=	sljit_rump.c
+.PATH:			${.CURDIR}/arch/arm
+
+RUMPCOMP_INCS_DIR:=	${.PARSEDIR}
+RUMPCOMP_USER_CPPFLAGS=-I${RUMPCOMP_INCS_DIR}
+
+# Link to libarm to get arm_sync_icache(2)
+LDADD+=	-larm
+.endif
+
 .include bsd.lib.mk
 .include bsd.klinks.mk

Added files:

Index: src/sys/rump/kern/lib/libsljit/arch/arm/cpufunc.c
diff -u /dev/null src/sys/rump/kern/lib/libsljit/arch/arm/cpufunc.c:1.1
--- /dev/null	Wed Jul 23 07:16:14 2014
+++ src/sys/rump/kern/lib/libsljit/arch/arm/cpufunc.c	Wed Jul 23 07:16:14 2014
@@ -0,0 +1,52 @@
+/*	$NetBSD: cpufunc.c,v 1.1 2014/07/23 07:16:14 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__KERNEL_RCSID(0, $NetBSD: cpufunc.c,v 1.1 2014/07/23 07:16:14 alnsn Exp $);
+
+/*
+ * Barebone implementation of arm cpufunc routines for rump.
+ */
+
+#include machine/types.h
+#include arm/cpufunc.h
+
+#include sljit_rump.h
+
+static void icache_sync_range(vaddr_t, vsize_t);
+
+struct cpu_functions cpufuncs = {
+	.cf_icache_sync_range = icache_sync_range
+};
+
+static void
+icache_sync_range(vaddr_t va, vsize_t sz)
+{
+
+	(void)rumpcomp_sync_icache((void *)va, (uint64_t)sz);
+}
Index: src/sys/rump/kern/lib/libsljit/arch/arm/sljit_rump.c
diff -u /dev/null src/sys/rump/kern/lib/libsljit/arch/arm/sljit_rump.c:1.1
--- /dev/null	Wed Jul 23 07:16:14 2014
+++ src/sys/rump/kern/lib/libsljit/arch/arm/sljit_rump.c

CVS commit: src/sys/net

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 08:20:08 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Don't use scratch registers for X and to restore A after BPF_COPX call.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.28 src/sys/net/bpfjit.c:1.29
--- src/sys/net/bpfjit.c:1.28	Sun Jul 13 21:54:46 2014
+++ src/sys/net/bpfjit.c	Tue Jul 22 08:20:08 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.28 2014/07/13 21:54:46 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.29 2014/07/22 08:20:08 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.28 2014/07/13 21:54:46 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.29 2014/07/22 08:20:08 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.28 2014/07/13 21:54:46 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.29 2014/07/22 08:20:08 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -89,11 +89,12 @@ __RCSID($NetBSD: bpfjit.c,v 1.28 2014/0
 #define BJ_BUF		SLJIT_SAVED_REG1
 //#define BJ_ARGS	SLJIT_SAVED_REG2
 #define BJ_BUFLEN	SLJIT_SAVED_REG3
+#define BJ_XREG		SLJIT_SAVED_EREG1
+#define BJ_ASAVE	SLJIT_SAVED_EREG2
 #define BJ_AREG		SLJIT_SCRATCH_REG1
 #define BJ_TMP1REG	SLJIT_SCRATCH_REG2
 #define BJ_TMP2REG	SLJIT_SCRATCH_REG3
-#define BJ_XREG		SLJIT_TEMPORARY_EREG1
-#define BJ_TMP3REG	SLJIT_TEMPORARY_EREG2
+#define BJ_TMP3REG	SLJIT_TEMPORARY_EREG1
 
 #ifdef _KERNEL
 #define MAX_MEMWORDS BPF_MAX_MEMWORDS
@@ -118,11 +119,12 @@ __RCSID($NetBSD: bpfjit.c,v 1.28 2014/0
 typedef unsigned int bpfjit_hint_t;
 #define BJ_HINT_ABS  0x01 /* packet read at absolute offset   */
 #define BJ_HINT_IND  0x02 /* packet read at variable offset   */
-#define BJ_HINT_COP  0x04 /* BPF_COP or BPF_COPX instruction  */
-#define BJ_HINT_COPX 0x08 /* BPF_COPX instruction */
-#define BJ_HINT_XREG 0x10 /* BJ_XREG is needed*/
-#define BJ_HINT_LDX  0x20 /* BPF_LDX instruction  */
-#define BJ_HINT_PKT  (BJ_HINT_ABS|BJ_HINT_IND) /* packet read */
+#define BJ_HINT_MSH  0x04 /* BPF_MSH instruction  */
+#define BJ_HINT_COP  0x08 /* BPF_COP or BPF_COPX instruction  */
+#define BJ_HINT_COPX 0x10 /* BPF_COPX instruction */
+#define BJ_HINT_XREG 0x20 /* BJ_XREG is needed*/
+#define BJ_HINT_LDX  0x40 /* BPF_LDX instruction  */
+#define BJ_HINT_PKT  (BJ_HINT_ABS|BJ_HINT_IND|BJ_HINT_MSH)
 
 /*
  * Datatype for Array Bounds Check Elimination (ABC) pass.
@@ -257,17 +259,29 @@ nscratches(bpfjit_hint_t hints)
 	if (hints  BJ_HINT_COP)
 		rv = 3; /* calls copfunc with three arguments */
 
+	if (hints  BJ_HINT_COPX)
+		rv = 4; /* uses BJ_TMP3REG */
+
+	return rv;
+}
+
+/*
+ * Return a number of saved registers to pass
+ * to sljit_emit_enter() function.
+ */
+static sljit_si
+nsaveds(bpfjit_hint_t hints)
+{
+	sljit_si rv = 3;
+
 	if (hints  BJ_HINT_XREG)
 		rv = 4; /* uses BJ_XREG */
 
 #ifdef _KERNEL
 	if (hints  BJ_HINT_LDX)
-		rv = 5; /* uses BJ_TMP3REG */
+		rv = 5; /* uses BJ_ASAVE */
 #endif
 
-	if (hints  BJ_HINT_COPX)
-		rv = 5; /* uses BJ_TMP3REG */
-
 	return rv;
 }
 
@@ -518,26 +532,16 @@ emit_xcall(struct sljit_compiler *compil
 int dst, struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize,
 uint32_t (*fn)(const struct mbuf *, uint32_t, int *))
 {
-#if BJ_XREG== SLJIT_RETURN_REG   || \
-BJ_XREG== SLJIT_SCRATCH_REG1 || \
-BJ_XREG== SLJIT_SCRATCH_REG2 || \
-BJ_XREG== SLJIT_SCRATCH_REG3 || \
-BJ_TMP3REG == SLJIT_RETURN_REG   || \
-BJ_TMP3REG == SLJIT_SCRATCH_REG1 || \
-BJ_TMP3REG == SLJIT_SCRATCH_REG2 || \
-BJ_TMP3REG == SLJIT_SCRATCH_REG3
-#error Not supported assignment of registers.
-#endif
 	struct sljit_jump *jump;
 	int status;
 
-	BJ_ASSERT(dst != BJ_TMP2REG  dst != BJ_TMP3REG);
+	BJ_ASSERT(dst != BJ_ASAVE);
 
 	if (BPF_CLASS(pc-code) == BPF_LDX) {
 		/* save A */
 		status = sljit_emit_op1(compiler,
 		SLJIT_MOV,
-		BJ_TMP3REG, 0,
+		BJ_ASAVE, 0,
 		BJ_AREG, 0);
 		if (status != SLJIT_SUCCESS)
 			return status;
@@ -633,7 +637,7 @@ emit_xcall(struct sljit_compiler *compil
 		status = sljit_emit_op1(compiler,
 		SLJIT_MOV,
 		BJ_AREG, 0,
-		BJ_TMP3REG, 0);
+		BJ_ASAVE, 0);
 		if (status != SLJIT_SUCCESS)
 			return status;
 	}
@@ -650,11 +654,7 @@ emit_cop(struct sljit_compiler *compiler
 const bpf_ctx_t *bc, const struct bpf_insn *pc,
 struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize)
 {
-#if BJ_XREG== SLJIT_RETURN_REG   || \
-BJ_XREG== SLJIT_SCRATCH_REG1 || \
-BJ_XREG== SLJIT_SCRATCH_REG2 || \
-BJ_XREG== SLJIT_SCRATCH_REG3 || \
-BJ_TMP3REG == SLJIT_SCRATCH_REG1

CVS commit: src/sys/net

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 08:29:51 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Two tweaks: don't use a temporary register to dereference the err agrument
after xcall and don't generate ((tmp1  0xf)  2) twice in emit_msh().


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.29 src/sys/net/bpfjit.c:1.30
--- src/sys/net/bpfjit.c:1.29	Tue Jul 22 08:20:08 2014
+++ src/sys/net/bpfjit.c	Tue Jul 22 08:29:51 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.29 2014/07/22 08:20:08 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.30 2014/07/22 08:29:51 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.29 2014/07/22 08:20:08 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.30 2014/07/22 08:29:51 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.29 2014/07/22 08:20:08 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.30 2014/07/22 08:29:51 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -612,19 +612,11 @@ emit_xcall(struct sljit_compiler *compil
 			return status;
 	}
 
-	/* tmp2 = *err; */
-	status = sljit_emit_op1(compiler,
-	SLJIT_MOV_UI,
-	BJ_TMP2REG, 0,
-	SLJIT_MEM1(SLJIT_LOCALS_REG),
-	offsetof(struct bpfjit_stack, err));
-	if (status != SLJIT_SUCCESS)
-		return status;
-
-	/* if (tmp2 != 0) return 0; */
+	/* if (*err != 0) return 0; */
 	jump = sljit_emit_cmp(compiler,
-	SLJIT_C_NOT_EQUAL,
-	BJ_TMP2REG, 0,
+	SLJIT_C_NOT_EQUAL|SLJIT_INT_OP,
+	SLJIT_MEM1(SLJIT_LOCALS_REG),
+	offsetof(struct bpfjit_stack, err),
 	SLJIT_IMM, 0);
 	if (jump == NULL)
 		return SLJIT_ERR_ALLOC_FAILED;
@@ -989,24 +981,6 @@ emit_msh(struct sljit_compiler *compiler
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-	/* tmp1 = 0xf */
-	status = sljit_emit_op2(compiler,
-	SLJIT_AND,
-	BJ_TMP1REG, 0,
-	BJ_TMP1REG, 0,
-	SLJIT_IMM, 0xf);
-	if (status != SLJIT_SUCCESS)
-		return status;
-
-	/* tmp1 = tmp1  2 */
-	status = sljit_emit_op2(compiler,
-	SLJIT_SHL,
-	BJ_XREG, 0,
-	BJ_TMP1REG, 0,
-	SLJIT_IMM, 2);
-	if (status != SLJIT_SUCCESS)
-		return status;
-
 #ifdef _KERNEL
 	over_mchain_jump = sljit_emit_jump(compiler, SLJIT_JUMP);
 	if (over_mchain_jump == NULL)
@@ -1035,6 +1009,12 @@ emit_msh(struct sljit_compiler *compiler
 	if (status != SLJIT_SUCCESS)
 		return status;
 
+	label = sljit_emit_label(compiler);
+	if (label == NULL)
+		return SLJIT_ERR_ALLOC_FAILED;
+	sljit_set_label(over_mchain_jump, label);
+#endif
+
 	/* tmp1 = 0xf */
 	status = sljit_emit_op2(compiler,
 	SLJIT_AND,
@@ -1044,7 +1024,7 @@ emit_msh(struct sljit_compiler *compiler
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-	/* tmp1 = tmp1  2 */
+	/* X = tmp1  2 */
 	status = sljit_emit_op2(compiler,
 	SLJIT_SHL,
 	BJ_XREG, 0,
@@ -1053,13 +1033,6 @@ emit_msh(struct sljit_compiler *compiler
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-
-	label = sljit_emit_label(compiler);
-	if (label == NULL)
-		return SLJIT_ERR_ALLOC_FAILED;
-	sljit_set_label(over_mchain_jump, label);
-#endif
-
 	return SLJIT_SUCCESS;
 }
 
@@ -2107,8 +2080,8 @@ bpfjit_generate_code(const bpf_ctx_t *bc
 	sljit_compiler_verbose(compiler, stderr);
 #endif
 
-	status = sljit_emit_enter(compiler, 2, nscratches(hints),
-	nsaveds(hints), sizeof(struct bpfjit_stack));
+	status = sljit_emit_enter(compiler,
+	2, nscratches(hints), nsaveds(hints), sizeof(struct bpfjit_stack));
 	if (status != SLJIT_SUCCESS)
 		goto fail;
 



CVS commit: src/sys/arch/mips/include

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 19:54:55 UTC 2014

Modified Files:
src/sys/arch/mips/include: sljitarch.h

Log Message:
Define SLJIT_CACHE_FLUSH() for mips.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/mips/include/sljitarch.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/include/sljitarch.h
diff -u src/sys/arch/mips/include/sljitarch.h:1.3 src/sys/arch/mips/include/sljitarch.h:1.4
--- src/sys/arch/mips/include/sljitarch.h:1.3	Sun Nov 17 12:01:58 2013
+++ src/sys/arch/mips/include/sljitarch.h	Tue Jul 22 19:54:55 2014
@@ -1,7 +1,7 @@
-/*	$NetBSD: sljitarch.h,v 1.3 2013/11/17 12:01:58 alnsn Exp $	*/
+/*	$NetBSD: sljitarch.h,v 1.4 2014/07/22 19:54:55 alnsn Exp $	*/
 
 /*-
- * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * Copyright (c) 2012,2014 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,8 +29,24 @@
 #ifndef _MIPS_SLJITARCH_H
 #define _MIPS_SLJITARCH_H
 
-#ifndef _LP64
+#ifdef _LP64
+#define SLJIT_CONFIG_MIPS_64 1
+#else
 #define SLJIT_CONFIG_MIPS_32 1
 #endif
 
+#include sys/types.h
+
+#ifdef _KERNEL
+#include mips/cache.h
+
+#define SLJIT_CACHE_FLUSH(from, to) mips_icache_sync_range( \
+	(vaddr_t)(from), (vsize_t)((const char *)(to) - (const char *)(from)))
+#else
+#include mips/cachectl.h
+
+#define SLJIT_CACHE_FLUSH(from, to) \
+	(void)_cacheflush((void*)(from), (size_t)((to) - (from)), ICACHE)
+#endif
+
 #endif



CVS commit: src/sys/arch/arm/include

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 20:16:39 UTC 2014

Modified Files:
src/sys/arch/arm/include: sljitarch.h

Log Message:
Add parentheses around macro arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/include/sljitarch.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/include/sljitarch.h
diff -u src/sys/arch/arm/include/sljitarch.h:1.1 src/sys/arch/arm/include/sljitarch.h:1.2
--- src/sys/arch/arm/include/sljitarch.h:1.1	Tue Jun 17 06:36:39 2014
+++ src/sys/arch/arm/include/sljitarch.h	Tue Jul 22 20:16:39 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sljitarch.h,v 1.1 2014/06/17 06:36:39 alnsn Exp $	*/
+/*	$NetBSD: sljitarch.h,v 1.2 2014/07/22 20:16:39 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2014 Alexander Nasonov.
@@ -53,7 +53,7 @@
 	cpu_icache_sync_range((vaddr_t)(from), (vsize_t)((to) - (from)))
 #else
 #define SLJIT_CACHE_FLUSH(from, to) \
-	(void)arm_sync_icache((uintptr_t)(from), (size_t)(to - from))
+	(void)arm_sync_icache((uintptr_t)(from), (size_t)((to) - (from)))
 #endif
 
 #endif



CVS commit: src

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 20:19:57 UTC 2014

Modified Files:
src/distrib/sets/lists/comp: md.cobalt md.pmax
src/sys/arch/cobalt/include: Makefile
src/sys/arch/pmax/include: Makefile
Added Files:
src/sys/arch/cobalt/include: sljitarch.h
src/sys/arch/pmax/include: sljitarch.h

Log Message:
Add sljitarch.h to cobalt and pmax.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/distrib/sets/lists/comp/md.cobalt
cvs rdiff -u -r1.63 -r1.64 src/distrib/sets/lists/comp/md.pmax
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/cobalt/include/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/arch/cobalt/include/sljitarch.h
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/pmax/include/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/arch/pmax/include/sljitarch.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/md.cobalt
diff -u src/distrib/sets/lists/comp/md.cobalt:1.24 src/distrib/sets/lists/comp/md.cobalt:1.25
--- src/distrib/sets/lists/comp/md.cobalt:1.24	Sun Jul 17 20:54:31 2011
+++ src/distrib/sets/lists/comp/md.cobalt	Tue Jul 22 20:19:57 2014
@@ -1,4 +1,4 @@
-# $NetBSD: md.cobalt,v 1.24 2011/07/17 20:54:31 joerg Exp $
+# $NetBSD: md.cobalt,v 1.25 2014/07/22 20:19:57 alnsn Exp $
 ./usr/include/cobaltcomp-c-include
 ./usr/include/cobalt/_G_config.h		comp-obsolete		obsolete
 ./usr/include/cobalt/ansi.h			comp-c-include
@@ -52,6 +52,7 @@
 ./usr/include/cobalt/rwlock.h			comp-c-include
 ./usr/include/cobalt/setjmp.h			comp-c-include
 ./usr/include/cobalt/signal.h			comp-c-include
+./usr/include/cobalt/sljitarch.h		comp-c-include
 ./usr/include/cobalt/stdarg.h			comp-obsolete		obsolete
 ./usr/include/cobalt/trap.h			comp-c-include
 ./usr/include/cobalt/types.h			comp-c-include

Index: src/distrib/sets/lists/comp/md.pmax
diff -u src/distrib/sets/lists/comp/md.pmax:1.63 src/distrib/sets/lists/comp/md.pmax:1.64
--- src/distrib/sets/lists/comp/md.pmax:1.63	Sun Jul 17 20:54:31 2011
+++ src/distrib/sets/lists/comp/md.pmax	Tue Jul 22 20:19:57 2014
@@ -1,4 +1,4 @@
-# $NetBSD: md.pmax,v 1.63 2011/07/17 20:54:31 joerg Exp $
+# $NetBSD: md.pmax,v 1.64 2014/07/22 20:19:57 alnsn Exp $
 ./usr/include/ieeefp.hcomp-c-include
 ./usr/include/pmaxcomp-c-include
 ./usr/include/pmax/_G_config.h			comp-obsolete		obsolete
@@ -58,6 +58,7 @@
 ./usr/include/pmax/rwlock.h			comp-c-include
 ./usr/include/pmax/setjmp.h			comp-c-include
 ./usr/include/pmax/signal.h			comp-c-include
+./usr/include/pmax/sljitarch.h			comp-c-include
 ./usr/include/pmax/stdarg.h			comp-obsolete		obsolete
 ./usr/include/pmax/tc_machdep.h			comp-c-include
 ./usr/include/pmax/trap.h			comp-c-include

Index: src/sys/arch/cobalt/include/Makefile
diff -u src/sys/arch/cobalt/include/Makefile:1.20 src/sys/arch/cobalt/include/Makefile:1.21
--- src/sys/arch/cobalt/include/Makefile:1.20	Sun Jul 17 20:54:38 2011
+++ src/sys/arch/cobalt/include/Makefile	Tue Jul 22 20:19:57 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.20 2011/07/17 20:54:38 joerg Exp $
+#	$NetBSD: Makefile,v 1.21 2014/07/22 20:19:57 alnsn Exp $
 
 INCSDIR= /usr/include/cobalt
 
@@ -17,7 +17,7 @@ INCS=	ansi.h asm.h autoconf.h \
 	nvram.h \
 	param.h pcb.h pmap.h pmc.h proc.h profile.h psl.h pte.h ptrace.h \
 	reg.h regdef.h regnum.h reloc.h rwlock.h \
-	setjmp.h signal.h \
+	setjmp.h signal.h sljitarch.h \
 	trap.h types.h \
 	vmparam.h \
 	wchar_limits.h

Index: src/sys/arch/pmax/include/Makefile
diff -u src/sys/arch/pmax/include/Makefile:1.35 src/sys/arch/pmax/include/Makefile:1.36
--- src/sys/arch/pmax/include/Makefile:1.35	Sun Jul 17 20:54:45 2011
+++ src/sys/arch/pmax/include/Makefile	Tue Jul 22 20:19:57 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.35 2011/07/17 20:54:45 joerg Exp $
+#	$NetBSD: Makefile,v 1.36 2014/07/22 20:19:57 alnsn Exp $
 
 INCSDIR= /usr/include/pmax
 
@@ -17,7 +17,7 @@ INCS=	ansi.h asm.h autoconf.h \
 	param.h pcb.h pmap.h pmc.h \
 	proc.h profile.h psl.h pte.h ptrace.h \
 	reg.h regdef.h regnum.h reloc.h rwlock.h \
-	setjmp.h signal.h \
+	setjmp.h signal.h sljitarch.h \
 	tc_machdep.h trap.h types.h \
 	vmparam.h \
 	wchar_limits.h

Added files:

Index: src/sys/arch/cobalt/include/sljitarch.h
diff -u /dev/null src/sys/arch/cobalt/include/sljitarch.h:1.1
--- /dev/null	Tue Jul 22 20:19:57 2014
+++ src/sys/arch/cobalt/include/sljitarch.h	Tue Jul 22 20:19:57 2014
@@ -0,0 +1,3 @@
+/*	$NetBSD: sljitarch.h,v 1.1 2014/07/22 20:19:57 alnsn Exp $	*/
+
+#include mips/sljitarch.h

Index: src/sys/arch/pmax/include/sljitarch.h
diff -u /dev/null src/sys/arch/pmax/include/sljitarch.h:1.1
--- /dev/null	Tue Jul 22 20:19:57 2014
+++ src/sys/arch/pmax/include/sljitarch.h	Tue Jul 22 20:19:57 2014
@@ -0,0 +1,3 @@
+/*	$NetBSD: sljitarch.h,v 1.1 2014/07/22 20:19:57 alnsn Exp $	*/
+
+#include mips/sljitarch.h



CVS commit: src/sys/rump

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 20:25:13 UTC 2014

Modified Files:
src/sys/rump: Makefile.rump
src/sys/rump/kern/lib/libsljit: Makefile
Added Files:
src/sys/rump/kern/lib/libsljit: sljit_rump.h
src/sys/rump/kern/lib/libsljit/arch/mips: cache.c sljit_rump.c

Log Message:
Implement rumpcomp_sync_icache() hyprecall for mips and add
a barebone implementation if mips cache ops to librumpkern_sljit.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/rump/Makefile.rump
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/kern/lib/libsljit/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/rump/kern/lib/libsljit/sljit_rump.h
cvs rdiff -u -r0 -r1.1 src/sys/rump/kern/lib/libsljit/arch/mips/cache.c \
src/sys/rump/kern/lib/libsljit/arch/mips/sljit_rump.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/Makefile.rump
diff -u src/sys/rump/Makefile.rump:1.98 src/sys/rump/Makefile.rump:1.99
--- src/sys/rump/Makefile.rump:1.98	Fri Jun 20 11:57:56 2014
+++ src/sys/rump/Makefile.rump	Tue Jul 22 20:25:13 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.rump,v 1.98 2014/06/20 11:57:56 pooka Exp $
+#	$NetBSD: Makefile.rump,v 1.99 2014/07/22 20:25:13 alnsn Exp $
 #
 
 .if !defined(_RUMP_MK)
@@ -20,6 +20,16 @@ CPPFLAGS:=	-I${RUMPTOP}/include ${CPPFLA
 CPPFLAGS+=	-D_RUMPKERNEL -I${RUMPTOP}/librump/rumpkern
 .endif
 
+# Define baseline cpu for mips ports, required for
+# rumpcomp_sync_icache() hypercall.
+.if !empty(MACHINE_ARCH:Mmips*)
+.if !empty(MACHINE_ARCH:Mmips64*)
+CPPFLAGS+=	-DMIPS64=1
+.else
+CPPFLAGS+=	-DMIPS1=1
+.endif
+.endif
+
 CPPFLAGS+=	-DMAXUSERS=32
 CPPFLAGS+=	-DCOMPAT_50=1 -DCOMPAT_60=1
 

Index: src/sys/rump/kern/lib/libsljit/Makefile
diff -u src/sys/rump/kern/lib/libsljit/Makefile:1.1 src/sys/rump/kern/lib/libsljit/Makefile:1.2
--- src/sys/rump/kern/lib/libsljit/Makefile:1.1	Sat Nov 16 01:23:37 2013
+++ src/sys/rump/kern/lib/libsljit/Makefile	Tue Jul 22 20:25:13 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.1 2013/11/16 01:23:37 rmind Exp $
+#	$NetBSD: Makefile,v 1.2 2014/07/22 20:25:13 alnsn Exp $
 #
 # Public Domain.
 #
@@ -10,5 +10,18 @@ LIB=	rumpkern_sljit
 
 SRCS=	sljitLir.c sljit_mod.c
 
+# NOTE This is not the best place for icache sync routine but only
+# sljit uses it at the moment.
+# XXX Think about a good hypercall interface (hi, pooka!) and move
+# this stuff to rumpuser.
+.if !empty(MACHINE_ARCH:Mmips*)
+SRCS+=			cache.c
+RUMPCOMP_USER_SRCS=	sljit_rump.c
+.PATH:			${.CURDIR}/arch/mips
+
+RUMPCOMP_INCS_DIR:=	${.PARSEDIR}
+RUMPCOMP_USER_CPPFLAGS=-I${RUMPCOMP_INCS_DIR}
+.endif
+
 .include bsd.lib.mk
 .include bsd.klinks.mk

Added files:

Index: src/sys/rump/kern/lib/libsljit/sljit_rump.h
diff -u /dev/null src/sys/rump/kern/lib/libsljit/sljit_rump.h:1.1
--- /dev/null	Tue Jul 22 20:25:13 2014
+++ src/sys/rump/kern/lib/libsljit/sljit_rump.h	Tue Jul 22 20:25:13 2014
@@ -0,0 +1,29 @@
+/*  $NetBSD: sljit_rump.h,v 1.1 2014/07/22 20:25:13 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+int rumpcomp_sync_icache(void *, uint64_t);

Index: src/sys/rump/kern/lib/libsljit/arch/mips/cache.c
diff -u /dev/null src/sys/rump/kern/lib/libsljit/arch/mips/cache.c:1.1
--- /dev/null	Tue Jul 22 20:25:13 2014
+++ src/sys/rump/kern/lib/libsljit/arch/mips/cache.c	Tue Jul 22 20:25:13 2014
@@ -0,0 +1,52 @@
+/*  $NetBSD: cache.c,v 1.1 2014/07/22 20:25:13 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted

CVS commit: src/sys/arch/sparc/include

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 20:41:37 UTC 2014

Modified Files:
src/sys/arch/sparc/include: sljitarch.h

Log Message:
Cast to sparc_cache_flush() argument types. This change makes it clear
thatr sparc_cache_flush() is defined by sljit (unlike other ports).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/sparc/include/sljitarch.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sparc/include/sljitarch.h
diff -u src/sys/arch/sparc/include/sljitarch.h:1.2 src/sys/arch/sparc/include/sljitarch.h:1.3
--- src/sys/arch/sparc/include/sljitarch.h:1.2	Sun Nov 17 12:01:58 2013
+++ src/sys/arch/sparc/include/sljitarch.h	Tue Jul 22 20:41:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sljitarch.h,v 1.2 2013/11/17 12:01:58 alnsn Exp $	*/
+/*	$NetBSD: sljitarch.h,v 1.3 2014/07/22 20:41:37 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2012-2013 The NetBSD Foundation, Inc.
@@ -34,6 +34,6 @@
 #endif
 
 #define SLJIT_CACHE_FLUSH(from, to) \
-	sparc_cache_flush((from), (to))
+	sparc_cache_flush((sljit_ins *)(from), (sljit_ins *)(to))
 
 #endif



CVS commit: src/sys/arch/powerpc/include

2014-07-22 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul 22 20:38:55 UTC 2014

Modified Files:
src/sys/arch/powerpc/include: sljitarch.h

Log Message:
Cast to __syncicache() argument types.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/powerpc/include/sljitarch.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/include/sljitarch.h
diff -u src/sys/arch/powerpc/include/sljitarch.h:1.2 src/sys/arch/powerpc/include/sljitarch.h:1.3
--- src/sys/arch/powerpc/include/sljitarch.h:1.2	Mon Nov 25 23:53:44 2013
+++ src/sys/arch/powerpc/include/sljitarch.h	Tue Jul 22 20:38:55 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sljitarch.h,v 1.2 2013/11/25 23:53:44 alnsn Exp $	*/
+/*	$NetBSD: sljitarch.h,v 1.3 2014/07/22 20:38:55 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -39,6 +39,6 @@
 #endif
 
 #define SLJIT_CACHE_FLUSH(from, to) \
-	__syncicache((from), (to)-(from))
+	__syncicache((void *)(from), (size_t)((to) - (from)))
 
 #endif



CVS commit: src/sys/arch

2014-07-20 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sun Jul 20 10:06:11 UTC 2014

Modified Files:
src/sys/arch/algor/conf: P4032 P5064 P6032
src/sys/arch/arc/conf: ARCTIC GENERIC M403 MIMORI PICA RPC44
src/sys/arch/cobalt/conf: GENERIC INSTALL
src/sys/arch/evbmips/conf: ADM5120 ADM5120-NB ADM5120-USB ALCHEMY AP30
CPMBR1400 DB120 GDIUM LOONGSON MALTA MERAKI RB153 RB433UAH WGT624V3
XLSATX ZYXELKX
src/sys/arch/ews4800mips/conf: GENERIC
src/sys/arch/hpcmips/conf: GENERIC LCARD LROUTER MPC303 TX3912 TX3922
VR41XX
src/sys/arch/newsmips/conf: DEJIKO GENERIC WAPIKO
src/sys/arch/pmax/conf: GENERIC GENERIC64 INSTALL INSTALL64
src/sys/arch/sbmips/conf: GENERIC
src/sys/arch/sgimips/conf: GENERIC32_IP12 GENERIC32_IP2x GENERIC32_IP3x

Log Message:
Add commented out bpfjit options to mips kernels.
While here, add 2 missing RCS ids.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/algor/conf/P4032
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/algor/conf/P5064
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/algor/conf/P6032
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/arc/conf/ARCTIC
cvs rdiff -u -r1.179 -r1.180 src/sys/arch/arc/conf/GENERIC
cvs rdiff -u -r1.61 -r1.62 src/sys/arch/arc/conf/M403
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/arc/conf/MIMORI
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/arc/conf/PICA
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/arc/conf/RPC44
cvs rdiff -u -r1.142 -r1.143 src/sys/arch/cobalt/conf/GENERIC
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/cobalt/conf/INSTALL
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/evbmips/conf/ADM5120
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/evbmips/conf/ADM5120-NB \
src/sys/arch/evbmips/conf/ADM5120-USB src/sys/arch/evbmips/conf/CPMBR1400
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/evbmips/conf/ALCHEMY
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/evbmips/conf/AP30
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/evbmips/conf/DB120
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/evbmips/conf/GDIUM
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/evbmips/conf/LOONGSON
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/evbmips/conf/MALTA
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/evbmips/conf/MERAKI
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/evbmips/conf/RB153
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/evbmips/conf/RB433UAH
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/evbmips/conf/WGT624V3
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/evbmips/conf/XLSATX
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbmips/conf/ZYXELKX
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/ews4800mips/conf/GENERIC
cvs rdiff -u -r1.223 -r1.224 src/sys/arch/hpcmips/conf/GENERIC
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/hpcmips/conf/LCARD
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/hpcmips/conf/LROUTER
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/hpcmips/conf/MPC303
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/hpcmips/conf/TX3912
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/hpcmips/conf/TX3922
cvs rdiff -u -r1.61 -r1.62 src/sys/arch/hpcmips/conf/VR41XX
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/newsmips/conf/DEJIKO
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/newsmips/conf/GENERIC
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/newsmips/conf/WAPIKO
cvs rdiff -u -r1.180 -r1.181 src/sys/arch/pmax/conf/GENERIC
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/pmax/conf/GENERIC64
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/pmax/conf/INSTALL
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/pmax/conf/INSTALL64
cvs rdiff -u -r1.95 -r1.96 src/sys/arch/sbmips/conf/GENERIC
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/sgimips/conf/GENERIC32_IP12
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/sgimips/conf/GENERIC32_IP2x
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/sgimips/conf/GENERIC32_IP3x

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/algor/conf/P4032
diff -u src/sys/arch/algor/conf/P4032:1.69 src/sys/arch/algor/conf/P4032:1.70
--- src/sys/arch/algor/conf/P4032:1.69	Wed Jun  5 23:07:59 2013
+++ src/sys/arch/algor/conf/P4032	Sun Jul 20 10:06:10 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: P4032,v 1.69 2013/06/05 23:07:59 christos Exp $
+#	$NetBSD: P4032,v 1.70 2014/07/20 10:06:10 alnsn Exp $
 #
 # Algorithmics P-4032 kernel.
 #
@@ -7,7 +7,7 @@ include	arch/algor/conf/std.algor
 
 #options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		P4032-$Revision: 1.69 $
+#ident 		P4032-$Revision: 1.70 $
 
 maxusers 32
 
@@ -56,6 +56,10 @@ options 	INET6		# IPV6
 options 	IPSEC		# IP security
 #options 	IPSEC_DEBUG	# debug for IP security
 
+# JIT compiler for bpfilter
+#options	SLJIT
+#options	BPFJIT
+
 # 4.3BSD compatibility.  Should be optional, but necessary for now.
 options 	COMPAT_43
 

Index: src/sys/arch/algor/conf/P5064
diff -u src/sys/arch/algor/conf/P5064:1.79 src/sys/arch/algor/conf/P5064:1.80
--- src/sys/arch/algor/conf/P5064:1.79	Wed Jun  5 23:07:59 2013
+++ src/sys/arch/algor/conf/P5064	Sun Jul 20 10:06:10 2014
@@ -1,4 +1,4 @@
-#	

CVS commit: src/sys/arch

2014-07-20 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sun Jul 20 10:22:55 UTC 2014

Modified Files:
src/sys/arch/algor/conf: files.algor
src/sys/arch/arc/conf: files.arc
src/sys/arch/cobalt/conf: files.cobalt
src/sys/arch/evbmips/conf: files.adm5120 files.alchemy files.gdium
files.loongson files.malta files.rasoc files.rmixl
src/sys/arch/ews4800mips/conf: files.ews4800mips
src/sys/arch/hpcmips/conf: files.hpcmips
src/sys/arch/newsmips/conf: files.newsmips
src/sys/arch/pmax/conf: files.pmax
src/sys/arch/sbmips/conf: files.sbmips
src/sys/arch/sgimips/conf: files.sgimips

Log Message:
Include sljit files.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/algor/conf/files.algor
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/arc/conf/files.arc
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/cobalt/conf/files.cobalt
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/evbmips/conf/files.adm5120
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/evbmips/conf/files.alchemy
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbmips/conf/files.gdium \
src/sys/arch/evbmips/conf/files.rasoc
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbmips/conf/files.loongson \
src/sys/arch/evbmips/conf/files.rmixl
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/evbmips/conf/files.malta
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/ews4800mips/conf/files.ews4800mips
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/hpcmips/conf/files.hpcmips
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/newsmips/conf/files.newsmips
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/pmax/conf/files.pmax
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/sbmips/conf/files.sbmips
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/sgimips/conf/files.sgimips

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/algor/conf/files.algor
diff -u src/sys/arch/algor/conf/files.algor:1.30 src/sys/arch/algor/conf/files.algor:1.31
--- src/sys/arch/algor/conf/files.algor:1.30	Tue Oct  2 23:54:51 2012
+++ src/sys/arch/algor/conf/files.algor	Sun Jul 20 10:22:54 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.algor,v 1.30 2012/10/02 23:54:51 christos Exp $
+#	$NetBSD: files.algor,v 1.31 2014/07/20 10:22:54 alnsn Exp $
 
 # Algorithmics evaluation board specific configuration info.
 
@@ -66,6 +66,11 @@ file	arch/evbmips/evbmips/cpu.c		cpu
 device	mcclock: mc146818
 
 #
+# Stack-less Just-In-Time compiler
+#
+include	external/bsd/sljit/conf/files.sljit
+
+#
 # Machine-independent I2O drivers.
 #
 include dev/i2o/files.i2o

Index: src/sys/arch/arc/conf/files.arc
diff -u src/sys/arch/arc/conf/files.arc:1.64 src/sys/arch/arc/conf/files.arc:1.65
--- src/sys/arch/arc/conf/files.arc:1.64	Sun Feb 20 07:52:42 2011
+++ src/sys/arch/arc/conf/files.arc	Sun Jul 20 10:22:54 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.arc,v 1.64 2011/02/20 07:52:42 matt Exp $
+#	$NetBSD: files.arc,v 1.65 2014/07/20 10:22:54 alnsn Exp $
 #	$OpenBSD: files.arc,v 1.21 1999/09/11 10:20:20 niklas Exp $
 #
 # maxpartitions must be first item in files.${ARCH}
@@ -80,6 +80,11 @@ file	arch/arc/arc/arcbios.c
 
 file	arch/mips/mips/mips3_clock.c
 
+#
+# Stack-less Just-In-Time compiler
+#
+include	external/bsd/sljit/conf/files.sljit
+
 ##
 ##	Machine-independent ATAPI drivers
 ##

Index: src/sys/arch/cobalt/conf/files.cobalt
diff -u src/sys/arch/cobalt/conf/files.cobalt:1.36 src/sys/arch/cobalt/conf/files.cobalt:1.37
--- src/sys/arch/cobalt/conf/files.cobalt:1.36	Tue Oct  2 23:54:52 2012
+++ src/sys/arch/cobalt/conf/files.cobalt	Sun Jul 20 10:22:54 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.cobalt,v 1.36 2012/10/02 23:54:52 christos Exp $
+#	$NetBSD: files.cobalt,v 1.37 2014/07/20 10:22:54 alnsn Exp $
 
 maxpartitions 16
 
@@ -53,6 +53,9 @@ file dev/md_root.c			memory_disk_hooks
 file dev/cons.c
 file dev/cninit.c
 
+# Stack-less Just-In-Time compiler
+include	external/bsd/sljit/conf/files.sljit
+
 include dev/i2o/files.i2o
 
 include dev/pci/files.pci

Index: src/sys/arch/evbmips/conf/files.adm5120
diff -u src/sys/arch/evbmips/conf/files.adm5120:1.7 src/sys/arch/evbmips/conf/files.adm5120:1.8
--- src/sys/arch/evbmips/conf/files.adm5120:1.7	Sun Feb 20 07:48:34 2011
+++ src/sys/arch/evbmips/conf/files.adm5120	Sun Jul 20 10:22:54 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.adm5120,v 1.7 2011/02/20 07:48:34 matt Exp $
+#	$NetBSD: files.adm5120,v 1.8 2014/07/20 10:22:54 alnsn Exp $
 
 file	arch/evbmips/adm5120/autoconf.c
 file	arch/evbmips/adm5120/machdep.c
@@ -19,6 +19,9 @@ device	cpu
 attach	cpu at mainbus
 file	arch/evbmips/evbmips/cpu.c		cpu
 
+# Stack-less Just-In-Time compiler
+include	external/bsd/sljit/conf/files.sljit
+
 # Machine-independent SCSI drivers
 include dev/scsipi/files.scsipi
 

Index: src/sys/arch/evbmips/conf/files.alchemy
diff -u src/sys/arch/evbmips/conf/files.alchemy:1.11 src/sys/arch/evbmips/conf/files.alchemy:1.12
--- src/sys/arch/evbmips/conf/files.alchemy:1.11	Sun Feb 20 07:48:34 2011
+++ 

CVS commit: src

2014-07-19 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul 19 14:35:10 UTC 2014

Modified Files:
src/distrib/sets/lists/comp: md.emips md.mipsco
src/sys/arch/emips/include: Makefile
src/sys/arch/mipsco/include: Makefile
Removed Files:
src/sys/arch/emips/include: sljitarch.h
src/sys/arch/mipsco/include: sljitarch.h

Log Message:
Sljit doesn't support MIPS I. Make sljitarch.h obsolete.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/distrib/sets/lists/comp/md.emips
cvs rdiff -u -r1.22 -r1.23 src/distrib/sets/lists/comp/md.mipsco
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/emips/include/Makefile
cvs rdiff -u -r1.1 -r0 src/sys/arch/emips/include/sljitarch.h
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/mipsco/include/Makefile
cvs rdiff -u -r1.1 -r0 src/sys/arch/mipsco/include/sljitarch.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/md.emips
diff -u src/distrib/sets/lists/comp/md.emips:1.4 src/distrib/sets/lists/comp/md.emips:1.5
--- src/distrib/sets/lists/comp/md.emips:1.4	Sun Aug 11 22:29:02 2013
+++ src/distrib/sets/lists/comp/md.emips	Sat Jul 19 14:35:10 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: md.emips,v 1.4 2013/08/11 22:29:02 joerg Exp $
+#	$NetBSD: md.emips,v 1.5 2014/07/19 14:35:10 alnsn Exp $
 #
 ./usr/include/emipscomp-c-include
 ./usr/include/emips/ansi.h			comp-c-include
@@ -48,7 +48,7 @@
 ./usr/include/emips/rwlock.h			comp-c-include
 ./usr/include/emips/setjmp.h			comp-c-include
 ./usr/include/emips/signal.h			comp-c-include
-./usr/include/emips/sljitarch.h			comp-c-include
+./usr/include/emips/sljitarch.h			comp-obsolete		obsolete
 ./usr/include/emips/stdarg.h			comp-obsolete		obsolete
 ./usr/include/emips/trap.h			comp-c-include
 ./usr/include/emips/types.h			comp-c-include

Index: src/distrib/sets/lists/comp/md.mipsco
diff -u src/distrib/sets/lists/comp/md.mipsco:1.22 src/distrib/sets/lists/comp/md.mipsco:1.23
--- src/distrib/sets/lists/comp/md.mipsco:1.22	Wed Jan 16 16:01:06 2013
+++ src/distrib/sets/lists/comp/md.mipsco	Sat Jul 19 14:35:10 2014
@@ -1,4 +1,4 @@
-# $NetBSD: md.mipsco,v 1.22 2013/01/16 16:01:06 christos Exp $
+# $NetBSD: md.mipsco,v 1.23 2014/07/19 14:35:10 alnsn Exp $
 ./usr/include/ieeefp.hcomp-c-include
 ./usr/include/mipscocomp-c-include
 ./usr/include/mipsco/_G_config.h		comp-obsolete		obsolete
@@ -54,7 +54,7 @@
 ./usr/include/mipsco/rwlock.h			comp-c-include
 ./usr/include/mipsco/setjmp.h			comp-c-include
 ./usr/include/mipsco/signal.h			comp-c-include
-./usr/include/mipsco/sljitarch.h		comp-c-include
+./usr/include/mipsco/sljitarch.h		comp-obsolete		obsolete
 ./usr/include/mipsco/stdarg.h			comp-obsolete		obsolete
 ./usr/include/mipsco/sysconf.h			comp-c-include
 ./usr/include/mipsco/trap.h			comp-c-include

Index: src/sys/arch/emips/include/Makefile
diff -u src/sys/arch/emips/include/Makefile:1.3 src/sys/arch/emips/include/Makefile:1.4
--- src/sys/arch/emips/include/Makefile:1.3	Sun Nov 25 21:55:50 2012
+++ src/sys/arch/emips/include/Makefile	Sat Jul 19 14:35:10 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.3 2012/11/25 21:55:50 alnsn Exp $
+#	$NetBSD: Makefile,v 1.4 2014/07/19 14:35:10 alnsn Exp $
 
 INCSDIR= /usr/include/emips
 
@@ -17,7 +17,7 @@ INCS=	ansi.h asm.h autoconf.h \
 	param.h pcb.h pmap.h pmc.h \
 	proc.h profile.h psl.h pte.h ptrace.h \
 	reg.h regdef.h regnum.h reloc.h rwlock.h \
-	setjmp.h signal.h sljitarch.h \
+	setjmp.h signal.h \
 	trap.h types.h \
 	vmparam.h \
 	wchar_limits.h

Index: src/sys/arch/mipsco/include/Makefile
diff -u src/sys/arch/mipsco/include/Makefile:1.21 src/sys/arch/mipsco/include/Makefile:1.22
--- src/sys/arch/mipsco/include/Makefile:1.21	Sun Nov 25 21:55:51 2012
+++ src/sys/arch/mipsco/include/Makefile	Sat Jul 19 14:35:10 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.21 2012/11/25 21:55:51 alnsn Exp $
+#	$NetBSD: Makefile,v 1.22 2014/07/19 14:35:10 alnsn Exp $
 
 INCSDIR= /usr/include/mipsco
 
@@ -16,7 +16,7 @@ INCS=	ansi.h asm.h autoconf.h \
 	mainboard.h math.h mcontext.h mips_opcode.h mutex.h \
 	param.h pcb.h pmap.h pmc.h proc.h profile.h psl.h pte.h ptrace.h \
 	reg.h regdef.h regnum.h reloc.h rwlock.h \
-	setjmp.h signal.h sljitarch.h sysconf.h \
+	setjmp.h signal.h sysconf.h \
 	trap.h types.h \
 	vmparam.h \
 	wchar_limits.h \



CVS commit: src/sys/external/bsd/sljit/dist/sljit_src

2014-07-18 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Fri Jul 18 19:38:02 UTC 2014

Modified Files:
src/sys/external/bsd/sljit/dist/sljit_src: sljitConfig.h

Log Message:
Disable FPU in kernel space.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.10 src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.11
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.10	Tue Jun 17 19:36:45 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h	Fri Jul 18 19:38:02 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: sljitConfig.h,v 1.10 2014/06/17 19:36:45 alnsn Exp $	*/
+/*	$NetBSD: sljitConfig.h,v 1.11 2014/07/18 19:38:02 alnsn Exp $	*/
 
 /*
  *Stack-less Just-In-Time compiler
@@ -90,6 +90,10 @@
 #endif
 
 #ifdef _KERNEL
+#define SLJIT_IS_FPU_AVAILABLE 0
+#endif
+
+#ifdef _KERNEL
 #include sys/cdefs.h
 #include sys/malloc.h
 #include sys/param.h



CVS commit: src/lib/librumpuser

2014-07-14 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jul 14 10:36:33 UTC 2014

Removed Files:
src/lib/librumpuser: rumpuser_cache.c

Log Message:
Remove unused file.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r0 src/lib/librumpuser/rumpuser_cache.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/lib/libbpfjit

2014-07-14 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jul 14 19:11:15 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_extmem.c

Log Message:
Add a link to ../../net/bpfjit/t_extmem.c.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libbpfjit/t_extmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_extmem.c
diff -u src/tests/lib/libbpfjit/t_extmem.c:1.2 src/tests/lib/libbpfjit/t_extmem.c:1.3
--- src/tests/lib/libbpfjit/t_extmem.c:1.2	Tue Jul  8 21:13:01 2014
+++ src/tests/lib/libbpfjit/t_extmem.c	Mon Jul 14 19:11:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_extmem.c,v 1.2 2014/07/08 21:13:01 alnsn Exp $ */
+/*	$NetBSD: t_extmem.c,v 1.3 2014/07/14 19:11:15 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_extmem.c,v 1.2 2014/07/08 21:13:01 alnsn Exp $);
+__RCSID($NetBSD: t_extmem.c,v 1.3 2014/07/14 19:11:15 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -464,6 +464,10 @@ ATF_TC_BODY(libbpfjit_copx_ret_preinited
 ATF_TP_ADD_TCS(tp)
 {
 
+	/*
+	 * For every new test please also add a similar test
+	 * to ../../net/bpfjit/t_extmem.c
+	 */
 	ATF_TP_ADD_TC(tp, libbpfjit_extmem_load_default);
 	ATF_TP_ADD_TC(tp, libbpfjit_extmem_load_preinited);
 	ATF_TP_ADD_TC(tp, libbpfjit_extmem_invalid_load);



CVS commit: src/sys/net

2014-07-13 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sun Jul 13 18:48:27 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Don't use BJ_TMP2REG for 32bit packet reads. Assign this register to (buf+X)
in BPF_LD+BPF_IND and save one instruction.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.26 src/sys/net/bpfjit.c:1.27
--- src/sys/net/bpfjit.c:1.26	Sat Jul 12 20:14:18 2014
+++ src/sys/net/bpfjit.c	Sun Jul 13 18:48:27 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.26 2014/07/12 20:14:18 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.27 2014/07/13 18:48:27 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.26 2014/07/12 20:14:18 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.27 2014/07/13 18:48:27 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.26 2014/07/12 20:14:18 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.27 2014/07/13 18:48:27 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -123,11 +123,12 @@ __RCSID($NetBSD: bpfjit.c,v 1.26 2014/0
  * Optimization hints.
  */
 typedef unsigned int bpfjit_hint_t;
-#define BJ_HINT_PKT  0x01 /* packet read */
-#define BJ_HINT_LDW  0x02 /* 32-bit load */
-#define BJ_HINT_COP  0x04 /* BPF_COP or BPF_COPX instruction  */
+#define BJ_HINT_ABS  0x01 /* packet read at absolute offset  */
+#define BJ_HINT_IND  0x02 /* packet read at variable offset  */
+#define BJ_HINT_COP  0x04 /* BPF_COP or BPF_COPX instruction */
 #define BJ_HINT_XREG 0x08 /* BJ_XREG is needed   */
 #define BJ_HINT_LDX  0x10 /* BPF_LDX instruction */
+#define BJ_HINT_PKT  (BJ_HINT_ABS|BJ_HINT_IND) /* packet read */
 
 /*
  * Datatype for Array Bounds Check Elimination (ABC) pass.
@@ -256,7 +257,7 @@ nscratches(bpfjit_hint_t hints)
 		rv = 3; /* xcall with three arguments */
 #endif
 
-	if (hints  (BJ_HINT_LDW|BJ_HINT_PKT))
+	if (hints  BJ_HINT_IND)
 		rv = 3; /* uses BJ_TMP2REG */
 
 	if (hints  BJ_HINT_COP)
@@ -354,44 +355,46 @@ append_jump(struct sljit_jump *jump, str
  * Emit code for BPF_LD+BPF_B+BPF_ABSA - P[k:1].
  */
 static int
-emit_read8(struct sljit_compiler *compiler, uint32_t k)
+emit_read8(struct sljit_compiler *compiler, sljit_si src, uint32_t k)
 {
 
 	return sljit_emit_op1(compiler,
 	SLJIT_MOV_UB,
 	BJ_AREG, 0,
-	SLJIT_MEM1(BJ_BUF), k);
+	SLJIT_MEM1(src), k);
 }
 
 /*
  * Emit code for BPF_LD+BPF_H+BPF_ABSA - P[k:2].
  */
 static int
-emit_read16(struct sljit_compiler *compiler, uint32_t k)
+emit_read16(struct sljit_compiler *compiler, sljit_si src, uint32_t k)
 {
 	int status;
 
-	/* tmp1 = buf[k]; */
+	BJ_ASSERT(k = UINT32_MAX - 1);
+
+	/* A = buf[k]; */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UB,
-	BJ_TMP1REG, 0,
-	SLJIT_MEM1(BJ_BUF), k);
+	BJ_AREG, 0,
+	SLJIT_MEM1(src), k);
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-	/* A = buf[k+1]; */
+	/* tmp1 = buf[k+1]; */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UB,
-	BJ_AREG, 0,
-	SLJIT_MEM1(BJ_BUF), k+1);
+	BJ_TMP1REG, 0,
+	SLJIT_MEM1(src), k+1);
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-	/* tmp1 = tmp1  8; */
+	/* A = A  8; */
 	status = sljit_emit_op2(compiler,
 	SLJIT_SHL,
-	BJ_TMP1REG, 0,
-	BJ_TMP1REG, 0,
+	BJ_AREG, 0,
+	BJ_AREG, 0,
 	SLJIT_IMM, 8);
 	if (status != SLJIT_SUCCESS)
 		return status;
@@ -409,40 +412,34 @@ emit_read16(struct sljit_compiler *compi
  * Emit code for BPF_LD+BPF_W+BPF_ABSA - P[k:4].
  */
 static int
-emit_read32(struct sljit_compiler *compiler, uint32_t k)
+emit_read32(struct sljit_compiler *compiler, sljit_si src, uint32_t k)
 {
 	int status;
 
-	/* tmp1 = buf[k]; */
-	status = sljit_emit_op1(compiler,
-	SLJIT_MOV_UB,
-	BJ_TMP1REG, 0,
-	SLJIT_MEM1(BJ_BUF), k);
-	if (status != SLJIT_SUCCESS)
-		return status;
+	BJ_ASSERT(k = UINT32_MAX - 3);
 
-	/* tmp2 = buf[k+1]; */
+	/* A = buf[k]; */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UB,
-	BJ_TMP2REG, 0,
-	SLJIT_MEM1(BJ_BUF), k+1);
+	BJ_AREG, 0,
+	SLJIT_MEM1(src), k);
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-	/* A = buf[k+3]; */
+	/* tmp1 = buf[k+1]; */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UB,
-	BJ_AREG, 0,
-	SLJIT_MEM1(BJ_BUF), k+3);
+	BJ_TMP1REG, 0,
+	SLJIT_MEM1(src), k+1);
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-	/* tmp1 = tmp1  24; */
+	/* A = A  8; */
 	status = sljit_emit_op2(compiler,
 	SLJIT_SHL,
-	BJ_TMP1REG, 0,
-	BJ_TMP1REG, 0,
-	SLJIT_IMM, 24);
+	BJ_AREG, 0,
+	BJ_AREG, 0,
+	SLJIT_IMM, 8);
 	if (status != SLJIT_SUCCESS)
 		return status;
 
@@ -459,33 +456,41 @@ emit_read32(struct sljit_compiler *compi
 	status = sljit_emit_op1

CVS commit: src/tests

2014-07-13 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sun Jul 13 21:35:33 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_cop.c
src/tests/net/bpfjit: t_cop.c

Log Message:
Add bpfjit_cop_copx and bpfjit_copx_cop tests.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libbpfjit/t_cop.c
cvs rdiff -u -r1.2 -r1.3 src/tests/net/bpfjit/t_cop.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_cop.c
diff -u src/tests/lib/libbpfjit/t_cop.c:1.3 src/tests/lib/libbpfjit/t_cop.c:1.4
--- src/tests/lib/libbpfjit/t_cop.c:1.3	Tue Jul  8 21:13:01 2014
+++ src/tests/lib/libbpfjit/t_cop.c	Sun Jul 13 21:35:33 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_cop.c,v 1.3 2014/07/08 21:13:01 alnsn Exp $ */
+/*	$NetBSD: t_cop.c,v 1.4 2014/07/13 21:35:33 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2013-2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_cop.c,v 1.3 2014/07/08 21:13:01 alnsn Exp $);
+__RCSID($NetBSD: t_cop.c,v 1.4 2014/07/13 21:35:33 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -296,6 +296,45 @@ ATF_TC_BODY(libbpfjit_cop_side_effect, t
 	bpfjit_free_code(code);
 }
 
+ATF_TC(libbpfjit_cop_copx);
+ATF_TC_HEAD(libbpfjit_cop_copx, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test BPF_COP call followed by BPF_COPX call);
+}
+
+ATF_TC_BODY(libbpfjit_cop_copx, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 1), /* A - 1*/
+		BPF_STMT(BPF_MISC+BPF_COP, 0),   /* retA  */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),   /* X - A*/
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0),   /* A = P[0]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 1),  /* A = A + X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),   /* X - A*/
+		BPF_STMT(BPF_MISC+BPF_COPX, 0),  /* retNF */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 1),  /* A = A + X */
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1] = { 2 };
+	bpf_args_t args = {
+		.pkt = pkt,
+		.buflen = sizeof(pkt),
+		.wirelen = sizeof(pkt),
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	code = bpfjit_generate_code(ctx, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(code(ctx, args) == 3 + ctx.nfuncs);
+
+	bpfjit_free_code(code);
+}
+
 ATF_TC(libbpfjit_cop_invalid_index);
 ATF_TC_HEAD(libbpfjit_cop_invalid_index, tc)
 {
@@ -516,6 +555,46 @@ ATF_TC_BODY(libbpfjit_copx_side_effect, 
 	bpfjit_free_code(code);
 }
 
+ATF_TC(libbpfjit_copx_cop);
+ATF_TC_HEAD(libbpfjit_copx_cop, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test BPF_COPX call followed by BPF_COP call);
+}
+
+ATF_TC_BODY(libbpfjit_copx_cop, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LDX+BPF_IMM, 2),/* X - 2*/
+		BPF_STMT(BPF_MISC+BPF_COPX, 0),  /* retWL */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 1),  /* A = A + X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),   /* X - A*/
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0),   /* A = P[0]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 1),  /* A = A + X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),   /* X - A*/
+		BPF_STMT(BPF_MISC+BPF_COP, 3),  /* retNF */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 1),  /* A = A + X */
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1] = { 2 };
+	bpf_args_t args = {
+		.pkt = pkt,
+		.buflen = sizeof(pkt),
+		.wirelen = sizeof(pkt),
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	code = bpfjit_generate_code(ctx, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(code(ctx, args) == 5 + ctx.nfuncs);
+
+	bpfjit_free_code(code);
+}
+
 ATF_TC(libbpfjit_copx_invalid_index);
 ATF_TC_HEAD(libbpfjit_copx_invalid_index, tc)
 {
@@ -552,12 +631,17 @@ ATF_TC_BODY(libbpfjit_copx_invalid_index
 ATF_TP_ADD_TCS(tp)
 {
 
+	/*
+	 * For every new test please also add a similar test
+	 * to ../../net/bpfjit/t_cop.c
+	 */
 	ATF_TP_ADD_TC(tp, libbpfjit_cop_no_ctx);
 	ATF_TP_ADD_TC(tp, libbpfjit_cop_ret_A);
 	ATF_TP_ADD_TC(tp, libbpfjit_cop_ret_buflen);
 	ATF_TP_ADD_TC(tp, libbpfjit_cop_ret_wirelen);
 	ATF_TP_ADD_TC(tp, libbpfjit_cop_ret_nfuncs);
 	ATF_TP_ADD_TC(tp, libbpfjit_cop_side_effect);
+	ATF_TP_ADD_TC(tp, libbpfjit_cop_copx);
 	ATF_TP_ADD_TC(tp, libbpfjit_cop_invalid_index);
 
 	ATF_TP_ADD_TC(tp, libbpfjit_copx_no_ctx);
@@ -566,6 +650,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, libbpfjit_copx_ret_wirelen);
 	ATF_TP_ADD_TC(tp, libbpfjit_copx_ret_nfuncs);
 	ATF_TP_ADD_TC(tp, libbpfjit_copx_side_effect);
+	ATF_TP_ADD_TC(tp, libbpfjit_copx_cop);
 	ATF_TP_ADD_TC(tp, libbpfjit_copx_invalid_index);
 
 	return atf_no_error();

Index: src/tests/net/bpfjit/t_cop.c
diff -u src/tests/net/bpfjit/t_cop.c:1.2 src/tests/net/bpfjit/t_cop.c:1.3
--- src/tests/net/bpfjit/t_cop.c:1.2	Wed Jul  9 15:56:12 2014
+++ src/tests/net/bpfjit/t_cop.c	Sun Jul 13 21:35:33 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_cop.c,v 1.2 2014/07/09 15:56:12 alnsn Exp $ */
+/*	$NetBSD

CVS commit: src/sys/net

2014-07-13 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sun Jul 13 21:54:46 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Refactor BPF_COPX code. New version doesn't load buf and buflen after copx call.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.27 src/sys/net/bpfjit.c:1.28
--- src/sys/net/bpfjit.c:1.27	Sun Jul 13 18:48:27 2014
+++ src/sys/net/bpfjit.c	Sun Jul 13 21:54:46 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.27 2014/07/13 18:48:27 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.28 2014/07/13 21:54:46 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.27 2014/07/13 18:48:27 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.28 2014/07/13 21:54:46 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.27 2014/07/13 18:48:27 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.28 2014/07/13 21:54:46 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -95,13 +95,6 @@ __RCSID($NetBSD: bpfjit.c,v 1.27 2014/0
 #define BJ_XREG		SLJIT_TEMPORARY_EREG1
 #define BJ_TMP3REG	SLJIT_TEMPORARY_EREG2
 
-/*
- * EREG registers can't be used for indirect calls, reuse BJ_BUF and
- * BJ_BUFLEN registers. They can be easily restored from BJ_ARGS.
- */
-#define BJ_COPF_PTR	SLJIT_SAVED_REG1
-#define BJ_COPF_IDX	SLJIT_SAVED_REG3
-
 #ifdef _KERNEL
 #define MAX_MEMWORDS BPF_MAX_MEMWORDS
 #else
@@ -123,11 +116,12 @@ __RCSID($NetBSD: bpfjit.c,v 1.27 2014/0
  * Optimization hints.
  */
 typedef unsigned int bpfjit_hint_t;
-#define BJ_HINT_ABS  0x01 /* packet read at absolute offset  */
-#define BJ_HINT_IND  0x02 /* packet read at variable offset  */
-#define BJ_HINT_COP  0x04 /* BPF_COP or BPF_COPX instruction */
-#define BJ_HINT_XREG 0x08 /* BJ_XREG is needed   */
-#define BJ_HINT_LDX  0x10 /* BPF_LDX instruction */
+#define BJ_HINT_ABS  0x01 /* packet read at absolute offset   */
+#define BJ_HINT_IND  0x02 /* packet read at variable offset   */
+#define BJ_HINT_COP  0x04 /* BPF_COP or BPF_COPX instruction  */
+#define BJ_HINT_COPX 0x08 /* BPF_COPX instruction */
+#define BJ_HINT_XREG 0x10 /* BJ_XREG is needed*/
+#define BJ_HINT_LDX  0x20 /* BPF_LDX instruction  */
 #define BJ_HINT_PKT  (BJ_HINT_ABS|BJ_HINT_IND) /* packet read */
 
 /*
@@ -271,6 +265,9 @@ nscratches(bpfjit_hint_t hints)
 		rv = 5; /* uses BJ_TMP3REG */
 #endif
 
+	if (hints  BJ_HINT_COPX)
+		rv = 5; /* uses BJ_TMP3REG */
+
 	return rv;
 }
 
@@ -649,26 +646,31 @@ emit_xcall(struct sljit_compiler *compil
  * Emit code for BPF_COP and BPF_COPX instructions.
  */
 static int
-emit_cop(struct sljit_compiler *compiler, const bpf_ctx_t *bc,
-const struct bpf_insn *pc, struct sljit_jump **ret0_jump)
+emit_cop(struct sljit_compiler *compiler,
+const bpf_ctx_t *bc, const struct bpf_insn *pc,
+struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize)
 {
-#if BJ_XREG == SLJIT_RETURN_REG   || \
-BJ_XREG == SLJIT_SCRATCH_REG1 || \
-BJ_XREG == SLJIT_SCRATCH_REG2 || \
-BJ_XREG == SLJIT_SCRATCH_REG3 || \
-BJ_COPF_PTR == BJ_ARGS|| \
-BJ_COPF_IDX	== BJ_ARGS
+#if BJ_XREG== SLJIT_RETURN_REG   || \
+BJ_XREG== SLJIT_SCRATCH_REG1 || \
+BJ_XREG== SLJIT_SCRATCH_REG2 || \
+BJ_XREG== SLJIT_SCRATCH_REG3 || \
+BJ_TMP3REG == SLJIT_SCRATCH_REG1 || \
+BJ_TMP3REG == SLJIT_SCRATCH_REG2 || \
+BJ_TMP3REG == SLJIT_SCRATCH_REG3
 #error Not supported assignment of registers.
 #endif
 
 	struct sljit_jump *jump;
+	sljit_si call_reg;
+	sljit_sw call_off;
 	int status;
 
-	jump = NULL;
-
 	BJ_ASSERT(bc != NULL  bc-copfuncs != NULL);
 
-	if (BPF_MISCOP(pc-code) == BPF_COPX) {
+	if (BPF_MISCOP(pc-code) == BPF_COP) {
+		call_reg = SLJIT_IMM;
+		call_off = SLJIT_FUNC_OFFSET(bc-copfuncs[pc-k]);
+	} else {
 		/* if (X = bc-nfuncs) return 0; */
 		jump = sljit_emit_cmp(compiler,
 		SLJIT_C_GREATER_EQUAL,
@@ -676,10 +678,46 @@ emit_cop(struct sljit_compiler *compiler
 		SLJIT_IMM, bc-nfuncs);
 		if (jump == NULL)
 			return SLJIT_ERR_ALLOC_FAILED;
-	}
+		if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
+			return SLJIT_ERR_ALLOC_FAILED;
+
+		/* tmp1 = ctx; */
+		status = sljit_emit_op1(compiler,
+		SLJIT_MOV_P,
+		BJ_TMP1REG, 0,
+		SLJIT_MEM1(SLJIT_LOCALS_REG),
+		offsetof(struct bpfjit_stack, ctx));
+		if (status != SLJIT_SUCCESS)
+			return status;
+
+		/* tmp1 = ctx-copfuncs; */
+		status = sljit_emit_op1(compiler,
+		SLJIT_MOV_P,
+		BJ_TMP1REG, 0,
+		SLJIT_MEM1(BJ_TMP1REG),
+		offsetof(struct bpf_ctx, copfuncs));
+		if (status != SLJIT_SUCCESS)
+			return status;
+
+		/* tmp2 = X; */
+		status = sljit_emit_op1(compiler,
+		SLJIT_MOV,
+		BJ_TMP2REG, 0,
+		BJ_XREG, 0

CVS commit: src/sys/net

2014-07-12 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul 12 16:13:57 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Some small changes: add missing error checks; move sjump initialisation away
from optimize(); +BJ_HINT_PKT, -BJ_HINT_IND; tweak comments.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.23 src/sys/net/bpfjit.c:1.24
--- src/sys/net/bpfjit.c:1.23	Fri Jul 11 20:43:33 2014
+++ src/sys/net/bpfjit.c	Sat Jul 12 16:13:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.23 2014/07/11 20:43:33 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.24 2014/07/12 16:13:57 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.23 2014/07/11 20:43:33 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.24 2014/07/12 16:13:57 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.23 2014/07/11 20:43:33 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.24 2014/07/12 16:13:57 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -123,8 +123,8 @@ __RCSID($NetBSD: bpfjit.c,v 1.23 2014/0
  * Optimization hints.
  */
 typedef unsigned int bpfjit_hint_t;
-#define BJ_HINT_LDW  0x01 /* 32-bit packet read  */
-#define BJ_HINT_IND  0x02 /* packet read at a variable offset */
+#define BJ_HINT_PKT  0x01 /* packet read */
+#define BJ_HINT_LDW  0x02 /* 32-bit load */
 #define BJ_HINT_COP  0x04 /* BPF_COP or BPF_COPX instruction  */
 #define BJ_HINT_XREG 0x08 /* BJ_XREG is needed   */
 #define BJ_HINT_LDX  0x10 /* BPF_LDX instruction */
@@ -252,14 +252,11 @@ nscratches(bpfjit_hint_t hints)
 	sljit_si rv = 2;
 
 #ifdef _KERNEL
-	/*
-	 * Most kernel programs load packet bytes and they generate
-	 * m_xword/m_xhalf/m_xbyte() calls with three arguments.
-	 */
-	rv = 3;
+	if (hints  BJ_HINT_PKT)
+		rv = 3; /* xcall with three arguments */
 #endif
 
-	if (hints  BJ_HINT_LDW)
+	if (hints  (BJ_HINT_LDW|BJ_HINT_PKT))
 		rv = 3; /* uses BJ_TMP2REG */
 
 	if (hints  BJ_HINT_COP)
@@ -354,7 +351,7 @@ append_jump(struct sljit_jump *jump, str
 }
 
 /*
- * Generate code for BPF_LD+BPF_B+BPF_ABSA - P[k:1].
+ * Emit code for BPF_LD+BPF_B+BPF_ABSA - P[k:1].
  */
 static int
 emit_read8(struct sljit_compiler *compiler, uint32_t k)
@@ -367,7 +364,7 @@ emit_read8(struct sljit_compiler *compil
 }
 
 /*
- * Generate code for BPF_LD+BPF_H+BPF_ABSA - P[k:2].
+ * Emit code for BPF_LD+BPF_H+BPF_ABSA - P[k:2].
  */
 static int
 emit_read16(struct sljit_compiler *compiler, uint32_t k)
@@ -409,7 +406,7 @@ emit_read16(struct sljit_compiler *compi
 }
 
 /*
- * Generate code for BPF_LD+BPF_W+BPF_ABSA - P[k:4].
+ * Emit code for BPF_LD+BPF_W+BPF_ABSA - P[k:4].
  */
 static int
 emit_read32(struct sljit_compiler *compiler, uint32_t k)
@@ -504,21 +501,15 @@ emit_read32(struct sljit_compiler *compi
 
 #ifdef _KERNEL
 /*
- * Generate m_xword/m_xhalf/m_xbyte call.
- *
- * pc is one of:
- * BPF_LD+BPF_W+BPF_ABSA - P[k:4]
- * BPF_LD+BPF_H+BPF_ABSA - P[k:2]
- * BPF_LD+BPF_B+BPF_ABSA - P[k:1]
- * BPF_LD+BPF_W+BPF_INDA - P[X+k:4]
- * BPF_LD+BPF_H+BPF_INDA - P[X+k:2]
- * BPF_LD+BPF_B+BPF_INDA - P[X+k:1]
- * BPF_LDX+BPF_B+BPF_MSH   X - 4*(P[k:1]0xf)
+ * Emit code for m_xword/m_xhalf/m_xbyte call.
  *
- * The dst variable should be
- *  - BJ_AREG when emitting code for BPF_LD instructions,
- *  - BJ_XREG or BJ_TMP1REG register when emitting code
- *for BPF_MSH instruction.
+ * @pc BPF_LD+BPF_W+BPF_ABSA - P[k:4]
+ * BPF_LD+BPF_H+BPF_ABSA - P[k:2]
+ * BPF_LD+BPF_B+BPF_ABSA - P[k:1]
+ * BPF_LD+BPF_W+BPF_INDA - P[X+k:4]
+ * BPF_LD+BPF_H+BPF_INDA - P[X+k:2]
+ * BPF_LD+BPF_B+BPF_INDA - P[X+k:1]
+ * BPF_LDX+BPF_B+BPF_MSH   X - 4*(P[k:1]0xf)
  */
 static int
 emit_xcall(struct sljit_compiler *compiler, const struct bpf_insn *pc,
@@ -567,6 +558,8 @@ emit_xcall(struct sljit_compiler *compil
 		SLJIT_SCRATCH_REG2, 0,
 		BJ_XREG, 0,
 		SLJIT_IMM, (uint32_t)pc-k);
+		if (status != SLJIT_SUCCESS)
+			return status;
 
 		/* if (k  X) return 0; */
 		jump = sljit_emit_cmp(compiler,
@@ -584,11 +577,10 @@ emit_xcall(struct sljit_compiler *compil
 		SLJIT_MOV,
 		SLJIT_SCRATCH_REG2, 0,
 		SLJIT_IMM, (uint32_t)pc-k);
+		if (status != SLJIT_SUCCESS)
+			return status;
 	}
 
-	if (status != SLJIT_SUCCESS)
-		return status;
-
 	/*
 	 * The third argument of fn is an address on stack.
 	 */
@@ -602,6 +594,8 @@ emit_xcall(struct sljit_compiler *compil
 	status = sljit_emit_ijump(compiler,
 	SLJIT_CALL3,
 	SLJIT_IMM, SLJIT_FUNC_OFFSET(fn));
+	if (status != SLJIT_SUCCESS)
+		return status;
 
 	if (dst != SLJIT_RETURN_REG) {
 		/* move return value to dst */
@@ -643,7 +637,7 @@ emit_xcall(struct sljit_compiler

CVS commit: src/sys/net

2014-07-12 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul 12 16:52:57 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Initialise status to avoid -Wuninitialized warning.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.24 src/sys/net/bpfjit.c:1.25
--- src/sys/net/bpfjit.c:1.24	Sat Jul 12 16:13:57 2014
+++ src/sys/net/bpfjit.c	Sat Jul 12 16:52:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.24 2014/07/12 16:13:57 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.25 2014/07/12 16:52:57 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.24 2014/07/12 16:13:57 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.25 2014/07/12 16:52:57 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.24 2014/07/12 16:13:57 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.25 2014/07/12 16:52:57 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -769,7 +769,7 @@ emit_pkt_read(struct sljit_compiler *com
 const struct bpf_insn *pc, struct sljit_jump *to_mchain_jump,
 struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize)
 {
-	int status;
+	int status = SLJIT_ERR_ALLOC_FAILED;
 	uint32_t width;
 	struct sljit_jump *jump;
 #ifdef _KERNEL



CVS commit: src/sys/net

2014-07-12 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul 12 20:14:18 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
emit_xcall: check overflow by comparing X with (UINT32_MAX - pk-k), restore
the A register after checking that xcall succeeded.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.25 src/sys/net/bpfjit.c:1.26
--- src/sys/net/bpfjit.c:1.25	Sat Jul 12 16:52:57 2014
+++ src/sys/net/bpfjit.c	Sat Jul 12 20:14:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.25 2014/07/12 16:52:57 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.26 2014/07/12 20:14:18 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.25 2014/07/12 16:52:57 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.26 2014/07/12 20:14:18 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.25 2014/07/12 16:52:57 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.26 2014/07/12 20:14:18 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -552,25 +552,24 @@ emit_xcall(struct sljit_compiler *compil
 		return status;
 
 	if (BPF_CLASS(pc-code) == BPF_LD  BPF_MODE(pc-code) == BPF_IND) {
+		/* if (X  UINT32_MAX - pc-k) return 0; */
+		jump = sljit_emit_cmp(compiler,
+		SLJIT_C_GREATER,
+		BJ_XREG, 0,
+		SLJIT_IMM, UINT32_MAX - pc-k);
+		if (jump == NULL)
+			return SLJIT_ERR_ALLOC_FAILED;
+		if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
+			return SLJIT_ERR_ALLOC_FAILED;
+
 		/* k = X + pc-k; */
 		status = sljit_emit_op2(compiler,
-		SLJIT_ADD | SLJIT_INT_OP,
+		SLJIT_ADD,
 		SLJIT_SCRATCH_REG2, 0,
 		BJ_XREG, 0,
 		SLJIT_IMM, (uint32_t)pc-k);
 		if (status != SLJIT_SUCCESS)
 			return status;
-
-		/* if (k  X) return 0; */
-		jump = sljit_emit_cmp(compiler,
-		SLJIT_C_LESS,
-		SLJIT_SCRATCH_REG2, 0,
-		BJ_XREG, 0);
-		if (jump == NULL)
-			return SLJIT_ERR_ALLOC_FAILED;
-
-		if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
-			return SLJIT_ERR_ALLOC_FAILED;
 	} else {
 		/* k = pc-k */
 		status = sljit_emit_op1(compiler,
@@ -607,16 +606,6 @@ emit_xcall(struct sljit_compiler *compil
 			return status;
 	}
 
-	if (BPF_CLASS(pc-code) == BPF_LDX) {
-		/* restore A */
-		status = sljit_emit_op1(compiler,
-		SLJIT_MOV,
-		BJ_AREG, 0,
-		BJ_TMP3REG, 0);
-		if (status != SLJIT_SUCCESS)
-			return status;
-	}
-
 	/* tmp2 = *err; */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UI,
@@ -637,6 +626,16 @@ emit_xcall(struct sljit_compiler *compil
 	if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
 		return SLJIT_ERR_ALLOC_FAILED;
 
+	if (BPF_CLASS(pc-code) == BPF_LDX) {
+		/* restore A */
+		status = sljit_emit_op1(compiler,
+		SLJIT_MOV,
+		BJ_AREG, 0,
+		BJ_TMP3REG, 0);
+		if (status != SLJIT_SUCCESS)
+			return status;
+	}
+
 	return SLJIT_SUCCESS;
 }
 #endif



CVS commit: src/sys/net

2014-07-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Fri Jul 11 20:43:33 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Handle overflow in BPF_LD+BPF_IND for mbuf chains and make two minor changes:
move sljit_emit_return() to generate_insn_code() and use a different register
for checking errors after xcall.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.22 src/sys/net/bpfjit.c:1.23
--- src/sys/net/bpfjit.c:1.22	Tue Jul  8 11:30:31 2014
+++ src/sys/net/bpfjit.c	Fri Jul 11 20:43:33 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.22 2014/07/08 11:30:31 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.23 2014/07/11 20:43:33 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.22 2014/07/08 11:30:31 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.23 2014/07/11 20:43:33 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.22 2014/07/08 11:30:31 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.23 2014/07/11 20:43:33 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -517,22 +517,29 @@ emit_read32(struct sljit_compiler *compi
  *
  * The dst variable should be
  *  - BJ_AREG when emitting code for BPF_LD instructions,
- *  - BJ_XREG or any of BJ_TMP[1-3]REG registers when emitting
- *code for BPF_MSH instruction.
+ *  - BJ_XREG or BJ_TMP1REG register when emitting code
+ *for BPF_MSH instruction.
  */
 static int
 emit_xcall(struct sljit_compiler *compiler, const struct bpf_insn *pc,
-int dst, sljit_sw dstw, struct sljit_jump **ret0_jump,
+int dst, struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize,
 uint32_t (*fn)(const struct mbuf *, uint32_t, int *))
 {
-#if BJ_XREG == SLJIT_RETURN_REG   || \
-BJ_XREG == SLJIT_SCRATCH_REG1 || \
-BJ_XREG == SLJIT_SCRATCH_REG2 || \
-BJ_XREG == SLJIT_SCRATCH_REG3
+#if BJ_XREG== SLJIT_RETURN_REG   || \
+BJ_XREG== SLJIT_SCRATCH_REG1 || \
+BJ_XREG== SLJIT_SCRATCH_REG2 || \
+BJ_XREG== SLJIT_SCRATCH_REG3 || \
+BJ_TMP3REG == SLJIT_RETURN_REG   || \
+BJ_TMP3REG == SLJIT_SCRATCH_REG1 || \
+BJ_TMP3REG == SLJIT_SCRATCH_REG2 || \
+BJ_TMP3REG == SLJIT_SCRATCH_REG3
 #error Not supported assignment of registers.
 #endif
+	struct sljit_jump *jump;
 	int status;
 
+	BJ_ASSERT(dst != BJ_TMP2REG  dst != BJ_TMP3REG);
+
 	if (BPF_CLASS(pc-code) == BPF_LDX) {
 		/* save A */
 		status = sljit_emit_op1(compiler,
@@ -544,7 +551,7 @@ emit_xcall(struct sljit_compiler *compil
 	}
 
 	/*
-	 * Prepare registers for fn(buf, k, err) call.
+	 * Prepare registers for fn(mbuf, k, err) call.
 	 */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV,
@@ -554,12 +561,25 @@ emit_xcall(struct sljit_compiler *compil
 		return status;
 
 	if (BPF_CLASS(pc-code) == BPF_LD  BPF_MODE(pc-code) == BPF_IND) {
+		/* k = X + pc-k; */
 		status = sljit_emit_op2(compiler,
-		SLJIT_ADD,
+		SLJIT_ADD | SLJIT_INT_OP,
 		SLJIT_SCRATCH_REG2, 0,
 		BJ_XREG, 0,
 		SLJIT_IMM, (uint32_t)pc-k);
+
+		/* if (k  X) return 0; */
+		jump = sljit_emit_cmp(compiler,
+		SLJIT_C_LESS,
+		SLJIT_SCRATCH_REG2, 0,
+		BJ_XREG, 0);
+		if (jump == NULL)
+			return SLJIT_ERR_ALLOC_FAILED;
+
+		if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
+			return SLJIT_ERR_ALLOC_FAILED;
 	} else {
+		/* k = pc-k */
 		status = sljit_emit_op1(compiler,
 		SLJIT_MOV,
 		SLJIT_SCRATCH_REG2, 0,
@@ -587,7 +607,7 @@ emit_xcall(struct sljit_compiler *compil
 		/* move return value to dst */
 		status = sljit_emit_op1(compiler,
 		SLJIT_MOV,
-		dst, dstw,
+		dst, 0,
 		SLJIT_RETURN_REG, 0);
 		if (status != SLJIT_SUCCESS)
 			return status;
@@ -603,21 +623,24 @@ emit_xcall(struct sljit_compiler *compil
 			return status;
 	}
 
-	/* tmp3 = *err; */
+	/* tmp2 = *err; */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UI,
-	SLJIT_SCRATCH_REG3, 0,
+	BJ_TMP2REG, 0,
 	SLJIT_MEM1(SLJIT_LOCALS_REG),
 	offsetof(struct bpfjit_stack, err));
 	if (status != SLJIT_SUCCESS)
 		return status;
 
-	/* if (tmp3 != 0) return 0; */
-	*ret0_jump = sljit_emit_cmp(compiler,
+	/* if (tmp2 != 0) return 0; */
+	jump = sljit_emit_cmp(compiler,
 	SLJIT_C_NOT_EQUAL,
-	SLJIT_SCRATCH_REG3, 0,
+	BJ_TMP2REG, 0,
 	SLJIT_IMM, 0);
-	if (*ret0_jump == NULL)
+	if (jump == NULL)
+		return SLJIT_ERR_ALLOC_FAILED;
+
+	if (!append_jump(jump, ret0, ret0_size, ret0_maxsize))
 		return SLJIT_ERR_ALLOC_FAILED;
 
 	return status;
@@ -856,22 +879,22 @@ emit_pkt_read(struct sljit_compiler *com
 
 	switch (width) {
 	case 4:
-		status = emit_xcall(compiler, pc, BJ_AREG, 0, jump, m_xword);
+		status = emit_xcall(compiler, pc, BJ_AREG,
+		ret0, ret0_size, ret0_maxsize, m_xword

CVS commit: src/doc

2014-07-11 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Fri Jul 11 22:33:03 UTC 2014

Modified Files:
src/doc: 3RDPARTY

Log Message:
Current wpa_supplicant version is 2.2, released 2014-06-04.


To generate a diff of this commit:
cvs rdiff -u -r1.1132 -r1.1133 src/doc/3RDPARTY

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1132 src/doc/3RDPARTY:1.1133
--- src/doc/3RDPARTY:1.1132	Tue Jul  8 22:39:38 2014
+++ src/doc/3RDPARTY	Fri Jul 11 22:33:03 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1132 2014/07/08 22:39:38 riastradh Exp $
+#	$NetBSD: 3RDPARTY,v 1.1133 2014/07/11 22:33:03 alnsn Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -1305,7 +1305,7 @@ is too much inertia to apply them. Check
 
 Package:	wpa_supplicant/hostapd
 Version:	2.0
-Current Vers:	2.0
+Current Vers:	2.2
 Maintainer:	Jouni Malinen jkmal...@cc.hut.fi
 Archive Site:	http://hostap.epitest.fi/releases/
 Home Page:	http://hostap.epitest.fi/wpa_supplicant/



CVS commit: src/tests/net/bpfjit

2014-07-09 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jul  9 13:49:49 UTC 2014

Added Files:
src/tests/net/bpfjit: t_cop.c t_extmem.c

Log Message:
Add t_cop and t_extmem kernel bpfjit tests.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/bpfjit/t_cop.c \
src/tests/net/bpfjit/t_extmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/bpfjit/t_cop.c
diff -u /dev/null src/tests/net/bpfjit/t_cop.c:1.1
--- /dev/null	Wed Jul  9 13:49:49 2014
+++ src/tests/net/bpfjit/t_cop.c	Wed Jul  9 13:49:49 2014
@@ -0,0 +1,664 @@
+/*	$NetBSD: t_cop.c,v 1.1 2014/07/09 13:49:49 alnsn Exp $ */
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__RCSID($NetBSD: t_cop.c,v 1.1 2014/07/09 13:49:49 alnsn Exp $);
+
+#include stdint.h
+#include string.h
+
+#define __BPF_PRIVATE
+#include net/bpf.h
+#include net/bpfjit.h
+
+#include ../../net/bpf/h_bpf.h
+
+/* XXX: atf-c.h has collisions with mbuf */
+#undef m_type
+#undef m_data
+#include atf-c.h
+
+#include ../../h_macros.h
+
+static uint32_t retA(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t retBL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t retWL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t retNF(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t setARG(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+
+static const bpf_copfunc_t copfuncs[] = {
+	retA,
+	retBL,
+	retWL,
+	retNF,
+	setARG
+};
+
+static const bpf_ctx_t ctx = {
+	.copfuncs = copfuncs,
+	.nfuncs = sizeof(copfuncs) / sizeof(copfuncs[0]),
+	.extwords = 0
+};
+
+static uint32_t
+retA(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return A;
+}
+
+static uint32_t
+retBL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return args-buflen;
+}
+
+static uint32_t
+retWL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return args-wirelen;
+}
+
+static uint32_t
+retNF(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return bc-nfuncs;
+}
+
+/*
+ * COP function with a side effect.
+ */
+static uint32_t
+setARG(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+	bool *arg = (bool *)args-arg;
+	bool old = *arg;
+
+	*arg = true;
+	return old;
+}
+
+ATF_TC(bpfjit_cop_no_ctx);
+ATF_TC_HEAD(bpfjit_cop_no_ctx, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test that bpf program with BPF_COP 
+	instruction isn't valid without a context);
+}
+
+ATF_TC_BODY(bpfjit_cop_no_ctx, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_MISC+BPF_COP, 0),
+		BPF_STMT(BPF_RET+BPF_K, 7)
+	};
+
+	bpfjit_func_t code;
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	ATF_CHECK(!prog_validate(insns, insn_count));
+
+	rump_schedule();
+	code = rumpns_bpfjit_generate_code(NULL, insns, insn_count);
+	rump_unschedule();
+	ATF_CHECK(code == NULL);
+}
+
+ATF_TC(bpfjit_cop_ret_A);
+ATF_TC_HEAD(bpfjit_cop_ret_A, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test coprocessor function 
+	that returns a content of the A register);
+}
+
+ATF_TC_BODY(bpfjit_cop_ret_A, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 13),
+		BPF_STMT(BPF_MISC+BPF_COP, 0), // retA
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1] = { 0 };
+	bpf_args_t args = {
+		.pkt = pkt,
+		.buflen = sizeof(pkt),
+		.wirelen = sizeof(pkt),
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	RZ(rump_init());
+
+	rump_schedule();
+	code

CVS commit: src

2014-07-09 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jul  9 13:50:48 UTC 2014

Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/tests/net/bpfjit: Makefile

Log Message:
Add t_cop and t_extmem kernel bpfjit tests to the build.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.578 -r1.579 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.3 -r1.4 src/tests/net/bpfjit/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.70 src/distrib/sets/lists/debug/mi:1.71
--- src/distrib/sets/lists/debug/mi:1.70	Tue Jul  8 21:47:21 2014
+++ src/distrib/sets/lists/debug/mi	Wed Jul  9 13:50:48 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.70 2014/07/08 21:47:21 alnsn Exp $
+# $NetBSD: mi,v 1.71 2014/07/09 13:50:48 alnsn Exp $
 
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib
@@ -2131,6 +2131,8 @@
 ./usr/libdata/debug/usr/tests/net/bpf/t_mbuf.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpfilter/t_bpfilter.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpfjit/t_bpfjit.debug		tests-net-debug		debug,atf,sljit,rump
+./usr/libdata/debug/usr/tests/net/bpfjit/t_cop.debug		tests-net-debug		debug,atf,sljit,rump
+./usr/libdata/debug/usr/tests/net/bpfjit/t_extmem.debug		tests-net-debug		debug,atf,sljit,rump
 ./usr/libdata/debug/usr/tests/net/bpfjit/t_mbuf.debug		tests-net-debug		debug,atf,sljit,rump
 ./usr/libdata/debug/usr/tests/net/carp/t_basic.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/fdpass/fdpass32.debug		tests-net-debug		debug,atf

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.578 src/distrib/sets/lists/tests/mi:1.579
--- src/distrib/sets/lists/tests/mi:1.578	Tue Jul  8 21:47:21 2014
+++ src/distrib/sets/lists/tests/mi	Wed Jul  9 13:50:48 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.578 2014/07/08 21:47:21 alnsn Exp $
+# $NetBSD: mi,v 1.579 2014/07/09 13:50:48 alnsn Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -3090,6 +3090,8 @@
 ./usr/tests/net/bpfjit/Atffile		tests-net-tests		atf,sljit,rump
 ./usr/tests/net/bpfjit/Kyuafile		tests-net-tests		atf,sljit,rump,kyua
 ./usr/tests/net/bpfjit/t_bpfjit		tests-net-tests		atf,sljit,rump
+./usr/tests/net/bpfjit/t_cop		tests-net-tests		atf,sljit,rump
+./usr/tests/net/bpfjit/t_extmem		tests-net-tests		atf,sljit,rump
 ./usr/tests/net/bpfjit/t_mbuf		tests-net-tests		atf,sljit,rump
 ./usr/tests/net/carptests-net-tests
 ./usr/tests/net/carp/Atffile			tests-net-tests		atf,rump

Index: src/tests/net/bpfjit/Makefile
diff -u src/tests/net/bpfjit/Makefile:1.3 src/tests/net/bpfjit/Makefile:1.4
--- src/tests/net/bpfjit/Makefile:1.3	Tue Jul  8 21:47:22 2014
+++ src/tests/net/bpfjit/Makefile	Wed Jul  9 13:50:48 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2014/07/08 21:47:22 alnsn Exp $
+# $NetBSD: Makefile,v 1.4 2014/07/09 13:50:48 alnsn Exp $
 #
 
 .include bsd.own.mk
@@ -6,6 +6,8 @@
 TESTSDIR=	${TESTSBASE}/net/bpfjit
 
 TESTS_C=	t_bpfjit
+TESTS_C+=	t_cop
+TESTS_C+=	t_extmem
 TESTS_C+=	t_mbuf
 
 LDADD+=		-lrumpnet_bpfjit -lrumpkern_sljit



CVS commit: src/tests/net/bpfjit

2014-07-09 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jul  9 15:56:12 UTC 2014

Modified Files:
src/tests/net/bpfjit: t_cop.c

Log Message:
Fix copy/paste error: s/rump_unschedule/rump_schedule/.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/bpfjit/t_cop.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfjit/t_cop.c
diff -u src/tests/net/bpfjit/t_cop.c:1.1 src/tests/net/bpfjit/t_cop.c:1.2
--- src/tests/net/bpfjit/t_cop.c:1.1	Wed Jul  9 13:49:49 2014
+++ src/tests/net/bpfjit/t_cop.c	Wed Jul  9 15:56:12 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_cop.c,v 1.1 2014/07/09 13:49:49 alnsn Exp $ */
+/*	$NetBSD: t_cop.c,v 1.2 2014/07/09 15:56:12 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_cop.c,v 1.1 2014/07/09 13:49:49 alnsn Exp $);
+__RCSID($NetBSD: t_cop.c,v 1.2 2014/07/09 15:56:12 alnsn Exp $);
 
 #include stdint.h
 #include string.h
@@ -467,7 +467,7 @@ ATF_TC_BODY(bpfjit_copx_ret_buflen, tc)
 
 	ATF_CHECK(code(ctx, args) == sizeof(pkt));
 
-	rump_unschedule();
+	rump_schedule();
 	rumpns_bpfjit_free_code(code);
 	rump_unschedule();
 }



CVS commit: src/sys/net

2014-07-08 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul  8 11:30:31 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Most filter programs in the kernel need 3 scratch registers.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.21 src/sys/net/bpfjit.c:1.22
--- src/sys/net/bpfjit.c:1.21	Sat Jul  5 11:13:13 2014
+++ src/sys/net/bpfjit.c	Tue Jul  8 11:30:31 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.21 2014/07/05 11:13:13 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.22 2014/07/08 11:30:31 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.21 2014/07/05 11:13:13 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.22 2014/07/08 11:30:31 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.21 2014/07/05 11:13:13 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.22 2014/07/08 11:30:31 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -251,6 +251,14 @@ nscratches(bpfjit_hint_t hints)
 {
 	sljit_si rv = 2;
 
+#ifdef _KERNEL
+	/*
+	 * Most kernel programs load packet bytes and they generate
+	 * m_xword/m_xhalf/m_xbyte() calls with three arguments.
+	 */
+	rv = 3;
+#endif
+
 	if (hints  BJ_HINT_LDW)
 		rv = 3; /* uses BJ_TMP2REG */
 



CVS commit: src/tests/lib/libbpfjit

2014-07-08 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul  8 21:07:52 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Rename bpfjit tests to libbpfjit, don't test zero buflen and a couple of
cosmetic changes.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.5 src/tests/lib/libbpfjit/t_bpfjit.c:1.6
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.5	Tue Jun 24 10:53:30 2014
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Tue Jul  8 21:07:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.5 2014/06/24 10:53:30 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.5 2014/06/24 10:53:30 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -56,28 +56,28 @@ unsigned int jitcall(bpfjit_func_t fn,
 	return fn(NULL, args);
 }
 
-ATF_TC(bpfjit_empty);
-ATF_TC_HEAD(bpfjit_empty, tc)
+ATF_TC(libbpfjit_empty);
+ATF_TC_HEAD(libbpfjit_empty, tc)
 {
 	atf_tc_set_md_var(tc, descr,
-	Test that JIT compilation for an empty bpf program fails);
+	Test that JIT compilation of an empty bpf program fails);
 }
 
-ATF_TC_BODY(bpfjit_empty, tc)
+ATF_TC_BODY(libbpfjit_empty, tc)
 {
 	struct bpf_insn dummy;
 
 	ATF_CHECK(bpfjit_generate_code(NULL, dummy, 0) == NULL);
 }
 
-ATF_TC(bpfjit_alu_add_k);
-ATF_TC_HEAD(bpfjit_alu_add_k, tc)
+ATF_TC(libbpfjit_alu_add_k);
+ATF_TC_HEAD(libbpfjit_alu_add_k, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test JIT compilation of BPF_ALU+BPF_ADD+BPF_K);
 }
 
-ATF_TC_BODY(bpfjit_alu_add_k, tc)
+ATF_TC_BODY(libbpfjit_alu_add_k, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 3),
@@ -100,14 +100,14 @@ ATF_TC_BODY(bpfjit_alu_add_k, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_alu_sub_k);
-ATF_TC_HEAD(bpfjit_alu_sub_k, tc)
+ATF_TC(libbpfjit_alu_sub_k);
+ATF_TC_HEAD(libbpfjit_alu_sub_k, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test JIT compilation of BPF_ALU+BPF_SUB+BPF_K);
 }
 
-ATF_TC_BODY(bpfjit_alu_sub_k, tc)
+ATF_TC_BODY(libbpfjit_alu_sub_k, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 1),
@@ -130,14 +130,14 @@ ATF_TC_BODY(bpfjit_alu_sub_k, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_alu_mul_k);
-ATF_TC_HEAD(bpfjit_alu_mul_k, tc)
+ATF_TC(libbpfjit_alu_mul_k);
+ATF_TC_HEAD(libbpfjit_alu_mul_k, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test JIT compilation of BPF_ALU+BPF_MUL+BPF_K);
 }
 
-ATF_TC_BODY(bpfjit_alu_mul_k, tc)
+ATF_TC_BODY(libbpfjit_alu_mul_k, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x)),
@@ -160,14 +160,14 @@ ATF_TC_BODY(bpfjit_alu_mul_k, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_alu_div0_k);
-ATF_TC_HEAD(bpfjit_alu_div0_k, tc)
+ATF_TC(libbpfjit_alu_div0_k);
+ATF_TC_HEAD(libbpfjit_alu_div0_k, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=0);
 }
 
-ATF_TC_BODY(bpfjit_alu_div0_k, tc)
+ATF_TC_BODY(libbpfjit_alu_div0_k, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 0),
@@ -189,14 +189,14 @@ ATF_TC_BODY(bpfjit_alu_div0_k, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_alu_div1_k);
-ATF_TC_HEAD(bpfjit_alu_div1_k, tc)
+ATF_TC(libbpfjit_alu_div1_k);
+ATF_TC_HEAD(libbpfjit_alu_div1_k, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=1);
 }
 
-ATF_TC_BODY(bpfjit_alu_div1_k, tc)
+ATF_TC_BODY(libbpfjit_alu_div1_k, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 7),
@@ -219,14 +219,14 @@ ATF_TC_BODY(bpfjit_alu_div1_k, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_alu_div2_k);
-ATF_TC_HEAD(bpfjit_alu_div2_k, tc)
+ATF_TC(libbpfjit_alu_div2_k);
+ATF_TC_HEAD(libbpfjit_alu_div2_k, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=2);
 }
 
-ATF_TC_BODY(bpfjit_alu_div2_k, tc)
+ATF_TC_BODY(libbpfjit_alu_div2_k, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 7),
@@ -249,14 +249,14 @@ ATF_TC_BODY(bpfjit_alu_div2_k, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_alu_div4_k);
-ATF_TC_HEAD(bpfjit_alu_div4_k, tc)
+ATF_TC(libbpfjit_alu_div4_k);
+ATF_TC_HEAD(libbpfjit_alu_div4_k, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=4);
 }
 
-ATF_TC_BODY(bpfjit_alu_div4_k, tc)
+ATF_TC_BODY(libbpfjit_alu_div4_k, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x)),
@@ -279,14 +279,14 @@ ATF_TC_BODY(bpfjit_alu_div4_k, tc)
 	bpfjit_free_code(code

CVS commit: src/tests/lib/libbpfjit

2014-07-08 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul  8 21:13:01 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_cop.c t_extmem.c

Log Message:
Rename bpfjit tests to libbpfjit.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libbpfjit/t_cop.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libbpfjit/t_extmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_cop.c
diff -u src/tests/lib/libbpfjit/t_cop.c:1.2 src/tests/lib/libbpfjit/t_cop.c:1.3
--- src/tests/lib/libbpfjit/t_cop.c:1.2	Wed Jun 25 18:16:40 2014
+++ src/tests/lib/libbpfjit/t_cop.c	Tue Jul  8 21:13:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_cop.c,v 1.2 2014/06/25 18:16:40 alnsn Exp $ */
+/*	$NetBSD: t_cop.c,v 1.3 2014/07/08 21:13:01 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2013-2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_cop.c,v 1.2 2014/06/25 18:16:40 alnsn Exp $);
+__RCSID($NetBSD: t_cop.c,v 1.3 2014/07/08 21:13:01 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -101,14 +101,14 @@ setARG(const bpf_ctx_t *bc, bpf_args_t *
 	return old;
 }
 
-ATF_TC(bpfjit_cop_no_ctx);
-ATF_TC_HEAD(bpfjit_cop_no_ctx, tc)
+ATF_TC(libbpfjit_cop_no_ctx);
+ATF_TC_HEAD(libbpfjit_cop_no_ctx, tc)
 {
 	atf_tc_set_md_var(tc, descr, Test that bpf program with BPF_COP 
 	instruction isn't valid without a context);
 }
 
-ATF_TC_BODY(bpfjit_cop_no_ctx, tc)
+ATF_TC_BODY(libbpfjit_cop_no_ctx, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_MISC+BPF_COP, 0),
@@ -125,14 +125,14 @@ ATF_TC_BODY(bpfjit_cop_no_ctx, tc)
 	ATF_CHECK(code == NULL);
 }
 
-ATF_TC(bpfjit_cop_ret_A);
-ATF_TC_HEAD(bpfjit_cop_ret_A, tc)
+ATF_TC(libbpfjit_cop_ret_A);
+ATF_TC_HEAD(libbpfjit_cop_ret_A, tc)
 {
 	atf_tc_set_md_var(tc, descr, Test coprocessor function 
 	that returns a content of the A register);
 }
 
-ATF_TC_BODY(bpfjit_cop_ret_A, tc)
+ATF_TC_BODY(libbpfjit_cop_ret_A, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 13),
@@ -158,14 +158,14 @@ ATF_TC_BODY(bpfjit_cop_ret_A, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_cop_ret_buflen);
-ATF_TC_HEAD(bpfjit_cop_ret_buflen, tc)
+ATF_TC(libbpfjit_cop_ret_buflen);
+ATF_TC_HEAD(libbpfjit_cop_ret_buflen, tc)
 {
 	atf_tc_set_md_var(tc, descr, Test coprocessor function 
 	that returns the buflen argument);
 }
 
-ATF_TC_BODY(bpfjit_cop_ret_buflen, tc)
+ATF_TC_BODY(libbpfjit_cop_ret_buflen, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 13),
@@ -191,14 +191,14 @@ ATF_TC_BODY(bpfjit_cop_ret_buflen, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_cop_ret_wirelen);
-ATF_TC_HEAD(bpfjit_cop_ret_wirelen, tc)
+ATF_TC(libbpfjit_cop_ret_wirelen);
+ATF_TC_HEAD(libbpfjit_cop_ret_wirelen, tc)
 {
 	atf_tc_set_md_var(tc, descr, Test coprocessor function 
 	that returns the wirelen argument);
 }
 
-ATF_TC_BODY(bpfjit_cop_ret_wirelen, tc)
+ATF_TC_BODY(libbpfjit_cop_ret_wirelen, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 13),
@@ -224,14 +224,14 @@ ATF_TC_BODY(bpfjit_cop_ret_wirelen, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_cop_ret_nfuncs);
-ATF_TC_HEAD(bpfjit_cop_ret_nfuncs, tc)
+ATF_TC(libbpfjit_cop_ret_nfuncs);
+ATF_TC_HEAD(libbpfjit_cop_ret_nfuncs, tc)
 {
 	atf_tc_set_md_var(tc, descr, Test coprocessor function 
 	that returns nfuncs member of the context argument);
 }
 
-ATF_TC_BODY(bpfjit_cop_ret_nfuncs, tc)
+ATF_TC_BODY(libbpfjit_cop_ret_nfuncs, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 13),
@@ -257,14 +257,14 @@ ATF_TC_BODY(bpfjit_cop_ret_nfuncs, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_cop_side_effect);
-ATF_TC_HEAD(bpfjit_cop_side_effect, tc)
+ATF_TC(libbpfjit_cop_side_effect);
+ATF_TC_HEAD(libbpfjit_cop_side_effect, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test that ABC optimization doesn't skip BPF_COP call);
 }
 
-ATF_TC_BODY(bpfjit_cop_side_effect, tc)
+ATF_TC_BODY(libbpfjit_cop_side_effect, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 13),
@@ -296,14 +296,14 @@ ATF_TC_BODY(bpfjit_cop_side_effect, tc)
 	bpfjit_free_code(code);
 }
 
-ATF_TC(bpfjit_cop_invalid_index);
-ATF_TC_HEAD(bpfjit_cop_invalid_index, tc)
+ATF_TC(libbpfjit_cop_invalid_index);
+ATF_TC_HEAD(libbpfjit_cop_invalid_index, tc)
 {
 	atf_tc_set_md_var(tc, descr,
 	Test that out-of-range coprocessor function fails validation);
 }
 
-ATF_TC_BODY(bpfjit_cop_invalid_index, tc)
+ATF_TC_BODY(libbpfjit_cop_invalid_index, tc)
 {
 	static struct bpf_insn insns[] = {
 		BPF_STMT(BPF_LD+BPF_IMM, 13),
@@ -316,14 +316,14 @@ ATF_TC_BODY(bpfjit_cop_invalid_index, tc
 	ATF_CHECK(bpfjit_generate_code(ctx, insns, insn_count) == NULL);
 }
 
-ATF_TC(bpfjit_copx_no_ctx);
-ATF_TC_HEAD(bpfjit_copx_no_ctx, tc)
+ATF_TC(libbpfjit_copx_no_ctx);
+ATF_TC_HEAD(libbpfjit_copx_no_ctx, tc)
 {
 	atf_tc_set_md_var(tc, descr, Test

CVS commit: src/tests/net/bpfjit

2014-07-08 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul  8 21:45:55 UTC 2014

Added Files:
src/tests/net/bpfjit: t_mbuf.c

Log Message:
Move bpfjit mbuf tests to t_mbuf.c.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/bpfjit/t_mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/bpfjit/t_mbuf.c
diff -u /dev/null src/tests/net/bpfjit/t_mbuf.c:1.1
--- /dev/null	Tue Jul  8 21:45:55 2014
+++ src/tests/net/bpfjit/t_mbuf.c	Tue Jul  8 21:45:55 2014
@@ -0,0 +1,982 @@
+/*	$NetBSD: t_mbuf.c,v 1.1 2014/07/08 21:45:55 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__RCSID($NetBSD: t_mbuf.c,v 1.1 2014/07/08 21:45:55 alnsn Exp $);
+
+#include sys/param.h
+#include sys/mbuf.h
+
+#include net/bpf.h
+#include net/bpfjit.h
+
+#include stdint.h
+#include string.h
+
+#include rump/rump.h
+#include rump/rump_syscalls.h
+
+#include ../../net/bpf/h_bpf.h
+
+/* XXX: atf-c.h has collisions with mbuf */
+#undef m_type
+#undef m_data
+#include atf-c.h
+
+#include ../../h_macros.h
+
+static bool
+test_ldb_abs(size_t split)
+{
+	/* Return a product of all packet bytes. */
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X - 1 */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0),  /* A - P[0]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 1),  /* A - P[1]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 2),  /* A - P[2]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 3),  /* A - P[3]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 4),  /* A - P[4]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_RET+BPF_A, 0), /* ret A  */
+	};
+
+	static unsigned char P[] = { 1, 2, 3, 4, 5 };
+	const unsigned int res = 120;
+	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	if (!prog_validate(insns, insn_count))
+		return false;
+
+	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
+}
+
+static bool
+test_ldh_abs(size_t split)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 0),  /* A - P[0:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A   */
+
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 1),  /* A - P[1:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A   */
+
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 2),  /* A - P[2:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A   */
+
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 3),  /* A - P[3:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_RET+BPF_A, 0), /* ret A*/
+	};
+
+	static unsigned char P[] = { 1, 2, 3, 4, 5 };
+	const unsigned int res = 0x0a0e; /* 10 14 */
+	const size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	if (!prog_validate(insns, insn_count))
+		return false;
+
+	return exec_prog_mchain2(insns, insn_count, P, sizeof(P), split) == res;
+}
+
+static bool
+test_ldw_abs(size_t split)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 0),  /* A - P[0

CVS commit: src

2014-07-08 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul  8 21:47:22 UTC 2014

Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/tests/net/bpfjit: Makefile

Log Message:
Add t_mbuf tests to the build.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.577 -r1.578 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.2 -r1.3 src/tests/net/bpfjit/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.69 src/distrib/sets/lists/debug/mi:1.70
--- src/distrib/sets/lists/debug/mi:1.69	Tue Jul  8 11:13:24 2014
+++ src/distrib/sets/lists/debug/mi	Tue Jul  8 21:47:21 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.69 2014/07/08 11:13:24 martin Exp $
+# $NetBSD: mi,v 1.70 2014/07/08 21:47:21 alnsn Exp $
 
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib
@@ -2131,6 +2131,7 @@
 ./usr/libdata/debug/usr/tests/net/bpf/t_mbuf.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpfilter/t_bpfilter.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpfjit/t_bpfjit.debug		tests-net-debug		debug,atf,sljit,rump
+./usr/libdata/debug/usr/tests/net/bpfjit/t_mbuf.debug		tests-net-debug		debug,atf,sljit,rump
 ./usr/libdata/debug/usr/tests/net/carp/t_basic.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/fdpass/fdpass32.debug		tests-net-debug		debug,atf
 ./usr/libdata/debug/usr/tests/net/fdpass/fdpass64.debug		tests-net-debug		debug,atf

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.577 src/distrib/sets/lists/tests/mi:1.578
--- src/distrib/sets/lists/tests/mi:1.577	Mon Jul  7 19:41:22 2014
+++ src/distrib/sets/lists/tests/mi	Tue Jul  8 21:47:21 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.577 2014/07/07 19:41:22 alnsn Exp $
+# $NetBSD: mi,v 1.578 2014/07/08 21:47:21 alnsn Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -3090,6 +3090,7 @@
 ./usr/tests/net/bpfjit/Atffile		tests-net-tests		atf,sljit,rump
 ./usr/tests/net/bpfjit/Kyuafile		tests-net-tests		atf,sljit,rump,kyua
 ./usr/tests/net/bpfjit/t_bpfjit		tests-net-tests		atf,sljit,rump
+./usr/tests/net/bpfjit/t_mbuf		tests-net-tests		atf,sljit,rump
 ./usr/tests/net/carptests-net-tests
 ./usr/tests/net/carp/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/carp/Kyuafile			tests-net-tests		atf,rump,kyua

Index: src/tests/net/bpfjit/Makefile
diff -u src/tests/net/bpfjit/Makefile:1.2 src/tests/net/bpfjit/Makefile:1.3
--- src/tests/net/bpfjit/Makefile:1.2	Mon Jun 30 21:34:22 2014
+++ src/tests/net/bpfjit/Makefile	Tue Jul  8 21:47:22 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2014/06/30 21:34:22 alnsn Exp $
+# $NetBSD: Makefile,v 1.3 2014/07/08 21:47:22 alnsn Exp $
 #
 
 .include bsd.own.mk
@@ -6,6 +6,7 @@
 TESTSDIR=	${TESTSBASE}/net/bpfjit
 
 TESTS_C=	t_bpfjit
+TESTS_C+=	t_mbuf
 
 LDADD+=		-lrumpnet_bpfjit -lrumpkern_sljit
 LDADD+=		-lrumpdev_bpf -lrumpnet_net -lrumpnet



CVS commit: src/tests/net/bpf

2014-07-07 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jul  7 19:40:28 UTC 2014

Added Files:
src/tests/net/bpf: t_mbuf.c

Log Message:
Add rump tests for checking how bpf_validate() works with mbuf chains.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/bpf/t_mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/bpf/t_mbuf.c
diff -u /dev/null src/tests/net/bpf/t_mbuf.c:1.1
--- /dev/null	Mon Jul  7 19:40:28 2014
+++ src/tests/net/bpf/t_mbuf.c	Mon Jul  7 19:40:28 2014
@@ -0,0 +1,963 @@
+/*	$NetBSD: t_mbuf.c,v 1.1 2014/07/07 19:40:28 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__RCSID($NetBSD: t_mbuf.c,v 1.1 2014/07/07 19:40:28 alnsn Exp $);
+
+#include sys/param.h
+#include sys/mbuf.h
+#include unistd.h
+
+#include net/bpf.h
+
+#include stdint.h
+#include stdio.h
+#include string.h
+
+#include rump/rump.h
+#include rump/rump_syscalls.h
+
+#include ../../net/bpf/h_bpf.h
+
+/* XXX: atf-c.h has collisions with mbuf */
+#undef m_type
+#undef m_data
+#include atf-c.h
+
+#include ../../h_macros.h
+
+static bool
+test_ldb_abs(size_t split)
+{
+	/* Return a product of all packet bytes. */
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X - 1 */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0),  /* A - P[0]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 1),  /* A - P[1]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 2),  /* A - P[2]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 3),  /* A - P[3]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 4),  /* A - P[4]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_RET+BPF_A, 0), /* ret A  */
+	};
+
+	static char P[] = { 1, 2, 3, 4, 5 };
+	const unsigned int res = 120;
+
+	if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
+		return false;
+
+	return interp_prog_mchain2(insns, P, sizeof(P), split) == res;
+}
+
+static bool
+test_ldh_abs(size_t split)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 0),  /* A - P[0:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A   */
+
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 1),  /* A - P[1:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A   */
+
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 2),  /* A - P[2:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A   */
+
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 3),  /* A - P[3:2]  */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X   */
+		BPF_STMT(BPF_RET+BPF_A, 0), /* ret A*/
+	};
+
+	static char P[] = { 1, 2, 3, 4, 5 };
+	const unsigned int res = 0x0a0e; /* 10 14 */
+
+	if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
+		return false;
+
+	return interp_prog_mchain2(insns, P, sizeof(P), split) == res;
+}
+
+static bool
+test_ldw_abs(size_t split)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 0),  /* A - P[0:4] */
+		BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0), /* A - A + X  */
+		BPF_STMT(BPF_MISC

CVS commit: src

2014-07-07 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jul  7 19:41:22 UTC 2014

Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
src/tests/net/bpf: Makefile

Log Message:
Add bpf/t_mbuf test to the build.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.576 -r1.577 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.4 -r1.5 src/tests/net/bpf/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.67 src/distrib/sets/lists/debug/mi:1.68
--- src/distrib/sets/lists/debug/mi:1.67	Sun Jul  6 21:06:48 2014
+++ src/distrib/sets/lists/debug/mi	Mon Jul  7 19:41:22 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.67 2014/07/06 21:06:48 tron Exp $
+# $NetBSD: mi,v 1.68 2014/07/07 19:41:22 alnsn Exp $
 
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib
@@ -2125,6 +2125,7 @@
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_dlvsym.debug		tests-libexec-debug	debug,atf,pic
 ./usr/libdata/debug/usr/tests/net/bpf/t_bpf.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpf/t_div-by-zero.debug		tests-net-debug		debug,atf,rump
+./usr/libdata/debug/usr/tests/net/bpf/t_mbuf.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpfilter/t_bpfilter.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpfjit/t_bpfjit.debug		tests-net-debug		debug,atf,sljit,rump
 ./usr/libdata/debug/usr/tests/net/carp/t_basic.debug		tests-net-debug		debug,atf,rump

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.576 src/distrib/sets/lists/tests/mi:1.577
--- src/distrib/sets/lists/tests/mi:1.576	Tue Jul  1 03:43:09 2014
+++ src/distrib/sets/lists/tests/mi	Mon Jul  7 19:41:22 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.576 2014/07/01 03:43:09 htodd Exp $
+# $NetBSD: mi,v 1.577 2014/07/07 19:41:22 alnsn Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -3081,6 +3081,7 @@
 ./usr/tests/net/bpf/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/bpf/t_bpf		tests-net-tests		atf,rump
 ./usr/tests/net/bpf/t_div-by-zero		tests-net-tests		atf,rump
+./usr/tests/net/bpf/t_mbuf		tests-net-tests		atf,rump
 ./usr/tests/net/bpfilter			tests-net-tests
 ./usr/tests/net/bpfilter/Atffile		tests-net-tests		atf,rump
 ./usr/tests/net/bpfilter/Kyuafile		tests-net-tests		atf,rump,kyua

Index: src/tests/net/bpf/Makefile
diff -u src/tests/net/bpf/Makefile:1.4 src/tests/net/bpf/Makefile:1.5
--- src/tests/net/bpf/Makefile:1.4	Tue Jun 10 04:28:40 2014
+++ src/tests/net/bpf/Makefile	Mon Jul  7 19:41:22 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2014/06/10 04:28:40 he Exp $
+# $NetBSD: Makefile,v 1.5 2014/07/07 19:41:22 alnsn Exp $
 #
 
 .include bsd.own.mk
@@ -7,6 +7,7 @@ TESTSDIR=	${TESTSBASE}/net/bpf
 
 TESTS_C=	t_bpf
 TESTS_C+=	t_div-by-zero
+TESTS_C+=	t_mbuf
 
 LDADD+=		-lrumpnet_shmif
 LDADD+=		-lrumpdev_bpf -lrumpdev -lrumpnet_netinet -lrumpnet_net



CVS commit: src/tests/net/bpf

2014-07-07 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jul  7 19:34:32 UTC 2014

Added Files:
src/tests/net/bpf: h_bpf.h

Log Message:
Add some helper functions for bpf/bpfjit rump tests.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/bpf/h_bpf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/bpf/h_bpf.h
diff -u /dev/null src/tests/net/bpf/h_bpf.h:1.1
--- /dev/null	Mon Jul  7 19:34:32 2014
+++ src/tests/net/bpf/h_bpf.h	Mon Jul  7 19:34:32 2014
@@ -0,0 +1,143 @@
+/*	$NetBSD: h_bpf.h,v 1.1 2014/07/07 19:34:32 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _TESTS_NET_BPF_H_BPF_H_
+#define _TESTS_NET_BPF_H_BPF_H_
+
+#include sys/param.h
+#include sys/mbuf.h
+
+#include net/bpf.h
+#include net/bpfjit.h
+
+#include rump/rump.h
+#include rump/rump_syscalls.h
+
+#include stdint.h
+#include string.h
+
+/* XXX These declarations don't look kosher. */
+int rumpns_bpf_validate(const struct bpf_insn *, int);
+unsigned int rumpns_bpf_filter_ext(const bpf_ctx_t *,
+const struct bpf_insn *, bpf_args_t *);
+bpfjit_func_t rumpns_bpfjit_generate_code(const bpf_ctx_t *,
+const struct bpf_insn *, size_t);
+void rumpns_bpfjit_free_code(bpfjit_func_t);
+
+/*
+ * Init mbuf chain with one or two chunks. The first chunk holds
+ * [pkt, pkt + split] bytes, the second chunk (if it's not empty)
+ * holds (pkt + split, pkt + pktsize) bytes.
+ * The function returns (const uint8_t *)mb1.
+ */
+static inline const uint8_t *
+init_mchain2(struct mbuf *mb1, struct mbuf *mb2,
+char pkt[], size_t pktsize, size_t split)
+{
+
+	(void)memset(mb1, 0, sizeof(*mb1));
+	mb1-m_data = pkt;
+	mb1-m_next = (split  pktsize) ? mb2 : NULL;
+	mb1-m_len = (split  pktsize) ? split : pktsize;
+
+	if (split  pktsize) {
+		(void)memset(mb2, 0, sizeof(*mb2));
+		mb2-m_next = NULL;
+		mb2-m_data = pkt[split];
+		mb2-m_len = pktsize - split;
+	}
+
+	return (const uint8_t*)mb1;
+}
+
+/*
+ * Interpret a filter program with mbuf chain passed to bpf_filter_ext().
+ */
+static inline unsigned int
+interp_prog_mchain2(struct bpf_insn *insns,
+char *pkt, size_t pktsize, size_t split)
+{
+	uint32_t mem[BPF_MEMWORDS];
+	struct mbuf mb1, mb2;
+	bpf_args_t args;
+	unsigned int res;
+
+	args.pkt = init_mchain2(mb1, mb2, pkt, pktsize, split);
+	args.buflen = 0;
+	args.wirelen = pktsize;
+	args.mem = mem;
+
+	rump_schedule();
+	res = rumpns_bpf_filter_ext(NULL, insns, args);
+	rump_unschedule();
+
+	return res;
+}
+
+/*
+ * Compile and run a filter program with mbuf chain passed to compiled function.
+ */
+static inline unsigned int
+exec_prog_mchain2(struct bpf_insn *insns, size_t insn_count,
+char *pkt, size_t pktsize, size_t split)
+{
+	bpfjit_func_t fn;
+	struct mbuf mb1, mb2;
+	bpf_args_t args;
+	unsigned int res;
+
+	args.pkt = init_mchain2(mb1, mb2, pkt, pktsize, split);
+	args.buflen = 0;
+	args.wirelen = pktsize;
+
+	rump_schedule();
+	fn = rumpns_bpfjit_generate_code(NULL, insns, insn_count);
+	rump_unschedule();
+
+	res = fn(NULL, args);
+
+	rump_schedule();
+	rumpns_bpfjit_free_code(fn);
+	rump_unschedule();
+
+	return res;
+}
+
+static inline bool
+prog_validate(struct bpf_insn *insns, size_t insn_count)
+{
+	bool res;
+
+	rump_schedule();
+	res = rumpns_bpf_validate(insns, insn_count);
+	rump_unschedule();
+
+	return res;
+}
+
+#endif /* _TESTS_NET_BPF_H_BPF_H_ */



CVS commit: src/sys/net

2014-07-07 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jul  7 19:56:03 UTC 2014

Modified Files:
src/sys/net: bpf_filter.c

Log Message:
Arithmetic overflow when calculating variable offsets (BPF_LD+BPF_IND
instructions) should be handled uniformly for contiguous buffers and mbufs.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/net/bpf_filter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf_filter.c
diff -u src/sys/net/bpf_filter.c:1.66 src/sys/net/bpf_filter.c:1.67
--- src/sys/net/bpf_filter.c:1.66	Sat Jul  5 22:06:11 2014
+++ src/sys/net/bpf_filter.c	Mon Jul  7 19:56:03 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf_filter.c,v 1.66 2014/07/05 22:06:11 alnsn Exp $	*/
+/*	$NetBSD: bpf_filter.c,v 1.67 2014/07/07 19:56:03 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.66 2014/07/05 22:06:11 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.67 2014/07/07 19:56:03 alnsn Exp $);
 
 #if 0
 #if !(defined(lint) || defined(KERNEL))
@@ -327,13 +327,12 @@ bpf_filter(const struct bpf_insn *pc, co
 
 		case BPF_LD|BPF_W|BPF_IND:
 			k = X + pc-k;
-			if (pc-k  args-buflen ||
-			X  args-buflen - pc-k ||
+			if (k  X || k = args-buflen ||
 			sizeof(int32_t)  args-buflen - k) {
 #ifdef _KERNEL
 int merr;
 
-if (args-buflen != 0)
+if (k  X || args-buflen != 0)
 	return 0;
 A = xword(args-pkt, k, merr);
 if (merr != 0)
@@ -348,13 +347,12 @@ bpf_filter(const struct bpf_insn *pc, co
 
 		case BPF_LD|BPF_H|BPF_IND:
 			k = X + pc-k;
-			if (pc-k  args-buflen ||
-			X  args-buflen - pc-k ||
+			if (k  X || k = args-buflen ||
 			sizeof(int16_t)  args-buflen - k) {
 #ifdef _KERNEL
 int merr;
 
-if (args-buflen != 0)
+if (k  X || args-buflen != 0)
 	return 0;
 A = xhalf(args-pkt, k, merr);
 if (merr != 0)
@@ -369,12 +367,11 @@ bpf_filter(const struct bpf_insn *pc, co
 
 		case BPF_LD|BPF_B|BPF_IND:
 			k = X + pc-k;
-			if (pc-k = args-buflen ||
-			X = args-buflen - pc-k) {
+			if (k  X || k = args-buflen) {
 #ifdef _KERNEL
 int merr;
 
-if (args-buflen != 0)
+if (k  X || args-buflen != 0)
 	return 0;
 A = xbyte(args-pkt, k, merr);
 if (merr != 0)



CVS commit: src/sys/net

2014-07-05 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul  5 11:13:13 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Review some SLJIT_MOV instructions with respect to width.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.20 src/sys/net/bpfjit.c:1.21
--- src/sys/net/bpfjit.c:1.20	Fri Jul  4 21:32:08 2014
+++ src/sys/net/bpfjit.c	Sat Jul  5 11:13:13 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.20 2014/07/04 21:32:08 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.21 2014/07/05 11:13:13 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.20 2014/07/04 21:32:08 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.21 2014/07/05 11:13:13 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.20 2014/07/04 21:32:08 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.21 2014/07/05 11:13:13 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -140,7 +140,7 @@ struct bpfjit_stack
 	bpf_ctx_t *ctx;
 	uint32_t *extmem; /* pointer to external memory store */
 #ifdef _KERNEL
-	void *tmp;
+	int err; /* 3rd argument for m_xword/m_xhalf/m_xbyte function call */
 #endif
 	uint32_t mem[BPF_MEMWORDS]; /* internal memory store */
 };
@@ -243,7 +243,7 @@ bpfjit_modcmd(modcmd_t cmd, void *arg)
 #endif
 
 /*
- * Return a number of scratch regiters to pass
+ * Return a number of scratch registers to pass
  * to sljit_emit_enter() function.
  */
 static sljit_si
@@ -303,7 +303,7 @@ load_buf_buflen(struct sljit_compiler *c
 		return status;
 
 	status = sljit_emit_op1(compiler,
-	SLJIT_MOV,
+	SLJIT_MOV, /* size_t source */
 	BJ_BUFLEN, 0,
 	SLJIT_MEM1(BJ_ARGS),
 	offsetof(struct bpf_args, buflen));
@@ -525,11 +525,6 @@ emit_xcall(struct sljit_compiler *compil
 #endif
 	int status;
 
-	/*
-	 * The third argument of fn is an address on stack.
-	 */
-	const int arg3_offset = offsetof(struct bpfjit_stack, tmp);
-
 	if (BPF_CLASS(pc-code) == BPF_LDX) {
 		/* save A */
 		status = sljit_emit_op1(compiler,
@@ -566,8 +561,12 @@ emit_xcall(struct sljit_compiler *compil
 	if (status != SLJIT_SUCCESS)
 		return status;
 
+	/*
+	 * The third argument of fn is an address on stack.
+	 */
 	status = sljit_get_local_base(compiler,
-	SLJIT_SCRATCH_REG3, 0, arg3_offset);
+	SLJIT_SCRATCH_REG3, 0,
+	offsetof(struct bpfjit_stack, err));
 	if (status != SLJIT_SUCCESS)
 		return status;
 
@@ -600,7 +599,8 @@ emit_xcall(struct sljit_compiler *compil
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UI,
 	SLJIT_SCRATCH_REG3, 0,
-	SLJIT_MEM1(SLJIT_LOCALS_REG), arg3_offset);
+	SLJIT_MEM1(SLJIT_LOCALS_REG),
+	offsetof(struct bpfjit_stack, err));
 	if (status != SLJIT_SUCCESS)
 		return status;
 
@@ -700,7 +700,7 @@ emit_cop(struct sljit_compiler *compiler
 		 * memory addressing.
 		 */
 		status = sljit_emit_op1(compiler,
-		SLJIT_MOV_P,
+		SLJIT_MOV,
 		BJ_COPF_IDX, 0,
 		BJ_XREG, 0);
 		if (status != SLJIT_SUCCESS)
@@ -1708,7 +1708,7 @@ generate_insn_code(struct sljit_compiler
 			/* BPF_LD+BPF_W+BPF_LENA - len */
 			if (pc-code == (BPF_LD|BPF_W|BPF_LEN)) {
 status = sljit_emit_op1(compiler,
-SLJIT_MOV,
+SLJIT_MOV, /* size_t source */
 BJ_AREG, 0,
 SLJIT_MEM1(BJ_ARGS),
 offsetof(struct bpf_args, wirelen));
@@ -1754,7 +1754,7 @@ generate_insn_code(struct sljit_compiler
 if (BPF_SIZE(pc-code) != BPF_W)
 	goto fail;
 status = sljit_emit_op1(compiler,
-SLJIT_MOV,
+SLJIT_MOV, /* size_t source */
 BJ_XREG, 0,
 SLJIT_MEM1(BJ_ARGS),
 offsetof(struct bpf_args, wirelen));



CVS commit: src/sys/net

2014-07-05 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Sat Jul  5 22:06:11 UTC 2014

Modified Files:
src/sys/net: bpf_filter.c

Log Message:
Implement error checking in m_xbyte() and check for errors after m_xbyte() call.
Reuse (len - k) expression in m_xword() and m_xhalf() to give an optimization
hint to a compiler.

When m_xbyte() didn't exist, bpf_filter() handled out-of-bounds BPF_B loads
correctly because return 0 inside MINDEX() was aborting filter programs.
After the change that added m_xbyte() zero values were passed to A or X
registers instead of aborting a filter program.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/net/bpf_filter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf_filter.c
diff -u src/sys/net/bpf_filter.c:1.65 src/sys/net/bpf_filter.c:1.66
--- src/sys/net/bpf_filter.c:1.65	Wed Jun 25 09:51:34 2014
+++ src/sys/net/bpf_filter.c	Sat Jul  5 22:06:11 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf_filter.c,v 1.65 2014/06/25 09:51:34 alnsn Exp $	*/
+/*	$NetBSD: bpf_filter.c,v 1.66 2014/07/05 22:06:11 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.65 2014/06/25 09:51:34 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.66 2014/07/05 22:06:11 alnsn Exp $);
 
 #if 0
 #if !(defined(lint) || defined(KERNEL))
@@ -124,12 +124,12 @@ m_xword(const struct mbuf *m, uint32_t k
 	*err = 1;
 	MINDEX(len, m, k);
 	cp = mtod(m, u_char *) + k;
-	if (len = k + 4) {
+	if (len - k = 4) {
 		*err = 0;
 		return EXTRACT_LONG(cp);
 	}
 	m0 = m-m_next;
-	if (m0 == 0 || m0-m_len + len - k  4)
+	if (m0 == 0 || (len - k) + m0-m_len  4)
 		return 0;
 	*err = 0;
 	np = mtod(m0, u_char *);
@@ -154,7 +154,7 @@ m_xhalf(const struct mbuf *m, uint32_t k
 	*err = 1;
 	MINDEX(len, m, k);
 	cp = mtod(m, u_char *) + k;
-	if (len = k + 2) {
+	if (len - k = 2) {
 		*err = 0;
 		return EXTRACT_SHORT(cp);
 	}
@@ -170,8 +170,9 @@ m_xbyte(const struct mbuf *m, uint32_t k
 {
 	int len;
 
-	*err = 0;
+	*err = 1;
 	MINDEX(len, m, k);
+	*err = 0;
 	return mtod(m, u_char *)[k];
 }
 #else /* _KERNEL */
@@ -306,6 +307,8 @@ bpf_filter(const struct bpf_insn *pc, co
 if (args-buflen != 0)
 	return 0;
 A = xbyte(args-pkt, k, merr);
+if (merr != 0)
+	return 0;
 continue;
 #else
 return 0;
@@ -374,6 +377,8 @@ bpf_filter(const struct bpf_insn *pc, co
 if (args-buflen != 0)
 	return 0;
 A = xbyte(args-pkt, k, merr);
+if (merr != 0)
+	return 0;
 continue;
 #else
 return 0;
@@ -391,6 +396,8 @@ bpf_filter(const struct bpf_insn *pc, co
 if (args-buflen != 0)
 	return 0;
 X = (xbyte(args-pkt, k, merr)  0xf)  2;
+if (merr != 0)
+	return 0;
 continue;
 #else
 return 0;



CVS commit: src/sys/net

2014-07-04 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Fri Jul  4 21:32:08 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Add optimization hints. They replace nscratches and ncopfuncs and improve
readability.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.19 src/sys/net/bpfjit.c:1.20
--- src/sys/net/bpfjit.c:1.19	Tue Jul  1 16:18:55 2014
+++ src/sys/net/bpfjit.c	Fri Jul  4 21:32:08 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.19 2014/07/01 16:18:55 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.20 2014/07/04 21:32:08 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.19 2014/07/01 16:18:55 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.20 2014/07/04 21:32:08 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.19 2014/07/01 16:18:55 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.20 2014/07/04 21:32:08 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -120,6 +120,16 @@ __RCSID($NetBSD: bpfjit.c,v 1.19 2014/0
 #define GET_MEMWORDS(bc) (GET_EXTWORDS(bc) ? GET_EXTWORDS(bc) : BPF_MEMWORDS)
 
 /*
+ * Optimization hints.
+ */
+typedef unsigned int bpfjit_hint_t;
+#define BJ_HINT_LDW  0x01 /* 32-bit packet read  */
+#define BJ_HINT_IND  0x02 /* packet read at a variable offset */
+#define BJ_HINT_COP  0x04 /* BPF_COP or BPF_COPX instruction  */
+#define BJ_HINT_XREG 0x08 /* BJ_XREG is needed   */
+#define BJ_HINT_LDX  0x10 /* BPF_LDX instruction */
+
+/*
  * Datatype for Array Bounds Check Elimination (ABC) pass.
  */
 typedef uint64_t bpfjit_abc_length_t;
@@ -232,6 +242,32 @@ bpfjit_modcmd(modcmd_t cmd, void *arg)
 }
 #endif
 
+/*
+ * Return a number of scratch regiters to pass
+ * to sljit_emit_enter() function.
+ */
+static sljit_si
+nscratches(bpfjit_hint_t hints)
+{
+	sljit_si rv = 2;
+
+	if (hints  BJ_HINT_LDW)
+		rv = 3; /* uses BJ_TMP2REG */
+
+	if (hints  BJ_HINT_COP)
+		rv = 3; /* calls copfunc with three arguments */
+
+	if (hints  BJ_HINT_XREG)
+		rv = 4; /* uses BJ_XREG */
+
+#ifdef _KERNEL
+	if (hints  BJ_HINT_LDX)
+		rv = 5; /* uses BJ_TMP3REG */
+#endif
+
+	return rv;
+}
+
 static uint32_t
 read_width(const struct bpf_insn *pc)
 {
@@ -1163,7 +1199,7 @@ optimize_init(struct bpfjit_insn_data *i
 static bool
 optimize_pass1(const bpf_ctx_t *bc, const struct bpf_insn *insns,
 struct bpfjit_insn_data *insn_dat, size_t insn_count,
-bpf_memword_init_t *initmask, int *nscratches, int *ncopfuncs)
+bpf_memword_init_t *initmask, bpfjit_hint_t *hints)
 {
 	struct bpfjit_jump *jtf;
 	size_t i;
@@ -1174,8 +1210,7 @@ optimize_pass1(const bpf_ctx_t *bc, cons
 
 	const size_t memwords = GET_MEMWORDS(bc);
 
-	*ncopfuncs = 0;
-	*nscratches = 2;
+	*hints = 0;
 	*initmask = BJ_INIT_NOBITS;
 
 	unreachable = false;
@@ -1203,22 +1238,16 @@ optimize_pass1(const bpf_ctx_t *bc, cons
 			continue;
 
 		case BPF_LD:
-			if (BPF_MODE(insns[i].code) == BPF_IND ||
-			BPF_MODE(insns[i].code) == BPF_ABS) {
-if (BPF_MODE(insns[i].code) == BPF_IND 
-*nscratches  4) {
-	/* uses BJ_XREG */
-	*nscratches = 4;
-}
-if (*nscratches  3 
-read_width(insns[i]) == 4) {
-	/* uses BJ_TMP2REG */
-	*nscratches = 3;
-}
+			if ((BPF_MODE(insns[i].code) == BPF_IND ||
+			BPF_MODE(insns[i].code) == BPF_ABS) 
+			read_width(insns[i]) == 4) {
+*hints |= BJ_HINT_LDW;
 			}
 
-			if (BPF_MODE(insns[i].code) == BPF_IND)
+			if (BPF_MODE(insns[i].code) == BPF_IND) {
+*hints |= BJ_HINT_XREG | BJ_HINT_IND;
 *initmask |= invalid  BJ_INIT_XBIT;
+			}
 
 			if (BPF_MODE(insns[i].code) == BPF_MEM 
 			(uint32_t)insns[i].k  memwords) {
@@ -1229,13 +1258,7 @@ optimize_pass1(const bpf_ctx_t *bc, cons
 			continue;
 
 		case BPF_LDX:
-#if defined(_KERNEL)
-			/* uses BJ_TMP3REG */
-			*nscratches = 5;
-#endif
-			/* uses BJ_XREG */
-			if (*nscratches  4)
-*nscratches = 4;
+			*hints |= BJ_HINT_XREG | BJ_HINT_LDX;
 
 			if (BPF_MODE(insns[i].code) == BPF_MEM 
 			(uint32_t)insns[i].k  memwords) {
@@ -1254,10 +1277,7 @@ optimize_pass1(const bpf_ctx_t *bc, cons
 			continue;
 
 		case BPF_STX:
-			/* uses BJ_XREG */
-			if (*nscratches  4)
-*nscratches = 4;
-
+			*hints |= BJ_HINT_XREG;
 			*initmask |= invalid  BJ_INIT_XBIT;
 
 			if ((uint32_t)insns[i].k  memwords)
@@ -1270,11 +1290,8 @@ optimize_pass1(const bpf_ctx_t *bc, cons
 
 			if (insns[i].code != (BPF_ALU|BPF_NEG) 
 			BPF_SRC(insns[i].code) == BPF_X) {
+*hints |= BJ_HINT_XREG;
 *initmask |= invalid  BJ_INIT_XBIT;
-/* uses BJ_XREG */
-if (*nscratches  4)
-	*nscratches = 4;
-
 			}
 
 			invalid = ~BJ_INIT_ABIT;
@@ -1283,35 +1300,23 @@ optimize_pass1(const bpf_ctx_t *bc, cons
 		case BPF_MISC:
 			switch (BPF_MISCOP(insns

CVS commit: src/distrib/sets/lists/debug

2014-07-02 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jul  2 13:38:05 UTC 2014

Modified Files:
src/distrib/sets/lists/debug: md.amd64 md.i386 mi

Log Message:
Move t_bpfjit.debug entries back to mi and add sljit tag to them.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/distrib/sets/lists/debug/md.amd64
cvs rdiff -u -r1.6 -r1.7 src/distrib/sets/lists/debug/md.i386
cvs rdiff -u -r1.65 -r1.66 src/distrib/sets/lists/debug/mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/md.amd64
diff -u src/distrib/sets/lists/debug/md.amd64:1.56 src/distrib/sets/lists/debug/md.amd64:1.57
--- src/distrib/sets/lists/debug/md.amd64:1.56	Wed Jul  2 05:23:20 2014
+++ src/distrib/sets/lists/debug/md.amd64	Wed Jul  2 13:38:05 2014
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.56 2014/07/02 05:23:20 htodd Exp $
+# $NetBSD: md.amd64,v 1.57 2014/07/02 13:38:05 alnsn Exp $
 ./usr/lib/i386/i18n/libBIG5_g.a			comp-c-debuglib		compat,debuglib
 ./usr/lib/i386/i18n/libDECHanyu_g.a		comp-c-debuglib		compat,debuglib
 ./usr/lib/i386/i18n/libEUCTW_g.a		comp-c-debuglib		compat,debuglib
@@ -338,5 +338,3 @@
 ./usr/libdata/debug/usr/libexec/ld.elf_so-i386.debug	comp-sys-debug		debug,compat
 ./usr/libdata/debug/usr/sbin/acpidump.debug	comp-sysutil-debug	debug
 ./usr/libdata/debug/usr/sbin/amldb.debug	comp-sysutil-debug	debug
-./usr/libdata/debug/usr/tests/lib/libbpfjit/t_bpfjit.debug		tests-lib-debug		debug,atf,sljit
-./usr/libdata/debug/usr/tests/net/bpfjit/t_bpfjit.debug		tests-net-debug		debug,atf,rump

Index: src/distrib/sets/lists/debug/md.i386
diff -u src/distrib/sets/lists/debug/md.i386:1.6 src/distrib/sets/lists/debug/md.i386:1.7
--- src/distrib/sets/lists/debug/md.i386:1.6	Wed Jul  2 05:23:20 2014
+++ src/distrib/sets/lists/debug/md.i386	Wed Jul  2 13:38:05 2014
@@ -1,4 +1,4 @@
-# $NetBSD: md.i386,v 1.6 2014/07/02 05:23:20 htodd Exp $
+# $NetBSD: md.i386,v 1.7 2014/07/02 13:38:05 alnsn Exp $
 ./usr/lib/libi386_g.acomp-c-debuglib		debuglib
 ./usr/lib/libm387_g.acomp-c-debuglib		debuglib
 ./usr/lib/libpmc_g.acomp-c-debuglib		debuglib
@@ -17,5 +17,3 @@
 ./usr/libdata/debug/usr/sbin/bad144.debug	comp-sysutil-debug	debug
 ./usr/libdata/debug/usr/sbin/ipwctl.debug	comp-sysutil-debug	debug
 ./usr/libdata/debug/usr/sbin/ndiscvt.debug	comp-sysutil-debug	debug
-./usr/libdata/debug/usr/tests/lib/libbpfjit/t_bpfjit.debug		tests-lib-debug		debug,atf,sljit
-./usr/libdata/debug/usr/tests/net/bpfjit/t_bpfjit.debug

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.65 src/distrib/sets/lists/debug/mi:1.66
--- src/distrib/sets/lists/debug/mi:1.65	Wed Jul  2 05:23:20 2014
+++ src/distrib/sets/lists/debug/mi	Wed Jul  2 13:38:05 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.65 2014/07/02 05:23:20 htodd Exp $
+# $NetBSD: mi,v 1.66 2014/07/02 13:38:05 alnsn Exp $
 
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib
@@ -1774,6 +1774,7 @@
 ./usr/libdata/debug/usr/tests/lib/libbluetooth/t_sdp_match.debug	tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libbluetooth/t_sdp_put.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libbluetooth/t_sdp_set.debug		tests-lib-debug		debug,atf
+./usr/libdata/debug/usr/tests/lib/libbpfjit/t_bpfjit.debug		tests-lib-debug		debug,atf,sljit
 ./usr/libdata/debug/usr/tests/lib/libbpfjit/t_extmem.debug		tests-lib-debug		debug,atf,sljit
 ./usr/libdata/debug/usr/tests/lib/libbpfjit/t_cop.debug			tests-lib-debug		debug,atf,sljit
 ./usr/libdata/debug/usr/tests/lib/libc/c063/t_faccessat.debug		tests-lib-debug		debug,atf
@@ -2124,6 +2125,7 @@
 ./usr/libdata/debug/usr/tests/net/bpf/t_bpf.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpf/t_div-by-zero.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/bpfilter/t_bpfilter.debug		tests-net-debug		debug,atf,rump
+./usr/libdata/debug/usr/tests/net/bpfjit/t_bpfjit.debug		tests-net-debug		debug,atf,sljit,rump
 ./usr/libdata/debug/usr/tests/net/carp/t_basic.debug		tests-net-debug		debug,atf,rump
 ./usr/libdata/debug/usr/tests/net/fdpass/fdpass32.debug		tests-net-debug		debug,atf
 ./usr/libdata/debug/usr/tests/net/fdpass/fdpass64.debug		tests-net-debug		debug,atf



CVS commit: src/sys/net

2014-07-01 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jul  1 16:18:55 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Move the main loop in bpfjit_generate_code() to a new function and make few
small changes.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.18 src/sys/net/bpfjit.c:1.19
--- src/sys/net/bpfjit.c:1.18	Wed Jun 25 13:53:40 2014
+++ src/sys/net/bpfjit.c	Tue Jul  1 16:18:55 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.19 2014/07/01 16:18:55 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.19 2014/07/01 16:18:55 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.19 2014/07/01 16:18:55 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -114,6 +114,12 @@ __RCSID($NetBSD: bpfjit.c,v 1.18 2014/0
 #define BJ_INIT_XBITBJ_INIT_MBIT(MAX_MEMWORDS + 1)
 
 /*
+ * Get a number of memwords and external memwords from a bpf_ctx object.
+ */
+#define GET_EXTWORDS(bc) ((bc) ? (bc)-extwords : 0)
+#define GET_MEMWORDS(bc) (GET_EXTWORDS(bc) ? GET_EXTWORDS(bc) : BPF_MEMWORDS)
+
+/*
  * Datatype for Array Bounds Check Elimination (ABC) pass.
  */
 typedef uint64_t bpfjit_abc_length_t;
@@ -307,7 +313,7 @@ append_jump(struct sljit_jump *jump, str
  * Generate code for BPF_LD+BPF_B+BPF_ABSA - P[k:1].
  */
 static int
-emit_read8(struct sljit_compiler* compiler, uint32_t k)
+emit_read8(struct sljit_compiler *compiler, uint32_t k)
 {
 
 	return sljit_emit_op1(compiler,
@@ -320,7 +326,7 @@ emit_read8(struct sljit_compiler* compil
  * Generate code for BPF_LD+BPF_H+BPF_ABSA - P[k:2].
  */
 static int
-emit_read16(struct sljit_compiler* compiler, uint32_t k)
+emit_read16(struct sljit_compiler *compiler, uint32_t k)
 {
 	int status;
 
@@ -362,7 +368,7 @@ emit_read16(struct sljit_compiler* compi
  * Generate code for BPF_LD+BPF_W+BPF_ABSA - P[k:4].
  */
 static int
-emit_read32(struct sljit_compiler* compiler, uint32_t k)
+emit_read32(struct sljit_compiler *compiler, uint32_t k)
 {
 	int status;
 
@@ -471,7 +477,7 @@ emit_read32(struct sljit_compiler* compi
  *code for BPF_MSH instruction.
  */
 static int
-emit_xcall(struct sljit_compiler* compiler, const struct bpf_insn *pc,
+emit_xcall(struct sljit_compiler *compiler, const struct bpf_insn *pc,
 int dst, sljit_sw dstw, struct sljit_jump **ret0_jump,
 uint32_t (*fn)(const struct mbuf *, uint32_t, int *))
 {
@@ -578,7 +584,7 @@ emit_xcall(struct sljit_compiler* compil
  * Emit code for BPF_COP and BPF_COPX instructions.
  */
 static int
-emit_cop(struct sljit_compiler* compiler, const bpf_ctx_t *bc,
+emit_cop(struct sljit_compiler *compiler, const bpf_ctx_t *bc,
 const struct bpf_insn *pc, struct sljit_jump **ret0_jump)
 {
 #if BJ_XREG == SLJIT_RETURN_REG   || \
@@ -698,7 +704,7 @@ emit_cop(struct sljit_compiler* compiler
  * BPF_LD+BPF_B+BPF_INDA - P[X+k:1]
  */
 static int
-emit_pkt_read(struct sljit_compiler* compiler,
+emit_pkt_read(struct sljit_compiler *compiler,
 const struct bpf_insn *pc, struct sljit_jump *to_mchain_jump,
 struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize)
 {
@@ -832,7 +838,7 @@ emit_pkt_read(struct sljit_compiler* com
 }
 
 static int
-emit_memload(struct sljit_compiler* compiler,
+emit_memload(struct sljit_compiler *compiler,
 sljit_si dst, uint32_t k, size_t extwords)
 {
 	int status;
@@ -860,7 +866,7 @@ emit_memload(struct sljit_compiler* comp
 }
 
 static int
-emit_memstore(struct sljit_compiler* compiler,
+emit_memstore(struct sljit_compiler *compiler,
 sljit_si src, uint32_t k, size_t extwords)
 {
 	int status;
@@ -891,7 +897,7 @@ emit_memstore(struct sljit_compiler* com
  * Generate code for BPF_LDX+BPF_B+BPF_MSHX - 4*(P[k:1]0xf).
  */
 static int
-emit_msh(struct sljit_compiler* compiler,
+emit_msh(struct sljit_compiler *compiler,
 const struct bpf_insn *pc, struct sljit_jump *to_mchain_jump,
 struct sljit_jump ***ret0, size_t *ret0_size, size_t *ret0_maxsize)
 {
@@ -999,7 +1005,7 @@ emit_msh(struct sljit_compiler* compiler
 }
 
 static int
-emit_pow2_division(struct sljit_compiler* compiler, uint32_t k)
+emit_pow2_division(struct sljit_compiler *compiler, uint32_t k)
 {
 	int shift = 0;
 	int status = SLJIT_SUCCESS;
@@ -1036,7 +1042,7 @@ divide(sljit_uw x, sljit_uw y)
  * divt,divw are either SLJIT_IMM,pc-k or BJ_XREG,0.
  */
 static int
-emit_division(struct sljit_compiler* compiler, int divt, sljit_sw divw)
+emit_division(struct sljit_compiler *compiler, int divt, sljit_sw divw

CVS commit: src/tests/net

2014-06-30 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jun 30 21:30:51 UTC 2014

Modified Files:
src/tests/net: Makefile
Added Files:
src/tests/net/bpfjit: Makefile t_bpfjit.c

Log Message:
Add bpfjit kernel tests for loading from mbuf chain.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/net/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/bpfjit/Makefile \
src/tests/net/bpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/Makefile
diff -u src/tests/net/Makefile:1.16 src/tests/net/Makefile:1.17
--- src/tests/net/Makefile:1.16	Tue Mar 18 18:20:44 2014
+++ src/tests/net/Makefile	Mon Jun 30 21:30:51 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.16 2014/03/18 18:20:44 riastradh Exp $
+# $NetBSD: Makefile,v 1.17 2014/06/30 21:30:51 alnsn Exp $
 
 .include bsd.own.mk
 
@@ -7,6 +7,9 @@ TESTSDIR=	${TESTSBASE}/net
 TESTS_SUBDIRS=		fdpass net route sys
 .if (${MKRUMP} != no)
 TESTS_SUBDIRS+=		bpf bpfilter carp icmp if if_loop mpls npf
+.if (${MKSLJIT} != no)
+TESTS_SUBDIRS+=		bpfjit
+.endif
 .endif
 
 .include bsd.test.mk

Added files:

Index: src/tests/net/bpfjit/Makefile
diff -u /dev/null src/tests/net/bpfjit/Makefile:1.1
--- /dev/null	Mon Jun 30 21:30:51 2014
+++ src/tests/net/bpfjit/Makefile	Mon Jun 30 21:30:51 2014
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2014/06/30 21:30:51 alnsn Exp $
+#
+
+.include bsd.own.mk
+
+TESTSDIR=	${TESTSBASE}/kernel/bpfjit
+
+TESTS_C=	t_bpfjit
+
+LDADD+=		-lrumpnet_bpfjit -lrumpkern_sljit
+LDADD+=		-lrumpdev_bpf -lrumpnet_net -lrumpnet
+LDADD+=		-lrump -lrumpuser -lpthread
+
+.include bsd.test.mk
Index: src/tests/net/bpfjit/t_bpfjit.c
diff -u /dev/null src/tests/net/bpfjit/t_bpfjit.c:1.1
--- /dev/null	Mon Jun 30 21:30:51 2014
+++ src/tests/net/bpfjit/t_bpfjit.c	Mon Jun 30 21:30:51 2014
@@ -0,0 +1,664 @@
+/*	$NetBSD: t_bpfjit.c,v 1.1 2014/06/30 21:30:51 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include sys/cdefs.h
+__RCSID($NetBSD: t_bpfjit.c,v 1.1 2014/06/30 21:30:51 alnsn Exp $);
+
+#include sys/param.h
+#include sys/mbuf.h
+#include unistd.h
+
+#include net/bpf.h
+#include net/bpfjit.h
+
+#include stdint.h
+#include stdio.h
+#include string.h
+
+#include rump/rump.h
+#include rump/rump_syscalls.h
+
+/* XXX: atf-c.h has collisions with mbuf */
+#undef m_type
+#undef m_data
+#include atf-c.h
+
+#include ../../h_macros.h
+
+/* XXX These declarations don't look kosher. */
+bpfjit_func_t rumpns_bpfjit_generate_code(const bpf_ctx_t *,
+const struct bpf_insn *, size_t);
+void rumpns_bpfjit_free_code(bpfjit_func_t);
+
+static bool
+test_ldb_abs(size_t split)
+{
+	static char P[] = { 1, 2, 3, 4, 5 };
+
+	/* Return a product of all packet bytes. */
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1), /* X - 1 */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0),  /* A - P[0]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 1),  /* A - P[1]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 2),  /* A - P[2]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 3),  /* A - P[3]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X */
+		BPF_STMT(BPF_MISC+BPF_TAX, 0),  /* X - A */
+
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 4),  /* A - P[4]  */
+		BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0), /* A - A * X

CVS commit: src

2014-06-30 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jun 30 21:32:59 UTC 2014

Modified Files:
src/distrib/sets/lists/tests: mi
src/etc/mtree: NetBSD.dist.tests

Log Message:
Add new net/t_bpfjit test.


To generate a diff of this commit:
cvs rdiff -u -r1.574 -r1.575 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.107 -r1.108 src/etc/mtree/NetBSD.dist.tests

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.574 src/distrib/sets/lists/tests/mi:1.575
--- src/distrib/sets/lists/tests/mi:1.574	Wed Jun 25 19:20:46 2014
+++ src/distrib/sets/lists/tests/mi	Mon Jun 30 21:32:59 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.574 2014/06/25 19:20:46 alnsn Exp $
+# $NetBSD: mi,v 1.575 2014/06/30 21:32:59 alnsn Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -142,6 +142,7 @@
 ./usr/libdata/debug/usr/tests/net	tests-net-debug
 ./usr/libdata/debug/usr/tests/net/bpf	tests-net-debug
 ./usr/libdata/debug/usr/tests/net/bpfiltertests-net-debug
+./usr/libdata/debug/usr/tests/net/bpfjittests-net-debug
 ./usr/libdata/debug/usr/tests/net/carp	tests-net-debug
 ./usr/libdata/debug/usr/tests/net/fdpasstests-net-debug
 ./usr/libdata/debug/usr/tests/net/icmp	tests-net-debug
@@ -3064,6 +3065,10 @@
 ./usr/tests/net/bpfilter/Atffile		tests-net-tests		atf,rump
 ./usr/tests/net/bpfilter/Kyuafile		tests-net-tests		atf,rump,kyua
 ./usr/tests/net/bpfilter/t_bpfilter		tests-net-tests		atf,rump
+./usr/tests/net/bpfjit			tests-net-tests
+./usr/tests/net/bpfjit/Atffile		tests-net-tests		atf,sljit,rump
+./usr/tests/net/bpfjit/Kyuafile		tests-net-tests		atf,sljit,rump,kyua
+./usr/tests/net/bpfjit/t_bpfjit		tests-net-tests		atf,sljit,rump
 ./usr/tests/net/carptests-net-tests
 ./usr/tests/net/carp/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/carp/Kyuafile			tests-net-tests		atf,rump,kyua

Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.107 src/etc/mtree/NetBSD.dist.tests:1.108
--- src/etc/mtree/NetBSD.dist.tests:1.107	Sat May 31 14:36:53 2014
+++ src/etc/mtree/NetBSD.dist.tests	Mon Jun 30 21:32:59 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.107 2014/05/31 14:36:53 christos Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.108 2014/06/30 21:32:59 alnsn Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -128,6 +128,7 @@
 ./usr/libdata/debug/usr/tests/net
 ./usr/libdata/debug/usr/tests/net/bpf
 ./usr/libdata/debug/usr/tests/net/bpfilter
+./usr/libdata/debug/usr/tests/net/bpfjit
 ./usr/libdata/debug/usr/tests/net/carp
 ./usr/libdata/debug/usr/tests/net/fdpass
 ./usr/libdata/debug/usr/tests/net/icmp
@@ -301,6 +302,7 @@
 ./usr/tests/net
 ./usr/tests/net/bpf
 ./usr/tests/net/bpfilter
+./usr/tests/net/bpfjit
 ./usr/tests/net/carp
 ./usr/tests/net/fdpass
 ./usr/tests/net/icmp



CVS commit: src/tests/net/bpfjit

2014-06-30 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jun 30 21:34:22 UTC 2014

Modified Files:
src/tests/net/bpfjit: Makefile

Log Message:
Fix test directory.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/bpfjit/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfjit/Makefile
diff -u src/tests/net/bpfjit/Makefile:1.1 src/tests/net/bpfjit/Makefile:1.2
--- src/tests/net/bpfjit/Makefile:1.1	Mon Jun 30 21:30:51 2014
+++ src/tests/net/bpfjit/Makefile	Mon Jun 30 21:34:22 2014
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.1 2014/06/30 21:30:51 alnsn Exp $
+# $NetBSD: Makefile,v 1.2 2014/06/30 21:34:22 alnsn Exp $
 #
 
 .include bsd.own.mk
 
-TESTSDIR=	${TESTSBASE}/kernel/bpfjit
+TESTSDIR=	${TESTSBASE}/net/bpfjit
 
 TESTS_C=	t_bpfjit
 



CVS commit: src/sys/net

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 09:51:34 UTC 2014

Modified Files:
src/sys/net: bpf_filter.c

Log Message:
Check preinited argument of bpf_set_extmem().


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/net/bpf_filter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf_filter.c
diff -u src/sys/net/bpf_filter.c:1.64 src/sys/net/bpf_filter.c:1.65
--- src/sys/net/bpf_filter.c:1.64	Tue Jun 24 22:27:40 2014
+++ src/sys/net/bpf_filter.c	Wed Jun 25 09:51:34 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf_filter.c,v 1.64 2014/06/24 22:27:40 rmind Exp $	*/
+/*	$NetBSD: bpf_filter.c,v 1.65 2014/06/25 09:51:34 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.64 2014/06/24 22:27:40 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpf_filter.c,v 1.65 2014/06/25 09:51:34 alnsn Exp $);
 
 #if 0
 #if !(defined(lint) || defined(KERNEL))
@@ -79,7 +79,7 @@ bpf_set_cop(bpf_ctx_t *bc, const bpf_cop
 int
 bpf_set_extmem(bpf_ctx_t *bc, size_t nwords, bpf_memword_init_t preinited)
 {
-	if (nwords  BPF_MAX_MEMWORDS) {
+	if (nwords  BPF_MAX_MEMWORDS || (preinited  nwords) != 0) {
 		return EINVAL;
 	}
 	bc-extwords = nwords;



CVS commit: src/sys/net

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 11:13:28 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Use SLJIT_MOV_P to copy extmem pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.15 src/sys/net/bpfjit.c:1.16
--- src/sys/net/bpfjit.c:1.15	Wed Jun 25 01:21:36 2014
+++ src/sys/net/bpfjit.c	Wed Jun 25 11:13:28 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.15 2014/06/25 01:21:36 rmind Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.16 2014/06/25 11:13:28 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.15 2014/06/25 01:21:36 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.16 2014/06/25 11:13:28 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.15 2014/06/25 01:21:36 rmind Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.16 2014/06/25 11:13:28 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -847,7 +847,7 @@ emit_memload(struct sljit_compiler* comp
 	} else {
 		/* copy extmem pointer to the tmp1 register */
 		status = sljit_emit_op1(compiler,
-		SLJIT_MOV_UI,
+		SLJIT_MOV_P,
 		BJ_TMP1REG, 0,
 		SLJIT_MEM1(SLJIT_LOCALS_REG),
 		offsetof(struct bpfjit_stack, extmem));
@@ -875,7 +875,7 @@ emit_memstore(struct sljit_compiler* com
 	} else {
 		/* copy extmem pointer to the tmp1 register */
 		status = sljit_emit_op1(compiler,
-		SLJIT_MOV_UI,
+		SLJIT_MOV_P,
 		BJ_TMP1REG, 0,
 		SLJIT_MEM1(SLJIT_LOCALS_REG),
 		offsetof(struct bpfjit_stack, extmem));



CVS commit: src/sys/net

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 11:58:15 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
New jitcode takes two arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.16 src/sys/net/bpfjit.c:1.17
--- src/sys/net/bpfjit.c:1.16	Wed Jun 25 11:13:28 2014
+++ src/sys/net/bpfjit.c	Wed Jun 25 11:58:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.16 2014/06/25 11:13:28 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.16 2014/06/25 11:13:28 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.16 2014/06/25 11:13:28 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -1650,7 +1650,7 @@ bpfjit_generate_code(const bpf_ctx_t *bc
 #endif
 
 	status = sljit_emit_enter(compiler,
-	3, nscratches, 3, sizeof(struct bpfjit_stack));
+	2, nscratches, 3, sizeof(struct bpfjit_stack));
 	if (status != SLJIT_SUCCESS)
 		goto fail;
 



CVS commit: src/sys/net

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 13:53:40 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Default initialize external memwords.

This change doesn't affect performance of valid bpf kernel programs
because bpf_filter_ext() checks that all memwords are initialized
explicitly.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.17 src/sys/net/bpfjit.c:1.18
--- src/sys/net/bpfjit.c:1.17	Wed Jun 25 11:58:15 2014
+++ src/sys/net/bpfjit.c	Wed Jun 25 13:53:40 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.17 2014/06/25 11:58:15 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.18 2014/06/25 13:53:40 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -1594,6 +1594,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
 	bpf_memword_init_t initmask;
 	int nscratches, ncopfuncs;
 
+	/* memory store location for initial zero initialization */
+	sljit_si mem_reg;
+	sljit_sw mem_off;
+
 	/* a list of jumps to out-of-bound return from a generated function */
 	struct sljit_jump **ret0;
 	size_t ret0_size, ret0_maxsize;
@@ -1665,7 +1669,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
 			goto fail;
 	}
 
-	if (extwords != 0) {
+	if (extwords == 0) {
+		mem_reg = SLJIT_MEM1(SLJIT_LOCALS_REG);
+		mem_off = offsetof(struct bpfjit_stack, mem);
+	} else {
 		/* copy mem argument from bpf_args to bpfjit_stack */
 		status = sljit_emit_op1(compiler,
 		SLJIT_MOV_P,
@@ -1681,11 +1688,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
 		BJ_TMP1REG, 0);
 		if (status != SLJIT_SUCCESS)
 			goto fail;
-	}
 
-	status = load_buf_buflen(compiler);
-	if (status != SLJIT_SUCCESS)
-		goto fail;
+		mem_reg = SLJIT_MEM1(BJ_TMP1REG);
+		mem_off = 0;
+	}
 
 	/*
 	 * Exclude pre-initialised external memory words but keep
@@ -1703,9 +1709,7 @@ bpfjit_generate_code(const bpf_ctx_t *bc
 			/* M[i] = 0; */
 			status = sljit_emit_op1(compiler,
 			SLJIT_MOV_UI,
-			SLJIT_MEM1(SLJIT_LOCALS_REG),
-			offsetof(struct bpfjit_stack, mem) +
-			i * sizeof(uint32_t),
+			mem_reg, mem_off + i * sizeof(uint32_t),
 			SLJIT_IMM, 0);
 			if (status != SLJIT_SUCCESS)
 goto fail;
@@ -1732,6 +1736,10 @@ bpfjit_generate_code(const bpf_ctx_t *bc
 			goto fail;
 	}
 
+	status = load_buf_buflen(compiler);
+	if (status != SLJIT_SUCCESS)
+		goto fail;
+
 	for (i = 0; i  insn_count; i++) {
 		if (insn_dat[i].unreachable)
 			continue;



CVS commit: src/tests/lib/libbpfjit

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 18:04:05 UTC 2014

Added Files:
src/tests/lib/libbpfjit: t_cop.c

Log Message:
Add BPF_COP and BPF_COPX tests.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/lib/libbpfjit/t_cop.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/lib/libbpfjit/t_cop.c
diff -u /dev/null src/tests/lib/libbpfjit/t_cop.c:1.1
--- /dev/null	Wed Jun 25 18:04:05 2014
+++ src/tests/lib/libbpfjit/t_cop.c	Wed Jun 25 18:04:05 2014
@@ -0,0 +1,572 @@
+/*	$NetBSD: t_cop.c,v 1.1 2014/06/25 18:04:05 alnsn Exp $ */
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__RCSID($NetBSD: t_cop.c,v 1.1 2014/06/25 18:04:05 alnsn Exp $);
+
+#include atf-c.h
+#include stdint.h
+#include string.h
+
+#define __BPF_PRIVATE
+#include net/bpf.h
+#include net/bpfjit.h
+
+static uint32_t retA(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t retBL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t retWL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t retNF(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+static uint32_t setARG(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+
+static const bpf_copfunc_t copfuncs[] = {
+	retA,
+	retBL,
+	retWL,
+	retNF,
+	setARG
+};
+
+static const bpf_ctx_t ctx = {
+	.copfuncs = copfuncs,
+	.nfuncs = sizeof(copfuncs) / sizeof(copfuncs[0]),
+	.extwords = 0
+};
+
+static uint32_t
+retA(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return A;
+}
+
+static uint32_t
+retBL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return args-buflen;
+}
+
+static uint32_t
+retWL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return args-wirelen;
+}
+
+static uint32_t
+retNF(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return bc-nfuncs;
+}
+
+/*
+ * COP function with a side effect.
+ */
+static uint32_t
+setARG(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+	bool *arg = (bool *)args-arg;
+	bool old = *arg;
+
+	*arg = true;
+	return old;
+}
+
+ATF_TC(bpfjit_cop_no_ctx);
+ATF_TC_HEAD(bpfjit_cop_no_ctx, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test that bpf program with BPF_COP 
+	instruction isn't valid without a context);
+}
+
+ATF_TC_BODY(bpfjit_cop_no_ctx, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_MISC+BPF_COP, 0),
+		BPF_STMT(BPF_RET+BPF_K, 7)
+	};
+
+	bpfjit_func_t code;
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(!bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(NULL, insns, insn_count);
+	ATF_CHECK(code == NULL);
+}
+
+ATF_TC(bpfjit_cop_ret_A);
+ATF_TC_HEAD(bpfjit_cop_ret_A, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test coprocessor function 
+	that returns a content of the A register);
+}
+
+ATF_TC_BODY(bpfjit_cop_ret_A, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_IMM, 13),
+		BPF_STMT(BPF_MISC+BPF_COP, 0), // retA
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1] = { 0 };
+	bpf_args_t args = {
+		.pkt = pkt,
+		.buflen = sizeof(pkt),
+		.wirelen = sizeof(pkt),
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	code = bpfjit_generate_code(ctx, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(code(ctx, args) == 13);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(bpfjit_cop_ret_buflen);
+ATF_TC_HEAD(bpfjit_cop_ret_buflen, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test coprocessor function 
+	that returns the buflen argument

CVS commit: src/tests/lib/libbpfjit

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 18:04:44 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: Makefile

Log Message:
Add t_cop test.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libbpfjit/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/Makefile
diff -u src/tests/lib/libbpfjit/Makefile:1.3 src/tests/lib/libbpfjit/Makefile:1.4
--- src/tests/lib/libbpfjit/Makefile:1.3	Tue Jun 17 19:26:18 2014
+++ src/tests/lib/libbpfjit/Makefile	Wed Jun 25 18:04:44 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2014/06/17 19:26:18 alnsn Exp $
+# $NetBSD: Makefile,v 1.4 2014/06/25 18:04:44 alnsn Exp $
 
 .include bsd.own.mk
 .include ../../../external/bsd/sljit/Makefile.inc
@@ -6,6 +6,7 @@
 TESTSDIR=	${TESTSBASE}/lib/libbpfjit
 
 TESTS_C+=	t_bpfjit
+TESTS_C+=	t_cop
 
 # XXX this variable doesn't belong to here
 LIBBPFJITDIR!=	cd ${NETBSDSRCDIR}/lib/libbpfjit  ${PRINTOBJDIR}



CVS commit: src/tests/lib/libbpfjit

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 18:16:40 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_cop.c

Log Message:
Fix copyright. These tests are based on tests created in 2013 on github.com.

https://github.com/alnsn/bpfjit , files test/test_cop{,x}.c.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libbpfjit/t_cop.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_cop.c
diff -u src/tests/lib/libbpfjit/t_cop.c:1.1 src/tests/lib/libbpfjit/t_cop.c:1.2
--- src/tests/lib/libbpfjit/t_cop.c:1.1	Wed Jun 25 18:04:05 2014
+++ src/tests/lib/libbpfjit/t_cop.c	Wed Jun 25 18:16:40 2014
@@ -1,7 +1,7 @@
-/*	$NetBSD: t_cop.c,v 1.1 2014/06/25 18:04:05 alnsn Exp $ */
+/*	$NetBSD: t_cop.c,v 1.2 2014/06/25 18:16:40 alnsn Exp $ */
 
 /*-
- * Copyright (c) 2014 Alexander Nasonov.
+ * Copyright (c) 2013-2014 Alexander Nasonov.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_cop.c,v 1.1 2014/06/25 18:04:05 alnsn Exp $);
+__RCSID($NetBSD: t_cop.c,v 1.2 2014/06/25 18:16:40 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h



CVS commit: src/tests/lib/libbpfjit

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 19:13:03 UTC 2014

Added Files:
src/tests/lib/libbpfjit: t_extmem.c

Log Message:
Add external memory tests.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/lib/libbpfjit/t_extmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/lib/libbpfjit/t_extmem.c
diff -u /dev/null src/tests/lib/libbpfjit/t_extmem.c:1.1
--- /dev/null	Wed Jun 25 19:13:03 2014
+++ src/tests/lib/libbpfjit/t_extmem.c	Wed Jun 25 19:13:03 2014
@@ -0,0 +1,479 @@
+/*	$NetBSD: t_extmem.c,v 1.1 2014/06/25 19:13:03 alnsn Exp $ */
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__RCSID($NetBSD: t_extmem.c,v 1.1 2014/06/25 19:13:03 alnsn Exp $);
+
+#include atf-c.h
+#include stdint.h
+#include string.h
+
+#define __BPF_PRIVATE
+#include net/bpf.h
+#include net/bpfjit.h
+
+static uint32_t retM(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A);
+
+static const bpf_copfunc_t copfuncs[] = {
+	retM
+};
+
+static const bpf_ctx_t ctx = {
+	.copfuncs = copfuncs,
+	.nfuncs = sizeof(copfuncs) / sizeof(copfuncs[0]),
+	.extwords = 4,
+	.preinited = BPF_MEMWORD_INIT(0) | BPF_MEMWORD_INIT(3),
+};
+
+static uint32_t
+retM(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+{
+
+	return args-mem[(uintptr_t)args-arg];
+}
+
+
+ATF_TC(bpfjit_extmem_load_default);
+ATF_TC_HEAD(bpfjit_extmem_load_default, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test that external memory 
+	is zero initialized by default);
+}
+
+ATF_TC_BODY(bpfjit_extmem_load_default, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_MEM, 1),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1] = { 0 };
+	uint32_t mem[ctx.extwords];
+
+	/* Pre-inited words. */
+	mem[0] = 0;
+	mem[3] = 3;
+
+	bpf_args_t args = {
+		.pkt = pkt,
+		.buflen = sizeof(pkt),
+		.wirelen = sizeof(pkt),
+		.mem = mem,
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	code = bpfjit_generate_code(ctx, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(code(ctx, args) == 0);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(bpfjit_extmem_load_preinited);
+ATF_TC_HEAD(bpfjit_extmem_load_preinited, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test a load of external 
+	pre-initialized memory);
+}
+
+ATF_TC_BODY(bpfjit_extmem_load_preinited, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_MEM, 3),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1] = { 0 };
+	uint32_t mem[ctx.extwords];
+
+	/* Pre-inited words. */
+	mem[0] = 0;
+	mem[3] = 3;
+
+	bpf_args_t args = {
+		.pkt = pkt,
+		.buflen = sizeof(pkt),
+		.wirelen = sizeof(pkt),
+		.mem = mem,
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	code = bpfjit_generate_code(ctx, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(code(ctx, args) == 3);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(bpfjit_extmem_invalid_load);
+ATF_TC_HEAD(bpfjit_extmem_invalid_load, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test that out-of-range load 
+	fails validation);
+}
+
+ATF_TC_BODY(bpfjit_extmem_invalid_load, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_MEM, 4),
+		BPF_STMT(BPF_RET+BPF_A, 0)
+	};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpfjit_generate_code(ctx, insns, insn_count) == NULL);
+}
+
+ATF_TC(bpfjit_extmem_store);
+ATF_TC_HEAD(bpfjit_extmem_store, tc)
+{
+	atf_tc_set_md_var(tc, descr, Test stores to external memory);
+}
+
+ATF_TC_BODY

CVS commit: src/tests/lib/libbpfjit

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 19:13:27 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: Makefile

Log Message:
Add t_extmem test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libbpfjit/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/Makefile
diff -u src/tests/lib/libbpfjit/Makefile:1.4 src/tests/lib/libbpfjit/Makefile:1.5
--- src/tests/lib/libbpfjit/Makefile:1.4	Wed Jun 25 18:04:44 2014
+++ src/tests/lib/libbpfjit/Makefile	Wed Jun 25 19:13:27 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2014/06/25 18:04:44 alnsn Exp $
+# $NetBSD: Makefile,v 1.5 2014/06/25 19:13:27 alnsn Exp $
 
 .include bsd.own.mk
 .include ../../../external/bsd/sljit/Makefile.inc
@@ -6,6 +6,7 @@
 TESTSDIR=	${TESTSBASE}/lib/libbpfjit
 
 TESTS_C+=	t_bpfjit
+TESTS_C+=	t_extmem
 TESTS_C+=	t_cop
 
 # XXX this variable doesn't belong to here



CVS commit: src/distrib/sets/lists

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 19:20:47 UTC 2014

Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi

Log Message:
Add new libbpfjit tests.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.573 -r1.574 src/distrib/sets/lists/tests/mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.62 src/distrib/sets/lists/debug/mi:1.63
--- src/distrib/sets/lists/debug/mi:1.62	Mon Jun 23 10:53:20 2014
+++ src/distrib/sets/lists/debug/mi	Wed Jun 25 19:20:46 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.62 2014/06/23 10:53:20 shm Exp $
+# $NetBSD: mi,v 1.63 2014/06/25 19:20:46 alnsn Exp $
 
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib
@@ -1775,6 +1775,8 @@
 ./usr/libdata/debug/usr/tests/lib/libbluetooth/t_sdp_put.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libbluetooth/t_sdp_set.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libbpfjit/t_bpfjit.debug		tests-lib-debug		debug,atf,sljit
+./usr/libdata/debug/usr/tests/lib/libbpfjit/t_extmem.debug		tests-lib-debug		debug,atf,sljit
+./usr/libdata/debug/usr/tests/lib/libbpfjit/t_cop.debug			tests-lib-debug		debug,atf,sljit
 ./usr/libdata/debug/usr/tests/lib/libc/c063/t_faccessat.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/c063/t_fchmodat.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/c063/t_fchownat.debug		tests-lib-debug		debug,atf

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.573 src/distrib/sets/lists/tests/mi:1.574
--- src/distrib/sets/lists/tests/mi:1.573	Mon Jun 23 10:53:20 2014
+++ src/distrib/sets/lists/tests/mi	Wed Jun 25 19:20:46 2014
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.573 2014/06/23 10:53:20 shm Exp $
+# $NetBSD: mi,v 1.574 2014/06/25 19:20:46 alnsn Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -2297,6 +2297,8 @@
 ./usr/tests/lib/libbpfjit/Atffile		tests-lib-tests		atf,sljit
 ./usr/tests/lib/libbpfjit/Kyuafile		tests-lib-tests		atf,sljit,kyua
 ./usr/tests/lib/libbpfjit/t_bpfjit		tests-lib-tests		atf,sljit
+./usr/tests/lib/libbpfjit/t_extmem		tests-lib-tests		atf,sljit
+./usr/tests/lib/libbpfjit/t_cop			tests-lib-tests		atf,sljit
 ./usr/tests/lib/libctests-lib-tests
 ./usr/tests/lib/libc/Atffile			tests-lib-tests		atf
 ./usr/tests/lib/libc/Kyuafile			tests-lib-tests		atf,kyua



CVS commit: src/sys/net

2014-06-25 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 25 19:32:37 UTC 2014

Modified Files:
src/sys/net: bpfjit.h

Log Message:
Fix copyright years.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/net/bpfjit.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.h
diff -u src/sys/net/bpfjit.h:1.3 src/sys/net/bpfjit.h:1.4
--- src/sys/net/bpfjit.h:1.3	Tue Jun 24 10:53:30 2014
+++ src/sys/net/bpfjit.h	Wed Jun 25 19:32:37 2014
@@ -1,7 +1,7 @@
-/*	$NetBSD: bpfjit.h,v 1.3 2014/06/24 10:53:30 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.h,v 1.4 2014/06/25 19:32:37 alnsn Exp $	*/
 
 /*-
- * Copyright (c) 2011-2012,2014 Alexander Nasonov.
+ * Copyright (c) 2011-2014 Alexander Nasonov.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without



CVS commit: src/sys/net/npf

2014-06-24 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 24 11:31:49 UTC 2014

Modified Files:
src/sys/net/npf: npf_bpf.c

Log Message:
Fix signatures of copfuncs.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/net/npf/npf_bpf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/npf/npf_bpf.c
diff -u src/sys/net/npf/npf_bpf.c:1.6 src/sys/net/npf/npf_bpf.c:1.7
--- src/sys/net/npf/npf_bpf.c:1.6	Fri Dec  6 01:33:37 2013
+++ src/sys/net/npf/npf_bpf.c	Tue Jun 24 11:31:49 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_bpf.c,v 1.6 2013/12/06 01:33:37 rmind Exp $	*/
+/*	$NetBSD: npf_bpf.c,v 1.7 2014/06/24 11:31:49 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: npf_bpf.c,v 1.6 2013/12/06 01:33:37 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: npf_bpf.c,v 1.7 2014/06/24 11:31:49 alnsn Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -51,8 +51,8 @@ __KERNEL_RCSID(0, $NetBSD: npf_bpf.c,v 
 
 static bpf_ctx_t *npf_bpfctx __read_mostly;
 
-static uint32_t	npf_cop_l3(bpf_ctx_t *, bpf_args_t *, uint32_t);
-static uint32_t	npf_cop_table(bpf_ctx_t *, bpf_args_t *, uint32_t);
+static uint32_t	npf_cop_l3(const bpf_ctx_t *, bpf_args_t *, uint32_t);
+static uint32_t	npf_cop_table(const bpf_ctx_t *, bpf_args_t *, uint32_t);
 
 static const bpf_copfunc_t npf_bpfcop[] = {
 	[NPF_COP_L3]	= npf_cop_l3,
@@ -112,7 +112,7 @@ npf_bpf_validate(const void *code, size_
  *	BPF_MW_L4PROTO	L4 protocol.
  */
 static uint32_t
-npf_cop_l3(bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+npf_cop_l3(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
 {
 	const npf_cache_t * const npc = (const npf_cache_t *)args-arg;
 	uint32_t * const M = args-mem;
@@ -144,7 +144,7 @@ npf_cop_l3(bpf_ctx_t *bc, bpf_args_t *ar
  *	A - non-zero (true) if found and zero (false) otherwise
  */
 static uint32_t
-npf_cop_table(bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
+npf_cop_table(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A)
 {
 	const npf_cache_t * const npc = (const npf_cache_t *)args-arg;
 	npf_tableset_t *tblset = npf_config_tableset();



CVS commit: src/tests/net/bpfilter

2014-06-24 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 24 11:32:36 UTC 2014

Modified Files:
src/tests/net/bpfilter: t_bpfilter.c

Log Message:
Zap trailing spaces.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/net/bpfilter/t_bpfilter.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/bpfilter/t_bpfilter.c
diff -u src/tests/net/bpfilter/t_bpfilter.c:1.7 src/tests/net/bpfilter/t_bpfilter.c:1.8
--- src/tests/net/bpfilter/t_bpfilter.c:1.7	Wed Dec 18 22:39:16 2013
+++ src/tests/net/bpfilter/t_bpfilter.c	Tue Jun 24 11:32:36 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfilter.c,v 1.7 2013/12/18 22:39:16 alnsn Exp $	*/
+/*	$NetBSD: t_bpfilter.c,v 1.8 2014/06/24 11:32:36 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfilter.c,v 1.7 2013/12/18 22:39:16 alnsn Exp $);
+__RCSID($NetBSD: t_bpfilter.c,v 1.8 2014/06/24 11:32:36 alnsn Exp $);
 
 #include sys/param.h
 #include sys/ioctl.h
@@ -178,8 +178,8 @@ pingtest(const char *dst, unsigned int w
 
 	memcpy(pkt + pktsize - 7, tail, 7);
 	icmp-icmp_type = ICMP_ECHO;
-	icmp-icmp_id = htons(37); 
-	icmp-icmp_seq = htons(1); 
+	icmp-icmp_id = htons(37);
+	icmp-icmp_seq = htons(1);
 	icmp-icmp_cksum = in_cksum(pkt, pktsize);
 
 	slen = sizeof(sin);



CVS commit: src/sys/rump/include/rump

2014-06-18 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Wed Jun 18 19:50:32 UTC 2014

Modified Files:
src/sys/rump/include/rump: rumpuser.h

Log Message:
Revert last change. This is not the right place for rumpuser_sync_icache().


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/rump/include/rump/rumpuser.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/include/rump/rumpuser.h
diff -u src/sys/rump/include/rump/rumpuser.h:1.112 src/sys/rump/include/rump/rumpuser.h:1.113
--- src/sys/rump/include/rump/rumpuser.h:1.112	Tue Jun 17 06:31:47 2014
+++ src/sys/rump/include/rump/rumpuser.h	Wed Jun 18 19:50:32 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.h,v 1.112 2014/06/17 06:31:47 alnsn Exp $	*/
+/*	$NetBSD: rumpuser.h,v 1.113 2014/06/18 19:50:32 alnsn Exp $	*/
 
 /*
  * Copyright (c) 2007-2013 Antti Kantee.  All Rights Reserved.
@@ -229,11 +229,6 @@ typedef void (*rump_compload_fn)(const s
 void rumpuser_dl_bootstrap(rump_modinit_fn, rump_symload_fn, rump_compload_fn);
 
 /*
- * cache management
- */
-int rumpuser_sync_icache(void *addr, uint64_t len);
-
-/*
  * misc management
  */
 



CVS commit: src

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 06:31:47 UTC 2014

Modified Files:
src/lib/librumpuser: Makefile
src/sys/rump/include/rump: rumpuser.h
src/sys/rump/librump/rumpkern/arch/arm: Makefile.inc
Added Files:
src/lib/librumpuser: rumpuser_cache.c
src/sys/rump/librump/rumpkern/arch/arm: cpufunc.c

Log Message:
Implement rumpuser_sync_icache hypercall.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/librumpuser/Makefile
cvs rdiff -u -r0 -r1.1 src/lib/librumpuser/rumpuser_cache.c
cvs rdiff -u -r1.111 -r1.112 src/sys/rump/include/rump/rumpuser.h
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/sys/rump/librump/rumpkern/arch/arm/cpufunc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/Makefile
diff -u src/lib/librumpuser/Makefile:1.16 src/lib/librumpuser/Makefile:1.17
--- src/lib/librumpuser/Makefile:1.16	Thu Feb 20 00:42:27 2014
+++ src/lib/librumpuser/Makefile	Tue Jun 17 06:31:47 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.16 2014/02/20 00:42:27 pooka Exp $
+#	$NetBSD: Makefile,v 1.17 2014/06/17 06:31:47 alnsn Exp $
 #
 
 .include bsd.own.mk
@@ -20,6 +20,7 @@ CPPFLAGS+=	-DLIBRUMPUSER
 SRCS=		rumpuser.c
 SRCS+=		rumpuser_pth.c
 SRCS+=		rumpuser_component.c rumpuser_bio.c
+SRCS+=		rumpuser_cache.c
 
 SRCS+=		rumpuser_errtrans.c rumpuser_sigtrans.c
 

Index: src/sys/rump/include/rump/rumpuser.h
diff -u src/sys/rump/include/rump/rumpuser.h:1.111 src/sys/rump/include/rump/rumpuser.h:1.112
--- src/sys/rump/include/rump/rumpuser.h:1.111	Sun Apr 27 15:18:59 2014
+++ src/sys/rump/include/rump/rumpuser.h	Tue Jun 17 06:31:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.h,v 1.111 2014/04/27 15:18:59 pooka Exp $	*/
+/*	$NetBSD: rumpuser.h,v 1.112 2014/06/17 06:31:47 alnsn Exp $	*/
 
 /*
  * Copyright (c) 2007-2013 Antti Kantee.  All Rights Reserved.
@@ -229,6 +229,11 @@ typedef void (*rump_compload_fn)(const s
 void rumpuser_dl_bootstrap(rump_modinit_fn, rump_symload_fn, rump_compload_fn);
 
 /*
+ * cache management
+ */
+int rumpuser_sync_icache(void *addr, uint64_t len);
+
+/*
  * misc management
  */
 

Index: src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc
diff -u src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc:1.2 src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc:1.3
--- src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc:1.2	Wed Feb 12 22:28:43 2014
+++ src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc	Tue Jun 17 06:31:47 2014
@@ -1,7 +1,9 @@
-# $NetBSD: Makefile.inc,v 1.2 2014/02/12 22:28:43 pooka Exp $
+# $NetBSD: Makefile.inc,v 1.3 2014/06/17 06:31:47 alnsn Exp $
 
 CPPFLAGS+=	-DARCH_ELFSIZE=32
 
+SRCS+=		cpufunc.c
+
 .PATH:  ${RUMPTOP}/../arch/arm/arm32
 SRCS+=  	kobj_machdep.c
 

Added files:

Index: src/lib/librumpuser/rumpuser_cache.c
diff -u /dev/null src/lib/librumpuser/rumpuser_cache.c:1.1
--- /dev/null	Tue Jun 17 06:31:47 2014
+++ src/lib/librumpuser/rumpuser_cache.c	Tue Jun 17 06:31:47 2014
@@ -0,0 +1,61 @@
+/*	$NetBSD: rumpuser_cache.c,v 1.1 2014/06/17 06:31:47 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include rumpuser_port.h
+
+#if !defined(lint)
+__RCSID($NetBSD: rumpuser_cache.c,v 1.1 2014/06/17 06:31:47 alnsn Exp $);
+#endif /* !lint */
+
+#include sys/types.h
+
+#include machine/sysarch.h
+#include machine/types.h
+
+#include rump/rumpuser.h
+
+
+int
+rumpuser_sync_icache(void *addr, uint64_t len)
+{
+#if defined(__arm__)
+	/*
+	 * arm_sync_icache is recommended over sysarch but
+	 * it adds a link dependency -l

CVS commit: src/tests/lib

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 06:36:01 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: Makefile
src/tests/lib/libsljit: Makefile

Log Message:
Link with -l${MACHINE_CPU}.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libbpfjit/Makefile
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libsljit/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/Makefile
diff -u src/tests/lib/libbpfjit/Makefile:1.1 src/tests/lib/libbpfjit/Makefile:1.2
--- src/tests/lib/libbpfjit/Makefile:1.1	Sun Nov 11 17:37:34 2012
+++ src/tests/lib/libbpfjit/Makefile	Tue Jun 17 06:36:01 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2012/11/11 17:37:34 alnsn Exp $
+# $NetBSD: Makefile,v 1.2 2014/06/17 06:36:01 alnsn Exp $
 
 .include bsd.own.mk
 .include ../../../external/bsd/sljit/Makefile.inc
@@ -16,6 +16,9 @@ DPADD+=		${LIBBPFJITDIR}/libbpfjit.a
 LDADD+=		-L${LIBSLJITDIR} -lsljit
 DPADD+=		${LIBSLJITDIR}/libsljit.a
 
+# I-cache sync routines for arm and mips
+LDADD+=		-l${MACHINE_CPU}
+
 LDADD+=		${LIBPCAP}
 
 .include bsd.test.mk

Index: src/tests/lib/libsljit/Makefile
diff -u src/tests/lib/libsljit/Makefile:1.1 src/tests/lib/libsljit/Makefile:1.2
--- src/tests/lib/libsljit/Makefile:1.1	Mon Nov  5 00:34:28 2012
+++ src/tests/lib/libsljit/Makefile	Tue Jun 17 06:36:01 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2012/11/05 00:34:28 alnsn Exp $
+# $NetBSD: Makefile,v 1.2 2014/06/17 06:36:01 alnsn Exp $
 
 TESTSDIR=	${TESTSBASE}/lib/libsljit
 
@@ -20,4 +20,7 @@ WARNS=		3
 LDADD+=		-L${LIBSLJITDIR} -lsljit
 DPADD+=		${LIBSLJITDIR}/libsljit.a
 
+# I-cache sync routines for arm and mips
+LDADD+=		-l${MACHINE_CPU}
+
 .include bsd.test.mk



CVS commit: src

2014-06-17 Thread Alexander Nasonov
/sys/arch/evbarm/include/Makefile	Tue Jun 17 06:36:40 2014
@@ -1,7 +1,7 @@
-#	$NetBSD: Makefile,v 1.20 2013/05/02 03:56:40 matt Exp $
+#	$NetBSD: Makefile,v 1.21 2014/06/17 06:36:40 alnsn Exp $
 
 INCSDIR=	/usr/include/evbarm
 
-INCS=
+INCS=		sljitarch.h
 
 .include ../../arm/include/Makefile.common

Index: src/sys/arch/hpcarm/include/Makefile
diff -u src/sys/arch/hpcarm/include/Makefile:1.29 src/sys/arch/hpcarm/include/Makefile:1.30
--- src/sys/arch/hpcarm/include/Makefile:1.29	Thu May  2 03:56:41 2013
+++ src/sys/arch/hpcarm/include/Makefile	Tue Jun 17 06:36:40 2014
@@ -1,6 +1,6 @@
-#	$NetBSD: Makefile,v 1.29 2013/05/02 03:56:41 matt Exp $
+#	$NetBSD: Makefile,v 1.30 2014/06/17 06:36:40 alnsn Exp $
 
 INCSDIR=	/usr/include/hpcarm
-INCS=
+INCS=		sljitarch.h
 
 .include ../../arm/include/Makefile.common

Index: src/sys/arch/iyonix/include/Makefile
diff -u src/sys/arch/iyonix/include/Makefile:1.9 src/sys/arch/iyonix/include/Makefile:1.10
--- src/sys/arch/iyonix/include/Makefile:1.9	Thu May  2 03:56:41 2013
+++ src/sys/arch/iyonix/include/Makefile	Tue Jun 17 06:36:40 2014
@@ -1,6 +1,6 @@
-#	$NetBSD: Makefile,v 1.9 2013/05/02 03:56:41 matt Exp $
+#	$NetBSD: Makefile,v 1.10 2014/06/17 06:36:40 alnsn Exp $
 
 INCSDIR=	/usr/include/iyonix
-INCS=
+INCS=		sljitarch.h
 
 .include ../../arm/include/Makefile.common

Index: src/sys/arch/zaurus/include/Makefile
diff -u src/sys/arch/zaurus/include/Makefile:1.9 src/sys/arch/zaurus/include/Makefile:1.10
--- src/sys/arch/zaurus/include/Makefile:1.9	Thu May  2 03:56:41 2013
+++ src/sys/arch/zaurus/include/Makefile	Tue Jun 17 06:36:40 2014
@@ -1,6 +1,6 @@
-#	$NetBSD: Makefile,v 1.9 2013/05/02 03:56:41 matt Exp $
+#	$NetBSD: Makefile,v 1.10 2014/06/17 06:36:40 alnsn Exp $
 
 INCSDIR=	/usr/include/zaurus
-INCS=
+INCS=		sljitarch.h
 
 .include ../../arm/include/Makefile.common

Added files:

Index: src/sys/arch/arm/include/sljitarch.h
diff -u /dev/null src/sys/arch/arm/include/sljitarch.h:1.1
--- /dev/null	Tue Jun 17 06:36:40 2014
+++ src/sys/arch/arm/include/sljitarch.h	Tue Jun 17 06:36:39 2014
@@ -0,0 +1,59 @@
+/*	$NetBSD: sljitarch.h,v 1.1 2014/06/17 06:36:39 alnsn Exp $	*/
+
+/*-
+ * Copyright (c) 2014 Alexander Nasonov.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_SLJITARCH_H
+#define _ARM_SLJITARCH_H
+
+#include sys/cdefs.h
+
+#ifdef _KERNEL
+#include machine/types.h
+#include arm/cpufunc.h
+#else
+#include stddef.h
+#include stdint.h
+#include arm/sysarch.h
+#endif
+
+#if defined(_ARM_ARCH_T2)
+#define SLJIT_CONFIG_ARM_THUMB2 1
+#elif defined(_ARM_ARCH_7)
+#define SLJIT_CONFIG_ARM_V7 1
+#else
+#define SLJIT_CONFIG_ARM_V5 1
+#endif
+
+#ifdef _KERNEL
+#define SLJIT_CACHE_FLUSH(from, to) \
+	cpu_icache_sync_range((vaddr_t)(from), (vsize_t)((to) - (from)))
+#else
+#define SLJIT_CACHE_FLUSH(from, to) \
+	(void)arm_sync_icache((uintptr_t)(from), (size_t)(to - from))
+#endif
+
+#endif

Index: src/sys/arch/evbarm/include/sljitarch.h
diff -u /dev/null src/sys/arch/evbarm/include/sljitarch.h:1.1
--- /dev/null	Tue Jun 17 06:36:40 2014
+++ src/sys/arch/evbarm/include/sljitarch.h	Tue Jun 17 06:36:40 2014
@@ -0,0 +1,3 @@
+/*	$NetBSD: sljitarch.h,v 1.1 2014/06/17 06:36:40 alnsn Exp $	*/
+
+#include arm/sljitarch.h

Index: src/sys/arch/hpcarm/include/sljitarch.h
diff -u /dev/null src/sys/arch/hpcarm/include/sljitarch.h:1.1
--- /dev/null	Tue Jun 17 06:36:40 2014
+++ src/sys/arch/hpcarm/include/sljitarch.h	Tue Jun 17 06:36:40 2014
@@ -0,0 +1,3 @@
+/*	$NetBSD: sljitarch.h,v 1.1 2014/06/17 06:36:40 alnsn Exp $	*/
+
+#include arm/sljitarch.h

Index: src/sys/arch/iyonix/include/sljitarch.h
diff -u /dev/null src/sys/arch/iyonix/include/sljitarch.h:1.1
--- /dev/null	Tue Jun 17 06:36:40 2014

CVS commit: src/lib/librumpuser

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 06:43:21 UTC 2014

Modified Files:
src/lib/librumpuser: rumpuser_pth_dummy.c

Log Message:
For consistency with other files in the same directory
don't include sys/cdefs.h before __RCSID.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/librumpuser/rumpuser_pth_dummy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/rumpuser_pth_dummy.c
diff -u src/lib/librumpuser/rumpuser_pth_dummy.c:1.16 src/lib/librumpuser/rumpuser_pth_dummy.c:1.17
--- src/lib/librumpuser/rumpuser_pth_dummy.c:1.16	Wed May 15 14:52:49 2013
+++ src/lib/librumpuser/rumpuser_pth_dummy.c	Tue Jun 17 06:43:21 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser_pth_dummy.c,v 1.16 2013/05/15 14:52:49 pooka Exp $	*/
+/*	$NetBSD: rumpuser_pth_dummy.c,v 1.17 2014/06/17 06:43:21 alnsn Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -27,9 +27,8 @@
 
 #include rumpuser_port.h
 
-#include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: rumpuser_pth_dummy.c,v 1.16 2013/05/15 14:52:49 pooka Exp $);
+__RCSID($NetBSD: rumpuser_pth_dummy.c,v 1.17 2014/06/17 06:43:21 alnsn Exp $);
 #endif /* !lint */
 
 #include sys/time.h



CVS commit: src/lib/librumpuser

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 08:42:35 UTC 2014

Modified Files:
src/lib/librumpuser: Makefile

Log Message:
Antti objected to including rumpuser_sync_icache. Exclude it from the build.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/librumpuser/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/Makefile
diff -u src/lib/librumpuser/Makefile:1.17 src/lib/librumpuser/Makefile:1.18
--- src/lib/librumpuser/Makefile:1.17	Tue Jun 17 06:31:47 2014
+++ src/lib/librumpuser/Makefile	Tue Jun 17 08:42:35 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.17 2014/06/17 06:31:47 alnsn Exp $
+#	$NetBSD: Makefile,v 1.18 2014/06/17 08:42:35 alnsn Exp $
 #
 
 .include bsd.own.mk
@@ -20,7 +20,6 @@ CPPFLAGS+=	-DLIBRUMPUSER
 SRCS=		rumpuser.c
 SRCS+=		rumpuser_pth.c
 SRCS+=		rumpuser_component.c rumpuser_bio.c
-SRCS+=		rumpuser_cache.c
 
 SRCS+=		rumpuser_errtrans.c rumpuser_sigtrans.c
 



CVS commit: src/sys/rump/librump/rumpkern/arch/arm

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 08:50:49 UTC 2014

Modified Files:
src/sys/rump/librump/rumpkern/arch/arm: Makefile.inc

Log Message:
Antti objected to including rumpuser_sync_icache. Exclude it from the build.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc
diff -u src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc:1.3 src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc:1.4
--- src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc:1.3	Tue Jun 17 06:31:47 2014
+++ src/sys/rump/librump/rumpkern/arch/arm/Makefile.inc	Tue Jun 17 08:50:48 2014
@@ -1,9 +1,7 @@
-# $NetBSD: Makefile.inc,v 1.3 2014/06/17 06:31:47 alnsn Exp $
+# $NetBSD: Makefile.inc,v 1.4 2014/06/17 08:50:48 alnsn Exp $
 
 CPPFLAGS+=	-DARCH_ELFSIZE=32
 
-SRCS+=		cpufunc.c
-
 .PATH:  ${RUMPTOP}/../arch/arm/arm32
 SRCS+=  	kobj_machdep.c
 



CVS import: src/sys/external/bsd/sljit/dist

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 15:37:44 UTC 2014

Update of /cvsroot/src/sys/external/bsd/sljit/dist
In directory ivanova.netbsd.org:/tmp/cvs-serv17842

Log Message:
Import sljit 0.91 (svn r257).

The changes since the last import are:

r257: Add missing ADJUST_LOCAL_OFFSET for ARM64.
r256: Move incorrectly placed array definitions.
r255: More work on testing environment.
r254: Refactor test default output.
r253: Pass entry adress in r12 on PPC-LE.
r252: Optimize calls on MIPS-64.
r251: Several minor fixes.
r250: Add missing SLJIT_IS_FPU_AVAILABLE checks and reorder U and S flags.
r249: Optimize jumps on ARM-64.
r248: Optimize jumps on PowerPC.
r247: MIPS64 support is mostly finished.
r246: MIPS arithmetic.
r245: Start working on MIPS64.
r244: Uniform names for TILE-Gx.
r243: Uniform the names of ARM compilers.
r242: Change ll to l on x86 and rename some instructions on ARM-64.
r241: Improved memory access in PPC and reordering the parameter type flags.
r240: Prepare for more registers on ARM-Thumb2 and renaming TMP_REGISTER to 
TMP_REG1 on x86.
r239: Prepare for more registers on ARMv5.
r238: Prepare for more registers on TILE-Gx.
r237: Prepare for more registers on MIPS and SPARC.
r236: Prepare for more registers on PPC.
r235: Prepare for more registers on x86.
r234: Most tests are pass on ARM-64 now.
r233: Around 25 test cases are now pass on ARM-64.
r232: More progress on ARM-64 and Thumb2 refactoring.
r231: Some progress an ARM-64 and ARM-T2 refactoring.
r230: Thumb2 code refactoring.
r229: Start working on ARM-64.
r228: Little endian PowerPC systems are supported now by the JIT compiler.
r227: TileGX architecture is now supported. Patch made by Jiong Wang.
r226: Cache flush for android. Patch by  Giuseppe D'Angelo.
r225: Add support for forcibly freeing unused executable memory. Inspired by 
Carsten Klein.
r224: Few typo fixes.
r223: Reorder madvise and posix_madvise.
r222: The missing sljit_get_float_register_index function is added.
r221: Remove an invalid shift on ARM.
r220: JIT compiler now supports 32 bit Macs thanks to Lawrence Velazquez.
r219: Better code size statistics.
r218: Improvements for x86 and LIR dump.
r217: ICC and SunPro C fixes
r216: A new file for tracking internal changes are added.
r215: Less GNU dependnet Makefile and Intel style assemby for x86-64 systems.
r214: Switch from stdcall to cdecl in x86-32.
r213: Upstreaming minor fixes. Thanks for Daniel Richard G.
r212: Documentation update and a fix for a locking issue.
r211: Renaming temporaries to scratches to match the new name of the register. 
Does not affect compatibility.
r210: Improving assertions.
r209: Port sljit to SunPro C compiler. Patch by Daniel Richard G.
r208: SLJIT_TEMPORARY_REGx registers are renamed to SLJIT_SCRATCH_REGx.
r207: Removing unused checks.
r206: Optimizations for arm.
r205: Some optimizations on powerpc, mips and sparc.
r204: Rename sljit_emit_cond_value to sljit_emit_op_flags.
r203: Small x86 optimization.
r202: Finish cond_value with AND and INT_OP.
r201: More x86 fixes and improvements.
r200: Rename buf and code to inst.
r199: Replacing constants with instruction names in x86. Greatly improves 
maintainability.
r198: Only xmm0-xmm5 is volatile on Win64, so xmm6 must be saved.
r197: PowerPC shift right always modifies the carry flag. We may need to 
restore it.
r196: Rename SLJIT_F* functions to SLJIT_*D
r195: SLJIT_INT_OP works in the same way as SLJIT_SINGLE_OP: the input register 
arguments must be generated by the output of another instruction with 
SLJIT_INT_OP flag
r194: Renaming sljit_w to sljit_sw, sljit_i to sljit_si, sljit_h to sljit_sh, 
and sljit_b to sljit_sb.
r193: ARM single precision support.
r192: Single precision support added for ppc, mips and sparc.
r191: Add single precision support. Only works on x86 now.
r190: Relace C types with sljit types. No functionality change.
r189: Change 0 to NULL for mmap.
r188: Support environments where MAP_ANON is not available.
r187: Adding type descriptors for pointers and doubles (preparing for x32 ABIs 
and single precision support).

Status:

Vendor Tag: TNF
Release Tags:   SLJIT-r257

N src/sys/external/bsd/sljit/dist/API_CHANGES
N src/sys/external/bsd/sljit/dist/INTERNAL_CHANGES
U src/sys/external/bsd/sljit/dist/Makefile
U src/sys/external/bsd/sljit/dist/README
U src/sys/external/bsd/sljit/dist/regex_src/regexMain.c
U src/sys/external/bsd/sljit/dist/regex_src/regexJIT.c
U src/sys/external/bsd/sljit/dist/regex_src/regexJIT.h
C src/sys/external/bsd/sljit/dist/test_src/sljitTest.c
C src/sys/external/bsd/sljit/dist/test_src/sljitMain.c
U src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.h
U src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_32.c
C src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c
N src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_32.c
C src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_32.c
C 

CVS commit: src/sys/net

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 16:52:33 UTC 2014

Modified Files:
src/sys/net: bpfjit.c

Log Message:
Update code to the latest sljit version.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/net/bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpfjit.c
diff -u src/sys/net/bpfjit.c:1.11 src/sys/net/bpfjit.c:1.12
--- src/sys/net/bpfjit.c:1.11	Fri May 23 22:04:09 2014
+++ src/sys/net/bpfjit.c	Tue Jun 17 16:52:33 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfjit.c,v 1.11 2014/05/23 22:04:09 alnsn Exp $	*/
+/*	$NetBSD: bpfjit.c,v 1.12 2014/06/17 16:52:33 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2011-2014 Alexander Nasonov.
@@ -31,9 +31,9 @@
 
 #include sys/cdefs.h
 #ifdef _KERNEL
-__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.11 2014/05/23 22:04:09 alnsn Exp $);
+__KERNEL_RCSID(0, $NetBSD: bpfjit.c,v 1.12 2014/06/17 16:52:33 alnsn Exp $);
 #else
-__RCSID($NetBSD: bpfjit.c,v 1.11 2014/05/23 22:04:09 alnsn Exp $);
+__RCSID($NetBSD: bpfjit.c,v 1.12 2014/06/17 16:52:33 alnsn Exp $);
 #endif
 
 #include sys/types.h
@@ -81,9 +81,9 @@ __RCSID($NetBSD: bpfjit.c,v 1.11 2014/0
 #define BJ_BUF		SLJIT_SAVED_REG1
 #define BJ_WIRELEN	SLJIT_SAVED_REG2
 #define BJ_BUFLEN	SLJIT_SAVED_REG3
-#define BJ_AREG		SLJIT_TEMPORARY_REG1
-#define BJ_TMP1REG	SLJIT_TEMPORARY_REG2
-#define BJ_TMP2REG	SLJIT_TEMPORARY_REG3
+#define BJ_AREG		SLJIT_SCRATCH_REG1
+#define BJ_TMP1REG	SLJIT_SCRATCH_REG2
+#define BJ_TMP2REG	SLJIT_SCRATCH_REG3
 #define BJ_XREG		SLJIT_TEMPORARY_EREG1
 #define BJ_TMP3REG	SLJIT_TEMPORARY_EREG2
 
@@ -425,13 +425,13 @@ emit_read32(struct sljit_compiler* compi
  */
 static int
 emit_xcall(struct sljit_compiler* compiler, const struct bpf_insn *pc,
-int dst, sljit_w dstw, struct sljit_jump **ret0_jump,
+int dst, sljit_sw dstw, struct sljit_jump **ret0_jump,
 uint32_t (*fn)(const struct mbuf *, uint32_t, int *))
 {
 #if BJ_XREG == SLJIT_RETURN_REG   || \
-BJ_XREG == SLJIT_TEMPORARY_REG1 || \
-BJ_XREG == SLJIT_TEMPORARY_REG2 || \
-BJ_XREG == SLJIT_TEMPORARY_REG3
+BJ_XREG == SLJIT_SCRATCH_REG1 || \
+BJ_XREG == SLJIT_SCRATCH_REG2 || \
+BJ_XREG == SLJIT_SCRATCH_REG3
 #error Not supported assignment of registers.
 #endif
 	int status;
@@ -456,7 +456,7 @@ emit_xcall(struct sljit_compiler* compil
 	 */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV,
-	SLJIT_TEMPORARY_REG1, 0,
+	SLJIT_SCRATCH_REG1, 0,
 	BJ_BUF, 0);
 	if (status != SLJIT_SUCCESS)
 		return status;
@@ -464,13 +464,13 @@ emit_xcall(struct sljit_compiler* compil
 	if (BPF_CLASS(pc-code) == BPF_LD  BPF_MODE(pc-code) == BPF_IND) {
 		status = sljit_emit_op2(compiler,
 		SLJIT_ADD,
-		SLJIT_TEMPORARY_REG2, 0,
+		SLJIT_SCRATCH_REG2, 0,
 		BJ_XREG, 0,
 		SLJIT_IMM, (uint32_t)pc-k);
 	} else {
 		status = sljit_emit_op1(compiler,
 		SLJIT_MOV,
-		SLJIT_TEMPORARY_REG2, 0,
+		SLJIT_SCRATCH_REG2, 0,
 		SLJIT_IMM, (uint32_t)pc-k);
 	}
 
@@ -478,7 +478,7 @@ emit_xcall(struct sljit_compiler* compil
 		return status;
 
 	status = sljit_get_local_base(compiler,
-	SLJIT_TEMPORARY_REG3, 0, arg3_offset);
+	SLJIT_SCRATCH_REG3, 0, arg3_offset);
 	if (status != SLJIT_SUCCESS)
 		return status;
 
@@ -510,7 +510,7 @@ emit_xcall(struct sljit_compiler* compil
 	/* tmp3 = *err; */
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV_UI,
-	SLJIT_TEMPORARY_REG3, 0,
+	SLJIT_SCRATCH_REG3, 0,
 	SLJIT_MEM1(SLJIT_LOCALS_REG), arg3_offset);
 	if (status != SLJIT_SUCCESS)
 		return status;
@@ -518,7 +518,7 @@ emit_xcall(struct sljit_compiler* compil
 	/* if (tmp3 != 0) return 0; */
 	*ret0_jump = sljit_emit_cmp(compiler,
 	SLJIT_C_NOT_EQUAL,
-	SLJIT_TEMPORARY_REG3, 0,
+	SLJIT_SCRATCH_REG3, 0,
 	SLJIT_IMM, 0);
 	if (*ret0_jump == NULL)
 		return SLJIT_ERR_ALLOC_FAILED;
@@ -819,21 +819,21 @@ divide(sljit_uw x, sljit_uw y)
  * divt,divw are either SLJIT_IMM,pc-k or BJ_XREG,0.
  */
 static int
-emit_division(struct sljit_compiler* compiler, int divt, sljit_w divw)
+emit_division(struct sljit_compiler* compiler, int divt, sljit_sw divw)
 {
 	int status;
 
 #if BJ_XREG == SLJIT_RETURN_REG   || \
-BJ_XREG == SLJIT_TEMPORARY_REG1 || \
-BJ_XREG == SLJIT_TEMPORARY_REG2 || \
-BJ_AREG == SLJIT_TEMPORARY_REG2
+BJ_XREG == SLJIT_SCRATCH_REG1 || \
+BJ_XREG == SLJIT_SCRATCH_REG2 || \
+BJ_AREG == SLJIT_SCRATCH_REG2
 #error Not supported assignment of registers.
 #endif
 
-#if BJ_AREG != SLJIT_TEMPORARY_REG1
+#if BJ_AREG != SLJIT_SCRATCH_REG1
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV,
-	SLJIT_TEMPORARY_REG1, 0,
+	SLJIT_SCRATCH_REG1, 0,
 	BJ_AREG, 0);
 	if (status != SLJIT_SUCCESS)
 		return status;
@@ -841,7 +841,7 @@ emit_division(struct sljit_compiler* com
 
 	status = sljit_emit_op1(compiler,
 	SLJIT_MOV,
-	SLJIT_TEMPORARY_REG2, 0,
+	SLJIT_SCRATCH_REG2, 0,
 	divt, divw

CVS commit: src/sys/external/bsd/sljit

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 16:49:11 UTC 2014

Modified Files:
src/sys/external/bsd/sljit: README.import

Log Message:
New sljit version is r257.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/sljit/README.import

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/sljit/README.import
diff -u src/sys/external/bsd/sljit/README.import:1.3 src/sys/external/bsd/sljit/README.import:1.4
--- src/sys/external/bsd/sljit/README.import:1.3	Sun Oct 28 09:41:12 2012
+++ src/sys/external/bsd/sljit/README.import	Tue Jun 17 16:49:11 2014
@@ -1,6 +1,6 @@
 There are no CVS/SVN ids in sljit repository but don't forget to
 remove .svn before importing the new version.
 
-Current sljit import is @ r186:
+Current sljit import is @ r257:
 
-svn co https://sljit.svn.sourceforge.net/svnroot/sljit@186 dist
+svn co https://sljit.svn.sourceforge.net/svnroot/sljit@257 dist



CVS commit: src/sys/external/bsd/sljit/dist/sljit_src

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 17:30:48 UTC 2014

Modified Files:
src/sys/external/bsd/sljit/dist/sljit_src: sljitConfigInternal.h

Log Message:
Don't redefine SLJIT_HALT_PROCESS().


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.7 src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.8
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.7	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h	Tue Jun 17 17:30:48 2014
@@ -488,8 +488,6 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_free
 #include assert.h
 #include stdlib.h
 
-#define SLJIT_HALT_PROCESS() abort()
-
 #define SLJIT_ASSERT(x) assert(x)
 
 #endif /* !SLJIT_ASSERT */



CVS commit: src/doc

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 18:48:35 UTC 2014

Modified Files:
src/doc: 3RDPARTY

Log Message:
Update sljit entry.


To generate a diff of this commit:
cvs rdiff -u -r1.1123 -r1.1124 src/doc/3RDPARTY

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1123 src/doc/3RDPARTY:1.1124
--- src/doc/3RDPARTY:1.1123	Sun Jun 15 17:55:43 2014
+++ src/doc/3RDPARTY	Tue Jun 17 18:48:35 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1123 2014/06/15 17:55:43 tls Exp $
+#	$NetBSD: 3RDPARTY,v 1.1124 2014/06/17 18:48:35 alnsn Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -1431,8 +1431,8 @@ Location:	external/cddl/osnet
 Notes:
 
 Package:	sljit
-Version:	svn revision 186
-Current Vers:	svn revision 226
+Version:	0.91 (svn revision 257)
+Current Vers:	svn revision 268
 Maintainer:	Zoltán Herczeg hzmes...@freemail.hu
 Archive Site:	http://sourceforge.net/projects/sljit/
 Home Page:	http://sljit.sourceforge.net/



CVS commit: src/tests/lib

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 19:26:18 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: Makefile
src/tests/lib/libsljit: Makefile

Log Message:
libarch on sparc isn't -l${MACHINE_CPU}. Don't link to it.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libbpfjit/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libsljit/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/Makefile
diff -u src/tests/lib/libbpfjit/Makefile:1.2 src/tests/lib/libbpfjit/Makefile:1.3
--- src/tests/lib/libbpfjit/Makefile:1.2	Tue Jun 17 06:36:01 2014
+++ src/tests/lib/libbpfjit/Makefile	Tue Jun 17 19:26:18 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2014/06/17 06:36:01 alnsn Exp $
+# $NetBSD: Makefile,v 1.3 2014/06/17 19:26:18 alnsn Exp $
 
 .include bsd.own.mk
 .include ../../../external/bsd/sljit/Makefile.inc
@@ -16,9 +16,6 @@ DPADD+=		${LIBBPFJITDIR}/libbpfjit.a
 LDADD+=		-L${LIBSLJITDIR} -lsljit
 DPADD+=		${LIBSLJITDIR}/libsljit.a
 
-# I-cache sync routines for arm and mips
-LDADD+=		-l${MACHINE_CPU}
-
 LDADD+=		${LIBPCAP}
 
 .include bsd.test.mk

Index: src/tests/lib/libsljit/Makefile
diff -u src/tests/lib/libsljit/Makefile:1.2 src/tests/lib/libsljit/Makefile:1.3
--- src/tests/lib/libsljit/Makefile:1.2	Tue Jun 17 06:36:01 2014
+++ src/tests/lib/libsljit/Makefile	Tue Jun 17 19:26:18 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2014/06/17 06:36:01 alnsn Exp $
+# $NetBSD: Makefile,v 1.3 2014/06/17 19:26:18 alnsn Exp $
 
 TESTSDIR=	${TESTSBASE}/lib/libsljit
 
@@ -20,7 +20,4 @@ WARNS=		3
 LDADD+=		-L${LIBSLJITDIR} -lsljit
 DPADD+=		${LIBSLJITDIR}/libsljit.a
 
-# I-cache sync routines for arm and mips
-LDADD+=		-l${MACHINE_CPU}
-
 .include bsd.test.mk



CVS commit: src/sys/external/bsd/sljit/dist/sljit_src

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 19:33:20 UTC 2014

Modified Files:
src/sys/external/bsd/sljit/dist/sljit_src: sljitExecAllocator.c
sljitLir.c sljitNativeARM_32.c sljitNativeARM_64.c
sljitNativeARM_T2_32.c sljitNativeMIPS_32.c sljitNativeMIPS_64.c
sljitNativeMIPS_common.c sljitNativePPC_32.c sljitNativePPC_64.c
sljitNativePPC_common.c sljitNativeSPARC_32.c
sljitNativeSPARC_common.c sljitNativeTILEGX-encoder.c
sljitNativeTILEGX_64.c sljitNativeX86_32.c sljitNativeX86_64.c
sljitNativeX86_common.c sljitUtils.c

Log Message:
Add $NetBSD$.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_common.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_32.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_32.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_64.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_T2_32.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeMIPS_64.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeTILEGX-encoder.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeTILEGX_64.c
cvs rdiff -u -r1.1.1.3 -r1.2 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeMIPS_32.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_32.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_64.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_64.c
cvs rdiff -u -r1.1.1.4 -r1.2 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeMIPS_common.c
cvs rdiff -u -r1.1.1.2 -r1.2 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeSPARC_32.c \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeSPARC_common.c
cvs rdiff -u -r1.5 -r1.6 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_common.c
cvs rdiff -u -r1.6 -r1.7 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitUtils.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c:1.3 src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c:1.4
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c:1.3	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c	Tue Jun 17 19:33:20 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitExecAllocator.c,v 1.4 2014/06/17 19:33:20 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *
Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c:1.3 src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c:1.4
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c:1.3	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c	Tue Jun 17 19:33:20 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitLir.c,v 1.4 2014/06/17 19:33:20 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *
Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_common.c
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_common.c:1.3 src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_common.c:1.4
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_common.c:1.3	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitNativePPC_common.c	Tue Jun 17 19:33:20 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitNativePPC_common.c,v 1.4 2014/06/17 19:33:20 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *
Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_32.c
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_32.c:1.3 src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_32.c:1.4
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_32.c:1.3	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeX86_32.c	Tue Jun 17 19:33:20 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitNativeX86_32.c,v 1.4 2014/06/17 19:33:20 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *

Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_32.c
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_32.c:1.1.1.1 src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_32.c:1.2
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_32.c:1.1.1.1	Tue Jun 17 15:37:41 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_32.c	Tue Jun 17 19:33:20 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitNativeARM_32.c,v 1.2 2014/06/17 19:33:20 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  

CVS commit: src/sys/external/bsd/sljit/dist/sljit_src

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 19:36:45 UTC 2014

Modified Files:
src/sys/external/bsd/sljit/dist/sljit_src: sljitConfig.h
sljitConfigInternal.h sljitLir.h

Log Message:
Add $NetBSD$.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h
cvs rdiff -u -r1.8 -r1.9 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h
cvs rdiff -u -r1.1.1.3 -r1.2 \
src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.9 src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.10
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h:1.9	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitConfig.h	Tue Jun 17 19:36:45 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitConfig.h,v 1.10 2014/06/17 19:36:45 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *

Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.8 src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.9
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h:1.8	Tue Jun 17 17:30:48 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitConfigInternal.h	Tue Jun 17 19:36:45 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitConfigInternal.h,v 1.9 2014/06/17 19:36:45 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *

Index: src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.h
diff -u src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.h:1.1.1.3 src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.h:1.2
--- src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.h:1.1.1.3	Tue Jun 17 15:37:41 2014
+++ src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.h	Tue Jun 17 19:36:45 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitLir.h,v 1.2 2014/06/17 19:36:45 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *



CVS commit: src/sys/external/bsd/sljit/dist/test_src

2014-06-17 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Tue Jun 17 19:37:03 UTC 2014

Modified Files:
src/sys/external/bsd/sljit/dist/test_src: sljitMain.c sljitTest.c

Log Message:
Add $NetBSD$.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/sljit/dist/test_src/sljitMain.c \
src/sys/external/bsd/sljit/dist/test_src/sljitTest.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/sljit/dist/test_src/sljitMain.c
diff -u src/sys/external/bsd/sljit/dist/test_src/sljitMain.c:1.3 src/sys/external/bsd/sljit/dist/test_src/sljitMain.c:1.4
--- src/sys/external/bsd/sljit/dist/test_src/sljitMain.c:1.3	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/test_src/sljitMain.c	Tue Jun 17 19:37:03 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitMain.c,v 1.4 2014/06/17 19:37:03 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *
Index: src/sys/external/bsd/sljit/dist/test_src/sljitTest.c
diff -u src/sys/external/bsd/sljit/dist/test_src/sljitTest.c:1.3 src/sys/external/bsd/sljit/dist/test_src/sljitTest.c:1.4
--- src/sys/external/bsd/sljit/dist/test_src/sljitTest.c:1.3	Tue Jun 17 16:48:24 2014
+++ src/sys/external/bsd/sljit/dist/test_src/sljitTest.c	Tue Jun 17 19:37:03 2014
@@ -1,3 +1,5 @@
+/*	$NetBSD: sljitTest.c,v 1.4 2014/06/17 19:37:03 alnsn Exp $	*/
+
 /*
  *Stack-less Just-In-Time compiler
  *



CVS commit: src/lib/librumpuser

2014-06-16 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Jun 16 21:07:28 UTC 2014

Modified Files:
src/lib/librumpuser: rumpuser_bio.c

Log Message:
Add __RCSID.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/librumpuser/rumpuser_bio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/rumpuser_bio.c
diff -u src/lib/librumpuser/rumpuser_bio.c:1.7 src/lib/librumpuser/rumpuser_bio.c:1.8
--- src/lib/librumpuser/rumpuser_bio.c:1.7	Wed May 15 14:58:24 2013
+++ src/lib/librumpuser/rumpuser_bio.c	Mon Jun 16 21:07:28 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser_bio.c,v 1.7 2013/05/15 14:58:24 pooka Exp $	*/
+/*	$NetBSD: rumpuser_bio.c,v 1.8 2014/06/16 21:07:28 alnsn Exp $	*/
 
 /*-
  * Copyright (c) 2013 Antti Kantee.  All Rights Reserved.
@@ -27,6 +27,10 @@
 
 #include rumpuser_port.h
 
+#if !defined(lint)
+__RCSID($NetBSD: rumpuser_bio.c,v 1.8 2014/06/16 21:07:28 alnsn Exp $);
+#endif /* !lint */
+
 #include sys/types.h
 
 #include assert.h



CVS commit: src/sys/arch/amd64/conf

2014-06-12 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Jun 12 12:13:36 UTC 2014

Modified Files:
src/sys/arch/amd64/conf: GENERIC

Log Message:
Add a comment about disabling INET6. Should fix kern/48901.


To generate a diff of this commit:
cvs rdiff -u -r1.388 -r1.389 src/sys/arch/amd64/conf/GENERIC

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/conf/GENERIC
diff -u src/sys/arch/amd64/conf/GENERIC:1.388 src/sys/arch/amd64/conf/GENERIC:1.389
--- src/sys/arch/amd64/conf/GENERIC:1.388	Tue Jun 10 01:42:39 2014
+++ src/sys/arch/amd64/conf/GENERIC	Thu Jun 12 12:13:36 2014
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.388 2014/06/10 01:42:39 hikaru Exp $
+# $NetBSD: GENERIC,v 1.389 2014/06/12 12:13:36 alnsn Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include	arch/amd64/conf/std.amd64
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		GENERIC-$Revision: 1.388 $
+#ident 		GENERIC-$Revision: 1.389 $
 
 maxusers	64		# estimated number of users
 
@@ -175,7 +175,7 @@ options 	NFSSERVER	# Network File System
 # Networking options
 #options 	GATEWAY		# packet forwarding
 options 	INET		# IP + ICMP + TCP + UDP
-options 	INET6		# IPV6
+options 	INET6		# IPV6 (disable it together with stf device)
 options 	IPSEC		# IP security
 #options 	IPSEC_DEBUG	# debug for IP security
 #options 	MPLS		# MultiProtocol Label Switching (needs ifmpls)



CVS commit: src/sys/arch/amd64/conf

2014-06-12 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Thu Jun 12 20:22:04 UTC 2014

Modified Files:
src/sys/arch/amd64/conf: GENERIC

Log Message:
Revert the previous (comment only change).


To generate a diff of this commit:
cvs rdiff -u -r1.389 -r1.390 src/sys/arch/amd64/conf/GENERIC

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/conf/GENERIC
diff -u src/sys/arch/amd64/conf/GENERIC:1.389 src/sys/arch/amd64/conf/GENERIC:1.390
--- src/sys/arch/amd64/conf/GENERIC:1.389	Thu Jun 12 12:13:36 2014
+++ src/sys/arch/amd64/conf/GENERIC	Thu Jun 12 20:22:04 2014
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.389 2014/06/12 12:13:36 alnsn Exp $
+# $NetBSD: GENERIC,v 1.390 2014/06/12 20:22:04 alnsn Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include	arch/amd64/conf/std.amd64
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		GENERIC-$Revision: 1.389 $
+#ident 		GENERIC-$Revision: 1.390 $
 
 maxusers	64		# estimated number of users
 
@@ -175,7 +175,7 @@ options 	NFSSERVER	# Network File System
 # Networking options
 #options 	GATEWAY		# packet forwarding
 options 	INET		# IP + ICMP + TCP + UDP
-options 	INET6		# IPV6 (disable it together with stf device)
+options 	INET6		# IPV6
 options 	IPSEC		# IP security
 #options 	IPSEC_DEBUG	# debug for IP security
 #options 	MPLS		# MultiProtocol Label Switching (needs ifmpls)



CVS commit: src/tests/lib/libbpfjit

2014-05-23 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Fri May 23 11:47:59 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Test Array Bounds Check Elimination (ABC) and test bpf programs from bpf(4).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.2 src/tests/lib/libbpfjit/t_bpfjit.c:1.3
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.2	Fri Nov 15 00:12:45 2013
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Fri May 23 11:47:59 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bpfjit.c,v 1.2 2013/11/15 00:12:45 rmind Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.3 2014/05/23 11:47:59 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2011-2012 Alexander Nasonov.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.2 2013/11/15 00:12:45 rmind Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.3 2014/05/23 11:47:59 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h
@@ -3290,6 +3290,540 @@ ATF_TC_BODY(bpfjit_opt_ld_ind_4, tc)
 	bpfjit_free_code(code);
 }
 
+ATF_TC(bpfjit_abc_ja);
+ATF_TC_HEAD(bpfjit_abc_ja, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test ABC optimization with a single BPF_JMP+BPF_JA);
+}
+
+ATF_TC_BODY(bpfjit_abc_ja, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 3), /* min. length 4 */
+		BPF_STMT(BPF_JMP+BPF_JA, 2),
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, UINT32_MAX - 1),
+		BPF_STMT(BPF_RET+BPF_K, 0),
+		BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 2), /* min. length 6 */
+		BPF_STMT(BPF_RET+BPF_A, 0),
+		BPF_STMT(BPF_RET+BPF_K, 1),
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 6),
+		BPF_STMT(BPF_RET+BPF_K, 2),
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
+		BPF_STMT(BPF_RET+BPF_K, 3),
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[6] = {0, 0, /* UINT32_MAX: */ 255, 255, 255, 255};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(bc, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(code(pkt, 0, 0) == 0);
+	ATF_CHECK(code(pkt, 1, 1) == 0);
+	ATF_CHECK(code(pkt, 2, 2) == 0);
+	ATF_CHECK(code(pkt, 3, 3) == 0);
+	ATF_CHECK(code(pkt, 4, 4) == 0);
+	ATF_CHECK(code(pkt, 5, 5) == 0);
+	ATF_CHECK(code(pkt, 6, 6) == UINT32_MAX);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(bpfjit_abc_ja_over);
+ATF_TC_HEAD(bpfjit_abc_ja_over, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test ABC optimization when BPF_JMP+BPF_JA jumps over all loads);
+}
+
+ATF_TC_BODY(bpfjit_abc_ja_over, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_JMP+BPF_JA, 2),
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 3),
+		BPF_STMT(BPF_RET+BPF_K, 0),
+		BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 4),
+		BPF_STMT(BPF_RET+BPF_K, 1),
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 5),
+		BPF_STMT(BPF_RET+BPF_K, 2),
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 6),
+		BPF_STMT(BPF_RET+BPF_K, 3),
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[1]; /* the program doesn't read any data */
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(bc, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
+
+	bpfjit_free_code(code);
+}
+
+ATF_TC(bpfjit_abc_ld_chain);
+ATF_TC_HEAD(bpfjit_abc_ld_chain, tc)
+{
+	atf_tc_set_md_var(tc, descr,
+	Test ABC optimization of a chain of BPF_LD instructions 
+	with exits leading to a single BPF_RET);
+}
+
+ATF_TC_BODY(bpfjit_abc_ld_chain, tc)
+{
+	static struct bpf_insn insns[] = {
+		BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 3), /* min. length 4 */
+		BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 8, 0, 4),
+		BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 4), /* min. length 6 */
+		BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 7, 0, 2),
+		BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 6), /* min. length 10 */
+		BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 6, 0, 1),
+		BPF_STMT(BPF_RET+BPF_K, 123456789),
+		BPF_STMT(BPF_RET+BPF_K, 987654321),
+	};
+
+	bpfjit_func_t code;
+	uint8_t pkt[10] = {};
+
+	size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+	ATF_CHECK(bpf_validate(insns, insn_count));
+
+	code = bpfjit_generate_code(bc, insns, insn_count);
+	ATF_REQUIRE(code != NULL);
+
+	/* Packet is too short. */
+	ATF_CHECK(code(pkt, 1, 1) == 0);
+	ATF_CHECK(code(pkt, 2, 2) == 0);
+	ATF_CHECK(code(pkt, 3, 3) == 0);
+
+	/* !(pkt[3] == 8) = return 123456789 */
+	ATF_CHECK(code(pkt, 4, 4) == 123456789);
+	ATF_CHECK(code(pkt, 5, 5) == 123456789);
+	ATF_CHECK(code(pkt, 6, 6) == 123456789);
+	ATF_CHECK(code(pkt, 7, 7) == 123456789);
+	ATF_CHECK(code(pkt, 8, 8) == 123456789);
+	ATF_CHECK(code(pkt, 9, 9) == 123456789);
+
+	/* !(pkt[4:2] = 7) = too short or return 123456789 */
+	pkt[3] = 8;
+	ATF_CHECK(code(pkt, 1, 1) == 0);
+	ATF_CHECK(code(pkt, 2, 2) == 0);
+	ATF_CHECK(code(pkt, 3, 3) == 0);
+	ATF_CHECK(code(pkt, 4, 4

CVS commit: src/tests/lib/libbpfjit

2014-05-23 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Fri May 23 11:48:26 UTC 2014

Modified Files:
src/tests/lib/libbpfjit: t_bpfjit.c

Log Message:
Update copyright year.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libbpfjit/t_bpfjit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libbpfjit/t_bpfjit.c
diff -u src/tests/lib/libbpfjit/t_bpfjit.c:1.3 src/tests/lib/libbpfjit/t_bpfjit.c:1.4
--- src/tests/lib/libbpfjit/t_bpfjit.c:1.3	Fri May 23 11:47:59 2014
+++ src/tests/lib/libbpfjit/t_bpfjit.c	Fri May 23 11:48:26 2014
@@ -1,7 +1,7 @@
-/*	$NetBSD: t_bpfjit.c,v 1.3 2014/05/23 11:47:59 alnsn Exp $ */
+/*	$NetBSD: t_bpfjit.c,v 1.4 2014/05/23 11:48:26 alnsn Exp $ */
 
 /*-
- * Copyright (c) 2011-2012 Alexander Nasonov.
+ * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_bpfjit.c,v 1.3 2014/05/23 11:47:59 alnsn Exp $);
+__RCSID($NetBSD: t_bpfjit.c,v 1.4 2014/05/23 11:48:26 alnsn Exp $);
 
 #include atf-c.h
 #include stdint.h



<    1   2   3   4   >