Example #1
0
int overwrite_version(version_node * vp, const char * content) {
	(vp->v).del_mark = 0;		// since we're overwriting, its not deleted anymore.
	int i = 0, j = 0;
	int l = strlen(content);
	int chunks_alloc = 0;
	
	if((l - (vp->v).off * CHUNKSIZE) > (int)(free_chunks() * CHUNKSIZE)) {
		fprintf(stderr, "ERROR: Not enough memory to backup.\n");
		return BACKUP_ERROR;
	}
	
	while(i < (vp->v).off && j < l) {
		strncpy((char*)(vp->v).contents[i], content+j, CHUNKSIZE);
		i++; j += CHUNKSIZE;
	}
	// either still content remaining to be written or all the content written.
	// if still more content to be written:
	while(j < l) {
		(vp->v).contents[(vp->v).off++] = (chunk *) getblock();
		if((vp->v).contents[(vp->v).off-1] == NULL) {
			fprintf(stderr, "ERROR: No free chunks.\n");
			return BACKUP_ERROR;
		}
		chunks_alloc++;
		strncpy((char*)(vp->v).contents[(vp->v).off-1], content+j, CHUNKSIZE);
		j += CHUNKSIZE;
	}
	return chunks_alloc;
}
Example #2
0
static void runTesselator(value contours)
{
  CAMLparam1(contours);

  gluTessBeginPolygon(tobj, NULL);
  while (contours != Val_int(0)) {
    value contour=Field(contours, 0);
    gluTessBeginContour(tobj);
    while (contour != Val_int(0)) {
      value v=Field(contour, 0);
      GLdouble *r =
        new_vertex(Double_val(Field(v, 0)),
                   Double_val(Field(v, 1)),
                   Double_val(Field(v, 2)));
      gluTessVertex(tobj, r, (void *)r);
      contour = Field(contour, 1);
    }
    contours = Field(contours, 1);
    gluTessEndContour(tobj);
  }
  gluTessEndPolygon(tobj);

  gluDeleteTess(tobj);
  tobj = NULL;
  free_chunks();
  CAMLreturn0;
}
Example #3
0
/* here the returned pointer is stored in our local allocation before we return. Hence at depth 50, we're not
	 able to GC anything. */
void* recursive_allocations2(int i) {
	void** ptr = malloc(i*100+128);
	if(i==0) return ptr;

	*ptr = recursive_allocations2(i-1);
	if(i==50) {
		gc();
		printf("Recursive2: At depth 50, %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());
	}
	return ptr;	
}
Example #4
0
// To add new version
int add_new_version(file * fileobj, version_node * vq1, version_node * vq2, int v, const char * content) {
	// check for space
	int l = strlen(content);
	int chunks_alloc = 0;
	if(l > free_chunks() * CHUNKSIZE) {
		fprintf(stderr, "ERROR: Not enough memory to backup.\n");
		return BACKUP_ERROR;
	}

	// initialize the version node
	version_node * temp_version = ALLOCATE_VERSION_NODE();
	(temp_version->v).v_no = v;
	(temp_version->v).del_mark = 0;
	(temp_version->v).off = 0;
	int i;
	for(i = 0; i < l; i++) {
		(temp_version->v).contents[(temp_version->v).off++] = (chunk *)getblock();
		if((temp_version->v).contents[(temp_version->v).off-1] == NULL) {
			fprintf(stderr, "ERROR: No free chunks.\n");
			return BACKUP_ERROR;
		}
		chunks_alloc++;
		strncpy((char*)(temp_version->v).contents[(temp_version->v).off-1], content+i, CHUNKSIZE);
		i += CHUNKSIZE;
	}
	// initialization of version node done.

	// find the place to insert the version.
	// there are 3 cases:
	// case 1: largest version number
	// case 2: somewhere in between
	// case 3: lowest version number
	
	// CASE 1:
	if(v > (vq2->v).v_no) {
		// insert in the front.
		temp_version->next = fileobj->vp;
		fileobj->vp = temp_version;
	}
	// CASE 3:
	else if(v < (vq1->v).v_no) {
		temp_version->next = vq1->next;
		vq1->next = temp_version;
	}
	// CASE 2:
	else {
		temp_version->next = vq2->next;
		vq2->next = temp_version;
	}
	return chunks_alloc;
}
Example #5
0
int backup_file_not_exists(const char * filename, int v,const char * content, int fd) {
	const int BACKUP_ERROR = -1;
	int chunks_alloc = 0;
	// filename doesn't exist
	// perform all allocations and initializations
	file_node *temp = ALLOCATE_FILE_NODE();
	temp->next = fp[fd];		// add it to the beginning.
	fp[fd] = temp; 
		
	strcpy((temp->file_obj).name, filename);
	((temp->file_obj).vp) = ALLOCATE_VERSION_NODE();
	version_node * vnptr = ((temp->file_obj).vp);
	vnptr->next = NULL;
	(vnptr->v).v_no = v;
	(vnptr->v).off = 0;
	(vnptr->v).del_mark = 0;	
	
		
	int l = strlen(content);
	// enough space?
	if(l > free_chunks() * CHUNKSIZE) {
		fprintf(stderr, "ERROR: Not enough memory to backup.\n");
		return BACKUP_ERROR;
	}
	
	int i = 0, j = 0;
	while(i < l && (vnptr->v).off < MAX_NUM_CHUNKS) {
		(vnptr->v).contents[j] = (chunk *)getblock();
		chunks_alloc++;
		if((vnptr->v).contents[j] == NULL) { // getblock returned null
			(vnptr->v).off = j;
			fprintf(stderr, "ERROR: No free chunks.\n");
			return BACKUP_ERROR;
		}
		bcopy(content+i, (vnptr->v).contents[j], CHUNKSIZE);
		i += CHUNKSIZE; // copied a chunk. go to next chunk. number of characters copied is the chunksize
		j++;
	}
	(vnptr->v).off = j;
	// successfully backup up.
	return chunks_alloc;
}
int prism2_fwapply(const struct ihex_binrec *rfptr, wlandevice_t *wlandev)
{
	signed int result = 0;
	struct p80211msg_dot11req_mibget getmsg;
	p80211itemd_t *item;
	u32 *data;

	
	ns3data = 0;
	memset(s3data, 0, sizeof(s3data));
	ns3plug = 0;
	memset(s3plug, 0, sizeof(s3plug));
	ns3crc = 0;
	memset(s3crc, 0, sizeof(s3crc));
	ns3info = 0;
	memset(s3info, 0, sizeof(s3info));
	startaddr = 0;

	nfchunks = 0;
	memset(fchunk, 0, sizeof(fchunk));
	memset(&nicid, 0, sizeof(nicid));
	memset(&rfid, 0, sizeof(rfid));
	memset(&macid, 0, sizeof(macid));
	memset(&priid, 0, sizeof(priid));

	
	memset(&pda, 0, sizeof(pda));
	pda.rec[0] = (hfa384x_pdrec_t *) pda.buf;
	pda.rec[0]->len = cpu_to_le16(2);	
	pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA);
	pda.nrec = 1;

	
	
	prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);

	
	if (read_cardpda(&pda, wlandev)) {
		printk(KERN_ERR "load_cardpda failed, exiting.\n");
		return 1;
	}

	
	memset(&getmsg, 0, sizeof(getmsg));
	getmsg.msgcode = DIDmsg_dot11req_mibget;
	getmsg.msglen = sizeof(getmsg);
	strcpy(getmsg.devname, wlandev->name);

	getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;
	getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
	getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;
	getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;

	item = (p80211itemd_t *) getmsg.mibattribute.data;
	item->did = DIDmib_p2_p2NIC_p2PRISupRange;
	item->status = P80211ENUM_msgitem_status_no_value;

	data = (u32 *) item->data;

	
	prism2mgmt_mibset_mibget(wlandev, &getmsg);
	if (getmsg.resultcode.data != P80211ENUM_resultcode_success)
		printk(KERN_ERR "Couldn't fetch PRI-SUP info\n");

	
	priid.role = *data++;
	priid.id = *data++;
	priid.variant = *data++;
	priid.bottom = *data++;
	priid.top = *data++;

	
	result = read_fwfile(rfptr);
	if (result) {
		printk(KERN_ERR "Failed to read the data exiting.\n");
		return 1;
	}

	result = validate_identity();

	if (result) {
		printk(KERN_ERR "Incompatible firmware image.\n");
		return 1;
	}

	if (startaddr == 0x00000000) {
		printk(KERN_ERR "Can't RAM download a Flash image!\n");
		return 1;
	}

	
	result = mkimage(fchunk, &nfchunks);

	
	result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
	if (result) {
		printk(KERN_ERR "Failed to plug data.\n");
		return 1;
	}

	
	if (crcimage(fchunk, nfchunks, s3crc, ns3crc)) {
		printk(KERN_ERR "Failed to insert all CRCs\n");
		return 1;
	}

	
	result = writeimage(wlandev, fchunk, nfchunks);
	if (result) {
		printk(KERN_ERR "Failed to ramwrite image data.\n");
		return 1;
	}

	
	free_chunks(fchunk, &nfchunks);
	free_srecs();

	printk(KERN_INFO "prism2_usb: firmware loading finished.\n");

	return result;
}
Example #7
0
/*----------------------------------------------------------------
* prism2_fwapply
*
* Apply the firmware loaded into memory
*
* Arguments:
*	rfptr	firmware image in kernel memory
*	wlandev device
*
* Returns:
*	0	- success
*	~0	- failure
----------------------------------------------------------------*/
int prism2_fwapply(const struct ihex_binrec *rfptr, wlandevice_t *wlandev)
{
	signed int result = 0;
	struct p80211msg_dot11req_mibget getmsg;
	p80211itemd_t *item;
	u32 *data;

	/* Initialize the data structures */
	ns3data = 0;
	memset(s3data, 0, sizeof(s3data));
	ns3plug = 0;
	memset(s3plug, 0, sizeof(s3plug));
	ns3crc = 0;
	memset(s3crc, 0, sizeof(s3crc));
	ns3info = 0;
	memset(s3info, 0, sizeof(s3info));
	startaddr = 0;

	nfchunks = 0;
	memset(fchunk, 0, sizeof(fchunk));
	memset(&nicid, 0, sizeof(nicid));
	memset(&rfid, 0, sizeof(rfid));
	memset(&macid, 0, sizeof(macid));
	memset(&priid, 0, sizeof(priid));

	/* clear the pda and add an initial END record */
	memset(&pda, 0, sizeof(pda));
	pda.rec[0] = (hfa384x_pdrec_t *) pda.buf;
	pda.rec[0]->len = cpu_to_le16(2);	/* len in words */
	pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA);
	pda.nrec = 1;

	/*-----------------------------------------------------*/
	/* Put card into fwload state */
	prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);

	/* Build the PDA we're going to use. */
	if (read_cardpda(&pda, wlandev)) {
;
		return 1;
	}

	/* read the card's PRI-SUP */
	memset(&getmsg, 0, sizeof(getmsg));
	getmsg.msgcode = DIDmsg_dot11req_mibget;
	getmsg.msglen = sizeof(getmsg);
	strcpy(getmsg.devname, wlandev->name);

	getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;
	getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
	getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;
	getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;

	item = (p80211itemd_t *) getmsg.mibattribute.data;
	item->did = DIDmib_p2_p2NIC_p2PRISupRange;
	item->status = P80211ENUM_msgitem_status_no_value;

	data = (u32 *) item->data;

	/* DIDmsg_dot11req_mibget */
	prism2mgmt_mibset_mibget(wlandev, &getmsg);
	if (getmsg.resultcode.data != P80211ENUM_resultcode_success)
;

	/* Already in host order */
	priid.role = *data++;
	priid.id = *data++;
	priid.variant = *data++;
	priid.bottom = *data++;
	priid.top = *data++;

	/* Read the S3 file */
	result = read_fwfile(rfptr);
	if (result) {
;
		return 1;
	}

	result = validate_identity();

	if (result) {
;
		return 1;
	}

	if (startaddr == 0x00000000) {
;
		return 1;
	}

	/* Make the image chunks */
	result = mkimage(fchunk, &nfchunks);

	/* Do any plugging */
	result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
	if (result) {
;
		return 1;
	}

	/* Insert any CRCs */
	if (crcimage(fchunk, nfchunks, s3crc, ns3crc)) {
;
		return 1;
	}

	/* Write the image */
	result = writeimage(wlandev, fchunk, nfchunks);
	if (result) {
;
		return 1;
	}

	/* clear any allocated memory */
	free_chunks(fchunk, &nfchunks);
	free_srecs();

;

	return result;
}
Example #8
0
File: peer.c Project: SunnyQ/cmu
void process_inbound_udp(int sock, bt_config_t *config)
{
    struct sockaddr_in from;
    socklen_t fromlen;
    char **chunk_list;
    char **haschunk_list;
    packet incomingPacket;
    bt_peer_t *curPeer;
    packet *p;
    int i;
    rttRecord *tempRtt;

    fromlen = sizeof(from);
    spiffy_recvfrom(sock, &incomingPacket, sizeof(incomingPacket), 0,
            (struct sockaddr *) &from, &fromlen);

    // check the node where the packet comes from depending on ip and port
    for (curPeer = config->peers; curPeer != NULL ; curPeer = curPeer->next)
        if (strcmp(inet_ntoa(curPeer->addr.sin_addr), inet_ntoa(from.sin_addr))
                == 0 && ntohs(curPeer->addr.sin_port) == ntohs(from.sin_port))
            nodeInMap = curPeer->id;

    switch (incomingPacket.type)
    {
    case WHOHAS:
        // sender
        dprintf(STDOUT_FILENO, "WHOHAS received\n");
        chunk_list = retrieve_chunk_list(&incomingPacket);
        haschunk_list = has_chunks(config, &incomingPacket, chunk_list);
        if (haschunk_list[0] != NULL )
            sendback_response(sock, haschunk_list, incomingPacket.payload[0],
                    from);
        free_chunks(chunk_list, incomingPacket.payload[0]);
        free_chunks(haschunk_list, incomingPacket.payload[0]);
        break;
    case IHAVE:
        // requester
        dprintf(STDOUT_FILENO, "IHAVE received\n");
        chunk_list = retrieve_chunk_list(&incomingPacket);
        allocate_peer_chunks(chunk_list, incomingPacket.payload[0]);
        sendGetSW(sock, from);
        free_chunks(chunk_list, incomingPacket.payload[0]);
        break;
    case GET:
        // sender
        dprintf(STDOUT_FILENO, "GET received\n");
        chunk_list = retrieve_chunk_list(&incomingPacket);
        jobs[nodeInMap] = getChunkId(chunk_list[0], config->has_chunk_file);
        // send a window to requester
        //congestion control started
        windowSize[nodeInMap] = 1;
        congestionState[nodeInMap] = 0;
        ssthresh[nodeInMap] = 64;
        lastSent[nodeInMap] = 0;
        for (i = 0; i < windowSize[nodeInMap]; i++)
            sendData(from, config);
        recordWindowSize(config);
        free_chunks(chunk_list, incomingPacket.payload[0]);
        break;
    case DATA:
        // requester
        dprintf(STDOUT_FILENO, "DATA received %d from %d\n",
                incomingPacket.sequence_num, nodeInMap);
        GETTTL[nodeInMap] = -1;

        // if sequence_num < expected, ignore as they might be channel-queued packets
        // if sequence_num > expected, something is lost or in wrong order
        if (incomingPacket.sequence_num > nextExpected[nodeInMap]
                && numMismatches < 3)
        {
            p = packet_factory(ACK);
            p->packet_length = 16;
            p->ack_num = nextExpected[nodeInMap] - 1;
            spiffy_sendto(sock, p, p->packet_length, 0,
                    (struct sockaddr *) &from, sizeof(from));
            numMismatches++;
            numDataMisses[nodeInMap] = 0;
        }
        else if (incomingPacket.sequence_num == nextExpected[nodeInMap])
        {
            numDataMisses[nodeInMap] = 0;
            numMismatches = 0;
            processData(&incomingPacket, config, sock, from);
            nextExpected[nodeInMap] = incomingPacket.sequence_num + 1;
            if (incomingPacket.sequence_num == BT_CHUNK_SIZE
                    && peers[nodeInMap]->next != NULL )
            {
                dprintf(STDOUT_FILENO, "Got %s\n", peers[nodeInMap]->chunkHash);
                linkNode *temp = peers[nodeInMap]; //cp1
                peers[nodeInMap] = peers[nodeInMap]->next;
                free(temp);
                sendGetSW(sock, from);
            }
            else if (incomingPacket.sequence_num == BT_CHUNK_SIZE
                    && peers[nodeInMap]->next == NULL )
            {
                dprintf(STDOUT_FILENO, "JOB is done\n");
                numDataMisses[nodeInMap] = -1;
            }
        }
        break;
    case ACK:
        dprintf(STDOUT_FILENO, "ACK received %d\n", incomingPacket.ack_num);
        // sender
        if (lastACKed[nodeInMap] == incomingPacket.ack_num)
            dup_ack[nodeInMap]++;
        // similarly, smaller received ack can be channel queued, ignore
        else if (incomingPacket.ack_num != lastACKed[nodeInMap] + 1)
            return;
        // duplicate acked
        else
            dup_ack[nodeInMap] = 0;

        // clear DATA TTL
        TTL[nodeInMap][incomingPacket.ack_num - 1] = -1;

        // retransmit
        if (dup_ack[nodeInMap] == 3) //loss
        {
            dprintf(STDOUT_FILENO, "dup retransmitting\n");
            congestionControlRetransmit(config); //change windowSize
            lastSent[nodeInMap] = lastACKed[nodeInMap];
            sendData(from, config);
            dup_ack[nodeInMap] = 0;
        }
        else //normal
        {
            congestionControlNormal(&incomingPacket, config);
            lastACKed[nodeInMap] = incomingPacket.ack_num;
            // ok... task finished
            if (incomingPacket.ack_num == BT_CHUNK_SIZE)
            {
                jobs[nodeInMap] = -1;
                lastACKed[nodeInMap] = 0;
                lastSent[nodeInMap] = 0;
                windowSize[nodeInMap] = 0;
                congestionState[nodeInMap] = -1;
                ssthresh[nodeInMap] = 64;
                resetCCRTT();
                dprintf(STDOUT_FILENO, "JOB is done\n");
                numDataMisses[nodeInMap] = -1;
            }
            else
            {
                for (i = lastSent[nodeInMap];
                        i < lastACKed[nodeInMap] + windowSize[nodeInMap]
                                && i < BT_CHUNK_SIZE; i++)
                    sendData(from, config);
                if (congestionState[nodeInMap] == CA) //test the RTT timer
                {
                    if (headRTT != NULL )
                    {
                        for (tempRtt = headRTT; tempRtt->next != NULL ;
                                tempRtt = tempRtt->next)
                            ;
                        tempRtt->next = (rttRecord *) malloc(sizeof(rttRecord));
                        tempRtt->next->seq = lastSent[nodeInMap];
                        tempRtt->next->next = NULL;
                    }
                    else
                    {
                        headRTT = (rttRecord *) malloc(sizeof(rttRecord));
                        headRTT->seq = lastSent[nodeInMap];
                        headRTT->next = NULL;
                    }
                }
            }
        }
        break;
    case DENIED:
        dprintf(STDOUT_FILENO, "DENIED received\n");
        break;
    default:
        perror("Unknown Command: Ignored...\n");
        break;
    }
}
Example #9
0
File: key.c Project: RAttab/ilka
void
ilka_key_free(struct ilka_key *key)
{
    free_chunks(key->chunk.next);
    ilka_key_init(key);
}
Example #10
0
File: main.c Project: HauptJ/dedup
int main (int argc, char*argv[]){ // will take a list of files to be fingerprinted

//bit_array_print_report();

  if(argc == 1) {print_usage();} // nothing specied

bits *bitmask, *poly;
char *files[1000];
int file_count = 0;
char* stdin_data;
int option;
int generate = -1, irreducible = -1, file = -1, standardin = -1, mask = -1, window = -1; 

  while ((option = getopt(argc, argv,"g:i:f:s:b:w:")) != -1) { // looping through specified opts 
    switch (option) {
      case 'g' : generate = atoi(optarg);
      break;
      case 'i' : irreducible = 0;
                 poly = bits_initstring(optarg);
      break;
      case 'f' : file = 0; 
      //get all files
     
      int index = optind-1;
      while(index < argc) {
        
        if(argv[index][0] != '-')
          files[file_count] = argv[index];
        else 
          break;
       
        file_count++;
        index++;
        if (file_count == MAX_FILES) 
          break;
      }
      break;	 
      case 's' : standardin = 0;
        stdin_data = optarg;
      break;
      case 'b' : mask = atoi(optarg);
      break;
      case 'w' : window = atoi(optarg);
      break;
      default: print_usage(); 
        exit(EXIT_FAILURE);
    }      
  }  

  if(generate > 0) {
    srand(time(0));
    if (generate > 32)
      printf("This may take awhile...\n");
    printf("%s\n",toStringHex(*createIrreducible(generate)));
  }
  
  if (irreducible == 0) {
    if (standardin < 0 && file < 0) {print_usage();}
  
    //set window
    if (window > 0) {
       if (window <= poly->size) {
       	 print_usage();
       	 exit(EXIT_FAILURE);
       }
    } else {
      //default poly->size+4
      window = poly->size+4;
    }
    
    //set bitmask
    if (mask > 0) {
      long max = ~0;
      long bits = ~(max << mask);
      bitmask = bits_initlong(bits);
    } else {
      //defualt 13
      bitmask = bits_initlong(0x1FFF);
    }
    if (file == 0) {
      //fingerprint i
      int i;
      for (i=0;i<file_count;i++) {
        //check file exist
        if (fileCheckM(files[i])) {
          chunks* hashes = find_fingerprints_file(files[i], window, poly, bitmask, 0, 0);
          print_chunks(hashes);

          //free data
          free_chunks(hashes);
        }
      }
    }
    
    //fingerprint std
    if (standardin == 0) {
      chunks* hashes = find_fingerprints_bytes(stdin_data, strlen(stdin_data), window, poly, bitmask, 0, 0);
      print_chunks(hashes);

      //free data
      free_chunks(hashes);
    }
    //free data
    free(poly->byte);
    free(poly);
    free(bitmask->byte);
    free(bitmask);
  }
  
  
  return 0;
}
Example #11
0
int main(int argc, char** argv) {
	pre=sbrk(0);
	bottom=malloc(256)-sizeof(size_t); // don't free this one - that keeps it an innocuous stub (a root with no graph attached)
 
	init_gc();

	timediff();
		 
	printf("Checking global root set handling an general GC functionality\n");

	/* the most basic allocation and clearing pointer exercise. This only checks for following the root set pointers one level. */
	void *pre = sbrk(0);
	for(int i=0;i<MAX_ALLOCATIONS;i++) 
		allocs[i]=malloc(i*2+128); 		 

	printf("Heap after first round of allocations: %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());

	for(int i=0;i<MAX_ALLOCATIONS;i++) 
		allocs[i]=0; 		 
	gc();
	printf("Heap after first gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());

	/* allocations which all point to each other. this checks for proper traversal of the chunk graph. */
	for(int i=0;i<MAX_ALLOCATIONS;i++) {
		allocs[i]=malloc(i*2+128); 
		if(i>0)
			*(void**)(allocs[i])=allocs[i-1];
	}
	printf("Heap after second round of allocations: %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());
	for(int i=0;i<MAX_ALLOCATIONS-1;i++) 
		allocs[i]=0;
	gc();
	// here, since we keep the last entry, which points to the next-to-last and so on, everything should still be around
	printf("Heap after clearing all but one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());

	allocs[MAX_ALLOCATIONS-1]=0;
	gc();
	printf("Heap after clearing last one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());


	/* allocations which all point to each other. this checks for proper traversal of the chunk graph. */
	for(int i=0;i<MAX_ALLOCATIONS;i++) {
		allocs[i]=malloc(i*2+128); 
		if(i>0) {
			void *start_of_new_alloc = allocs[i];
			void *start_of_prev_alloc = allocs[i-1];
			
			int offset_into_new_alloc = 8*random_up_to((i*2+120)/8);
			int offset_into_old_alloc = 8*random_up_to(((i-1)*2+120)/8);
			void **location_of_pointer = (void**)(start_of_new_alloc + offset_into_new_alloc);

			*location_of_pointer = start_of_prev_alloc + offset_into_old_alloc;
		}
	}
	printf("Heap after third round of allocations: %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());
	for(int i=0;i<MAX_ALLOCATIONS-1;i++) 
		allocs[i]=0;
	gc();
	// here, since we keep the last entry, which points to the next-to-last and so on, everything should still be around
	printf("Heap after clearing all but one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());

	allocs[MAX_ALLOCATIONS-1]=0;
	gc();
	printf("Heap after clearing last one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());

	printf("Now checking stack root set handling.\n");

	recursive_allocations(100);
	gc();
	printf("After Recursive1 %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());
		 
	recursive_allocations2(100);	 
	gc();
	printf("After Recursive2 %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks());
		 
}
Example #12
0
void dm_mem_cache_free(struct dm_mem_cache_client *cl,
		       struct dm_mem_cache_object *obj)
{
	free_chunks(cl, obj);
	mempool_free(obj, cl->objs_pool);
}
Example #13
0
/*----------------------------------------------------------------
 * prism2_fwapply
 *
 * Apply the firmware loaded into memory
 *
 * Arguments:
 *	rfptr	firmware image in kernel memory
 *	wlandev device
 *
 * Returns:
 *	0	- success
 *	~0	- failure
 *----------------------------------------------------------------
 */
static int prism2_fwapply(const struct ihex_binrec *rfptr,
			  struct wlandevice *wlandev)
{
	signed int result = 0;
	struct p80211msg_dot11req_mibget getmsg;
	struct p80211itemd *item;
	u32 *data;

	/* Initialize the data structures */
	ns3data = 0;
	s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL);
	if (!s3data) {
		result = -ENOMEM;
		goto out;
	}

	ns3plug = 0;
	memset(s3plug, 0, sizeof(s3plug));
	ns3crc = 0;
	memset(s3crc, 0, sizeof(s3crc));
	ns3info = 0;
	memset(s3info, 0, sizeof(s3info));
	startaddr = 0;

	nfchunks = 0;
	memset(fchunk, 0, sizeof(fchunk));
	memset(&nicid, 0, sizeof(nicid));
	memset(&rfid, 0, sizeof(rfid));
	memset(&macid, 0, sizeof(macid));
	memset(&priid, 0, sizeof(priid));

	/* clear the pda and add an initial END record */
	memset(&pda, 0, sizeof(pda));
	pda.rec[0] = (struct hfa384x_pdrec *)pda.buf;
	pda.rec[0]->len = cpu_to_le16(2);	/* len in words */
	pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA);
	pda.nrec = 1;

	/*-----------------------------------------------------*/
	/* Put card into fwload state */
	prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);

	/* Build the PDA we're going to use. */
	if (read_cardpda(&pda, wlandev)) {
		netdev_err(wlandev->netdev, "load_cardpda failed, exiting.\n");
		result = 1;
		goto out;
	}

	/* read the card's PRI-SUP */
	memset(&getmsg, 0, sizeof(getmsg));
	getmsg.msgcode = DIDmsg_dot11req_mibget;
	getmsg.msglen = sizeof(getmsg);
	strcpy(getmsg.devname, wlandev->name);

	getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;
	getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
	getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;
	getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;

	item = (struct p80211itemd *)getmsg.mibattribute.data;
	item->did = DIDmib_p2_p2NIC_p2PRISupRange;
	item->status = P80211ENUM_msgitem_status_no_value;

	data = (u32 *)item->data;

	/* DIDmsg_dot11req_mibget */
	prism2mgmt_mibset_mibget(wlandev, &getmsg);
	if (getmsg.resultcode.data != P80211ENUM_resultcode_success)
		netdev_err(wlandev->netdev, "Couldn't fetch PRI-SUP info\n");

	/* Already in host order */
	priid.role = *data++;
	priid.id = *data++;
	priid.variant = *data++;
	priid.bottom = *data++;
	priid.top = *data++;

	/* Read the S3 file */
	result = read_fwfile(rfptr);
	if (result) {
		netdev_err(wlandev->netdev,
			   "Failed to read the data exiting.\n");
		goto out;
	}

	result = validate_identity();
	if (result) {
		netdev_err(wlandev->netdev, "Incompatible firmware image.\n");
		goto out;
	}

	if (startaddr == 0x00000000) {
		netdev_err(wlandev->netdev,
			   "Can't RAM download a Flash image!\n");
		result = 1;
		goto out;
	}

	/* Make the image chunks */
	result = mkimage(fchunk, &nfchunks);
	if (result) {
		netdev_err(wlandev->netdev, "Failed to make image chunk.\n");
		goto free_chunks;
	}

	/* Do any plugging */
	result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
	if (result) {
		netdev_err(wlandev->netdev, "Failed to plug data.\n");
		goto free_chunks;
	}

	/* Insert any CRCs */
	result = crcimage(fchunk, nfchunks, s3crc, ns3crc);
	if (result) {
		netdev_err(wlandev->netdev, "Failed to insert all CRCs\n");
		goto free_chunks;
	}

	/* Write the image */
	result = writeimage(wlandev, fchunk, nfchunks);
	if (result) {
		netdev_err(wlandev->netdev, "Failed to ramwrite image data.\n");
		goto free_chunks;
	}

	netdev_info(wlandev->netdev, "prism2_usb: firmware loading finished.\n");

free_chunks:
	/* clear any allocated memory */
	free_chunks(fchunk, &nfchunks);
	free_srecs();

out:
	return result;
}