Example #1
0
bool handler__reset(globals_t * vars, char **argv, unsigned argc)
{
    USEPARAMS();

    if (vars->matches) { free(vars->matches); vars->matches = NULL; vars->num_matches = 0; }

    /* refresh list of regions */
    l_destroy(vars->regions);

    /* create a new linked list of regions */
    if ((vars->regions = l_init()) == NULL) {
        show_error("sorry, there was a problem allocating memory.\n");
        return false;
    }

    /* read in maps if a pid is known */
    if (vars->target && readmaps(vars->target, vars->regions) != true) {
        show_error("sorry, there was a problem getting a list of regions to search.\n");
        show_warn("the pid may be invalid, or you don't have permission.\n");
        vars->target = 0;
        return false;
    }

    return true;
}
Example #2
0
/*
  Removes the first item held by the list.
*/
void l_remove_front(linked_list list) {
  if(list->length > 1) {
      list->front = list->front->next; // points to next item in list
      list->length -= 1; // decrements size
      list->front->prev = NULL; // points to NULL
  }
  else {
      l_destroy(list); // if the list is equal to 1
  }    
}
Example #3
0
/* concatenate list src with list dst */
int l_concat(list_t *dst, list_t **src)
{
    void *data;
    element_t *n;

    n = (*src)->head;
    
    while (n) {
        l_remove(*src, NULL, &data);
        if (l_append(dst, NULL, data) == -1)
            return -1;
        
        n = (*src)->head;
    }
    
    l_destroy(*src);
    
    *src = NULL;
    
    return 0;
}
Example #4
0
FUNCTION objend ()
{
	register Ocb * o;
	extern int aggressive;

  Debug

	o = xqting_ocb;

	destroy_message_vector (o);

	if ( o->centry == DCRT || o->centry == DDES )
	{
		unmark_macro ( o->ci );
	}
	else
	{
		register Msgh * n;

		for ( n = fstigb ( o->ci ); n; n = nxtigb ( n ) )
		{
			if ( n->mtype != DYNDSMSG )
				unmark_macro ( n );
		}
	}

	if ( o->centry == INIT || o->centry == DCRT || o->centry == DDES )
	{
#ifdef SOM

	/* Update the phase's highest-seen ept field to the Ept of the event
	  just completed.  Also update the amount of total unrolled back work
	  done by the phase.  */

		o->Ept = o->sb->Ept;

#endif SOM
		save_state (o);
	}

	if ( o->centry == EVENT )
	{
		o->stats.numecomp++;

		o->eventTimePermitted -= o->sb->effectWork;
#ifdef SOM
	/* Update the phase's highest-seen ept field to the Ept of the event
	  just completed.  Also update the amount of total unrolled back work
	  done by the phase.  */

		o->Ept = o->sb->Ept;

#endif SOM

		save_state ( o );
	}
	else
	if ( o->centry == TERM )
	{
#ifdef RBC
		if ( o->uses_rbc )
			l_destroy ( o->sb );
		else
		/* destroy_state and rollback chip don't mix */
#endif
		destroy_state ( o->sb );

		o->sb = NULL;
		l_destroy ( o->stk );
		o->stk = NULL;
#ifdef RBC
		if ( o->uses_rbc && rollback_op ( o, 1, posinfPlus1 ) )
		{
			printf ( "weird error term objend for %s\n", o->name );
			tester();
		}
#endif

		o->ci = NULL;
		o->co = NULL;
		o->control = EDGE;
		o->runstat = BLKINF;
		if ( ! aggressive )
			cancel_omsgs ( o, o->svt, o->phase_end );
		l_remove ( o );
		o->svt = posinfPlus1;
		l_insert ( l_prev_macro ( _prqhd ), o );
 
		dispatch ();
		return;
	}

	go_forward ( o ) ;

	dispatch ();
}
Example #5
0
void big_test() {
    linked_list list = l_create();

  l_add_front(list, 3);

  length_test(list, 1);
  front_test(list, 3);
  back_test(list, 3);
  //list = 3


  l_add_back(list, 4);
  length_test(list, 2);
  front_test(list, 3);
  back_test(list, 4);
  //list = 3, 4

  
  l_add_front(list, 2);
  length_test(list, 3);
  front_test(list, 2);
  back_test(list, 4);
  //list = 2, 3, 4

  
  int array1[] = {2, 3, 4};
  print_test(list, array1, 3);


  l_add_front(list, 1);
  l_add_back(list, 5);
  length_test(list, 5);
  front_test(list, 1);
  back_test(list, 5);
  //list = 1, 2, 3, 4, 5

  
  find_test(list, 3, 1);
  link l = l_find(list, 3);
  l_remove(list, l);
  find_test(list, 3, 0);
  length_test(list, 4);
  front_test(list, 1);
  back_test(list, 5);
  //list = 1, 2, 4, 5

  
  int array2[] = {1, 2, 4, 5};
  print_test(list, array2, 4);

  
  l_remove_back(list);
  length_test(list, 3);
  back_test(list, 4);
  //list = 1, 2, 4
  
  l_remove_front(list);
  length_test(list, 2);
  front_test(list, 2);
  //list = 2, 4

  l_destroy(list);
}
Example #6
0
/* dregion [!][x][,x,...] */
bool handler__dregion(globals_t * vars, char **argv, unsigned argc)
{
    unsigned id;
    bool invert = false;
    char *end = NULL, *idstr = NULL, *block = NULL;
    element_t *np, *pp;
    list_t *keep = NULL;
    region_t *save;

    /* need an argument */
    if (argc < 2) {
        show_error("expected an argument, see `help dregion`.\n");
        return false;
    }

     /* check that there is a process known */
    if (vars->target == 0) {
        show_error("no target specified, see `help pid`\n");
        return false;
    }
    
    /* check for an inverted match */
    if (*argv[1] == '!') {
        invert = true;
        /* create a copy of the argument for strtok(), +1 to skip '!' */
        block = strdupa(argv[1] + 1);
        
        /* check for lone '!' */
        if (*block == '\0') {
            show_error("inverting an empty set, maybe try `reset` instead?\n");
            return false;
        }
        
        /* create a list to keep the specified regions */
        if ((keep = l_init()) == NULL) {
            show_error("memory allocation error.\n");
            return false;
        }
        
    } else {
        invert = false;
        block = strdupa(argv[1]);
    }

    /* loop for every number specified, eg "1,2,3,4,5" */
    while ((idstr = strtok(block, ",")) != NULL) {
        region_t *r = NULL;
        
        /* set block to NULL for strtok() */
        block = NULL;
        
        /* attempt to parse as a regionid */
        id = strtoul(idstr, &end, 0x00);

        /* check that worked, "1,abc,4,,5,6foo" */
        if (*end != '\0' || *idstr == '\0') {
            show_error("could not parse argument %s.\n", idstr);
            if (invert) {
                if (l_concat(vars->regions, &keep) == -1) {
                    show_error("there was a problem restoring saved regions.\n");
                    l_destroy(vars->regions);
                    l_destroy(keep);
                    return false;
                }
            }
            assert(keep == NULL);
            return false;
        }
        
        /* initialise list pointers */
        np = vars->regions->head;
        pp = NULL;
        
        /* find the correct region node */
        while (np) {
            r = np->data;
            
            /* compare the node id to the id the user specified */
            if (r->id == id)
                break;
            
            pp = np; /* keep track of prev for l_remove() */
            np = np->next;
        }

        /* check if a match was found */
        if (np == NULL) {
            show_error("no region matching %u, or already moved.\n", id);
            if (invert) {
                if (l_concat(vars->regions, &keep) == -1) {
                    show_error("there was a problem restoring saved regions.\n");
                    l_destroy(vars->regions);
                    l_destroy(keep);
                    return false;
                }
            }
            if (keep)
                l_destroy(keep);
            return false;
        }
        
        np = pp;
        
        /* save this region if the match is inverted */
        if (invert) {
            
            assert(keep != NULL);
            
            l_remove(vars->regions, np, (void *) &save);
            if (l_append(keep, keep->tail, save) == -1) {
                show_error("sorry, there was an internal memory error.\n");
                free(save);
                return false;
            }
            continue;
        }
        
        /* check for any affected matches before removing it */
        if(vars->num_matches > 0)
        {
            region_t *s;

            /* determine the correct pointer we're supposed to be checking */
            if (np) {
                assert(np->next);
                s = np->next->data;
            } else {
                /* head of list */
                s = vars->regions->head->data;
            }
            
            if (!(vars->matches = delete_by_region(vars->matches, &vars->num_matches, s, false)))
            {
                show_error("memory allocation error while deleting matches\n");
            }
        }

        l_remove(vars->regions, np, NULL);
    }

    if (invert) {
        region_t *s = keep->head->data;
        
        if (vars->num_matches > 0)
        {
            if (!(vars->matches = delete_by_region(vars->matches, &vars->num_matches, s, true)))
            {
                show_error("memory allocation error while deleting matches\n");
            }
        }
            
        /* okay, done with the regions list */
        l_destroy(vars->regions);
        
        /* and switch to the keep list */
        vars->regions = keep;
    }

    return true;
}