mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-23 22:11: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:
parent
2de15b9aec
commit
35d4b9f381
@ -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);
|
||||
|
@ -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) {
|
||||
perror(PAGEMAP_FILE);
|
||||
exit(1);
|
||||
fd = open(PAGEMAP_FILE, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
perror(PAGEMAP_FILE);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
while (len) {
|
||||
if (n >= vec_len) {
|
||||
close(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user