<commit_before>#include <arch/general/hardware-thread.hpp>
#include <scheduler/user/user-task.hpp>
#include <critical>
#include <cassert>
#include <panic>

namespace OS {

void HandleMemoryFault(VirtAddr addr, bool exec, bool write) {
  AssertCritical();
  
  Thread * th = HardwareThread::GetCurrent().GetThread();
  assert(th != NULL);
  Task * t = th->GetTask();
  if (t->IsKernel()) {
    Panic("kernel thread page faulted");
  }
  UserTask * task = static_cast<UserTask *>(t);
  SetCritical(false);
  bool result = task->GetCodeMap().HandleFault(addr, exec, write);
  SetCritical(true);
  
  if (result) return;
  SetCritical(false);
  Panic("Unhandled user page fault.");
  // TODO: here, we would ideally kill the task that faulted, but for now I
  // would rather just Panic so we can see what happened.
}

}<commit_msg>no need to leave critical section<commit_after>#include <arch/general/hardware-thread.hpp>
#include <scheduler/user/user-task.hpp>
#include <critical>
#include <cassert>
#include <panic>

namespace OS {

void HandleMemoryFault(VirtAddr addr, bool exec, bool write) {
  AssertCritical();
  
  Thread * th = HardwareThread::GetCurrent().GetThread();
  assert(th != NULL);
  Task * t = th->GetTask();
  if (t->IsKernel()) {
    Panic("kernel thread page faulted");
  }
  UserTask * task = static_cast<UserTask *>(t);
  SetCritical(false);
  bool result = task->GetCodeMap().HandleFault(addr, exec, write);
  SetCritical(true);
  
  if (result) return;
  
  Panic("Unhandled user page fault.");
  // TODO: here, we would ideally kill the task that faulted, but for now I
  // would rather just Panic so we can see what happened.
}

}
{'fraction_non_alphanumeric': 0.13940856970428486, 'fraction_numerical': 0.0, 'mean_word_length': 4.280254777070064, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6018724', 'n_tokens_mistral': 557, 'n_tokens_neox': 537, 'n_words': 158}