• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How does /dev/mem work?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How does /dev/mem work?


  • Subject: How does /dev/mem work?
  • From: Hajime Inoue <email@hidden>
  • Date: Mon, 2 Mar 2009 17:17:37 -0500

Hi,

I'm trying to understand the /dev/mem code in older versions of Darwin.  I'm
new
to xnu so I may simply not know some of the well known assumptions.

In

http://www.opensource.apple.com/darwinsource/10.3.9/xnu-517.12.7/bsd/dev/i38
6/mem.c,

I am trying to understand the following code:

		/* minor device 0 is physical memory */
		case 0:
			v = trunc_page(uio->uio_offset);
			if (uio->uio_offset >= mem_size)
				goto fault;

			size= PAGE_SIZE;
			if (kmem_alloc(kernel_map, &where, size)
				!= KERN_SUCCESS) {
				goto fault;
			}
			o = uio->uio_offset - v;
			c = min(PAGE_SIZE - o, (u_int)iov->iov_len);
			error = uiomove((caddr_t) (where + o), c, uio);
			kmem_free(kernel_map, where, PAGE_SIZE);
			continue;

This code appears to:

1) Calculate the address of the start of the page
2) Fail if the requested address is above physical memory size
3) Allocate a page of memory
4) Find the offset from the start of the page
5) Calculate the size of the copy
6) Copy the memory
7) Free the allocation

I do not see how the physical address requested, which I believe to
be uio->uio_offset, is ever retrieved by the uiomove, which points to
inside the newly allocated buffer.

I would really appreciate it if someone could explain this.

Thanks,
-Jim
 _______________________________________________
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

  • Follow-Ups:
    • Re: How does /dev/mem work?
      • From: Michael Smith <email@hidden>
  • Prev by Date: Re: rusage::ru_maxrss in bytes or kilobytes
  • Next by Date: Re: How does /dev/mem work?
  • Previous by thread: Re: PowerMac7_2_PlatformPlugin.kext remark and questions (work around temperature/power sensor problem)
  • Next by thread: Re: How does /dev/mem work?
  • Index(es):
    • Date
    • Thread