Advertisement
jazz_vico

orga 2 practica ej 7.a

Nov 10th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. typedef struct {
  2.     process_id pid1;    // pid1 - proceso que comparte
  3.     process_id pid2;    // pid2 - proceso con el que se quiere compartir
  4.     pyshical_address address;
  5.     bool assigned;   //dice si esta asignada para las dos
  6. } shared_page;
  7.  
  8. shared_page shared_pages[MAX_SHARED_PAGES];
  9. uint32_t first_free = 0; //ultimo indice en la lista
  10.  
  11. linear_adress  *getSharedPage(int otherProcess){
  12.     int idActual= getTareaActual();
  13.     physical_adress fisicaCompartida = null;
  14.     //busco en shared_pages
  15.     Shared_Page *paginaCompartida = searchSharedPage(otherProcess,idActual);
  16.     //si no encontre nada  
  17.     if (paginaCompartida == null)   {
  18.         fisicaCompartida = getNextFreeFramePage();
  19.         paginaCompartida = inicializar_siguiente_shared_page(idActual,otherProcess,fisicaCompartida);
  20.     }
  21.     else{
  22.         if (shared_page->assigned==1){ //si encontre y ya estaba asignada
  23.             uint16_t basePD=(rcr3()>>12)<<12;
  24.             return recuperarLineal( basePD, fisicaCompartida); 
  25.         }
  26.         else{ //si encontre y no estaba asignada
  27.             shared_page->assigned=1;
  28.             fisicaCompartida = paginaCompartida->address;  
  29.         }      
  30.     }
  31.     uint32_t cr3=rcr3();
  32.     linear_adress dirLineal = getNextFreePageEntry();
  33.     mmu_mapearPagina(dirLineal,cr3, fisicaCompartida);
  34. }
  35.  
  36. int getTareaActual(){
  37.     int res=readTR()>>3;
  38.     return res;
  39. }
  40.  
  41. shared_page *searchSharedPage(int id1, int id2){
  42.     shared_page res=null;
  43.     for(uint32_t i = 0; i < first_free; i++){
  44.         if (id1==shared_pages[i] && id2==shared_pages[2]){
  45.             return shared_pages[i];
  46.         }
  47.     }
  48. }
  49.  
  50. linear_adress recuperarLineal(basePD, pyshical_address dirFisica){ 
  51.     (PDentry*) pde=(PDentry*) basePD;
  52.     For(i=0, i<1024,i++){
  53.         if(pde[i].p){
  54.             (PTentry*) pte=(PTentry*) pde[i].base<<12;
  55.             for (int j = 0; j < 1024; ++j){
  56.                 if (pte[i].p && pte[i].base<<12==(dirFisica>>12)<<12 ){
  57.                     return (linear_adress)  ( (uint32) (i<<22) | (uint32) (j<<12) | (uint32) ((dirFisica<<20)>>20) );
  58.                 }
  59.             }
  60.         }
  61.     }
  62.  
  63. }
  64.  
  65. void inicializar_siguiente_shared_page(proc_id id1, proc_id id2, pysaddr address) {
  66.     int i = first_free++;
  67.     shared_pages[i].pid1 = pid1;
  68.     shared_pages[i].pid2 = pid2;
  69.     shared_pages[i].address = address;
  70.     shared_pages[i].assigned=0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement