-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a54372
Showing
7 changed files
with
653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#*# | ||
*.aux | ||
*.backup | ||
*.core | ||
*.dSYM | ||
*.dvi | ||
*.gcda | ||
*.gch | ||
*.log | ||
*.noopt | ||
*.o | ||
*.optimized | ||
*.pch | ||
*.unsafe | ||
*.xcodeproj | ||
*~ | ||
.DS_Store | ||
.cproject | ||
.deps | ||
.gitcheckout | ||
.goutputstream-* | ||
.hg | ||
.project | ||
.svn | ||
.vscode | ||
a.out | ||
core* | ||
cmake-build-* | ||
cscope.out | ||
pset.tgz | ||
pset[1-9].tgz | ||
pset[1-9]grade.tgz | ||
strace.out | ||
tags | ||
tags.* | ||
typescript | ||
vgcore* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CS 61 Sections | ||
============== | ||
|
||
This repository contains section material for Harvard’s CS 61 class, | ||
Systems Programming and Machine Organization. | ||
|
||
For more information, see the course site: | ||
https://cs61.seas.harvard.edu/ | ||
|
||
Follow the section discussion using the pages listed under “Sections” | ||
at https://cs61.seas.harvard.edu/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
# compiler flags | ||
CFLAGS := -std=gnu11 -Wall -Wextra -Wshadow -g $(DEFS) $(CFLAGS) | ||
CXXFLAGS := -std=gnu++2a -Wall -Wextra -Wshadow -g $(DEFS) $(CXXFLAGS) | ||
|
||
O ?= -O3 | ||
ifeq ($(filter 0 1 2 3 s z g fast,$(O)),$(strip $(O))) | ||
override O := -O$(O) | ||
endif | ||
|
||
PTHREAD ?= 0 | ||
ifeq ($(PTHREAD),1) | ||
CFLAGS += -pthread | ||
CXXFLAGS += -pthread | ||
WANT_TSAN ?= 1 | ||
endif | ||
|
||
PIE ?= 1 | ||
ifeq ($(PIE),0) | ||
LDFLAGS += -no-pie | ||
endif | ||
|
||
# compiler variant | ||
ifeq ($(COMPILER),clang) | ||
ifeq ($(origin CC),default) | ||
ifeq ($(shell if clang --version | grep -e 'LLVM\|clang' >/dev/null; then echo 1; else echo 0; fi),1) | ||
CC = clang | ||
endif | ||
endif | ||
ifeq ($(origin CXX),default) | ||
ifeq ($(shell if clang++ --version | grep -e 'LLVM\|clang' >/dev/null; then echo 1; else echo 0; fi),1) | ||
CXX = clang++ | ||
endif | ||
endif | ||
endif | ||
ifeq ($(COMPILER),gcc) | ||
ifeq ($(origin CC),default) | ||
ifeq ($(shell if gcc --version 2>&1 | grep -e 'Free Software' >/dev/null; then echo 1; else echo 0; fi),1) | ||
CC = gcc | ||
endif | ||
endif | ||
ifeq ($(origin CXX),default) | ||
ifeq ($(shell if g++ --version 2>&1 | grep -e 'Free Software' >/dev/null; then echo 1; else echo 0; fi),1) | ||
CXX = g++ | ||
endif | ||
endif | ||
endif | ||
|
||
ISCLANG := $(shell if $(CC) --version | grep -e 'LLVM\|clang' >/dev/null; then echo 1; else echo 0; fi) | ||
ifeq ($(ISCLANG),1) | ||
BADCXXFLAGS ?= -fno-if-conversion -fno-if-conversion2 | ||
endif | ||
|
||
ifeq ($(NEED_CXX_GCC),1) | ||
GXX_ISCLANG := $(shell if g++ --version | grep -e 'LLVM\|clang' >/dev/null; then echo 1; else echo 0; fi) | ||
ifeq ($(GXX_ISCLANG),1) | ||
ifeq ($(shell if g++-12 --version 2>/dev/null | grep -e 'Free Software' >/dev/null; then echo 1; else echo 0; fi),1) | ||
CXX_GCC = g++-12 | ||
else ifeq ($(shell if g++-11 --version 2>/dev/null | grep -e 'Free Software' >/dev/null; then echo 1; else echo 0; fi),1) | ||
CXX_GCC = g++-11 | ||
else ifeq ($(shell if g++-10 --version 2>/dev/null | grep -e 'Free Software' >/dev/null; then echo 1; else echo 0; fi),1) | ||
CXX_GCC = g++-10 | ||
else | ||
CXX_GCC = false | ||
endif | ||
else | ||
CXX_GCC = g++ | ||
endif | ||
endif | ||
|
||
# sanitizer arguments | ||
ifndef SAN | ||
SAN := $(SANITIZE) | ||
endif | ||
ifeq ($(SAN),1) | ||
ifndef ASAN | ||
ASAN := $(if $(strip $(shell $(CC) -v 2>&1 | grep 'build=aarch.*target=x86')),,1) | ||
endif | ||
endif | ||
ifndef TSAN | ||
ifeq ($(WANT_TSAN),1) | ||
TSAN := $(SAN) | ||
endif | ||
endif | ||
|
||
check_for_sanitizer = $(if $(strip $(shell $(CC) -fsanitize=$(1) -x c -E /dev/null 2>&1 | grep sanitize=)),$(info ** WARNING: The `$(CC)` compiler does not support `-fsanitize=$(1)`.),1) | ||
ifeq ($(TSAN),1) | ||
ifeq ($(call check_for_sanitizer,thread),1) | ||
CFLAGS += -fsanitize=thread | ||
CXXFLAGS += -fsanitize=thread | ||
endif | ||
else | ||
ifeq ($(or $(ASAN),$(LSAN),$(LEAKSAN)),1) | ||
ifeq ($(call check_for_sanitizer,address),1) | ||
CFLAGS += -fsanitize=address | ||
CXXFLAGS += -fsanitize=address | ||
endif | ||
endif | ||
ifeq ($(or $(LSAN),$(LEAKSAN)),1) | ||
ifeq ($(call check_for_sanitizer,leak),1) | ||
CFLAGS += -fsanitize=leak | ||
CXXFLAGS += -fsanitize=leak | ||
endif | ||
endif | ||
endif | ||
ifeq ($(or $(UBSAN),$(SAN)),1) | ||
ifeq ($(call check_for_sanitizer,undefined),1) | ||
CFLAGS += -fsanitize=undefined -fno-sanitize-recover=undefined | ||
CXXFLAGS += -fsanitize=undefined -fno-sanitize-recover=undefined | ||
endif | ||
endif | ||
|
||
# profiling | ||
ifeq ($(or $(PROFILE),$(PG)),1) | ||
CFLAGS += -pg | ||
CXXFLAGS += -pg | ||
endif | ||
|
||
# these rules ensure dependencies are created | ||
DEPCFLAGS = -MD -MF $(DEPSDIR)/$(patsubst %.o,%,$(@F)).d -MP | ||
DEPSDIR := .deps | ||
BUILDSTAMP := $(DEPSDIR)/rebuildstamp | ||
DEPFILES := $(wildcard $(DEPSDIR)/*.d) | ||
ifneq ($(DEPFILES),) | ||
include $(DEPFILES) | ||
endif | ||
|
||
# when the C compiler or optimization flags change, rebuild all objects | ||
ifneq ($(strip $(DEP_CC)),$(strip $(CC) $(CPPFLAGS) $(CFLAGS) $(O))) | ||
DEP_CC := $(shell mkdir -p $(DEPSDIR); echo >$(BUILDSTAMP); echo "DEP_CC:=$(CC) $(CPPFLAGS) $(CFLAGS) $(O)" >$(DEPSDIR)/_cc.d) | ||
endif | ||
ifneq ($(strip $(DEP_CXX)),$(strip $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(O) $(LDFLAGS))) | ||
DEP_CXX := $(shell mkdir -p $(DEPSDIR); echo >$(BUILDSTAMP); echo "DEP_CXX:=$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(O) $(LDFLAGS)" >$(DEPSDIR)/_cxx.d) | ||
endif | ||
|
||
|
||
V = 0 | ||
ifeq ($(V),1) | ||
run = $(1) $(3) | ||
xrun = /bin/echo "$(1) $(3)" && $(1) $(3) | ||
else | ||
run = @$(if $(2),/bin/echo " $(2) $(3)" &&,) $(1) $(3) | ||
xrun = $(if $(2),/bin/echo " $(2) $(3)" &&,) $(1) $(3) | ||
endif | ||
runquiet = @$(1) $(3) | ||
|
||
CXX_LINK_PREREQUISITES = $(CXX) $(CXXFLAGS) $(LDFLAGS) $(O) -o $@ $^ | ||
|
||
CLEANASM = 1 | ||
ifeq ($(CLEANASM),1) | ||
cleanasm = perl -ni -e '$$badsection = !!/\.note\.gnu/ if /^\s+\.section/; print if !/^(?:\# BB|\s+\.cfi|\s+\.p2align|\s+\.loc|\.LF[BE]|\.LVL|\s+\# =>This|\s+\# kill)/ && !$$badsection' $(1) | ||
else | ||
cleanasm = : | ||
endif | ||
|
||
DEFAULT_ASM_CXXFLAGS ?= $(O) | ||
flagged_compile = @ARGS=$$(grep '^//!' $< | sed 's/.*!//$(patsubst %,;s/ % */ /,$(BADCXXFLAGS));s/^ | $$//'); \ | ||
if test -z "$$ARGS"; then ARGS="$(DEFAULT_ASM_CXXFLAGS)"; fi; \ | ||
$(call xrun,$(CXX) $(3) $$ARGS -o $(2) $(1),COMPILE $$ARGS $(1) -o $(2)) | ||
flagged_compile_S = $(call flagged_compile,$(1),$(2),$(filter-out -g,$(3) -S)) && { $(call cleanasm,$(2)); } | ||
flagged_compile_c = $(call flagged_compile,$(1),$(2),$(3) -c) | ||
|
||
|
||
PERCENT := % | ||
|
||
# cancel implicit rules we don't want | ||
%: %.c | ||
%.o: %.c | ||
%: %.cc | ||
%.o: %.cc | ||
%: %.o | ||
%.o: %.s | ||
|
||
$(BUILDSTAMP): | ||
@mkdir -p $(@D) | ||
@echo >$@ | ||
|
||
always: | ||
@: | ||
|
||
clean-hook: | ||
@: | ||
|
||
.PHONY: always clean-hook | ||
.PRECIOUS: %.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#! /bin/bash | ||
|
||
maindir="" | ||
destdir=cs61-sections | ||
|
||
fresh= | ||
verbose=false | ||
arch="`arch`" | ||
tag= | ||
platform= | ||
while test "$#" -ne 0; do | ||
if test "$1" = "-f" -o "$1" = "--fresh"; then | ||
fresh=1 | ||
shift | ||
elif test "$1" = "-V" -o "$1" = "--verbose"; then | ||
verbose=true | ||
shift | ||
elif test "$1" = "-a" -o "$1" = "--arm" -o "$1" = "--arm64"; then | ||
if test "$arch" = "arm64" -o "$arch" = "aarch64"; then | ||
platform=linux/arm64 | ||
shift | ||
else | ||
echo "\`cs61-run-docker --arm\` only works on ARM64 hosts" 1>&2 | ||
exit 1 | ||
fi | ||
elif test "$1" = "-x" -o "$1" = "--x86-64" -o "$1" = "--x86_64" -o "$1" = "--amd64"; then | ||
platform=linux/amd64 | ||
shift | ||
else | ||
armtext= | ||
if test "$arch" = "arm64" -o "$arch" = "aarch64"; then | ||
armtext=" [-a|--arm] [-x|--x86-64]" | ||
fi | ||
echo "Usage: cs61-run-docker [-f|--fresh]$armtext [-V|--verbose]" 1>&2 | ||
exit 1 | ||
fi | ||
done | ||
if test -z "$platform" -a \( "$arch" = "arm64" -o "$arch" = "aarch64" \); then | ||
platform=linux/arm64 | ||
elif test -z "$platform"; then | ||
platform=linux/amd64 | ||
fi | ||
if test -z "$tag" -a "$platform" = linux/arm64; then | ||
tag=cs61:arm64 | ||
elif test -z "$tag"; then | ||
tag=cs61:latest | ||
fi | ||
|
||
|
||
vexec () { | ||
if $verbose; then | ||
echo "$@" | ||
fi | ||
exec "$@" | ||
} | ||
|
||
if stat --format %i / >/dev/null 2>&1; then | ||
statformatarg="--format" | ||
else | ||
statformatarg="-f" | ||
fi | ||
myfileid=`stat $statformatarg %d:%i "${BASH_SOURCE[0]}" 2>/dev/null` | ||
|
||
dir="`pwd`" | ||
subdir="" | ||
while test "$dir" != / -a "$dir" != ""; do | ||
thisfileid=`stat $statformatarg %d:%i "$dir"/cs61-run-docker 2>/dev/null` | ||
if test -n "$thisfileid" -a "$thisfileid" = "$myfileid"; then | ||
maindir="$dir" | ||
break | ||
fi | ||
subdir="/`basename "$dir"`$subdir" | ||
dir="`dirname "$dir"`" | ||
done | ||
|
||
if test -z "$maindir" && expr "${BASH_SOURCE[0]}" : / >/dev/null 2>&1; then | ||
maindir="`dirname "${BASH_SOURCE[0]}"`" | ||
subdir="" | ||
fi | ||
|
||
ssharg= | ||
sshenvarg= | ||
if test -n "$SSH_AUTH_SOCK" -a "`uname`" = Darwin; then | ||
ssharg=" --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock" | ||
sshenvarg=" -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock" | ||
fi | ||
|
||
if test -n "$maindir" -a -z "$fresh"; then | ||
existing_image="`docker ps -f status=running -f ancestor=$tag -f volume=/host_mnt"$maindir" --no-trunc --format "{{.CreatedAt}},{{.ID}}" | sort -r | head -n 1`" | ||
if test -n "$existing_image"; then | ||
created_at="`echo $existing_image | sed 's/,.*//'`" | ||
image="`echo $existing_image | sed 's/^.*,//'`" | ||
image12="`echo $image | head -c 12`" | ||
echo "* Using running container $image12, created $created_at" 1>&2 | ||
echo "- To start a new container, exit then \`cs61-run-docker -f\`" 1>&2 | ||
echo "- To kill this container, exit then \`docker kill $image12\`" 1>&2 | ||
vexec docker exec -it$sshenvarg $image /bin/bash | ||
fi | ||
fi | ||
|
||
netarg= | ||
if test `uname` = Darwin; then | ||
if ! netstat -n -a -p tcp | grep '\.6169[ ].*LISTEN' >/dev/null; then | ||
netarg="$netarg "'--expose=6169/tcp -p 6169:6169/tcp' | ||
fi | ||
if ! netstat -n -a -p tcp | grep '\.12949[ ].*LISTEN' >/dev/null; then | ||
netarg="$netarg "'--expose=12949/tcp -p 12949:12949/tcp' | ||
fi | ||
elif test -x /bin/netstat; then | ||
if ! netstat -n -a -p tcp | grep '\.6169[ ].*LISTEN' >/dev/null; then | ||
netarg="$netarg "'--expose=6169/tcp -p 6169:6169/tcp' | ||
fi | ||
if ! netstat -n -l -t | grep ':12949[ ]' >/dev/null; then | ||
netarg="$netarg "'--expose=12949/tcp -p 12949:12949/tcp' | ||
fi | ||
fi | ||
|
||
if test -n "$maindir"; then | ||
vexec docker run -it --platform $platform --rm --privileged --cap-add=SYS_PTRACE --cap-add=NET_ADMIN --security-opt seccomp=unconfined -v "$maindir":/home/cs61-user/$destdir$ssharg -w "/home/cs61-user/$destdir$subdir" $netarg$sshenvarg $tag | ||
else | ||
vexec docker run -it --platform $platform --rm --privileged --cap-add=SYS_PTRACE --cap-add=NET_ADMIN --security-opt seccomp=unconfined $netarg$sshenvarg $tag | ||
fi |
Oops, something went wrong.