# Automatic configuration of the UCW Library
-# (c) 2005 Martin Mares <mj@ucw.cz>
+# (c) 2005--2007 Martin Mares <mj@ucw.cz>
# (c) 2006 Robert Spalek <robert@ucw.cz>
### OS ###
Append("LIBS" => "-L/sw/lib");
Append("COPT" => "-I/sw/include");
# Fill in some constants not found in the system header files
- Set("PAGE_SIZE" => `sysctl -n hw.pagesize`);
- Set("SOL_TCP" => 6); #missing in /usr/include/netinet/tcp.h
+ Set("SOL_TCP" => 6); # missing in /usr/include/netinet/tcp.h
}
+# Determine page size
+Test("CPU_PAGE_SIZE", "Determining page size", sub {
+ my $p;
+ if (IsSet("CONFIG_DARWIN")) {
+ $p = `sysctl -n hw.pagesize`;
+ defined $p or Fail "sysctl hw.pagesize failed";
+ } elsif (IsSet("CONFIG_LINUX")) {
+ $p = `getconf PAGE_SIZE`;
+ defined $p or Fail "getconf PAGE_SIZE failed";
+ }
+ chomp $p;
+ return $p;
+});
+
if (IsSet("CONFIG_LARGE_FILES") && IsSet("CONFIG_LINUX")) {
# Use 64-bit versions of file functions
Set("CONFIG_LFS");
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
-#include <sys/user.h>
-static uns mmap_window_size = 16*PAGE_SIZE;
-static uns mmap_extend_size = 4*PAGE_SIZE;
+static uns mmap_window_size = 16*CPU_PAGE_SIZE;
+static uns mmap_extend_size = 4*CPU_PAGE_SIZE;
static struct cf_section fbmm_config = {
CF_ITEMS {
bfmm_map_window(struct fastbuf *f)
{
struct fb_mmap *F = FB_MMAP(f);
- sh_off_t pos0 = f->pos & ~(sh_off_t)(PAGE_SIZE-1);
+ sh_off_t pos0 = f->pos & ~(sh_off_t)(CPU_PAGE_SIZE-1);
int l = MIN((sh_off_t)mmap_window_size, F->file_extend - pos0);
- uns ll = ALIGN_TO(l, PAGE_SIZE);
- uns oll = ALIGN_TO(f->bufend - f->buffer, PAGE_SIZE);
+ uns ll = ALIGN_TO(l, CPU_PAGE_SIZE);
+ uns oll = ALIGN_TO(f->bufend - f->buffer, CPU_PAGE_SIZE);
int prot = ((F->mode & O_ACCMODE) == O_RDONLY) ? PROT_READ : (PROT_READ | PROT_WRITE);
DBG(" ... Mapping %x(%x)+%x(%x) len=%x extend=%x", (int)pos0, (int)f->pos, ll, l, (int)F->file_size, (int)F->file_extend);
if (f->buffer == (byte *) MAP_FAILED)
die("mmap(%s): %m", f->name);
#ifdef MADV_SEQUENTIAL
- if (ll > PAGE_SIZE)
+ if (ll > CPU_PAGE_SIZE)
madvise(f->buffer, ll, MADV_SEQUENTIAL);
#endif
f->bufend = f->buffer + l;
f->pos = end;
if (f->pos >= F->file_extend)
{
- F->file_extend = ALIGN_TO(F->file_extend + mmap_extend_size, (sh_off_t)PAGE_SIZE);
+ F->file_extend = ALIGN_TO(F->file_extend + mmap_extend_size, (sh_off_t)CPU_PAGE_SIZE);
if (sh_ftruncate(F->fd, F->file_extend))
die("ftruncate(%s): %m", f->name);
}
struct fb_mmap *F = FB_MMAP(f);
if (f->buffer)
- munmap(f->buffer, ALIGN_TO(f->bufend-f->buffer, PAGE_SIZE));
+ munmap(f->buffer, ALIGN_TO(f->bufend-f->buffer, CPU_PAGE_SIZE));
if (F->file_extend > F->file_size &&
sh_ftruncate(F->fd, F->file_size))
die("ftruncate(%s): %m", f->name);
#include "lib/lizard.h"
#include <sys/mman.h>
-#include <sys/user.h>
#include <fcntl.h>
#include <signal.h>
#include <setjmp.h>
{
unhandle_signal(SIGSEGV);
if (buf->ptr)
- munmap(buf->ptr, buf->len + PAGE_SIZE);
+ munmap(buf->ptr, buf->len + CPU_PAGE_SIZE);
xfree(buf);
}
static void
lizard_realloc(struct lizard_buffer *buf, uns max_len)
- /* max_len needs to be aligned to PAGE_SIZE */
+ /* max_len needs to be aligned to CPU_PAGE_SIZE */
{
if (max_len <= buf->len)
return;
max_len = 2*buf->len;
if (buf->ptr)
- munmap(buf->ptr, buf->len + PAGE_SIZE);
+ munmap(buf->ptr, buf->len + CPU_PAGE_SIZE);
buf->len = max_len;
- buf->ptr = mmap(NULL, buf->len + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ buf->ptr = mmap(NULL, buf->len + CPU_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (buf->ptr == MAP_FAILED)
- die("mmap(anonymous, %d bytes): %m", (uns)(buf->len + PAGE_SIZE));
- if (mprotect(buf->ptr + buf->len, PAGE_SIZE, PROT_NONE) < 0)
+ die("mmap(anonymous, %d bytes): %m", (uns)(buf->len + CPU_PAGE_SIZE));
+ if (mprotect(buf->ptr + buf->len, CPU_PAGE_SIZE, PROT_NONE) < 0)
die("mprotect: %m");
}
* case of buffer-overflow. The function is not re-entrant because of a
* static longjmp handler. */
{
- uns lock_offset = ALIGN_TO(expected_length + 3, PAGE_SIZE); // +3 due to the unaligned access
+ uns lock_offset = ALIGN_TO(expected_length + 3, CPU_PAGE_SIZE); // +3 due to the unaligned access
if (lock_offset > buf->len)
lizard_realloc(buf, lock_offset);
volatile sh_sighandler_t old_handler = set_signal_handler(SIGSEGV, sigsegv_handler);
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
-#include <sys/user.h>
static char *options = CF_SHORT_OPTS "cdtx";
static char *help = "\
else
{
int smaller_li;
- if (li >= (int) PAGE_SIZE)
- smaller_li = li - PAGE_SIZE;
+ if (li >= (int) CPU_PAGE_SIZE)
+ smaller_li = li - CPU_PAGE_SIZE;
else
smaller_li = 0;
struct lizard_buffer *buf = lizard_alloc();
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include <sys/user.h>
#ifdef CONFIG_PARTMAP_IS_MMAP
#define PARTMAP_WINDOW ~(size_t)0
if (p->start_map)
munmap(p->start_map, p->end_off - p->start_off);
sh_off_t end = start + size;
- sh_off_t win_start = start/PAGE_SIZE * PAGE_SIZE;
+ sh_off_t win_start = start/CPU_PAGE_SIZE * CPU_PAGE_SIZE;
size_t win_len = PARTMAP_WINDOW;
if ((sh_off_t) (win_start+win_len) > p->file_size)
- win_len = ALIGN_TO(p->file_size - win_start, PAGE_SIZE);
+ win_len = ALIGN_TO(p->file_size - win_start, CPU_PAGE_SIZE);
if ((sh_off_t) (win_start+win_len) < end)
die("partmap_map: Window is too small for mapping %d bytes", size);
p->start_map = sh_mmap(NULL, win_len, p->writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, p->fd, win_start);
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include <sys/user.h>
/*
* The cache lives in a mmapped file of the following format:
{
#ifndef CONFIG_LINUX
/* We don't need msyncing on Linux, since the mappings are guaranteed to be coherent */
- len += (start % PAGE_SIZE);
- start -= start % PAGE_SIZE;
- len = ALIGN_TO(len, PAGE_SIZE);
+ len += (start % CPU_PAGE_SIZE);
+ start -= start % CPU_PAGE_SIZE;
+ len = ALIGN_TO(len, CPU_PAGE_SIZE);
if (msync(q->mmap_data + start, len, MS_ASYNC | MS_INVALIDATE) < 0)
log(L_ERROR, "Cache %s: msync failed: %m", q->file_name);
#endif