kalloc.c
char*
kalloc(void)
{
  // PARAM CHANGE: track pid of process calling kalloc
  struct run *r;
//  char* v;
  if(kmem.use_lock)
    acquire(&kmem.lock);
  r = kmem.freelist;  // save next free frame in memory

  // // create the free frame
  // if (pid == 0 || (pid != -1 && pid != curPID)) { 
  //   v = (char*)PGROUNDUP((uint)&frames[count]);
  //   // should free frame we just made
  //   kfree(v);  // FIXME: lmao does this work
  //   curPID = pid;
  // }

  if (init2Done) {
    frames[count] = ((V2P(r)) & ~0xFFF) >> 12; // virtual >> physical and mask
    // cprintf("%d\n", frames[count]);
    count++;
  }
  // return the first free page available in the free list
  if(r)
    kmem.freelist = r->next;
  if(kmem.use_lock)
    release(&kmem.lock);
  return (char*)r;
}
// Allocate one 4096-byte page of physical memory.
// Returns a pointer that the kernel can use.
// Returns 0 if the memory cannot be allocated.
Allocate one 4096-byte page of physical memory.
Returns a pointer that the kernel can use.
Returns 0 if the memory cannot be allocated.
Allocate one 4096 - byte page of physical memory . Returns a pointer that the kernel can use . Returns 0 if the memory cannot be allocated .
char*
kalloc(void)
{
  struct run *r;
  if(kmem.use_lock)
    acquire(&kmem.lock);
  r = kmem.freelist;  
  if (init2Done) {
    frames[count] = ((V2P(r)) & ~0xFFF) >> 12; 
    count++;
  }
  if(r)
    kmem.freelist = r->next;
  if(kmem.use_lock)
    release(&kmem.lock);
  return (char*)r;
}
char * kalloc ( void ) { struct run * r ; if ( kmem . use_lock ) acquire ( & kmem . lock ) ; r = kmem . freelist ; if ( init2Done ) { frames [ count ] = ( ( V2P ( r ) ) & ~ 0xFFF ) >> 12 ; count ++ ; } if ( r ) kmem . freelist = r -> next ; if ( kmem . use_lock ) release ( & kmem . lock ) ; return ( char * ) r ; }
Allocate one 4096-byte page of physical memory.
Allocate one 4096 - byte page of physical memory .
// PARAM CHANGE: track pid of process calling kalloc //  char* v; // save next free frame in memory // // create the free frame // if (pid == 0 || (pid != -1 && pid != curPID)) {  //   v = (char*)PGROUNDUP((uint)&frames[count]); //   // should free frame we just made //   kfree(v);  // FIXME: lmao does this work //   curPID = pid; // } // virtual >> physical and mask // cprintf("%d\n", frames[count]); // return the first free page available in the free list