Exemplo n.º 1
0
Arquivo: elf.c Projeto: DIKU-EDU/DiMS
// Assumes stream points to the first byte of a program header entry.
// After this function, stream points to one past the end of the associated
// segment. Also, the first 6 words of the p_header will be set.
static inline int
copy_cur_segment_aux(FILE *stream, unsigned char *mem, size_t memsz) {
  int retval = 0;

  struct p_header phdr;

  if (read_be_words(stream, &phdr.p_type, 6) != 0) {
    error(0, 0, "couldn't read program header entry.");
    return ELF_ERROR_IO_ERROR;
  }

  switch(phdr.p_type) {
  case PT_NULL:
  case PT_NOTE:
  case PT_MIPS_ABIFLAGS:
    // Naïvely skip the above.
    break;
  case PT_LOAD:
    retval = copy_segment(stream, &phdr, mem, memsz);
    break;
  default:
    error(0, 0, "unknown program header entry type 0x%x", phdr.p_type);
    retval = ELF_ERROR_NOT_SUPPORTED;
    break;
  }

  return retval;
}
Exemplo n.º 2
0
int distdrop ( cell_map *elev,
               cell_map *dist, cell_map *dir,
               cell_map *up, cell_map *dw,
               seg_map *segment_info, move *movements,
               queue **redo_segments)
{
    int all_done = 1;

    int **neighbours = new_int_map ( ( int ) sizeof ( movements ),
                                     ( int ) sizeof ( movements[0] ), NULL );

    elev->fd = Rast_open_old ( elev->name, "" );
    elev->type = Rast_get_map_type( elev->fd );

    init_seg_map(elev, segment_info);
    copy_segment(elev, 0);

    //print_map_with_seg ( elev, segment_info );

    while ( all_done ){ // if all_done != 0? continue: break
        all_done = queue_pixel ( redo_segments,  elev, dist,
                                 dir, up, dw, segment_info,
                                 movements, neighbours);
    }
    return 0;
}
Exemplo n.º 3
0
RndfOverlay *
rndf_overlay_new (RndfRouteNetwork * rndf)
{
    RndfOverlay * r = calloc (1, sizeof (RndfOverlay));

    r->rndf = rndf;

    r->waypoint_hash = g_hash_table_new (hash_waypoint_id, equal_waypoint_id);
    r->lane_hash = g_hash_table_new (hash_lane_id, equal_lane_id);

    int i;
    r->num_segments = rndf->num_segments;
    r->segments = calloc (rndf->num_segments, sizeof (RndfOverlaySegment));
    for (i = 0; i < rndf->num_segments; i++)
        copy_segment (r, r->segments + i, rndf->segments + i);

    r->num_zones = rndf->num_zones;
    r->zones = calloc (rndf->num_zones, sizeof (RndfOverlayZone));
    for (i = 0; i < rndf->num_zones; i++)
        copy_zone (r, r->zones + i, rndf->zones + i);

    r->num_checkpoints = rndf->num_checkpoints;
    r->checkpoints = calloc (rndf->num_checkpoints,
            sizeof (RndfOverlayCheckpoint));
    for (i = 0; i < rndf->num_checkpoints; i++)
        copy_checkpoint (r, r->checkpoints + i, rndf->checkpoints + i);

    g_hash_table_foreach (r->waypoint_hash, add_exits, r);

    IntersectionState inter_state;
    memset (&inter_state, 0, sizeof (inter_state));
    inter_state.rndf = r;
    g_hash_table_foreach (r->waypoint_hash, add_segment_cache, &inter_state);
    g_hash_table_foreach (r->waypoint_hash, add_intersections, &inter_state);
    g_hash_table_foreach (r->waypoint_hash, add_yields, &inter_state);
    g_array_free (inter_state.segments_no_stop, TRUE);
    g_array_free (inter_state.segments_stopline, TRUE);

    compute_lane_boundary_expectations (r);

    for (i = 0; i < r->num_segments; i++)
        compute_lane_change_pointers (r, r->segments + i);

    // fill in lane hash
    for (int segidx = 0; segidx < r->num_segments; segidx++) {
        RndfOverlaySegment *seg = &r->segments[segidx];

        for (int laneidx = 0; laneidx < seg->num_lanes; laneidx++) {
            int32_t *id = malloc(2 * sizeof(int32_t));
            id[0] = seg->segment->id;
            id[1] = seg->lanes[laneidx].lane->id;
            g_hash_table_insert(r->lane_hash, id, &seg->lanes[laneidx]);
        }
    }

    return r;
}
Exemplo n.º 4
0
/* Loop through all load commands and dump them.  Then write the Mach
   header.  */
