CS318 - Pintos
Pintos source browser for JHU CS318 course
Functions | Variables
exception.c File Reference
#include "userprog/exception.h"
#include <inttypes.h>
#include <stdio.h>
#include "userprog/gdt.h"
#include "threads/interrupt.h"
#include "threads/thread.h"
Include dependency graph for exception.c:

Go to the source code of this file.

Functions

static void kill (struct intr_frame *f)
 Handler for an exception (probably) caused by a user process. More...
 
static void page_fault (struct intr_frame *f)
 Page fault handler. More...
 
void exception_init (void)
 Registers handlers for interrupts that can be caused by user programs. More...
 
void exception_print_stats (void)
 Prints exception statistics. More...
 

Variables

static long long page_fault_cnt
 Number of page faults processed. More...
 

Function Documentation

◆ exception_init()

void exception_init ( void  )

Registers handlers for interrupts that can be caused by user programs.

In a real Unix-like OS, most of these interrupts would be passed along to the user process in the form of signals, as described in [SV-386] 3-24 and 3-25, but we don't implement signals. Instead, we'll make them simply kill the user process.

Page faults are an exception. Here they are treated the same way as other exceptions, but this will need to change to implement virtual memory.

Refer to [IA32-v3a] section 5.15 "Exception and Interrupt Reference" for a description of each of these exceptions.

Definition at line 30 of file exception.c.

References INTR_OFF, INTR_ON, intr_register_int(), kill(), and page_fault().

Referenced by pintos_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exception_print_stats()

void exception_print_stats ( void  )

Prints exception statistics.

userprog/exception.h

Definition at line 65 of file exception.c.

References page_fault_cnt, and printf().

Referenced by print_stats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kill()

static void kill ( struct intr_frame f)
static

Handler for an exception (probably) caused by a user process.

Definition at line 72 of file exception.c.

References intr_frame::cs, intr_dump_frame(), intr_name(), PANIC, printf(), SEL_KCSEG, SEL_UCSEG, thread_exit(), thread_name(), and intr_frame::vec_no.

Referenced by exception_init(), and page_fault().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ page_fault()

static void page_fault ( struct intr_frame f)
static

Page fault handler.

This is a skeleton that must be filled in to implement virtual memory. Some solutions to project 2 may also require modifying this code.

At entry, the address that faulted is in CR2 (Control Register 2) and information about the fault, formatted as described in the PF_* macros in exception.h, is in F's error_code member. The example code here shows how to parse that information. You can find more information about both of these in the description of "Interrupt 14--Page Fault Exception (#PF)" in [IA32-v3a] section 5.15 "Exception and Interrupt Reference".

< True: not-present page, false: writing r/o page.

< True: access was write, false: access was read.

< True: access by user, false: access by kernel.

< Fault address.

Definition at line 123 of file exception.c.

References intr_frame::error_code, intr_enable(), kill(), page_fault_cnt, PF_P, PF_U, PF_W, printf(), and write().

Referenced by exception_init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ page_fault_cnt

long long page_fault_cnt
static

Number of page faults processed.

Definition at line 9 of file exception.c.

Referenced by exception_print_stats(), and page_fault().