示例#1
0
void deallocate_starting_address(puint_t address, size_t size) {
    if (size < 0x10000)
        return; // ignore section and just leave it as dead memory
    section_info_t* se = frame_pool;
    while (se->next_section != NULL)
        se = se->next_section;
    make_pool(size, address, se, NULL);
}
示例#2
0
int main(void)
{
  char word[100];
  Pool wordpool;

  dict = Dict_open(NULL);

  while (printf("word> "), fflush(stdout),
	 fgets(word, sizeof(word), stdin),
         (lenall = make_pool(word, &wordpool)) != 0) {
    for (len1=lenall; len1>=(lenall+2)/3; len1--) {
      find_subwords(&wordpool, len1, find_second_and_third);
    }
  }

  Dict_close(dict);
  return 0;
}
示例#3
0
void test(void)
{
   char *x1, *x2, *x3, *x4, *x5;

   pool *p = make_pool();

   push(p);

   x1 = allocate(p, 10);
   x2 = allocate(p, 20);
   push(p);
   x3 = allocate(p, 10);
   x4 = allocate(p, 20);

   *x1 = 'a';  
   *x2 = 'b';  

   x1[-1] = 'h'; 
   x1[10] = 'i'; 

   pop(p);

   *x3 = 'c';  
   *x4 = 'd';  

   *x1 = 'e';  
   *x2 = 'f';  

   x5 = allocate(p, 10);

   *x5 = 'g';  

   

   

   
}
示例#4
0
void test(void)
{
   char *x1, *x2, *x3, *x4, *x5;

   pool *p = make_pool();

   push(p);

   x1 = allocate(p, 10);
   x2 = allocate(p, 20);
   push(p);
   x3 = allocate(p, 10);
   x4 = allocate(p, 20);

   *x1 = 'a';  // valid
   *x2 = 'b';  // valid

   x1[-1] = 'h'; // invalid
   x1[10] = 'i'; // invalid

   pop(p);

   *x3 = 'c';  // invalid
   *x4 = 'd';  // invalid

   *x1 = 'e';  // valid
   *x2 = 'f';  // valid

   x5 = allocate(p, 10);

   *x5 = 'g';  // valid

   // pop(p);

   // *x5 = 'g';  // invalid

   // destroy_pool(p);
}
示例#5
0
int main(int argc, char **argv)
{
  Pool wordpool;
  int len, i;
  int found1st;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s letters\n", argv[0]);
    exit(2);
  }
  dict = Dict_open(NULL);

  len = make_pool(argv[1], &wordpool);
  found = found1st = FALSE;
  for (i=len; i>=0 && !(found && found1st); i--) {
    if (found) {found1st=TRUE; found=FALSE;}
    find_subwords(&wordpool, i, print_word_and_remainder);
    
  }

  Dict_close(dict);
  return 0;
}
示例#6
0
/**
 * Creates frame map from multiboot structure.
 *
 * Fills bitmaps for frame_map_usage, phys_map and returns bitmap for frame_map
 * from available ram entries.
 */
static void create_frame_pool(struct multiboot_info* mboot_addr) {
    section_info_t* firstfp = NULL;
    section_info_t* lastfp = NULL;

    if ((mboot_addr->flags & 0b100000) == 0b100000) {
        uint32_t mem = mboot_addr->mmap_addr + 4;
        while (mem < (mboot_addr->mmap_addr + mboot_addr->mmap_length)) {
            mboot_mem_t data = *((mboot_mem_t*) (uint64_t) mem);
            uint32_t size = *((uint32_t*) (uint64_t) (mem - 4));
            mem += size + 4;

            puint_t ba = data.address;
            size_t len = data.size;

            if (data.type != 1) // not a ram
                continue;
            if (len < 0x10000)
                continue; // waste of a section

            puint_t base_addr = ba;
            size_t length = len;

            while (true) {
                // if we fail to find any useful starting address but there is more to search
                // restart the search here
start_search_again:;

                // search from current base_addr up to maximum in the block
                if (base_addr >= len+ba)
                    break; // end of search
                for (puint_t test = base_addr; test<len; test+=0x1000) {
                    if (check_if_used(mboot_addr, test)) {
                        // memory address is used by some internal structure
                        // write up how much size we have for this pool and then
                        // decide upon it
                        length = test - base_addr;
                        if (length == 0) {
                            // first 0x1000 already used
                            // check if there is more, if so, continue from 0x1000 onwards
                            // if not, this section is garbage
                            if (base_addr+0x1000<ba+len) {
                                base_addr += 0x1000;
                                goto start_search_again;
                            } else {
                                goto finish_this_section;
                            }
                        } else if (length < 0x10000) {
                            // pool with size <0x10000, same as above
                            // but add length, skipping good but too small pool
                            if (base_addr+length<ba+len) {
                                base_addr += length;
                                goto start_search_again;
                            } else {
                                goto finish_this_section;
                            }
                        }
                        // found a barrier, can only use this much in a block
                        goto use_length_found;
                    }
                }
                // no used address up to len, awesome, use this as a pool
                length = len;

use_length_found:;
                section_info_t* section = make_pool(length, base_addr, lastfp, &firstfp);

                lastfp = section;

                // increment base address by length
                base_addr += length;
            }
finish_this_section:;

        }

    }

    // we have our pool, so we set it and thus disable temp. heap allocation for page structures
    frame_pool = firstfp;
}