/* Support for memory-mapped windows into a BFD.
- Copyright (C) 1995-2023 Free Software Foundation, Inc.
+ Copyright (C) 1995-2024 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
though. */
/*
-INTERNAL_DEFINITION
-
-.struct _bfd_window_internal {
+INTERNAL
+.typedef struct _bfd_window_internal
+.{
. struct _bfd_window_internal *next;
. void *data;
. bfd_size_type size;
. int refcount : 31; {* should be enough... *}
. unsigned mapped : 1; {* 1 = mmap, 0 = malloc *}
-.};
+.}
+.bfd_window_internal;
+.
+
+EXTERNAL
+.struct _bfd_window_internal;
+.
+.typedef struct _bfd_window
+.{
+. {* What the user asked for. *}
+. void *data;
+. bfd_size_type size;
+. {* The actual window used by BFD. Small user-requested read-only
+. regions sharing a page may share a single window into the object
+. file. Read-write versions shouldn't until I've fixed things to
+. keep track of which portions have been claimed by the
+. application; don't want to give the same region back when the
+. application wants two writable copies! *}
+. struct _bfd_window_internal *i;
+.}
+.bfd_window;
+.
+*/
+
+/*
+FUNCTION
+ bfd_init_window
+
+SYNOPSIS
+ void bfd_init_window (bfd_window *);
+
+DESCRIPTION
+ Initialise mmap window.
*/
void
windowp->size = 0;
}
+/*
+FUNCTION
+ bfd_free_window
+
+SYNOPSIS
+ void bfd_free_window (bfd_window *);
+
+DESCRIPTION
+ Finalise mmap window struct.
+*/
+
void
bfd_free_window (bfd_window *windowp)
{
free (i);
}
-static int ok_to_map = 1;
+/*
+FUNCTION
+ bfd_get_file_window
+
+SYNOPSIS
+ bool bfd_get_file_window
+ (bfd *, file_ptr, bfd_size_type, bfd_window *, bool {*writable*});
+
+DESCRIPTION
+ mmap from a bfd's iostream.
+*/
bool
bfd_get_file_window (bfd *abfd,
bfd_window *windowp,
bool writable)
{
+ static int ok_to_map = 1;
static size_t pagesize;
bfd_window_internal *i = windowp->i;
bfd_size_type size_to_alloc = size;
i->refcount = 1;
if (bfd_seek (abfd, offset, SEEK_SET) != 0)
goto free_and_fail;
- i->size = bfd_bread (i->data, size, abfd);
+ i->size = bfd_read (i->data, size, abfd);
if (i->size != size)
goto free_and_fail;
i->mapped = 0;