English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] camlimages and kernel memory
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-06-08 (13:36)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] camlimages and kernel memory
> For example, Linux (but other OS, too) allow userland processes to access the
> kernel memory by opening and mmapping the file /dev/kmem. This effects that
> kernel memory is mapped into the userland address space. However, mmap is
> usually restricted to 4k blocks, i.e. you can mmap only a whole number of
> 4k blocks.
> O'Caml can handle pointers to blocks that are outside of the region that is
> managed by its own routines. The blocks must have the right format, of course,
> i.e. strings must have the right O'Caml header. I suppose this header is not
> in the ringbuffer.
> If the ringbuffer happens to begin at a 4k boundary, you have won, because you
> can manage that there is such a header without modifying kernel memory, i.e.
> if the mmaped buffer begins at address A, just allocate anonymous memory in the
> 4k block before A and write the needed header into it.

This is the hard way :-)  A simpler way to memory map files or devices
in a Caml program is to use the function "map_file" from the Bigarray
library.  However, it currently always map the file from offset 0,
which is probably not appropriate for /dev/kmem...  I'll have to look
into this limitation.

> The other problem is whether camlimages can handle data that is
> organized as ring.  I don't have any ideas.

The type Image.t is a relatively complex data structure, so some work
is definitely needed to go from a raw string or bigarray
(corresponding to the memory-mapped file) to a value of type Image.t.
I'll let the authors of CamlImages comment on that.

- Xavier Leroy
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners