Beispiel #1
0
static void free_mapping_file(int cap, void *addr, size_t mapsize)
/* NOTE: addr needs to be the same as what was supplied by alloc_mapping_file */
{
  Q__printf("MAPPING: free, cap=%s, addr=%p, mapsize=%zx\n",
	cap, addr, mapsize);
  smfree(&pgmpool, addr);
}
Beispiel #2
0
static void free_mapping_shm(int cap, void *addr, size_t mapsize)
/* NOTE: addr needs to be the same as what was supplied by alloc_mapping_shm */
{
  Q__printf("MAPPING: free, cap=%s, addr=%p, mapsize=%zx\n",
	cap, addr, mapsize);
  munmap(addr, mapsize);
}
Beispiel #3
0
static void *realloc_mapping_shm(int cap, void *addr, size_t oldsize, size_t newsize)
{
  void *ret;
  Q__printf("MAPPING: realloc, cap=%s, addr=%p, oldsize=%zx, newsize=%zx\n",
	cap, addr, oldsize, newsize);

  if (newsize <= oldsize)
    return mremap(addr, oldsize, newsize, MREMAP_MAYMOVE);

  /* we can't expand shared anonymous memory using mremap
     so we must allocate a new region and memcpy to it */
  ret = alloc_mapping_shm(cap, newsize);
  if (ret != MAP_FAILED) {
    memcpy(ret, addr, oldsize);
    free_mapping_shm(cap, addr, oldsize);
  }
  return ret;
}
Beispiel #4
0
/*
 * NOTE: DPMI relies on realloc_mapping() _not_ changing the address ('addr'),
 *       when shrinking the memory region.
 */
static void *realloc_mapping_file(int cap, void *addr, size_t oldsize, size_t newsize)
{
  Q__printf("MAPPING: realloc, cap=%s, addr=%p, oldsize=%zx, newsize=%zx\n",
	cap, addr, oldsize, newsize);
  if (cap & (MAPPING_EMS | MAPPING_DPMI)) {
    int size = smget_area_size(&pgmpool, addr);
    void *addr_;

    if (!size || size != oldsize) return (void *)-1;
    if (size == newsize) return addr;
		/* NOTE: smrealloc() does not change addr,
		 *       when shrinking the memory region.
		 */
    addr_ = smrealloc(&pgmpool, addr, newsize);
    if (!addr_) {
      Q_printf("MAPPING: pgrealloc(0x%p,0x%zx,) failed\n",
		addr, newsize);
      return (void *)-1;
    }
    return addr_;
  }
  return (void *)-1;
}
Beispiel #5
0
static int munmap_mapping_file(int cap, void *addr, size_t mapsize)
{
  Q__printf("MAPPING: unmap, cap=%s, addr=%p, size=%zx\n",
	cap, addr, mapsize);
  return munmap(addr, mapsize);
}
Beispiel #6
0
static void *alloc_mapping_file(int cap, size_t mapsize)
{
  Q__printf("MAPPING: alloc, cap=%s, mapsize=%zx\n", cap, mapsize);
  return smalloc(&pgmpool, mapsize);
}
Beispiel #7
0
static void *alloc_mapping_shm(int cap, size_t mapsize)
{
  Q__printf("MAPPING: alloc, cap=%s, mapsize=%zx\n", cap, mapsize);
  return mmap(0, mapsize, PROT_READ | PROT_WRITE,
    MAP_SHARED | MAP_ANONYMOUS, -1, 0);
}