コード例 #1
0
// Return the size of the given block in multiples of the word size
static inline unsigned int block_size(const uint32_t* block) {
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));

    //return (block[0] & 0x3FFFFFFF);
	return (*block)&(~0x7);

}
コード例 #2
0
ファイル: trie.c プロジェクト: zhengguan/15122
// RETURNS: true iff the given trie TR contains a member that equal to s
bool trie_member(trie TR, char *s) {
  REQUIRES(is_trie(TR));
  REQUIRES(s != NULL && strlen(s) > 0);

  tnode *T = tnode_lookup(TR->root, s, 0);

  return T != NULL && T->is_end;
}
コード例 #3
0
ファイル: trie.c プロジェクト: zhengguan/15122
bool trie_prefix(trie TR, char *s) {
  REQUIRES(is_trie(TR));
  REQUIRES(s != NULL && strlen(s) > 0);

  tnode *T = tnode_lookup(TR->root, s, 0);

  return T != NULL && T->middle != NULL;
}
コード例 #4
0
// Mark the given block as free(1)/alloced(0) by marking the header and footer.
static inline void block_mark(uint32_t* block, int free) {
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));

    unsigned int next = block_size(block) + 1;
    block[0] = free ? block[0] & (int) 0xBFFFFFFF : block[0] | 0x40000000;
    block[next] = block[0];
}
コード例 #5
0
ファイル: mm-seg-best.c プロジェクト: mindbergh/malloc
// Set the size of the given block in multiples of 4 bytes
static inline void set_size(uint32_t* const block, unsigned int size) {
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));
    REQUIRES(size % 2 == 0);


    set_val(block, size);
}
コード例 #6
0
ファイル: mm-seg-best.c プロジェクト: mindbergh/malloc
// Return a pointer to the memory malloc should return
static inline uint32_t* block_mem(uint32_t* const block) {
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));
    REQUIRES(aligned(block + 1));
    if (VERBOSE)
        printf("Heap size = %d bytes \n", (int)mem_heapsize());
    return block + 1;
}
コード例 #7
0
ファイル: mm.c プロジェクト: msr23trini/malloclab
static void checkblock(void *bp)
{
    REQUIRES (bp!=NULL);
    REQUIRES ((size_t)(bp)%8 == 0);
    if ((size_t)bp % 8)
      printf("Error: %p is not doubleword aligned\n", bp);
    if (GET(HDRP(GET_LOC(bp))) != GET(FTRP(GET_LOC(bp))))
      printf("Error: header does not match footer\n");
}
コード例 #8
0
static int readRDNcomponent( INOUT STREAM *stream, 
							 INOUT DN_COMPONENT **dnComponentListPtrPtr,
							 IN_LENGTH_SHORT const int rdnDataLeft )
	{	
	CRYPT_ERRTYPE_TYPE dummy;
	BYTE stringBuffer[ MAX_ATTRIBUTE_SIZE + 8 ];
	void *value;
	const int rdnStart = stell( stream );
	int type, valueLength, valueStringType, stringTag;
	int flags = DN_FLAG_NOCHECK, status;

	assert( isWritePtr( stream, sizeof( STREAM ) ) );
	assert( isWritePtr( dnComponentListPtrPtr, sizeof( DN_COMPONENT * ) ) );

	REQUIRES( rdnDataLeft > 0 && rdnDataLeft < MAX_INTLENGTH_SHORT );
	REQUIRES( rdnStart > 0 && rdnStart < MAX_INTLENGTH_SHORT );

	/* Read the type information for this AVA */
	status = readAVA( stream, &type, &valueLength, &stringTag );
	if( cryptStatusError( status ) )
		return( status );
	if( valueLength <= 0 )
		{
		/* Skip broken AVAs with zero-length strings */
		return( CRYPT_OK );
		}
	status = sMemGetDataBlock( stream, &value, valueLength );
	if( cryptStatusOK( status ) )
		status = sSkip( stream, valueLength );
	if( cryptStatusError( status ) )
		return( status );
	ANALYSER_HINT( value != NULL );

	/* If there's room for another AVA, mark this one as being continued.  The
	   +10 value is the minimum length for an AVA: SEQUENCE { OID, value } 
	   (2-bytes SEQUENCE + 5 bytes OID + 2 bytes (tag + length) + 1 byte min-
	   length data).  We don't do a simple =/!= check to get around incorrectly 
	   encoded lengths */
	if( rdnDataLeft >= ( stell( stream ) - rdnStart ) + 10 )
		flags |= DN_FLAG_CONTINUED;

	/* Convert the string into the local character set */
	status = copyFromAsn1String( stringBuffer, MAX_ATTRIBUTE_SIZE, 
								 &valueLength, &valueStringType, value, 
								 valueLength, stringTag );
	if( cryptStatusError( status ) )
		return( status );

	/* Add the DN component to the DN.  If we hit a non-memory related error
	   we turn it into a generic CRYPT_ERROR_BADDATA error since the other
	   codes are somewhat too specific for this case, something like 
	   CRYPT_ERROR_INITED or an arg error isn't too useful for the caller */
	status = insertDNstring( dnComponentListPtrPtr, type, stringBuffer, 
							 valueLength, valueStringType, flags, &dummy );
	return( ( cryptStatusError( status ) && status != CRYPT_ERROR_MEMORY ) ? \
			CRYPT_ERROR_BADDATA : status );
	}
