/*
  mmlib.h
  Interface library for mergemod & mergemem
  
  This file is part of mergemem by Philipp Richter & Philipp Reisner

  mergemem is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.
  
  mergemem is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with mergemem; see the file COPYING.  If not, write to
  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/


/* 

   see man mmlib(3)

****
 !!COMMENTS WELCOME!!
****

        mergemem library 

The intention of this file is to provide a _stable_ interface for
both, the the mergemod programmers _and_ the mergemem programmers. 

* Hide the interface of mergemod
  (device & ioctls, syscalls, proc fs hacks, ... )
* Hide the semantics of mergemod
  (one merge per system call, many merges per system call)
* Allow different checksums
* See this calls not as commands, see them as advices to the 
  memory management subsystem of the kernel
* Not to predetermine the search heuristics.

*/
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>

typedef struct
{
  const void * v_addr;   /* virtual address  */
  const void * p_addr;   /* physical address */
  size_t count;          /* reference count  */
  unsigned long hash;    /* hash             */
} MPAGEINFO;

ssize_t m_getpageinfos(  
		       pid_t pid,          
		       const void * start,
		       const void * end,
		       MPAGEINFO * pageinfos,
		       size_t nel,
		       const void * * contp );

ssize_t m_hashpages(
		    pid_t pid,
		    MPAGEINFO * pageinfos,
		    size_t nel,
		    unsigned long (*hashfunction)(const void* addr, size_t size) );


ssize_t m_set_hash_default(
			   unsigned long (*hashfunction)(const void* addr, size_t size) );


unsigned long m_hash_addrothalf(const void* addr, size_t size);
unsigned long m_libhash_addrothalf(const void* addr, size_t size);

unsigned long m_hash_const(const void* addr, size_t size);
unsigned long m_libhash_const(const void* addr, size_t size);


#ifdef UWN__KERNEL__
typedef struct
{
  const pid_t spid;
  const void * const sv_addr;
  const pid_t dpid;
  const void * const dv_addr;
  int status;
} MEQUALPAIR;
#else
typedef struct
{
  pid_t spid;
  const void * sv_addr;
  pid_t dpid;
  const void * dv_addr;
  int status;
} MEQUALPAIR;
#endif

ssize_t m_merge(
		MEQUALPAIR * pagepairs,
		size_t nel );










