/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
#include <stdlib.h>
#include <memory.h>
#include <errno.h>
#include <libelf.h>
#include "decl.h"
#include "msg.h"
/*
* File input
* These functions read input files.
* On SVR4 and newer systems use mmap(2). On older systems (or on
* file systems that don't support mmap, this code simulates mmap.
* When reading a file, enough memory is allocated to hold the file's
* image, and reads are delayed. When another part of the library
* wants to use a part of the file, it "fetches" the needed regions.
*
* An elf descriptor has a bit array to manage this. Each bit
* represents one "page" of the file. Pages are grouped into regions.
* The page size is tunable. Its value should be at least one disk
* block and small enough to avoid superfluous traffic.
*
* NBITS The number of bits in an unsigned. Each unsigned object
* holds a "REGION." A byte must have at least 8 bits;
* it may have more, though the extra bits at the top of
* the unsigned will be unused. Thus, for 9-bit bytes and
* 36-bit words, 4 bits at the top will stay empty.
*
* This mechanism gives significant performance gains for library
* handling (among other things), because programs typically don't
* need to look at entire libraries. The fastest I/O is no I/O.
*/
/*
* This global is used to hold the value of the PAGESIZE macro.
*
* This is because the PAGESIZE macro actually calls the
* sysconfig(_CONFIG_PAGESIZE) system call and we don't want
* to repeatedly call this through out libelf.
*/
static unsigned long _elf_pagesize = 0;
{
/*
* always validate region
*/
/*
* range outside of file bounds.
*/
_elf_seterr(EFMT_VM, 0);
return (OK_NO);
}
/*
* their is nothing else for us to do.
*/
return (OK_YES);
/*
* This uses arithmetic instead of masking because
* sizeof (unsigned) might not be a power of 2.
*
* Tail gives one beyond the last offset that must be retrieved,
* NOT the last in the region.
*/
sz = 0;
/*
* Scan through the files 'page table' and make sure
* that all of the pages in the specified range have been
* loaded into memory. As the pages are loaded the appropriate
* bit in the 'page table' is set.
*
* Note: This loop will only read in those pages which havn't
* been previously loaded into memory, if the page is
* already present it will not be re-loaded.
*/
if (sz != 0) {
/*
* Read in a 'chunk' of the elf image.
*/
/*
* do not read past the end of the file
*/
return (OK_NO);
}
sz = 0;
}
off += _elf_pagesize;
} else {
_elf_seterr(EREQ_NOFD, 0);
return (OK_NO);
}
sz += _elf_pagesize;
}
hdbit = 1;
++hdreg;
} else
hdbit <<= 1;
}
if (sz != 0) {
/*
* do not read past the end of the file
*/
return (OK_NO);
}
}
return (OK_YES);
}
{
{
if (off == 0)
return (OK_YES);
if (off == -1) {
return (OK_NO);
}
_elf_seterr(EIO_FBIG, 0);
return (OK_NO);
}
}
/*
* If the file is mapped, elf->ed_vm will stay null
* and elf->ed_image will need to be unmapped someday.
* If the file is read, elf->ed_vm and the file image
* are allocated together; free() elf->ed_vm.
*
* If the file can be written, disallow mmap.
* Otherwise, the input mapping and the output mapping
* can collide. Moreover, elf_update will truncate
* the file, possibly invalidating the input mapping.
* Disallowing input mmap forces the library to malloc
* and read the space, which will make output mmap safe.
* Using mmap for output reduces the swap space needed
* for the process, so that is given preference.
*/
{
register char *p;
return (OK_YES);
}
}
if (_elf_pagesize == 0)
/*
* If mmap fails, try read. Some file systems don't mmap
*/
{
return (OK_NO);
}
}
}
void
{
if (p == 0 || sz == 0)
return;
}