Ejemplo n.º 1
0
void *save_realloc2(void *optr, size_t size, ReallocFunction rf){
  unsigned msize = save_mall_size(size);
  char *ptr;

  /* First we must dequeue the old save block, after that
     we try to realloc, if that succeeds we enqueue the new
     block, if it fails we have to enqueue the old one anew
     so we must deduce the size of that old block first. */

  struct mall_data *mdp0 = task_data->mall_data,
      **prevnext0 = &task_data->mall_data;
  while (mdp0 != NULL && mdp0->self != (((char *) optr))) { 
      prevnext0 = &mdp0->next;
      mdp0 = mdp0->next;
  }
  /* mdp0 == NULL (can) mean that the block that is realloced
   have been malloced with an (for example) ordinary malloc
   (that is not a save_malloc). This is handled like: no dequeing
   is done of that block, the new block is enqueued */ 
  if (mdp0 != NULL)
      save_mall_deq(((char *) optr));

  if ((ptr = (*rf)(optr, msize + sizeof(struct mall_data))) != NULL &&
      check_hook())
      save_mall_enq((void *) ptr, (void *) (ptr + msize));
  else if (mdp0 != NULL)
      /* re-enqueue the old block that has just been dequeued */
      save_mall_enq(((char *) optr), mdp0);
  
  return((void *) ptr);
}
Ejemplo n.º 2
0
void save_delete_hook(FUNCPTR func, caddr_t parm)
{
  if (check_hook()) {
    task_data->delete_hook = func;
    task_data->hook_data = parm;
  }
}
Ejemplo n.º 3
0
/* The dealing with FILE *'s below isn't strictly correct, we assume
   that one never has several pointing to the same fd - in the unlikely
   event that one does, all but the last one opened is forgotten */
FILE *save_fopen(const char *filename, char *type){
  FILE *fp;
    
  if ((fp = fopen(filename, type)) != NULL &&
      check_hook() && fileno(fp) < task_data->max_files)
    task_data->open_fps[fileno(fp)] = fp;
  return(fp);
}
Ejemplo n.º 4
0
void *save_malloc2(size_t size, MallocFunction mf){
  unsigned msize = save_mall_size(size);
  char *ptr;

  if ((ptr = (*mf)(msize + sizeof(struct mall_data))) != NULL &&
      check_hook())
    save_mall_enq((void *) ptr, (void *) (ptr + msize));
  return((void *) ptr);
}
Ejemplo n.º 5
0
void *save_calloc2(size_t nelem, size_t elsize, CallocFunction cf){
  unsigned msize = save_mall_size(nelem * elsize);
  char *ptr;

  if ((ptr = (*cf)(1, msize + sizeof(struct mall_data))) != NULL &&
      check_hook())
    save_mall_enq((void *) ptr, (void *) (ptr + msize));
  return((void *) ptr);
}
Ejemplo n.º 6
0
FILE *save_fdopen(int fd, char *type){
  FILE *fp;
    
  if ((fp = fdopen(fd, type)) != NULL &&
      check_hook() && fileno(fp) < task_data->max_files) {
    task_data->open_fps[fileno(fp)] = fp;
    FD_CLR(fd, &task_data->open_fds);
  }
  return(fp);
}
void test_tree()
{
	typedef boost::intrusive::rbtree<ValueUsingHook, boost::intrusive::base_hook<my_hook> > my_tree;
//	typedef boost::intrusive::rbtree<ValueUsingHook, boost::intrusive::base_hook<my_hook>, boost::intrusive::annotations<> > my_tree;

	my_tree tree;

	typedef my_tree::node_algorithms node_algorithms;
	typedef my_tree::node_traits node_traits;
	node_algorithms::node& header(*tree.end());

	ValueUsingHook::a = 0;
	for (int i = 0; i < 100; ++i) {
		tree.insert_equal(*(new ValueUsingHook));
		check_hook(&header, static_cast<my_hook*>(node_traits::get_left(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
	ValueUsingHook::a = -100;
	for (int i = 0; i < 100; ++i) {
		tree.insert_equal(*(new ValueUsingHook));
		check_hook(&header, static_cast<my_hook*>(node_traits::get_left(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
	ValueUsingHook::a = 0;
	for (int i = 0; i < 50; ++i) {
		tree.erase(tree.begin());
		check_hook(&header, static_cast<my_hook*>(node_traits::get_left(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
	for (int i = 0; i < 50; ++i) {
		my_tree::iterator endIt = tree.end();
		tree.erase(--endIt);
		check_hook(&header, static_cast<my_hook*>(node_traits::get_right(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
}
Ejemplo n.º 8
0
FILE *save_freopen(char *filename, char *type, FILE *stream){
  FILE *fp;

  if (check_hook()) {
    if(fileno(stream) < task_data->max_files &&
       task_data->open_fps[fileno(stream)] == stream)
      task_data->open_fps[fileno(stream)] = NULL;
    if ((fp = freopen(filename, type, stream)) != NULL &&
	fileno(fp) < task_data->max_files)
      task_data->open_fps[fileno(fp)] = fp;
  } else
    fp = freopen(filename, type, stream);
  return(fp);
}
void test_hook()
{
	typedef boost::intrusive::annotated_rbtree_algorithms<my_hook::boost_intrusive_tags::annotated_node_traits, my_annotation_list> node_algorithms;
//	typedef boost::intrusive::annotated_rbtree_algorithms<my_hook::boost_intrusive_tags::annotated_node_traits, boost::intrusive::annotations<> > node_algorithms;
	node_algorithms::node header;
	node_algorithms::init_header(&header);

	typedef node_algorithms ralgo;
	typedef ralgo::node_traits node_traits;

	for (int i = 0; i < 100; ++i) {
		ralgo::insert_equal(&header, &header, new ValueUsingHook(), CompareUsingHook());
		check_hook(&header, static_cast<my_hook*>(node_traits::get_left(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
	ValueUsingHook::a = -100;
	for (int i = 0; i < 100; ++i) {
		ralgo::insert_equal(&header, &header, new ValueUsingHook(), Compare());
		check_hook(&header, static_cast<my_hook*>(node_traits::get_left(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
	ValueUsingHook::a = 0;
	for (int i = 0; i < 50; ++i) {
		ralgo::erase(&header, my_annotated_node_traits::node_ptr(node_traits::get_left(&header)));
		check_hook(&header, static_cast<my_hook*>(node_traits::get_left(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
	for (int i = 0; i < 50; ++i) {
		ralgo::erase(&header, my_annotated_node_traits::node_ptr(node_traits::get_right(&header)));
		check_hook(&header, static_cast<my_hook*>(node_traits::get_right(&header)));
		std::cout << i << " ";
	}
	std::cout << std::endl;
}
Ejemplo n.º 10
0
int save_open(char *path, int flags, /*mode_t mode*/ ...){
  int fd;
  mode_t mode = 0;
  if(flags & O_CREAT){
      va_list pvar;
      va_start(pvar,flags);
#ifdef __GNUC__
#warning save_open() gives three known alignment warnings.
#endif
      mode = va_arg(pvar, mode_t);
      va_end(pvar);
  }
  if ((fd = open(path, flags, mode)) >= 0 && check_hook())
    FD_SET(fd, &task_data->open_fds);
  return(fd);
}
Ejemplo n.º 11
0
void save_cfree2(void *ptr, CfreeFunction cf)
{
  if (check_hook())
    save_mall_deq(((char *)ptr));
  (*cf)(ptr);
}
Ejemplo n.º 12
0
void save_free2(void *ptr, FreeFunction ff)
{
  if (check_hook())
    save_mall_deq(((char *) ptr));
  (*ff)(ptr);
}
Ejemplo n.º 13
0
void save_fd(int fd){
  if (fd >= 0 && check_hook() && fd < task_data->max_files)
    FD_SET(fd, &task_data->open_fds);
}
Ejemplo n.º 14
0
int save_creat(char *path, int mode){
  int fd;
  if ((fd = creat(path, mode)) >= 0 && check_hook())
    FD_SET(fd, &task_data->open_fds);
  return(fd);
}
Ejemplo n.º 15
0
int save_fclose(FILE *stream){
  if (check_hook() && fileno(stream) < task_data->max_files &&
      task_data->open_fps[fileno(stream)] == stream)
    task_data->open_fps[fileno(stream)] = NULL;
  return(fclose(stream));
}
Ejemplo n.º 16
0
int save_socket(int domain, int type, int protocol){
  int fd;
  if ((fd = socket(domain, type, protocol)) >= 0 && check_hook())
    FD_SET(fd, &task_data->open_fds);
  return(fd);
}
Ejemplo n.º 17
0
int save_accept(int s, struct sockaddr *addr, int *addrlen){
  int fd;
  if ((fd = accept(s, addr, addrlen)) >= 0 && check_hook())
    FD_SET(fd, &task_data->open_fds);
  return(fd);
}
Ejemplo n.º 18
0
int save_close(int fd){
  if (fd >= 0 && fd <= FD_SETSIZE && check_hook())
    FD_CLR(fd, &task_data->open_fds);
  return(close(fd));
}