Commit 5506903c authored by Evan Hunt's avatar Evan Hunt

Merge rt28412b

- check for mmap() in configure
- implement isc_file_mmap() and isc_file_munmap() to do
  malloc()/read() and free() when run on systems that do not
  support mmap().
parent 6451b4d9
......@@ -278,6 +278,9 @@ int sigwait(const unsigned int *set, int *sig);
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
/* Define to 1 if you have the `nanosleep' function. */
#undef HAVE_NANOSLEEP
......@@ -329,6 +332,9 @@ int sigwait(const unsigned int *set, int *sig);
/* Define to 1 if you have the <sys/dyntune.h> header file. */
#undef HAVE_SYS_DYNTUNE_H
/* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
......
This diff is collapsed.
......@@ -298,7 +298,7 @@ esac
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h,,,
AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h,,,
[$ac_includes_default
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
......@@ -311,6 +311,11 @@ AC_C_VOLATILE
AC_CHECK_FUNC(sysctlbyname, AC_DEFINE(HAVE_SYSCTLBYNAME))
AC_C_FLEXIBLE_ARRAY_MEMBER
#
# Check for the existence of mmap to enable the fast format zones
#
AC_CHECK_FUNCS(mmap)
#
# Older versions of HP/UX don't define seteuid() and setegid()
#
......
......@@ -174,16 +174,16 @@ static isc_result_t
openfile_text(dns_loadctx_t *lctx, const char *master_file);
static isc_result_t
openfile_raw(dns_loadctx_t *lctx, const char *master_file);
load_text(dns_loadctx_t *lctx);
static isc_result_t
openfile_fast(dns_loadctx_t *lctx, const char *master_file);
openfile_raw(dns_loadctx_t *lctx, const char *master_file);
static isc_result_t
load_text(dns_loadctx_t *lctx);
load_raw(dns_loadctx_t *lctx);
static isc_result_t
load_raw(dns_loadctx_t *lctx);
openfile_fast(dns_loadctx_t *lctx, const char *master_file);
static isc_result_t
load_fast(dns_loadctx_t *lctx);
......@@ -779,39 +779,6 @@ genname(char *name, int it, char *buffer, size_t length) {
return (ISC_R_SUCCESS);
}
static isc_result_t
openfile_text(dns_loadctx_t *lctx, const char *master_file) {
return (isc_lex_openfile(lctx->lex, master_file));
}
static isc_result_t
openfile_raw(dns_loadctx_t *lctx, const char *master_file) {
isc_result_t result;
result = isc_stdio_open(master_file, "r", &lctx->f);
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_stdio_open() failed: %s",
isc_result_totext(result));
}
return (result);
}
static isc_result_t
openfile_fast(dns_loadctx_t *lctx, const char *master_file) {
isc_result_t result;
result = isc_stdio_open(master_file, "r", &lctx->f);
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_stdio_open() failed: %s",
isc_result_totext(result));
}
return (result);
}
static isc_result_t
generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs,
const char *source, unsigned int line)
......@@ -1032,6 +999,11 @@ check_wildcard(dns_incctx_t *ictx, const char *source, unsigned long line,
}
}
static isc_result_t
openfile_text(dns_loadctx_t *lctx, const char *master_file) {
return (isc_lex_openfile(lctx->lex, master_file));
}
static isc_result_t
load_text(dns_loadctx_t *lctx) {
dns_rdataclass_t rdclass;
......@@ -2183,6 +2155,20 @@ load_header(dns_loadctx_t *lctx) {
return (ISC_R_SUCCESS);
}
static isc_result_t
openfile_fast(dns_loadctx_t *lctx, const char *master_file) {
isc_result_t result;
result = isc_stdio_open(master_file, "r", &lctx->f);
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_stdio_open() failed: %s",
isc_result_totext(result));
}
return (result);
}
/*
* Load a fast format file, using mmap() to access RBT trees directly
*/
......@@ -2208,6 +2194,20 @@ load_fast(dns_loadctx_t *lctx) {
return (ISC_R_SUCCESS);
}
static isc_result_t
openfile_raw(dns_loadctx_t *lctx, const char *master_file) {
isc_result_t result;
result = isc_stdio_open(master_file, "r", &lctx->f);
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_stdio_open() failed: %s",
isc_result_totext(result));
}
return (result);
}
static isc_result_t
load_raw(dns_loadctx_t *lctx) {
isc_result_t result = ISC_R_SUCCESS;
......
......@@ -1071,7 +1071,7 @@ free_rbtdb(dns_rbtdb_t *rbtdb, isc_boolean_t log, isc_event_t *event) {
isc_mem_detach(&rbtdb->hmctx);
if (rbtdb->mmap_location != NULL)
munmap(rbtdb->mmap_location, rbtdb->mmap_size);
isc_file_munmap(rbtdb->mmap_location, rbtdb->mmap_size);
isc_mem_putanddetach(&rbtdb->common.mctx, rbtdb, sizeof(*rbtdb));
isc_ondestroy_notify(&ondest, rbtdb);
......@@ -7198,7 +7198,7 @@ deserialize(void *arg, FILE *f, off_t offset) {
flags |= MAP_FILE;
#endif
base = mmap(NULL, filesize, protect, flags, fd, 0);
base = isc_file_mmap(NULL, filesize, protect, flags, fd, 0);
if (base == NULL || base == MAP_FAILED)
return (ISC_R_FAILURE);
......
......@@ -322,6 +322,22 @@ isc_file_getsizefd(int fd, off_t *size);
* - ISC_R_SUCCESS on success
*/
void *
isc_file_mmap(void *addr, size_t len, int prot,
int flags, int fd, off_t offset);
/*%<
* Portable front-end to mmap(). If mmap() is not defined on this
* platform, then we simulate it by calling malloc() and read().
* (In this event, the addr, prot, and flags parameters are ignored).
*/
int
isc_file_munmap(void *addr, size_t len);
/*%<
* Portable front-end to munmap(). If munmap() is not defined on
* this platform, then we simply free the memory.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_FILE_H */
......@@ -65,6 +65,10 @@
#include <sys/stat.h>
#include <sys/time.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#include <isc/dir.h>
#include <isc/file.h>
#include <isc/log.h>
......@@ -599,3 +603,46 @@ isc_file_splitpath(isc_mem_t *mctx, char *path, char **dirname, char **basename)
return (ISC_R_SUCCESS);
}
void *
isc_file_mmap(void *addr, size_t len, int prot,
int flags, int fd, off_t offset)
{
#ifdef HAVE_MMAP
return (mmap(addr, len, prot, flags, fd, offset));
#else
void *buf;
ssize_t ret;
off_t end;
UNUSED(addr);
UNUSED(prot);
UNUSED(flags);
end = lseek(fd, 0, SEEK_END);
lseek(fd, offset, SEEK_SET);
if (end - offset < (off_t) len)
len = end - offset;
buf = malloc(len);
ret = read(fd, buf, len);
if (ret != (ssize_t) len) {
free(buf);
buf = NULL;
}
return (buf);
#endif
}
int
isc_file_munmap(void *addr, size_t len) {
#ifdef HAVE_MMAP
return (munmap(addr, len));
#else
UNUSED(len);
free(addr);
return (0);
#endif
}
......@@ -661,3 +661,37 @@ isc_file_splitpath(isc_mem_t *mctx, char *path, char **dirname, char **basename)
return (ISC_R_SUCCESS);
}
void *
isc_file_mmap(void *addr, size_t len, int prot,
int flags, int fd, off_t offset)
{
void *buf;
ssize_t ret;
off_t end;
UNUSED(addr);
UNUSED(prot);
UNUSED(flags);
end = lseek(fd, 0, SEEK_END);
lseek(fd, offset, SEEK_SET);
if (end - offset < (off_t) len)
len = end - offset;
buf = malloc(len);
ret = read(fd, buf, len);
if (ret != (ssize_t) len) {
free(buf);
buf = NULL;
}
return (buf);
}
int
isc_file_munmap(void *addr, size_t len) {
UNUSED(len);
free(addr);
return (0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment