コード例 #1
0
ファイル: metal.c プロジェクト: Tlaskey/Old-Schoolwork
/*
 *  malloc()
 *
 *	Precondition: size: size of buffer to allocate
 *	Postcondition: pointer to allocated buffer is
 *		returned
 */
extern C_LINKAGE void *malloc(size_t size) {
  if( !first )
	/* initialize everything if this is the very first malloc() call */
    init();
  else
    alarm(0);
  
  lock();

  /* Allocate the buffer using mmap() */
  caddr_t allocation = (caddr_t) mmap(NULL,
				      size,
				      PROT_READ|PROT_WRITE,
				      MAP_PRIVATE|MAP_ANONYMOUS,
				      0,0);
  
  /* Update memory manager if we have room for the new information */
  if( myhandler.totalNumAddrs < myhandler.total_size){
    setMemSlots(size, allocation, myhandler.totalNumAddrs);
    myhandler.totalNumAddrs++;
  }else{
	/* Else use first fit algorithm to check for holes in memory
	 * If one is found, we save the information in this location 
	 */
    int i;
    for(i = 0; i < myhandler.total_size; i++){
      if(memSlots[i].del == 1 ){
        setMemSlots(size, allocation, myhandler.totalNumAddrs);
	    break;
      }
    }
    
	/* Extend memory if we are out of room and place the 
	 * new information on the end
	 */
    if( i >= myhandler.total_size){ 
      memSlots = extend1(memSlots, myhandler.total_size * sizeof(memSlots[0]) + pagesize);
      setMemSlots(size, allocation, myhandler.totalNumAddrs);
    }
  }
  
  /* If there is room for this page's information on the encryption 
   * handler, then mprotect it with PROT_NONE
   */
  if( !NO_OP && myhandler.encrNumAddrs < myhandler.encr_size ){
    if ( mprotect(allocation, size, PROT_NONE) < 0 )
      crash("mprotect - malloc");
  }else{
	/* Else extend encryption handler memory and then do mprotect */
	if( myhandler.encrNumAddrs < myhandler.encr_size )
		encrHandler = extend2( encrHandler, myhandler.encr_size * sizeof(encrHandler[0]) + pagesize);
	if ( mprotect(allocation, size, PROT_NONE) < 0 )
      crash("mprotect - malloc");
  }
  
  unlock();
  
  /* return buffer */
  return allocation;
}
コード例 #2
0
ファイル: fint1.c プロジェクト: 1014511134/src
void fint1_set (fint1 fnt, float* dat)
/*< set single-function grid >*/
{
    extend1 (fnt->nw,fnt->n1,dat,fnt->spl);
    fnt->spl[0] *= (5./6.);
    fnt->spl[fnt->n1+2*fnt->nw-1] *= (5./6.);
    sf_tridiagonal_solve (fnt->slv,fnt->spl);
}
コード例 #3
0
ファイル: fint1.c プロジェクト: 1014511134/src
void vint1_set (vint1 fnt, float** dat /* [dim][n1] */)
/*< set multi-function grid >*/
{
    int i;
    for (i = 0; i < fnt->dim; i++) {
	extend1 (fnt->nw,fnt->n1,dat[i],fnt->spl[i]);

	fnt->spl[i][                  0] *= (5./6.);
	fnt->spl[i][fnt->n1+2*fnt->nw-1] *= (5./6.);

	sf_tridiagonal_solve (fnt->slv,fnt->spl[i]);
    }
}