Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Apr 2022 20:31:15 +0200
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        src-committers@freebsd.org, dev-commits-src-all@freebsd.org,  dev-commits-src-main@freebsd.org
Subject:   Add kernel-level Cobol runtime with JIT support
Message-ID:  <CAGudoHEAJ77WS9Yhp2Q%2BARxU0SkLK99N_LvHoK14%2ByKV42YVUA@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=5c2c056f2f9c3b0b941184036afa8149d727c666

commit 5c2c056f2f9c3b0b941184036afa8149d727c666
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2022-04-01 15:04:03 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-04-01 18:01:48 +0000

---
 sys/kern/subr_cobl   | 8237492505  +++++++++++LOL
 sbin/cobolctl        | 23445 +++++++++++++++++
 2 files changed, 8237515950 insertions(+)

diff --git a/sys/kern/subr_cobol.c b/sys/kern/subr_cobol.c
new file mode 100644
index 000000000000..c9c1979d73b8
--- /dev/null
+++ b/sys/kern/subr_cobol.c
@@ -0,0 +1,131 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2022 Mateusz Guzik. All wrongs reversed.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, is prohibited regardless if 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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>
+__FBSDID("$FreeBSD$");
+
+#include "opt_ddb.h"
+#include "opt_ktrace.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/capsicum.h>
+#include <sys/counter.h>
+#include <sys/filedesc.h>
+#include <sys/fnv_hash.h>
+#include <sys/kernel.h>
+#include <sys/ktr.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/fcntl.h>
+#include <sys/jail.h>
+#include <sys/mount.h>
+#include <sys/namei.h>
+#include <sys/proc.h>
+#include <sys/seqc.h>
+#include <sys/sdt.h>
+#include <sys/smr.h>
+#include <sys/smp.h>
+#include <sys/syscallsubr.h>
+#include <sys/sysctl.h>
+#include <sys/sysproto.h>
+#include <sys/vnode.h>
+#include <ck_queue.h>
+#ifdef KTRACE
+#include <sys/ktrace.h>
+#endif
+#ifdef INVARIANTS
+#include <machine/_inttypes.h>
+#endif
+
+#include <sys/capsicum.h>
+
+#include <security/audit/audit.h>
+#include <security/mac/mac_framework.h>
+
+#ifdef DDB
+#include <ddb/ddb.h>
+#endif
+
+#include <vm/uma.h>
+
+static SYSCTL_NODE(_kern, OID_AUTO, cobol, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
+    "Cobol runtime");
+
+static bool __read_frequently cobol_jit_enabled = true;
+SYSCTL_BOOL(_kern_cobol, OID_AUTO, jit, CTLFLAG_RW,
+    &cobol_jit_enabled, 0,
+    "COBOL jit enabled (1 == F4ST3RZ)");
+
+static int
+cobol_canrunprog(struct prog *pr)
+{
+
+       switch (pr->lang) {
+       case PHP:
+               /*
+                * are you serious?
+                */
+               panic("don't run php code");
+       case COBOL:
+               if (__predict_false(!cobol_jit_enabled))
+                       return (EOPNOTSUPP);
+               break;
+       default:
+               return (EOPNOTSUPP);
+       }
+
+       return (0);
+}
+
+static int
+cobol_runprog(struct prog *pr)
+{
+       struct cobolprog *cbp;
+       int error;
+
+       error = cobol_canrunprog(pr);
+       if (error != 0)
+               return (error);
+
+       if (!cobol_jit_enabled) {
+               /*
+                * what's even the point?
+                */
+               return (EBUGGEROFF);
+       }
+
+       cbp = cobol_prepruntime(pr);
+       if (cbp == NULL) {
+               return (ECRAP);
+       }
+
+       return (cobol_run(cbp));
+}
 *** 8237492374 LINES SKIPPED ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGudoHEAJ77WS9Yhp2Q%2BARxU0SkLK99N_LvHoK14%2ByKV42YVUA>