Date: Sat, 10 Jul 2004 02:15:12 +0200 From: thefly <thefly@acaro.org> To: freebsd-hackers@freebsd.org Subject: mmap() implementation Message-ID: <20040710001512.GA13356@tyler>
next in thread | raw e-mail | index | archive | help
--YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello everybody, i'm implementing the mmap part of my nodegraph. At the moment i'm actually stuck at a point where the process can't actually access the memory allocation: this is the mmap() function: static int ng_counter_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot) { if (nprot !=3D VM_PROT_READ) return (-1); =20 *paddr =3D (vm_paddr_t) (ng_counters.B_array + offset / sizeof(u_in= t32_t)); =20 return (0); } ng_couters.B_array is u_int32_t *, and the memory is allocated via : counters->B_array =3D (u_int32_t*) contigmalloc((65536*2*sizeof(u_int32_t)= )+(65536*2*sizeof(u_int16_t)), M_NG_COUNTER, M_WAITOK | M_ZERO, 0, ~0, PAGE= _SIZE, 0); I actually need 2 u_int32_t arrays and two u_int16_t arrays, and need to ex= port all of them at the same time. I don't know if i need anything like vtophys() inside of that. The app in userspace does this: array =3D (unsigned int *) mmap(0, (65536*2*sizeof(u_int32_t))+(655= 36*2*sizeof(u_int16_t)), PROT_READ, 0, fd, 0); if(array =3D=3D (void *) -1){ printf("mmap failed\n"); return -1; } for(i=3D0; i<65536; i++){ printf("array[%d]=3D%u\n", i, *(array+i)); } i'm trying to print the values of the first array, but what i get is a lot of: array[484]=3D4294967295 array[485]=3D4294967295 array[486]=3D4294967295 array[487]=3D4294967295 array[488]=3D4294967295 array[489]=3D4294967295 Thanks in advance --=20 Claudio "thefly" Martella thefly@acaro.org GNU/PG keyid: 0x8EA95625 --YiEDa0DAkWCtVeE4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFA7zUPygeBqo6pViURAsA/AKDA7Gwp0rbrZ0L1CmcneXc62OmsNACdEM+w FL8+9wPfiTP0+cUMpH9dRyI= =VrLK -----END PGP SIGNATURE----- --YiEDa0DAkWCtVeE4--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040710001512.GA13356>