1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-27 15:41:53 +02:00

libubb/physmem.c: remove physmem_xlat; cache open pagemap fd

To avoid contamination, we open the pagemap file with O_CLOEXEC.
This commit is contained in:
Werner Almesberger 2013-01-16 10:26:51 -03:00
parent 2de15b9aec
commit 35d4b9f381
2 changed files with 9 additions and 21 deletions

View File

@ -24,7 +24,6 @@ struct physmem_vec {
void *physmem_malloc(size_t size);
void *physmem_calloc(size_t size);
unsigned long physmem_xlat(void *v);
int physmem_xlat_vec(void *v, size_t len,
struct physmem_vec *vec, int vec_len);
int physmem_flush(const void *data, size_t size);

View File

@ -11,6 +11,8 @@
*/
#define _GNU_SOURCE /* for O_CLOEXEC */
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
@ -128,35 +130,22 @@ static unsigned long xlat_one(int fd, unsigned long vaddr)
}
unsigned long physmem_xlat(void *v)
{
unsigned long res;
int fd;
fd = open(PAGEMAP_FILE, O_RDONLY);
if (fd < 0) {
perror(PAGEMAP_FILE);
exit(1);
}
res = xlat_one(fd, (unsigned long) v);
close(fd);
return res;
}
int physmem_xlat_vec(void *v, size_t len,
struct physmem_vec *vec, int vec_len)
{
static int fd = -1;
unsigned long vaddr = (unsigned long) v;
unsigned long offset, this_len;
int fd;
int n = 0;
fd = open(PAGEMAP_FILE, O_RDONLY);
if (fd < 0) {
fd = open(PAGEMAP_FILE, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
perror(PAGEMAP_FILE);
exit(1);
}
}
while (len) {
if (n >= vec_len) {
close(fd);