Re: Memory Mapping examples/documentation?
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Thanks, - Greg On Mar 3, 2008, at 9:54 PM, mm w wrote: $ cc wire.c -o test $ ./test Thanks for the example mousse, but I'm not really sure that this does... I compiled it and ran it like so: $ cc example.c $ sudo ./a.out And got a lot of output along these lines: addr = 800000 error = 268435459 addr = 802000 error = 268435459 addr = 802000 error = 268435459 addr = 803000 error = 268435459 addr = 803000 Am I correct in my understanding that task_wire(self,true) tells OS X not to page the program out from memory? What then is vm_wire() used for? Also, how do I use this for my purposes (which is to share memory between my kext and the user-land program)? - Greg On Mar 3, 2008, at 2:37 PM, mm w wrote: #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); 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 Mar 3, 2008, at 11:23 AM, mm w wrote: Hi Greg, 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). 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 (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/greg%40kinostudios.com -- -mmw _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/greg%40kinostudios.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... I understand basic concepts like what a virtual address is, what IPC is, etc. I understand that I need to send an address to the KEXT via IPC (or from the KEXT to the user-land app). However, I cannot do this if I don't know how to use the functions in the source code you just sent. Why is an error being printed out in the example? Is calling task_wire() necessary? Is vm_wire() the function that creates shared memory? What exactly are the effects of the flags VM_PROT_READ, VM_PROT_WRITE, and are there any other flags I should be aware of? Hi Greg, this is a basic question, I'm going to try to give you some leads, imagine, we are in two rooms separated by a cupboard with two entries (double access), my room is called the Forgotten City :) now I'm going open a drawer and put something inside for you (and sure I can lock some drawers (keymaster)), you have several options to find what I gave: try to open every drawer or I can send you somewhere the "address" of this drawer (IPC), one more constraint you can't use a device file :) On Mon, Mar 3, 2008 at 2:27 PM, Greg <greg@kinostudios.com> wrote: Thanks, and sorry for the lack of knowledge on my part, in my defense I would read the documentation if I knew what documentation to read! :-p 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); On Mon, Mar 3, 2008 at 11:06 AM, Greg <greg@kinostudios.com> wrote: 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, 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? This email sent to greg@kinostudios.com This email sent to greg@kinostudios.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Greg