Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- process_id pid1; // pid1 - proceso que comparte
- process_id pid2; // pid2 - proceso con el que se quiere compartir
- pyshical_address address;
- bool assigned; //dice si esta asignada para las dos
- } shared_page;
- shared_page shared_pages[MAX_SHARED_PAGES];
- uint32_t first_free = 0; //ultimo indice en la lista
- linear_adress *getSharedPage(int otherProcess){
- int idActual= getTareaActual();
- physical_adress fisicaCompartida = null;
- //busco en shared_pages
- Shared_Page *paginaCompartida = searchSharedPage(otherProcess,idActual);
- //si no encontre nada
- if (paginaCompartida == null) {
- fisicaCompartida = getNextFreeFramePage();
- paginaCompartida = inicializar_siguiente_shared_page(idActual,otherProcess,fisicaCompartida);
- }
- else{
- if (shared_page->assigned==1){ //si encontre y ya estaba asignada
- uint16_t basePD=(rcr3()>>12)<<12;
- return recuperarLineal( basePD, fisicaCompartida);
- }
- else{ //si encontre y no estaba asignada
- shared_page->assigned=1;
- fisicaCompartida = paginaCompartida->address;
- }
- }
- uint32_t cr3=rcr3();
- linear_adress dirLineal = getNextFreePageEntry();
- mmu_mapearPagina(dirLineal,cr3, fisicaCompartida);
- }
- int getTareaActual(){
- int res=readTR()>>3;
- return res;
- }
- shared_page *searchSharedPage(int id1, int id2){
- shared_page res=null;
- for(uint32_t i = 0; i < first_free; i++){
- if (id1==shared_pages[i] && id2==shared_pages[2]){
- return shared_pages[i];
- }
- }
- }
- linear_adress recuperarLineal(basePD, pyshical_address dirFisica){
- (PDentry*) pde=(PDentry*) basePD;
- For(i=0, i<1024,i++){
- if(pde[i].p){
- (PTentry*) pte=(PTentry*) pde[i].base<<12;
- for (int j = 0; j < 1024; ++j){
- if (pte[i].p && pte[i].base<<12==(dirFisica>>12)<<12 ){
- return (linear_adress) ( (uint32) (i<<22) | (uint32) (j<<12) | (uint32) ((dirFisica<<20)>>20) );
- }
- }
- }
- }
- }
- void inicializar_siguiente_shared_page(proc_id id1, proc_id id2, pysaddr address) {
- int i = first_free++;
- shared_pages[i].pid1 = pid1;
- shared_pages[i].pid2 = pid2;
- shared_pages[i].address = address;
- shared_pages[i].assigned=0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement