OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [mmalloc/] [mmalloc.texi] - Diff between revs 579 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
\input texinfo  @c                                  -*- Texinfo -*-
\input texinfo  @c                                  -*- Texinfo -*-
@setfilename mmalloc.info
@setfilename mmalloc.info
 
 
@ifinfo
@ifinfo
@format
@format
START-INFO-DIR-ENTRY
START-INFO-DIR-ENTRY
* Mmalloc: (mmalloc).           The GNU mapped-malloc package.
* Mmalloc: (mmalloc).           The GNU mapped-malloc package.
END-INFO-DIR-ENTRY
END-INFO-DIR-ENTRY
@end format
@end format
 
 
This file documents the GNU mmalloc (mapped-malloc) package, written by
This file documents the GNU mmalloc (mapped-malloc) package, written by
fnf@@cygnus.com, based on GNU malloc written by mike@@ai.mit.edu.
fnf@@cygnus.com, based on GNU malloc written by mike@@ai.mit.edu.
 
 
Copyright (C) 1992 Free Software Foundation, Inc.
Copyright (C) 1992 Free Software Foundation, Inc.
 
 
Permission is granted to make and distribute verbatim copies of
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
this manual provided the copyright notice and this permission notice
are preserved on all copies.
are preserved on all copies.
 
 
@ignore
@ignore
Permission is granted to process this file through Tex and print the
Permission is granted to process this file through Tex and print the
results, provided the printed document carries copying permission
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
(this paragraph not being relevant to the printed manual).
 
 
@end ignore
@end ignore
Permission is granted to copy and distribute modified versions of this
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
manual under the conditions for verbatim copying, provided also that the
entire resulting derived work is distributed under the terms of a
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
permission notice identical to this one.
 
 
Permission is granted to copy and distribute translations of this manual
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
into another language, under the above conditions for modified versions.
@end ifinfo
@end ifinfo
@iftex
@iftex
@c @finalout
@c @finalout
@setchapternewpage odd
@setchapternewpage odd
@settitle MMALLOC, the GNU memory-mapped malloc package
@settitle MMALLOC, the GNU memory-mapped malloc package
@titlepage
@titlepage
@title mmalloc
@title mmalloc
@subtitle The GNU memory-mapped malloc package
@subtitle The GNU memory-mapped malloc package
@author Fred Fish
@author Fred Fish
@author Cygnus Support
@author Cygnus Support
@author Mike Haertel
@author Mike Haertel
@author Free Software Foundation
@author Free Software Foundation
@page
@page
 
 
@tex
@tex
\def\$#1${{#1}}  % Kluge: collect RCS revision info without $...$
\def\$#1${{#1}}  % Kluge: collect RCS revision info without $...$
\xdef\manvers{\$Revision: 1.1.1.1 $}  % For use in headers, footers too
\xdef\manvers{\$Revision: 1.1.1.1 $}  % For use in headers, footers too
{\parskip=0pt
{\parskip=0pt
\hfill Cygnus Support\par
\hfill Cygnus Support\par
\hfill fnf\@cygnus.com\par
\hfill fnf\@cygnus.com\par
\hfill {\it MMALLOC, the GNU memory-mapped malloc package}, \manvers\par
\hfill {\it MMALLOC, the GNU memory-mapped malloc package}, \manvers\par
\hfill \TeX{}info \texinfoversion\par
\hfill \TeX{}info \texinfoversion\par
}
}
@end tex
@end tex
 
 
@vskip 0pt plus 1filll
@vskip 0pt plus 1filll
Copyright @copyright{} 1992 Free Software Foundation, Inc.
Copyright @copyright{} 1992 Free Software Foundation, Inc.
 
 
Permission is granted to make and distribute verbatim copies of
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
this manual provided the copyright notice and this permission notice
are preserved on all copies.
are preserved on all copies.
 
 
Permission is granted to copy and distribute modified versions of this
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that
manual under the conditions for verbatim copying, provided also that
the entire resulting derived work is distributed under the terms of a
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
permission notice identical to this one.
 
 
Permission is granted to copy and distribute translations of this manual
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
into another language, under the above conditions for modified versions.
@end titlepage
@end titlepage
@end iftex
@end iftex
 
 
@ifinfo
@ifinfo
@node Top, Overview, (dir), (dir)
@node Top, Overview, (dir), (dir)
@top mmalloc
@top mmalloc
This file documents the GNU memory-mapped malloc package mmalloc.
This file documents the GNU memory-mapped malloc package mmalloc.
 
 
@menu
@menu
* Overview::                    Overall Description
* Overview::                    Overall Description
* Implementation::              Implementation
* Implementation::              Implementation
 
 
 --- The Detailed Node Listing ---
 --- The Detailed Node Listing ---
 
 
