Re: Memory Mapping examples/documentation?
Re: Memory Mapping examples/documentation?
- Subject: Re: Memory Mapping examples/documentation?
- From: "mm w" <email@hidden>
- Date: Mon, 3 Mar 2008 11:37:24 -0800
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <mach/vm_map.h>
int main(int argc, char *argv[]) {
vm_map_t self;
kern_return_t kret;
self = mach_task_self();
kret = task_wire(self, true);
if (kret == KERN_INVALID_HOST)
fprintf(stderr, "vm_wire KERN_INVALID_HOST.\n");
else if (kret)
fprintf(stderr,"error = %d\n", kret);
vm_size_t size;
host_priv_t host;
host = mach_host_self();
void *ptr;
int i = 0;
host_page_size(host, &size);
do {
fork();
ptr = malloc(size);
printf("addr = %X\n" , ptr);
kret = vm_wire(host, self, (vm_address_t) ptr, size, VM_PROT_READ
| VM_PROT_WRITE);
if (kret == KERN_INVALID_HOST)
fprintf(stderr, "vm_wire KERN_PROTECTION_FAILURE.\n");
else if (kret == KERN_INVALID_HOST)
fprintf(stderr, "vm_wire KERN_INVALID_HOST.\n");
else if (kret)
fprintf(stderr,"error = %d\n", kret);
} while(++i < 5);
return 0;
}
On Mon, Mar 3, 2008 at 11:06 AM, Greg <email@hidden> wrote:
>
> On Mar 3, 2008, at 11:23 AM, mm w wrote:
>
> > Hi Greg,
> >
> > In the doc there is a small chapter regarding Memory wiring called:
> > Memory Mapping and Block Copying, I guess it's exactly what you asked,
> > as Michael said most people think that not using IOKit is more
> > efficient, for the most of cases, it's really wrong, as you have may
> > be noticed IOKit is not a full C++, it's based on Embedded C++, Iokit
> > provides many facilities and kern controls,
>
> The only reason that I don't want to make an IOKit kext is that I feel
> it would over-complicate my code. I don't have much time to learn all
> the paradigms of creating a driver and then a userclient when all I
> need is one function to start the kernel extension (kextname_start)
> and one function to stop it (kextname_stop).
>
>
>
> > and sure it depends on what you want to accomplish, if it's to learn
> > or implement something that doesn't exist, your are on the way, if
> > it's for implementing something that already exists not sure :), and
> > sure the xnu source is always your best doc: osfmk/vm/vm_user.c
>
> Are the functions in vm_user.c the only functions available to do what
> I want? And are you saying that no actual documentation on how to use
> those functions to do memory mapping exists?
>
> Because if that's the case then converting my extension to IOKit stuff
> might be easier than wading through kernel code.
>
> Thanks,
>
> - Greg
>
--
-mmw
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden