| 46 |
#include "libbfd.h" |
#include "libbfd.h" |
| 47 |
#include "libiberty.h" |
#include "libiberty.h" |
| 48 |
|
|
| 49 |
|
#ifdef HAVE_MMAP |
| 50 |
|
#include <sys/mman.h> |
| 51 |
|
#endif |
| 52 |
|
|
| 53 |
/* In some cases we can optimize cache operation when reopening files. |
/* In some cases we can optimize cache operation when reopening files. |
| 54 |
For instance, a flush is entirely unnecessary if the file is already |
For instance, a flush is entirely unnecessary if the file is already |
| 55 |
closed, so a flush would use CACHE_NO_OPEN. Similarly, a seek using |
closed, so a flush would use CACHE_NO_OPEN. Similarly, a seek using |
| 392 |
return sts; |
return sts; |
| 393 |
} |
} |
| 394 |
|
|
| 395 |
|
static void * |
| 396 |
|
cache_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED, |
| 397 |
|
void *addr ATTRIBUTE_UNUSED, |
| 398 |
|
bfd_size_type len ATTRIBUTE_UNUSED, |
| 399 |
|
int prot ATTRIBUTE_UNUSED, |
| 400 |
|
int flags ATTRIBUTE_UNUSED, |
| 401 |
|
file_ptr offset ATTRIBUTE_UNUSED) |
| 402 |
|
{ |
| 403 |
|
void *ret = (void *) -1; |
| 404 |
|
|
| 405 |
|
if ((abfd->flags & BFD_IN_MEMORY) != 0) |
| 406 |
|
abort (); |
| 407 |
|
#ifdef HAVE_MMAP |
| 408 |
|
else |
| 409 |
|
{ |
| 410 |
|
FILE *f = bfd_cache_lookup (abfd, CACHE_NO_SEEK_ERROR); |
| 411 |
|
if (f == NULL) |
| 412 |
|
return ret; |
| 413 |
|
|
| 414 |
|
ret = mmap (addr, len, prot, flags, fileno (f), offset); |
| 415 |
|
if (ret == (void *) -1) |
| 416 |
|
bfd_set_error (bfd_error_system_call); |
| 417 |
|
} |
| 418 |
|
#endif |
| 419 |
|
|
| 420 |
|
return ret; |
| 421 |
|
} |
| 422 |
|
|
| 423 |
static const struct bfd_iovec cache_iovec = |
static const struct bfd_iovec cache_iovec = |
| 424 |
{ |
{ |
| 425 |
&cache_bread, &cache_bwrite, &cache_btell, &cache_bseek, |
&cache_bread, &cache_bwrite, &cache_btell, &cache_bseek, |
| 426 |
&cache_bclose, &cache_bflush, &cache_bstat |
&cache_bclose, &cache_bflush, &cache_bstat, &cache_bmmap |
| 427 |
}; |
}; |
| 428 |
|
|
| 429 |
/* |
/* |