---
# System prepended metadata

title: CS162 Design Document

---

# CS162 Design Document

Group 64: 
- Aislin Liu
- Jesse Dai
- Michael Huang
- Lauren Leung


## Task 1: Argument Passing

### Data Structures

```c=x
int argc;
struct list arguments;
struct argument {
  struct list_elem elem;
  char* arg;
}
char** addresses;
int total_bytes;
```

The ```argc``` value is meant to keep track of the amount of arguments.
The list keeps track of all the arguments that will be split by the space delimiter using the Pintos linked list.
The ```addresses``` char* array will have the addresses of each string.
```total_bytes``` will keep track of the total number of bytes so we can pad correctly.

### Algorithm

1. Parse the inputs from ```char *file_name``` (based on spaces), basically strip by space excess spaces out and split the string by the space delimiter. Store the string in the ```arguments``` linked list using the ```argument``` struct, and add the number of bytes the string took to ```total_bytes```. Also increase ```agrc``` by one. Repeat this for all the arg strings in ```file_name```. Based off of what we did proj0, we should pad by ```total_bytes - 4 % 16```.
2. We initialize the ```addresses``` array to be of size ```argc```. Starting from ```PHYS_BASE```, or whatever ```esp``` initially is, read in the args to the stack and store that address in the ```addresses``` array. Then, add a null pointer sentinel representing ```argv[argc+1]```, and the address of each string. We want to make sure that the addresses of the strings are pushed in the correct order. Then we push argv and argc, and a dummy int for the return address.  

#### Potential Edge Cases
- Multiple spaces between arguments, but should be handled in our strip/split function.
- Too many arguments, we limit the size of the arguments to be 1024, 1/4 of the page/stack size. If the total bytes of the stack after we would have pushed everything to the stack is greater than 1024, we throw an error instead. ```total_bytes + padding + (argc + 4) * 4```

### Synchronization
No synchronization needed as multiple threads are not needed. 

### Rationale
We first add everything to a linked list because we have yet to determine everything that needs to be pushed to the stack, and we need to check if the size would be greater than 1024. We keep the linked list and the addresses array in the same order so that the final stack will be in the correct order. Runtime will be O(N), because we go through the entire list multiple times.

## Task 2: Process Control Syscalls
