Re: Add kernel-level Cobol runtime with JIT support

From: Cy Schubert <Cy.Schubert_at_cschubert.com>
Date: Fri, 01 Apr 2022 18:56:27 UTC
In message <CAGudoHEAJ77WS9Yhp2Q+ARxU0SkLK99N_LvHoK14+yKV42YVUA@mail.gmail.c
om>
, Mateusz Guzik writes:
> The branch main has been updated by mjg:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=5c2c056f2f9c3b0b941184036afa8149
> d727c666
>
> 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

This is the wrong. Should it not be GPLv3?

> + *
> + * 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 PURPOS
> E
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIA
> L
> + * 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, STRIC
> T
> + * 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.
> + */
> +

The other issue is, coming from a former COBOL programmer in a previous 
lifetime, actually many lifetimes ago, is that COBOL is a waste of cards. 
Each of my COBOL programs at the time had that very comment in the comment 
section. Can we put that comment in here?

Next question. Will we be adding drivers for the IBM 1402 or IBM 2540 card 
readers as well?

Thinking ahead, better EBCDIC support would be nice too.


-- 
Cheers,
Cy Schubert <Cy.Schubert@cschubert.com>
FreeBSD UNIX:  <cy@FreeBSD.org>   Web:  https://FreeBSD.org
NTP:           <cy@nwtime.org>    Web:  https://nwtime.org

	The need of the many outweighs the greed of the few.


> +#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 ***
>