Everyone:

Next week, we will return to the idea of virtualization and consider how the operating system abstracts physical memory for each process.

TL;DR

For this reading assignment, you are to read about address spaces, free-space management, address translation, and segmentation, and submit your responses to the Reading 08 Quiz.

Reading

The readings for next week are:

  1. Operating Systems: Three Easy Pieces

Quiz

Once you have done the readings, answer the following Reading 08 Quiz questions:

Program

For this week, you are to identify common memory problems. Given the following five snippets of code:

// Snippet A
for (int i = 1; i < argc; i++) {
    char *copy = strdup(argv[i]);
    puts(copy);
}

// Snippet B
char buffer[BUFSIZ];
puts(buffer);

// Snippet C
char *s = "string";
*s = 'S';

// Snippet D
char *s = "string";
free(s);

// Snippet E
char *buffer = calloc(1, strlen(argv[0]));
strcat(buffer, argv[0]);
puts(buffer);
free(buffer);

Identify if the code snippet demonstrates one of the following errors:

  1. segfault
  2. buffer overflow
  3. uninitialized read
  4. memory leak
  5. dangling pointer
  6. double free
  7. invalid free

In your program.c, simply use puts to print out the error:

int main(int argc, char *argv[]) {
    puts("segfault");
    ...
    puts("invalid free");
    return 0;
}

Submission

To submit you work, follow the same process outlined in Reading 01:

$ git checkout master                 # Make sure we are in master branch
$ git pull --rebase                   # Make sure we are up-to-date with GitLab

$ git checkout -b reading08           # Create reading08 branch and check it out

$ cd reading08                        # Go into reading08 folder
$ $EDITOR answers.json                # Edit your answers.json file

$ ../.scripts/check.py                # Check reading08 quiz
Checking reading08 quiz ...
     Q01 0.40
     Q02 0.30
     Q03 0.30
     Q04 0.60
     Q05 0.30
     Q06 0.50
     Q07 0.30
     Q08 0.30
   Score 3.00 / 3.00
  Status Success

$ git add answers.json                # Add answers.json to staging area
$ git commit -m "Reading 08: Quiz"    # Commit work

$ $EDITOR program.c                   # Edit your program.c file

$ make test-program                   # Check reading03 program
Testing reading08 program...
   Score 3.00 / 3.00
  Status Success

$ git add Makefile                    # Add Makefile to staging area
$ git add program.c                   # Add program.c to staging area
$ git commit -m "Reading 08: Code"    # Commit work

$ git push -u origin reading08        # Push branch to GitHub

Pull Request

Once you have committed your work and pushed it to GitHub, remember to create a pull request and assign it to the appropriate teaching assistant from the Reading 08 TA List.