コード例 #9
0
ファイル: mm-seg-best.c プロジェクト: mindbergh/malloc
/*
 * Merge block with adjacent free blocks
 * Return: the pointer to the new free block 
 */
static void *coalesce(void *block) {
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));

    uint32_t *prev_block = block_prev(block);
    uint32_t *next_block = block_next(block);
    int prev_free = block_free(prev_block);
    int next_free = block_free(next_block);
    unsigned int words = block_size(block);
    

    if (prev_free && next_free) {       // Case 4, both free

        block_delete(prev_block);
        block_delete(next_block);

        words += block_size(prev_block) + block_size(next_block) + 4;
        set_size(prev_block, words);
        block_mark(prev_block, FREE);
        block = (void *)prev_block;

        block_insert(block);
        ENSURES(in_list(block));    
    }

    else if (!prev_free && next_free) { // Case 2, next if free

        block_delete(next_block);

        words += block_size(next_block) + 2;
        set_size(block, words);
        block_mark(block, FREE);  

        block_insert(block);
        ENSURES(in_list(block));      
    }

    else if (prev_free && !next_free) { // Case 3, prev is free
        block_delete(prev_block);

        words += block_size(prev_block) + 2;
        set_size(prev_block, words);
        block_mark(prev_block, FREE);
        block = (void *)prev_block;

        block_insert(block);
        ENSURES(in_list(block));
    }

    else {                              // Case 1, both unfree
        block_insert(block);
        ENSURES(in_list(block));
        return block;
    }
    return block;
 } 
