// [VAtoKA] // // convert a user process virtual address (from the current process) // into a kernel-usable address. only valid for one page, need to // call again for next page. // // second argument is whether or not the page found will be written. // // return 0 on failure. (at the moment, all failures generate fatal // exceptions which will kill the process.) // // note: this argument takes and returns ints, but we're really // dealing with addresses. ints and addresses are both 4 bytes here. // i'd rather be using void* but this is consistent with the rest of // nachos. // int VAtoKA(int vAddr, bool writing) { int pAddr; // physical address, offset into main memory int kAddr; // kernel address, usable from within nachos ExceptionType exc; DEBUG('a', "VAtoKA conversion for 0x%x\n", vAddr); // keep translating until we succeed or raise a fatal exception. // a bug in exception handling may turn this into an infinite loop! while((exc = Translate(vAddr, &pAddr, 1, writing)) != NoException) machine->RaiseException(exc, vAddr); // convert the physical offset into a usable pointer kAddr = (int)&(machine->mainMemory[pAddr]); return kAddr; }