caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <prevost@maya.com>
To: caml-list@inria.fr
Subject: Internals details for cmmgen.ml
Date: 10 Dec 1999 03:12:14 -0500	[thread overview]
Message-ID: <87emcv5i5d.fsf@isil.maya.com> (raw)

Recently I posted about my work to add support for fast byte access to
regions of memory outside the O'Caml heap.  Since Francois Rouaix
helfully pointed me at fcntl for being sure of the access rights on
file descriptors, I'm continuing to polish things up.

My main focus has been on adding small bits of code to
asmcomp/cmmgen.ml for the new functionality.  Two of the new
primitives (Pregionrefs and Pregionsets) need to check the protection
bits recorded for the region before trying to access it, and somehow
raise an exception if the access check fails.

I'm currently using the following kludge to make bad region access
checks fail:

let region_checkaccess exp = function
  | Reg_Read ->
    Cifthenelse(
      Cop(Cand, [region_prot exp; Cconst_int 1]),
      Cconst_pointer 1,
      Cop(Ccheckbound, [Cconst_int 0; Cconst_int 0]))
  | Reg_Write ->
    Cifthenelse(
      Cop(Cand, [region_prot exp; Cconst_int 2]),
      Cconst_pointer 1,
      Cop(Ccheckbound, [Cconst_int 0; Cconst_int 0]))
(* XXX Bounds check on 0 is a kludge to force exception *)

(Please pardon my code--I may not know enough about C-- to produce the
best possible output, even without trying to finagle this access check.)

Is there a better way for me to cause an exception to be thrown at
this point?  Do I need to fall back to a Cextcall to ask someone to
throw an exception for me?  Or could (and should) I actually use
Craise with arcane knowledge that a certain exception maps to a
certain integer value?

John


P.S.  Kudos to everyone who's involved with the O'Caml compiler.  Now
that I'm getting into the internals a bit, I'm enjoying myself
immensely.  I'm convinced I could never deal with this style of
hackery in the Perl source.  Not only is the code of the various parts
of the compiler fairly easy to follow, but static typing has saved me
from burning myself several times already while modifying cmmgen.ml
and the associated type definitions.  Again, thanks!




             reply	other threads:[~1999-12-10 13:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-10  8:12 John Prevost [this message]
1999-12-11 18:09 ` Xavier Leroy
1999-12-18  0:51   ` John Prevost
1999-12-18 18:56     ` Jerome Vouillon
1999-12-23  5:26       ` John Prevost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87emcv5i5d.fsf@isil.maya.com \
    --to=prevost@maya.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).