コード例 #10
0
ファイル: sec_mem.c プロジェクト: VlaBst6/cryptlib-history
static int insertMemBlock( INOUT MEM_INFO_HEADER **allocatedListHeadPtr, 
						   INOUT MEM_INFO_HEADER **allocatedListTailPtr, 
						   INOUT MEM_INFO_HEADER *memHdrPtr )
	{
	MEM_INFO_HEADER *allocatedListHead = *allocatedListHeadPtr;
	MEM_INFO_HEADER *allocatedListTail = *allocatedListTailPtr;

	assert( isWritePtr( allocatedListHeadPtr, sizeof( MEM_INFO_HEADER * ) ) );
	assert( allocatedListHead == NULL || \
			isWritePtr( allocatedListHead, sizeof( MEM_INFO_HEADER ) ) );
	assert( isWritePtr( allocatedListTailPtr, sizeof( MEM_INFO_HEADER * ) ) );
	assert( allocatedListTail == NULL || \
			isWritePtr( allocatedListTail, sizeof( MEM_INFO_HEADER ) ) );
	assert( isWritePtr( memHdrPtr, sizeof( MEM_INFO_HEADER * ) ) );

	/* Precondition: The memory block list is empty, or there's at least a 
	   one-entry list present */
	REQUIRES( ( allocatedListHead == NULL && allocatedListTail == NULL ) || \
			  ( allocatedListHead != NULL && allocatedListTail != NULL ) );

	/* If it's a new list, set up the head and tail pointers and return */
	if( allocatedListHead == NULL )
		{
		/* In yet another of gcc's endless supply of compiler bugs, if the
		   following two lines of code are combined into a single line then
		   the write to the first value, *allocatedListHeadPtr, ends up 
		   going to some arbitrary memory location and only the second
		   write goes to the correct location (completely different code is
		   generated for the two writes)  This leaves 
		   krnlData->allocatedListHead as a NULL pointer, leading to an
		   exception being triggered the next time that it's accessed */
#if defined( __GNUC__ ) && ( __GNUC__ == 4 )
		*allocatedListHeadPtr = memHdrPtr;
		*allocatedListTailPtr = memHdrPtr;
#else
		*allocatedListHeadPtr = *allocatedListTailPtr = memHdrPtr;
#endif /* gcc 4.x compiler bug */

		return( CRYPT_OK );
		}

	/* It's an existing list, add the new element to the end */
	REQUIRES( checkMemBlockHdr( allocatedListTail ) );
	allocatedListTail->next = memHdrPtr;
	setMemChecksum( allocatedListTail );
	memHdrPtr->prev = allocatedListTail;
	*allocatedListTailPtr = memHdrPtr;

	/* Postcondition: The new block has been linked into the end of the 
	   list */
	ENSURES( allocatedListTail->next == memHdrPtr && \
			 memHdrPtr->prev == allocatedListTail && \
			 memHdrPtr->next == NULL );

	return( CRYPT_OK );
	}