static void
dump_it (void)
{
  int i;
  long linkedit_delta = 0;

  printf ("--- Load Commands written to Output File ---\n");

  for (i = 0; i < nlc; i++)
    switch (lca[i]->cmd)
      {
      case LC_SEGMENT:
	{
	  struct segment_command *scp = (struct segment_command *) lca[i];
	  if (strncmp (scp->segname, SEG_DATA, 16) == 0)
	    {
	      /* save data segment file offset and segment_command for
		 unrelocate */
	      if (data_segment_old_fileoff)
		unexec_error ("cannot handle multiple DATA segments"
			      " in input file");
	      data_segment_old_fileoff = scp->fileoff;
	      data_segment_scp = scp;

	      copy_data_segment (lca[i]);
	    }
	  else if (strncmp (scp->segname, EMACS_READ_ONLY_SEGMENT, 16) == 0)
	    {
	      copy_emacs_read_only_segment (lca[i]);
	    }
	  else
	    {
	      if (strncmp (scp->segname, SEG_LINKEDIT, 16) == 0)
		{
		  if (linkedit_delta)
		    unexec_error ("cannot handle multiple LINKEDIT segments"
				  " in input file");
		  linkedit_delta = curr_file_offset - scp->fileoff;
		}

	      copy_segment (lca[i]);
	    }
	}
	break;
      case LC_SYMTAB:
	copy_symtab (lca[i], linkedit_delta);
	break;
      case LC_DYSYMTAB:
	copy_dysymtab (lca[i], linkedit_delta);
	break;
      case LC_TWOLEVEL_HINTS:
	copy_twolevelhints (lca[i], linkedit_delta);
	break;
#ifdef LC_DYLD_INFO
      case LC_DYLD_INFO:
      case LC_DYLD_INFO_ONLY:
	copy_dyld_info (lca[i], linkedit_delta);
	break;
#endif
#ifdef LC_FUNCTION_STARTS
      case LC_FUNCTION_STARTS:
#ifdef LC_DATA_IN_CODE
      case LC_DATA_IN_CODE:
#endif
#ifdef LC_DYLIB_CODE_SIGN_DRS
      case LC_DYLIB_CODE_SIGN_DRS:
#endif
	copy_linkedit_data (lca[i], linkedit_delta);
	break;
#endif
      default:
	copy_other (lca[i]);
	break;
      }

  if (curr_header_offset > text_seg_lowest_offset)
    unexec_error ("not enough room for load commands for new __DATA segments");

  printf ("%ld unused bytes follow Mach-O header\n",
	  text_seg_lowest_offset - curr_header_offset);

  mh.sizeofcmds = curr_header_offset - sizeof (struct mach_header);
  if (!unexec_write (0, &mh, sizeof (struct mach_header)))
    unexec_error ("cannot write final header contents");
}
Exemplo n.º 5
0
void amend_trace(struct Region *aRegion, struct Trace *aTrace, double wdist, double wangle, double wlength, double wturns, struct Trace **rtTrace, struct Trace **dTrace)
{
	struct Item *aItem, *nextItem, *bItem; 
	struct Report *aRep, *nextRep, *newRep;
	struct CandRoad *newCandRoad;
	struct Duallist surCells;
	struct Cell *aCell;
	struct Point* modifiedPoint;
	struct Point* pTransVec;

	if (aTrace == NULL) {
		*rtTrace = NULL;
		*dTrace = NULL;
		return;
	}

	printf("Amending Trace: %s ...\n", aTrace->vName);

	*rtTrace = (struct Trace*) malloc(sizeof(struct Trace));
	sprintf((*rtTrace)->vName, "%sa", aTrace->vName);
	strncpy((*rtTrace)->onRoute, aTrace->onRoute, strlen(aTrace->onRoute)+1);
	(*rtTrace)->color.integer = aTrace->color.integer + 20;
	if(aTrace->type == FILE_ORIGINAL_GPS_TAXI)
		(*rtTrace)->type = FILE_MODIFIED_GPS_TAXI;
	else
		(*rtTrace)->type = FILE_MODIFIED_GPS_BUS;
	duallist_init(&(*rtTrace)->reports);

	*dTrace = (struct Trace*) malloc(sizeof(struct Trace));
	sprintf((*dTrace)->vName, "%sd", aTrace->vName);
	strncpy((*dTrace)->onRoute, aTrace->onRoute, strlen(aTrace->onRoute)+1);
	(*dTrace)->color.integer = aTrace->color.integer + 20;
	(*dTrace)->type = aTrace->type;
	duallist_init(&(*dTrace)->reports);



// my algorithm
// 0. initialize trace-v to be zero.
// 1. if there still report in the trace, translate the p_ogd to p_trans by vector trace-v, which is the overall translating error stored in the trace
// 2. caluculate the translation vector v_i from the p_trans to the perpendicular point to the nearest road
// 3. update the trace->v, by adding v_i to it.
// 4. let the perpendicular point to be the p_mgd
// 5. Iterate to the next report, go to step 1. 

	aItem = aTrace->reports.head;

	// 0. initialize trace-v to be zero.
	set_trace_transVec(aTrace, (double)0, (double)0);
	while(aItem!=NULL) {
		aTrace->at = aItem;

		aRep = (struct Report*)aItem->datap;
		if(aRep->candRoads.head == NULL) {
			duallist_init(&surCells);
			surroundings_from_point(&surCells, aRegion, &aRep->gPoint);
			bItem = surCells.head;
			while(bItem != NULL) {
				aCell = (struct Cell*)bItem->datap;
				if(aCell != NULL) {
					//add_candidate_roads(aCell, aRep, aTrace->isHeadingValid);
					modifiedPoint = (struct Point*)malloc(sizeof(struct Point));
					pTransVec = get_trace_transVec(aTrace);
					assert(pTransVec != NULL);
					modifiedPoint->x = aRep->gPoint.x + pTransVec->x;
					modifiedPoint->y = aRep->gPoint.y + pTransVec->y;
					add_candidate_roads_from_modified_point(aCell, aRep, aTrace->isHeadingValid, modifiedPoint);
					free(modifiedPoint);
				}
				bItem = bItem->next;
			}
			duallist_destroy(&surCells, NULL);
		}
		aRep->onRoad = aRep->candRoads.head;

/*		nextItem = aItem->next;
		if(nextItem != NULL) {
			nextRep = (struct Report*)nextItem->datap;
			duallist_init(&surCells);
			surroundings_from_point(&surCells, aRegion, &nextRep->gPoint);
			bItem = surCells.head;
			while(bItem != NULL) {
				aCell = (struct Cell*)bItem->datap;
				if(aCell != NULL) {
					//add_candidate_roads(aCell, nextRep, aTrace->isHeadingValid);
					modifiedPoint = (struct Point*)malloc(sizeof(struct Point));
					pTransVec = get_trace_transVec(aTrace);
					assert(pTransVec!=NULL);
					modifiedPoint->x = nextRep->gPoint.x + pTransVec->x;
					modifiedPoint->y = nextRep->gPoint.y + pTransVec->y;
					add_candidate_roads_from_modified_point(aCell, nextRep, aTrace->isHeadingValid, modifiedPoint);
					free(modifiedPoint);
				}
				bItem = bItem->next;
			}
			duallist_destroy(&surCells, NULL);
			nextRep->onRoad = nextRep->candRoads.head;
		}
*/		
		amend_report(aRegion, aTrace, wdist, wangle, wlength, wturns);
		if(aRep->onRoad) {
			newRep = (struct Report*)malloc(sizeof(struct Report));
			newRep->fromTrace = *rtTrace;
			newRep->timestamp = aRep->timestamp;
			newRep->speed = aRep->speed;
			newRep->angle = aRep->angle;
			newRep->state = aRep->state;
			newRep->msgType = aRep->msgType;
			newRep->routeLeng = aRep->routeLeng;
			newRep->gasVol = aRep->gasVol;
			newRep->errorInfo = aRep->errorInfo;
			duallist_init(&newRep->candRoads);
			newCandRoad = (struct CandRoad*)malloc(sizeof(struct CandRoad));
			newCandRoad->aRoad = ((struct CandRoad*)aRep->onRoad->datap)->aRoad;
			copy_segment(&newCandRoad->onSegment, &((struct CandRoad*)aRep->onRoad->datap)->onSegment);
			duallist_add_to_head(&newRep->candRoads, newCandRoad);
			newRep->onRoad = newRep->candRoads.head;
			newRep->onRoadId = newCandRoad->aRoad->id;
			newRep->onPath = NULL;
			newRep->gPoint.x = ((struct CandRoad*)aRep->onRoad->datap)->gPoint.x;
			newRep->gPoint.y = ((struct CandRoad*)aRep->onRoad->datap)->gPoint.y;
			duallist_add_to_tail(&(*rtTrace)->reports, newRep);
		} else {
			newRep = (struct Report*)malloc(sizeof(struct Report));
			newRep->fromTrace = aTrace;
			newRep->timestamp = aRep->timestamp;
			newRep->speed = aRep->speed;
			newRep->angle = aRep->angle;
			newRep->state = aRep->state;
			newRep->msgType = aRep->msgType;
			newRep->routeLeng = aRep->routeLeng;
			newRep->gasVol = aRep->gasVol;
			newRep->errorInfo = aRep->errorInfo;
			duallist_init(&newRep->candRoads);
			newRep->onRoad = NULL;
			newRep->onRoadId = -1;
			newRep->onPath = NULL;
			newRep->gPoint.x = aRep->gPoint.x;
			newRep->gPoint.y = aRep->gPoint.y;
			duallist_add_to_tail(&(*dTrace)->reports, newRep);
		}
		
		if(aItem->prev != aTrace->reports.head) 
			duallist_destroy(&((struct Report*)aItem->prev->datap)->candRoads, free);

		aItem = aItem->next;
	}

}
Exemplo n.º 6
0
static int pickup_copy(VSTREAM *qfile, VSTREAM *cleanup,
		               PICKUP_INFO *info, VSTRING *buf)
{
    time_t  now = time((time_t *) 0);
    int     status;
    char   *name;

    /*
     * Protect against time-warped time stamps. Warn about mail that has been
     * queued for an excessive amount of time. Allow for some time drift with
     * network clients that mount the maildrop remotely - especially clients
     * that can't get their daylight savings offsets right.
     */
#define DAY_SECONDS 86400
#define HOUR_SECONDS 3600

    if (info->st.st_mtime > now + 2 * HOUR_SECONDS) {
	msg_warn("%s: message dated %ld seconds into the future",
		 info->id, (long) (info->st.st_mtime - now));
	info->st.st_mtime = now;
    } else if (info->st.st_mtime < now - DAY_SECONDS) {
	msg_warn("%s: message has been queued for %d days",
		 info->id, (int) ((now - info->st.st_mtime) / DAY_SECONDS));
    }

    /*
     * Add content inspection transport. See also postsuper(1).
     */
    if (*var_filter_xport)
	rec_fprintf(cleanup, REC_TYPE_FILT, "%s", var_filter_xport);

    /*
     * Copy the message envelope segment. Allow only those records that we
     * expect to see in the envelope section. The envelope segment must
     * contain an envelope sender address.
     */
    if ((status = copy_segment(qfile, cleanup, info, buf, REC_TYPE_ENVELOPE)) != 0)
	return (status);
    if (info->sender == 0) {
	msg_warn("%s: uid=%ld: no envelope sender",
		 info->id, (long) info->st.st_uid);
	return (REMOVE_MESSAGE_FILE);
    }

    /*
     * For messages belonging to $mail_owner also log the maildrop queue id.
     * This supports message tracking for mail requeued via "postsuper -r".
     */
#define MAIL_IS_REQUEUED(info) \
    ((info)->st.st_uid == var_owner_uid && ((info)->st.st_mode & S_IROTH) == 0)

    if (MAIL_IS_REQUEUED(info)) {
	msg_info("%s: uid=%d from=<%s> orig_id=%s", info->id,
		 (int) info->st.st_uid, info->sender,
		 ((name = strrchr(info->path, '/')) != 0 ?
		  name + 1 : info->path));
    } else {
	msg_info("%s: uid=%d from=<%s>", info->id,
		 (int) info->st.st_uid, info->sender);
    }

    /*
     * Message content segment. Send a dummy message length. Prepend a
     * Received: header to the message contents. For tracing purposes,
     * include the message file ownership, without revealing the login name.
     */
    rec_fputs(cleanup, REC_TYPE_MESG, "");
    rec_fprintf(cleanup, REC_TYPE_NORM, "Received: by %s (%s, from userid %ld)",
		var_myhostname, var_mail_name, (long) info->st.st_uid);
    rec_fprintf(cleanup, REC_TYPE_NORM, "\tid %s; %s", info->id,
		mail_date(info->st.st_mtime));

    /*
     * Copy the message content segment. Allow only those records that we
     * expect to see in the message content section.
     */
    if ((status = copy_segment(qfile, cleanup, info, buf, REC_TYPE_CONTENT)) != 0)
	return (status);

    /*
     * Send the segment with information extracted from message headers.
     * Permit a non-empty extracted segment, so that list manager software
     * can to output recipients after the message, and so that sysadmins can
     * re-inject messages after a change of configuration.
     */
    rec_fputs(cleanup, REC_TYPE_XTRA, "");
    if ((status = copy_segment(qfile, cleanup, info, buf, REC_TYPE_EXTRACT)) != 0)
	return (status);

    /*
     * There are no errors. Send the end-of-data marker, and get the cleanup
     * service completion status. XXX Since the pickup service is unable to
     * bounce, the cleanup service can report only soft errors here.
     */
    rec_fputs(cleanup, REC_TYPE_END, "");
    if (attr_scan(cleanup, ATTR_FLAG_MISSING,
		  RECV_ATTR_INT(MAIL_ATTR_STATUS, &status),
		  RECV_ATTR_STR(MAIL_ATTR_WHY, buf),
		  ATTR_TYPE_END) != 2)
	return (cleanup_service_error(info, CLEANUP_STAT_WRITE));

    /*
     * Depending on the cleanup service completion status, delete the message
     * file, or try again later. Bounces are dealt with by the cleanup
     * service itself. The master process wakes up the cleanup service every
     * now and then.
     */
    if (status) {
	return (cleanup_service_error_reason(info, status, vstring_str(buf)));
    } else {
	return (REMOVE_MESSAGE_FILE);
    }
}