class: title # Address Spaces & Memory ## CSC 213 – September 12, 2025 --- # Agenda for Today 1. Department Events 2. Upcoming Work 3. Processes & System Calls, _continued_ 4. Assignment Discussion: Ngram Generator 5. Memory Errors & Address Spaces 6. Wrap Up --- # Department Events ## CS Picnic .indent[ Friday, September 12th at 5pm, Merrill Park West RSVP at
] ## CS Table: The BASIC Programming Language .indent[ Tuesday, September 16th at noon in JRC 224C ] *To receive 0.25% extra credit, send an email to let me know you attended no more than 48 hours after the event.* --- class: section, blue # Upcoming Work --- # Assignment 2: Sorted List **Due:** Monday, September 15th by 11:59pm ## Questions **Do we have to implement binary search for `sorted_list_count`?** No, you definitely don't need binary search, and that may not be helpful depending on how you decided to store your list. Any solution that is able to avoid traversing the full list in at least some cases meets the requirement for efficiency. --- # Shell Lab **Due:** Wednesday, September 17th by 11:59pm ## Questions *None so far.* --- class: section, blue # Processes & System Calls, _continued_ --- # Process API: Example 5 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { printf("A\n"); execlp("ls", "ls", "-l", NULL); printf("B\n"); } ``` --- # Process API: Example 6 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { printf("A\n"); execlp("ls", "noyce", "-l", NULL); printf("B\n"); } ``` --- # Process API: Example 7 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { printf("A\n"); execlp("noyce", "ls", "-l", NULL); printf("B\n"); } ``` --- # Process API: Example 8 What output do you expect this program to produce? ```c int main() { pid_t child_id = fork(); if (child_id == 0) { execlp("ls", "ls", "-l", NULL); perror("exec failed"); exit(EXIT_FAILURE); } else if (child_id > 0) { int status; wait(&status); printf("Child exited with status %d\n", WEXITSTATUS(status)); } else { perror("fork failed"); exit(EXIT_FAILURE); } } ``` --- class: section, green # Assignment Discussion: Ngram Generator --- class: section, blue # Memory Errors & Address Spaces --- # Discussion: Memory Errors For each type of memory error, answer the following questions: 1. What causes the error? 2. What happens when the error occurs? Consider the immediate consequences and any longer-term effects. -- ## Memory Errors - Invalid Pointer Write - Buffer Overflow - Uninitialized Read - Memory Leak - Dangling Pointer Read/Write - Double/Invalid Free *Start by thinking of answers on your own. I will let you know when to start discussion.* --- # Address Sanitizer Compile programs with Address Sanitizer to detect many memory errors. ## Instructions Compile with the option `-fsanitize=address`, for example: ``` clang -fsanitize=address -o program program.c ``` or in a `Makefile`: ```Makefile CFLAGS := -g -fsanitize=address ``` Run the program as usual. If Address Sanitizer detects an issue, it will interrupt the program and print an error message. --- # Discussion: Address Spaces **Questions for think, pair, share:** 1. What are the main pieces of a running program's address space? 2. What is the difference between virtual and physical addresses? 3. Why does the OS run programs in separate address spaces? *Start by thinking of answers on your own. I will let you know when to start discussion.* --- class: section, gray # Whiteboard: A Typical Address Space --- class: section, blue # Wrap Up --- # Reminders ## Assignment The sorted list assignment is due on Monday. Make sure you start early so you have time to ask for help if you get stuck. ## Lab The shell lab is due next Wednesday. Arrange times to work with your lab group, and leave lots of time for debugging/troubleshooting. ## Need Help? Book an appointment during my office hours, or come to the mentor session this weekend on Sunday from 3–5pm. ## Reading - **Mechanism: Address Translation** (OSTEP, Chapter 15) - **Paging: Introduction** (OSTEP, Chapter 18)