コード例 #11
0
ファイル: bst.c プロジェクト: zhengguan/15122
void bst_insert(bst B, elem x)
{
  REQUIRES(is_bst(B));
  REQUIRES(x != NULL);

  B->root = tree_insert(B->root, x, B);

  ENSURES(is_bst(B));
  return;
}
コード例 #12
0
ファイル: Mode.cpp プロジェクト: GMAC-lib/gmac
gmacError_t
Mode::memset(accptr_t addr, int c, size_t size)
{
    REQUIRES(addr != 0);
    REQUIRES(size > 0);

    gmacError_t ret;
    ret = Parent::memset(addr, c, size);

    return ret;
}
コード例 #13
0
ファイル: hardware.c プロジェクト: VlaBst6/cryptlib-history
static int deleteItemFunction( DEVICE_INFO *deviceInfo,
							   const KEYMGMT_ITEM_TYPE itemType,
							   const CRYPT_KEYID_TYPE keyIDtype,
							   const void *keyID, const int keyIDlength )
	{
	HARDWARE_INFO *hardwareInfo = deviceInfo->deviceHardware;
	MESSAGE_KEYMGMT_INFO getkeyInfo, deletekeyInfo;
	int status;

	assert( isWritePtr( deviceInfo, sizeof( DEVICE_INFO ) ) );
	assert( isReadPtr( keyID, keyIDlength ) );

	REQUIRES( itemType == KEYMGMT_ITEM_PUBLICKEY || \
			  itemType == KEYMGMT_ITEM_PRIVATEKEY );
	REQUIRES( keyIDtype == CRYPT_KEYID_NAME );
	REQUIRES( keyIDlength > 0 && keyIDlength <= CRYPT_MAX_TEXTSIZE );

	/* Perform the delete both from the PKCS #15 storage object and the
	   native storage.  This gets a bit complicated because in order to 
	   find the hardware object we have to extract the storageID, and in
	   order to get that we have to instantiate a dummy private-key object
	   to contain it.  In addition if the object that's stored isn't a
	   private-key object then there's no associated cryptographic 
	   hardware object.  To handle this we try and instantiate a dummy
	   private-key object in order to get the storageID.  If this succeeds,
	   we locate the underlying hardware object and delete it.  Finally, we
	   delete the PKCS #15 object, either a pure public-key/certificate 
	   object or the private-key metadata for the cryptographic hardware
	   object */
	if( hardwareInfo->iCryptKeyset == CRYPT_ERROR )
		return( CRYPT_ERROR_NOTINITED );
	setMessageKeymgmtInfo( &getkeyInfo, keyIDtype, keyID, keyIDlength,
						   NULL, 0, KEYMGMT_FLAG_NONE );
	status = krnlSendMessage( hardwareInfo->iCryptKeyset,
							  IMESSAGE_KEY_GETKEY, &getkeyInfo,
							  KEYMGMT_ITEM_PRIVATEKEY );
	if( cryptStatusOK( status ) )
		{
		int keyHandle;

		/* It's a private-key object, get its hardware reference and delete 
		   it.  If this fails we continue anyway because we know that 
		   there's also a PKCS #15 object to delete */
		status = getHardwareReference( getkeyInfo.cryptHandle, &keyHandle );
		if( cryptStatusOK( status ) )
			( void ) hwDeleteItem( keyHandle );
		krnlSendNotifier( getkeyInfo.cryptHandle, IMESSAGE_DECREFCOUNT );
		}
	setMessageKeymgmtInfo( &deletekeyInfo, keyIDtype, keyID, keyIDlength,
						   NULL, 0, KEYMGMT_FLAG_NONE );
	return( krnlSendMessage( hardwareInfo->iCryptKeyset,
							 IMESSAGE_KEY_DELETEKEY, &deletekeyInfo,
							 itemType ) );
	}
