22static bool load (
const char *cmdline,
void (**eip) (
void),
void **esp);
58 memset (&if_, 0,
sizeof if_);
75 asm volatile (
"movl %0, %%esp; jmp intr_exit" : :
"g" (&if_) :
"memory");
191#define PT_STACK 0x6474e551
215 bool success =
false;
220 if (t->pagedir ==
NULL)
247 for (i = 0; i < ehdr.
e_phnum; i++)
257 file_ofs +=
sizeof phdr;
283 read_bytes = page_offset + phdr.
p_filesz;
295 read_bytes, zero_bytes, writable))
309 *eip = (void (*) (void)) ehdr.
e_entry;
321static bool install_page (
void *upage,
void *kpage,
bool writable);
391 while (read_bytes > 0 || zero_bytes > 0)
396 size_t page_read_bytes = read_bytes <
PGSIZE ? read_bytes :
PGSIZE;
397 size_t page_zero_bytes =
PGSIZE - page_read_bytes;
405 if (
file_read (
file, kpage, page_read_bytes) != (
int) page_read_bytes)
410 memset (kpage + page_read_bytes, 0, page_zero_bytes);
420 read_bytes -= page_read_bytes;
421 zero_bytes -= page_zero_bytes;
433 bool success =
false;
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define NOT_REACHED()
lib/debug.h
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
void file_seek(struct file *file, off_t new_pos)
Sets the current position in FILE to NEW_POS bytes from the start of the file.
void file_close(struct file *file)
Closes FILE.
off_t file_length(struct file *file)
Returns the size of FILE in bytes.
off_t file_read(struct file *file, void *buffer, off_t size)
Reads SIZE bytes from FILE into BUFFER, starting at the file's current position.
struct file * filesys_open(const char *name)
Opens the file with the given NAME.
#define FLAG_IF
Interrupt Flag.
#define FLAG_MBS
EFLAGS Register.
#define SEL_UCSEG
Segment selectors.
#define SEL_UDSEG
User data selector.
int printf(const char *format,...)
Writes formatted output to the console.
int32_t off_t
An offset within a file.
uint32_t * pagedir_create(void)
Creates a new page directory that has mappings for kernel virtual addresses, but none for user virtua...
void * pagedir_get_page(uint32_t *pd, const void *uaddr)
Looks up the physical address that corresponds to user virtual address UADDR in PD.
bool pagedir_set_page(uint32_t *pd, void *upage, void *kpage, bool writable)
Adds a mapping in page directory PD from user virtual page UPAGE to the physical frame identified by ...
void pagedir_destroy(uint32_t *pd)
Destroys page directory PD, freeing all the pages it references.
void pagedir_activate(uint32_t *pd)
Loads page directory PD into the CPU's page directory base register.
void * palloc_get_page(enum palloc_flags flags)
Obtains a single free page and returns its kernel virtual address.
void palloc_free_page(void *page)
Frees the page at PAGE.
@ PAL_ZERO
Zero page contents.
static thread_func start_process NO_RETURN
tid_t process_execute(const char *file_name)
Starts a new thread running a user program loaded from FILENAME.
#define PT_STACK
Stack segment.
#define PT_DYNAMIC
Dynamic linking info.
void process_activate(void)
Sets up the CPU for running user code in the current thread.
static bool load_segment(struct file *file, off_t ofs, uint8_t *upage, uint32_t read_bytes, uint32_t zero_bytes, bool writable)
Loads a segment starting at offset OFS in FILE at address UPAGE.
int process_wait(tid_t child_tid UNUSED)
Waits for thread TID to die and returns its exit status.
static bool setup_stack(void **esp)
Create a minimal stack by mapping a zeroed page at the top of user virtual memory.
#define PT_PHDR
Program header table.
static bool validate_segment(const struct Elf32_Phdr *, struct file *)
Checks whether PHDR describes a valid, loadable segment in FILE and returns true if so,...
#define PT_NOTE
Auxiliary info.
#define PT_LOAD
Loadable segment.
#define PT_NULL
Values for p_type.
static bool install_page(void *upage, void *kpage, bool writable)
load() helpers.
#define PT_INTERP
Name of dynamic loader.
#define PT_SHLIB
Reserved.
void process_exit(void)
Free the current process's resources.
uint32_t Elf32_Word
We load ELF binaries.
static bool load(const char *cmdline, void(**eip)(void), void **esp)
Loads an ELF executable from FILE_NAME into the current thread.
static void start_process(void *file_name_)
A thread function that loads a user process and starts it running.
#define ROUND_UP(X, STEP)
Yields X rounded up to the nearest multiple of STEP.
unsigned short int uint16_t
int memcmp(const void *a_, const void *b_, size_t size)
Find the first differing byte in the two blocks of SIZE bytes at A and B.
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
size_t strlcpy(char *dst, const char *src, size_t size)
Copies string SRC to DST.
unsigned char e_ident[16]
uint16_t uint32_t eflags
Code segment for eip.
void(* eip)(void)
Next instruction to execute.
uint16_t uint16_t fs
Saved GS segment register.
uint16_t uint16_t uint16_t es
Saved FS segment register.
uint16_t uint16_t uint16_t uint16_t ds
Saved ES segment register.
void * esp
Saved stack pointer.
A kernel thread or user process.
static const char file_name[]
tests/filesys/base/syn-read.h
struct thread * thread_current(void)
Returns the running thread.
void thread_exit(void)
Deschedules the current thread and destroys it.
tid_t thread_create(const char *name, int priority, thread_func *function, void *aux)
Creates a new kernel thread named NAME with the given initial PRIORITY, which executes FUNCTION passi...
#define PRI_DEFAULT
Default priority.
#define TID_ERROR
Error value for tid_t.
int tid_t
Thread identifier type.
void thread_func(void *aux)
void tss_update(void)
Sets the ring 0 stack pointer in the TSS to point to the end of the thread stack.
#define PGSIZE
Bytes in a page.
static bool is_user_vaddr(const void *vaddr)
Returns true if VADDR is a user virtual address.
#define PHYS_BASE
Base address of the 1:1 physical-to-virtual mapping.
static unsigned pg_ofs(const void *va)
Offset within a page.
#define PGMASK
Page offset bits (0:12).