Implementation
Implementation
 
 
* Compatibility::               Backwards Compatibility
* Compatibility::               Backwards Compatibility
* Functions::                   Function Descriptions
* Functions::                   Function Descriptions
@end menu
@end menu
 
 
@end ifinfo
@end ifinfo
 
 
@node Overview, Implementation, Top, Top
@node Overview, Implementation, Top, Top
@chapter Overall Description
@chapter Overall Description
 
 
This is a heavily modified version of GNU @code{malloc}.  It uses
This is a heavily modified version of GNU @code{malloc}.  It uses
@code{mmap} as the basic mechanism for obtaining memory from the
@code{mmap} as the basic mechanism for obtaining memory from the
system, rather than @code{sbrk}.  This gives it several advantages over the
system, rather than @code{sbrk}.  This gives it several advantages over the
more traditional malloc:
more traditional malloc:
 
 
@itemize @bullet
@itemize @bullet
@item
@item
Several different heaps can be used, each of them growing
Several different heaps can be used, each of them growing
or shinking under control of @code{mmap}, with the @code{mmalloc} functions
or shinking under control of @code{mmap}, with the @code{mmalloc} functions
using a specific heap on a call by call basis.
using a specific heap on a call by call basis.
 
 
@item
@item
By using @code{mmap}, it is easy to create heaps which are intended to
By using @code{mmap}, it is easy to create heaps which are intended to
be persistent and exist as a filesystem object after the creating
be persistent and exist as a filesystem object after the creating
process has gone away.
process has gone away.
 
 
@item
@item
Because multiple heaps can be managed, data used for a
Because multiple heaps can be managed, data used for a
specific purpose can be allocated into its own heap, making
specific purpose can be allocated into its own heap, making
it easier to allow applications to ``dump'' and ``restore'' initialized
it easier to allow applications to ``dump'' and ``restore'' initialized
malloc-managed memory regions.  For example, the ``unexec'' hack popularized
malloc-managed memory regions.  For example, the ``unexec'' hack popularized
by GNU Emacs could potentially go away.
by GNU Emacs could potentially go away.
@end itemize
@end itemize
 
 
@node Implementation,  , Overview, Top
@node Implementation,  , Overview, Top
@chapter Implementation
@chapter Implementation
 
 
The @code{mmalloc} functions contain no internal static state.  All
The @code{mmalloc} functions contain no internal static state.  All
@code{mmalloc} internal data is allocated in the mapped in region, along
@code{mmalloc} internal data is allocated in the mapped in region, along
with the user data that it manages.  This allows it to manage multiple
with the user data that it manages.  This allows it to manage multiple
such regions and to ``pick up where it left off'' when such regions are
such regions and to ``pick up where it left off'' when such regions are
later dynamically mapped back in.
later dynamically mapped back in.
 
 
In some sense, malloc has been ``purified'' to contain no internal state
In some sense, malloc has been ``purified'' to contain no internal state
information and generalized to use multiple memory regions rather than a
information and generalized to use multiple memory regions rather than a
single region managed by @code{sbrk}.  However the new routines now need an
single region managed by @code{sbrk}.  However the new routines now need an
extra parameter which informs @code{mmalloc} which memory region it is dealing
extra parameter which informs @code{mmalloc} which memory region it is dealing
with (along with other information).  This parameter is called the
with (along with other information).  This parameter is called the
@dfn{malloc descriptor}.
@dfn{malloc descriptor}.
 
 
The functions initially provided by @code{mmalloc} are:
The functions initially provided by @code{mmalloc} are:
 
 
@example
@example
void *mmalloc_attach (int fd, void *baseaddr);
void *mmalloc_attach (int fd, void *baseaddr);
void *mmalloc_detach (void *md);
void *mmalloc_detach (void *md);
int mmalloc_errno (void *md);
int mmalloc_errno (void *md);
int mmalloc_setkey (void *md, int keynum, void *key);
int mmalloc_setkey (void *md, int keynum, void *key);
void *mmalloc_getkey (void *md, int keynum);
void *mmalloc_getkey (void *md, int keynum);
 
 
void *mmalloc (void *md, size_t size);
void *mmalloc (void *md, size_t size);
void *mrealloc (void *md, void *ptr, size_t size);
void *mrealloc (void *md, void *ptr, size_t size);
void *mvalloc (void *md, size_t size);
void *mvalloc (void *md, size_t size);
void mfree (void *md, void *ptr);
void mfree (void *md, void *ptr);
@end example
@end example
 
 
@menu
@menu
* Compatibility::               Backwards Compatibility
* Compatibility::               Backwards Compatibility
* Functions::                   Function Descriptions
* Functions::                   Function Descriptions
@end menu
@end menu
 
 
@node Compatibility, Functions, Implementation, Implementation
@node Compatibility, Functions, Implementation, Implementation
@section Backwards Compatibility
@section Backwards Compatibility
 
 
To allow a single malloc package to be used in a given application,
To allow a single malloc package to be used in a given application,
provision is made for the traditional @code{malloc}, @code{realloc}, and
provision is made for the traditional @code{malloc}, @code{realloc}, and
@code{free} functions to be implemented as special cases of the
@code{free} functions to be implemented as special cases of the
@code{mmalloc} functions.  In particular, if any of the functions that
@code{mmalloc} functions.  In particular, if any of the functions that
expect malloc descriptors are called with a @code{NULL} pointer rather than a
expect malloc descriptors are called with a @code{NULL} pointer rather than a
valid malloc descriptor, then they default to using an @code{sbrk} managed
valid malloc descriptor, then they default to using an @code{sbrk} managed
region.
region.
The @code{mmalloc} package provides compatible @code{malloc}, @code{realloc},
The @code{mmalloc} package provides compatible @code{malloc}, @code{realloc},
and @code{free} functions using this mechanism internally.
and @code{free} functions using this mechanism internally.
Applications can avoid this extra interface layer by simply including the
Applications can avoid this extra interface layer by simply including the
following defines:
following defines:
 
 
@example
@example
#define malloc(size)            mmalloc ((void *)0, (size))
#define malloc(size)            mmalloc ((void *)0, (size))
#define realloc(ptr,size)       mrealloc ((void *)0, (ptr), (size));
#define realloc(ptr,size)       mrealloc ((void *)0, (ptr), (size));
#define free(ptr)               mfree ((void *)0, (ptr))
#define free(ptr)               mfree ((void *)0, (ptr))
@end example
@end example
 
 
@noindent
@noindent
or replace the existing @code{malloc}, @code{realloc}, and @code{free}
or replace the existing @code{malloc}, @code{realloc}, and @code{free}
calls with the above patterns if using @code{#define} causes problems.
calls with the above patterns if using @code{#define} causes problems.
 
 
@node Functions,  , Compatibility, Implementation
@node Functions,  , Compatibility, Implementation
@section Function Descriptions
@section Function Descriptions
 
 
These are the details on the functions that make up the @code{mmalloc}
These are the details on the functions that make up the @code{mmalloc}
package.
package.
 
 
@table @code
@table @code
@item void *mmalloc_attach (int @var{fd}, void *@var{baseaddr});
@item void *mmalloc_attach (int @var{fd}, void *@var{baseaddr});
Initialize access to a @code{mmalloc} managed region.
Initialize access to a @code{mmalloc} managed region.
 
 
If @var{fd} is a valid file descriptor for an open file, then data for the
If @var{fd} is a valid file descriptor for an open file, then data for the
@code{mmalloc} managed region is mapped to that file.   Otherwise
@code{mmalloc} managed region is mapped to that file.   Otherwise
@file{/dev/zero} is used and the data will not exist in any filesystem object.
@file{/dev/zero} is used and the data will not exist in any filesystem object.
 
 
If the open file corresponding to @var{fd} is from a previous use of
If the open file corresponding to @var{fd} is from a previous use of
@code{mmalloc} and passes some basic sanity checks to ensure that it is
@code{mmalloc} and passes some basic sanity checks to ensure that it is
compatible with the current @code{mmalloc} package, then its data is
compatible with the current @code{mmalloc} package, then its data is
mapped in and is immediately accessible at the same addresses in
mapped in and is immediately accessible at the same addresses in
the current process as the process that created the file.
the current process as the process that created the file.
 
 
If @var{baseaddr} is not @code{NULL}, the mapping is established
If @var{baseaddr} is not @code{NULL}, the mapping is established
starting at the specified address in the process address space.  If
starting at the specified address in the process address space.  If
@var{baseaddr} is @code{NULL}, the @code{mmalloc} package chooses a
@var{baseaddr} is @code{NULL}, the @code{mmalloc} package chooses a
suitable address at which to start the mapped region, which will be the
suitable address at which to start the mapped region, which will be the
value of the previous mapping if opening an existing file which was
value of the previous mapping if opening an existing file which was
previously built by @code{mmalloc}, or for new files will be a value
previously built by @code{mmalloc}, or for new files will be a value
chosen by @code{mmap}.
chosen by @code{mmap}.
 
 
Specifying @var{baseaddr} provides more control over where the regions
Specifying @var{baseaddr} provides more control over where the regions
start and how big they can be before bumping into existing mapped
start and how big they can be before bumping into existing mapped
regions or future mapped regions.
regions or future mapped regions.
 
 
On success, returns a malloc descriptor which is used in subsequent
On success, returns a malloc descriptor which is used in subsequent
calls to other @code{mmalloc} package functions.  It is explicitly
calls to other @code{mmalloc} package functions.  It is explicitly
@samp{void *} (@samp{char *} for systems that don't fully support
@samp{void *} (@samp{char *} for systems that don't fully support
@code{void}) so that users of the package don't have to worry about the
@code{void}) so that users of the package don't have to worry about the
actual implementation details.
actual implementation details.
 
 
On failure returns @code{NULL}.
On failure returns @code{NULL}.
 
 
@item void *mmalloc_detach (void *@var{md});
@item void *mmalloc_detach (void *@var{md});
Terminate access to a @code{mmalloc} managed region identified by the
Terminate access to a @code{mmalloc} managed region identified by the
descriptor @var{md}, by closing the base file and unmapping all memory
descriptor @var{md}, by closing the base file and unmapping all memory
pages associated with the region.
pages associated with the region.
 
 
Returns @code{NULL} on success.
Returns @code{NULL} on success.
 
 
Returns the malloc descriptor on failure, which can subsequently
Returns the malloc descriptor on failure, which can subsequently
be used for further action (such as obtaining more information about
be used for further action (such as obtaining more information about
the nature of the failure).
the nature of the failure).
 
 
@item void *mmalloc (void *@var{md}, size_t @var{size});
@item void *mmalloc (void *@var{md}, size_t @var{size});
Given an @code{mmalloc} descriptor @var{md}, allocate additional memory of
Given an @code{mmalloc} descriptor @var{md}, allocate additional memory of
@var{size} bytes in the associated mapped region.
@var{size} bytes in the associated mapped region.
 
 
@item *mrealloc (void *@var{md}, void *@var{ptr}, size_t @var{size});
@item *mrealloc (void *@var{md}, void *@var{ptr}, size_t @var{size});
Given an @code{mmalloc} descriptor @var{md} and a pointer to memory
Given an @code{mmalloc} descriptor @var{md} and a pointer to memory
previously allocated by @code{mmalloc} in @var{ptr}, reallocate the
previously allocated by @code{mmalloc} in @var{ptr}, reallocate the
memory to be @var{size} bytes long, possibly moving the existing
memory to be @var{size} bytes long, possibly moving the existing
contents of memory if necessary.
contents of memory if necessary.
 
 
@item void *mvalloc (void *@var{md}, size_t @var{size});
@item void *mvalloc (void *@var{md}, size_t @var{size});
Like @code{mmalloc} but the resulting memory is aligned on a page boundary.
Like @code{mmalloc} but the resulting memory is aligned on a page boundary.
 
 
@item void mfree (void *@var{md}, void *@var{ptr});
@item void mfree (void *@var{md}, void *@var{ptr});
Given an @code{mmalloc} descriptor @var{md} and a pointer to memory previously
Given an @code{mmalloc} descriptor @var{md} and a pointer to memory previously
allocated by @code{mmalloc} in @var{ptr}, free the previously allocated memory.
allocated by @code{mmalloc} in @var{ptr}, free the previously allocated memory.
 
 
@item int mmalloc_errno (void *@var{md});
@item int mmalloc_errno (void *@var{md});
Given a @code{mmalloc} descriptor, if the last @code{mmalloc} operation
Given a @code{mmalloc} descriptor, if the last @code{mmalloc} operation
failed for some reason due to a system call failure, then
failed for some reason due to a system call failure, then
returns the associated @code{errno}.  Returns 0 otherwise.
returns the associated @code{errno}.  Returns 0 otherwise.
(This function is not yet implemented).
(This function is not yet implemented).
@end table
@end table
 
 
@bye
@bye
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.