コード例 #14
0
ファイル: mm.c プロジェクト: sunpan9209/15213
static void add_block_to_list(int index, void* block){
    REQUIRES(0 <= index && index <= NUM_FREE_LISTS);
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));

    set_prev_pointer(block, NULL);
    set_next_pointer(block, free_lists[index]);

    if(free_lists[index] != NULL) set_prev_pointer(free_lists[index], block);
    free_lists[index] = block;
}
コード例 #15
0
ファイル: Mode.cpp プロジェクト: GMAC-lib/gmac
gmacError_t
Mode::copyToAccelerator(accptr_t acc, const hostptr_t host, size_t size)
{
    REQUIRES(acc != 0);
    REQUIRES(host != NULL);
    REQUIRES(size > 0);

    gmacError_t ret;
    ret = Parent::copyToAccelerator(acc, host, size);

    return ret;
}
コード例 #16
0
ファイル: Mode.cpp プロジェクト: GMAC-lib/gmac
gmacError_t
Mode::bufferToAccelerator(accptr_t dst, IOBufferImpl &buffer, size_t size, size_t off)
{
    REQUIRES(size > 0);
    REQUIRES(off + size <= buffer.size());

    gmacError_t ret;

    ret = Parent::bufferToAccelerator(dst, buffer, size, off);

    return ret;
}
コード例 #17
0
ファイル: Mode.cpp プロジェクト: GMAC-lib/gmac
gmacError_t
Mode::acceleratorToBuffer(IOBufferImpl &buffer, const accptr_t dst, size_t size, size_t off)
{
    REQUIRES(size > 0);
    REQUIRES(off + size <= buffer.size());

    gmacError_t ret;

    ret = Parent::acceleratorToBuffer(buffer, dst, size, off);

    return ret;
}
コード例 #18
0
ファイル: trie.c プロジェクト: zhengguan/15122
// GIVEN: a tnode T and a non-empty string s[i,)
// RETURNS: if s[i,) is a prefix of T, return the node that corresponding
// to the last char of s, otherwise return NULL
tnode *tnode_lookup(tnode *T, char *s, size_t i) {
  REQUIRES(is_tnode_root(T));
  REQUIRES(s != NULL);
  REQUIRES(i < strlen(s));

  if (T == NULL) return NULL;
  if (s[i] < T->c) return tnode_lookup(T->left, s, i);
  if (s[i] > T->c) return tnode_lookup(T->right, s, i);
  if (s[i+1] == '\0') return T;

  return tnode_lookup(T->middle, s, i+1);
}
コード例 #19
0
ファイル: heap.c プロジェクト: deedeethan/Practice
bool is_heap_except_down(heap H, int n)
{
  REQUIRES(is_safe_heap(H));
  REQUIRES(1 <= n && n < H->next);
  for (int i = 2; i < H->next; i++)
  {
    ASSERT(2 <= i);
    if (!(i/2 == n || ok_above(H, i/2, i)))
      return false;
  }
  return true;
}
コード例 #20
0
ファイル: queue.c プロジェクト: mpai227/Lightsout-Solver
queue_elem deq(queue *Q) {
  REQUIRES(is_queue(Q));
  REQUIRES(!queue_empty(Q));

  queue_elem x = Q->front->data;  /* save old queue element to return */
  list *q = Q->front;             /* save old list node to free */
  Q->front = Q->front->next;
  free(q);                      /* free old list node */

  ENSURES(is_queue(Q));
  return x;                     /* return old queue element */
}
コード例 #21
0
ファイル: Mode.cpp プロジェクト: GMAC-lib/gmac
gmacError_t
Mode::copyToHost(hostptr_t host, const accptr_t acc, size_t size)
{
    REQUIRES(host != NULL);
    REQUIRES(acc != 0);
    REQUIRES(size > 0);

    gmacError_t ret;
    ret = Parent::copyToHost(host, acc, size);

    return ret;
}
コード例 #22
0
ファイル: Mode.cpp プロジェクト: GMAC-lib/gmac
gmacError_t
Mode::copyAccelerator(accptr_t dst, const accptr_t src, size_t size)
{
    REQUIRES(dst != 0);
    REQUIRES(src != 0);
    REQUIRES(size > 0);

    gmacError_t ret;
    ret = Parent::copyAccelerator(dst, src, size);

    return ret;
}
コード例 #23
0
ファイル: int_mem.c プロジェクト: huihoo/cryptlib-for-ios
int dynCreate( OUT DYNBUF *dynBuf, 
			   IN_HANDLE const CRYPT_HANDLE cryptHandle,
			   IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE attributeType )
	{
	assert( isWritePtr( dynBuf, sizeof( DYNBUF ) ) );

	REQUIRES( isHandleRangeValid( cryptHandle ) );
	REQUIRES( isAttribute( attributeType ) || \
			  isInternalAttribute( attributeType ) );

	return( getDynData( dynBuf, cryptHandle, IMESSAGE_GETATTRIBUTE_S,
						attributeType ) );
	}
コード例 #24
0
ファイル: trie.c プロジェクト: zhengguan/15122
// DETAILS: s might contains '*' which representa arbitrary number of arbitrary
// character
// EFFECT: add all members in the given T that match the given string
// s to q
void trie_member_generalized(trie T, char *s, Queue q) {
  REQUIRES(is_trie(T));
  REQUIRES(s != NULL);
  REQUIRES(is_Queue(q));

  struct strbuf *sb = strbuf_new(8);
  tnode_lookup_generalized(T->root, s, 0, strlen(s), sb, q);
  free(strbuf_dealloc(sb));

  ENSURES(is_Queue(q));
  return;

}
コード例 #25
0
ファイル: mm-seg-best.c プロジェクト: mindbergh/malloc
// Return the header to the successor free block
static inline uint32_t* block_succ(uint32_t* const block) {
    REQUIRES(block != NULL);
    REQUIRES(in_heap(block));

    uint32_t * address = heap_listp + block[2];

    ENSURES(address != NULL);
    ENSURES(in_heap(address));

    if (address == heap_listp)
        return NULL;
    else 
        return address;
}
コード例 #26
0
ファイル: bst.c プロジェクト: zhengguan/15122
// GIVNE: a tree T whose left and right subtrees are legal trees
// EFFECT: rotate T to the right side
// RETURNS: the rotated tree
tree* rotate_right(tree* T, bst B) {
  REQUIRES(T != NULL && T->left != NULL);
  REQUIRES(is_tree(T, B));
  REQUIRES(is_tree(T, B));

  tree* L = T->left;
  T->left = L->right;
  L->right = T;
  fix_height(T, B);
  fix_height(L, B);

  ENSURES(is_tree(L, B));
  return L;
}
コード例 #27
0
ファイル: Texture.cpp プロジェクト: hulcyp/GuildhallProjects
	void Texture::LoadSkyboxFromFile ( const std::string& texturePath )
	{
		REQUIRES( !IsLoaded() );
		REQUIRES( !texturePath.empty() );
	
		m_filePath = texturePath;
		m_texels = stbi_load( m_filePath.c_str(), &m_width, &m_height, &m_channels, 0 );
	
		
		LoadSkyboxToOpenGL();

		PROMISES( IsLoaded() );
		PROMISES( GetFilePath() == texturePath );
	}
コード例 #28
0
ファイル: bst.c プロジェクト: zhengguan/15122
// GIVNE: a tree T whose left and right subtrees are legal trees
// EFFECT: rotate T to the left size
// RETURNS: the rotated tree
tree* rotate_left(tree* T, bst B) {
  REQUIRES(T != NULL && T->right != NULL);
  REQUIRES(is_tree(T->left, B));
  REQUIRES(is_tree(T->right, B));

  tree* R = T->right;
  T->right = R->left;
  R->left = T;
  fix_height(T, B);
  fix_height(R, B);

  ENSURES(is_tree(R, B));
  return R;
}
コード例 #29
0
ファイル: tran.c プロジェクト: TorinYu/15213
void trans(int M, int N, int A[N][M], int B[M][N]){
    int i, j, tmp;

    REQUIRES(M > 0);
    REQUIRES(N > 0);

    for (i = 0; i < N; i++){
        for (j = 0; j < M; j++){
            tmp = A[i][j];
            B[j][i] = tmp;
        }
    }    

    ENSURES(is_transpose(M, N, A, B));
}
コード例 #30
0
ファイル: trans.c プロジェクト: ZHAOTING/ICS-lab
void basicBlockingTrans(int M, int N, int A[N][M], int B[M][N])
{
    int i, j, k, l, tmp;

    REQUIRES(M > 0);
    REQUIRES(N > 0);

    for (i = 0; i < N; i += 8) 
    {
        for (j = 0; j < M; j += 8) 
        {
            for (k = i; k <= i + 3 && k < N; k++)
            {
                for (l = j; l <= j + 3 && l < M; l++)
                {
                    tmp = A[k][l];
                    B[l][k] = tmp;
                }
            }
            for (k = i; k <= i + 3 && k < N; k++)
            {
                for (l = j + 4; l <= j + 7 && l < M; l++)
                {
                    tmp = A[k][l];
                    B[l][k] = tmp;
                }
            }
            for (k = i + 4; k <= i + 7 && k < N; k++)
            {
                for (l = j; l <= j + 4 && l < M; l++)
                {
                    tmp = A[k][l];
                    B[l][k] = tmp;
                }
            }
            for (k = i + 4; k <= i + 7 && k < N; k++)
            {
                for (l = j + 4; l <= j + 7 && l < M; l++)
                {
                    tmp = A[k][l];
                    B[l][k] = tmp;
                }
            }
        }
    }    

    ENSURES(is_transpose(M, N, A, B));
}