% // vim: set ft=tex:
\chapter{Summary}
Solved problems by the Rust ownership models are 
The Rust ownership model solves
\begin{itemize}
    \item use-after-free
    \item indexing out of bounds
    \item iterator invalidation
    \item data races
\end{itemize}

\chapter{Conclusions}
Safety - or security for this matter - is not something that can be achieved absolutely.
It grows successively and gives the \gls{os} developers and the end-users a \emph{feeling} of safety, until another vulnerability is found and disclosed.

\section{Trust In Hardware}
Memory management mechanisms are partially implemented in the target system's hardware which can't be verified by at time of development.

\subsection{The Necessary Evils of \textit{unsafe}}
TODO

\section{Rust Is Extendable For Memory-Safe OS Development}

* Macros help to prevent critical mistakes when defining interrupt handlers.

-

TODO

\section{Thesis Evaluation}

% TODO: repeat that rust *can* be used to increase safety in the OS,
% TODO: how?
% but it doesn't guarantee it per-se

\section{Rust's Strong Community}

\section{Next Steps}
TODO
\chapter{Scratchpad}

\begin{figure}[ht!]
\centering
\begin{subfigure}[T]{0.50\textwidth}
    \tikzmarkcountprep{callee}
    \begin{compactminted}[
            escapeinside=??,linenos,autogobble,highlightlines={}
    ]{nasm}
    mov    rax,QWORD PTR [rbp-0x48]?\tikzmarkcount?
    add    rsp,0x50?\tikzmarkcount?             
    pop    rbp?\tikzmarkcount?
    ret?\tikzmarkcount?
    \end{compactminted} 
    \tikzmarkdrawcircles
\caption{Subfig A}
\end{subfigure}
\begin{subfigure}[T]{0.45\textwidth}
    \foreach \x/\xtext in {
        1/{
            this is going to be a really long sentence with line wraps 
        },
        2/{
            second
        }
    } {\tikzmarkcircle{\x}\xtext\\}
\caption{Subfig B}
\end{subfigure}
\caption{Whadup}
\label{Whadup}
\end{figure}

\begin{listing}
    \tikzmarkcountprep{example1}
    \begin{minted}[
            label=example1,labelposition=all,escapeinside=??,linenos,autogobble,highlightlines={}
    ]{nasm}
    mov    rax,QWORD PTR [rbp-0x48]?\tikzmarkcount?  ?\tikzmark{brace1upper}?
    add    rsp,0x50?\tikzmarkcount?             
    pop    rbp?\tikzmarkcount?
    ret?\tikzmarkcount?                              ?\tikzmark{brace1lower}?
    \end{minted} 
    \begin{minted}[
            escapeinside=??,linenos,autogobble,highlightlines={}
    ]{nasm}
    mov    rax,QWORD PTR [rbp-0x48]?\tikzmarkcount?
    add    rsp,0x50                ?\tikzmarkcount?
    pop    rbp                     ?\tikzmarkcount?
    ret                            ?\tikzmarkcount?
    \end{minted} 
    \begin{tikzpicture}[remember picture,overlay]
        \draw[thick,decorate,decoration={brace,raise=1ex}] 
            (pic cs:brace1upper)+(0,1.5ex) -- node[shape=coordinate][right=1.5ex] (a) {} (pic cs:brace1lower);
        \fill (a)+(2ex,0) circle[opacity=1,radius=1.1ex] node[white,font=\small]{a};
    \end{tikzpicture}
    \tikzmarkdrawcircles
    \caption{Minted Listing A}
%
    \foreach \x/\xtext in {
        1/{
            this is going to be a really long sentence with line wraps 
        \\}
        ,2/{
            second
        \\} 
        ,5/{},6/{
            hi
        \\}
        ,a/{
            hi
        \\}
    } {\tikzmarkcircle{\x}\xtext}
%
\end{listing}
\FloatBarrier

\begin{listing}
    \tikzset{/minted/basename=example}
    \begin{minted}[label=caller,labelposition=topline,escapeinside=??,highlightlines={},autogobble,linenos,breaklines=true]{nasm}
    mov    rcx,QWORD PTR [rbp-0x40] ; copy 1st arg to rcx
    mov    rsi,QWORD PTR [rbp-0x38] ; copy 2nd arg to rsi
    mov    rdx,QWORD PTR [rbp-0x30] ; copy 3rd arg to rdx
    mov    QWORD PTR [rbp-0x60],rdi ; save rdi to make it available
    mov    rdi,rcx                  ; copy 1st arg to rdi
    mov    QWORD PTR [rbp-0x68],rax ; save rax to make it available
    call   7490?\tikzmark{exampleprecallfrom}? <_ZN14stack_handling3sum17h8f12d2383e075691E> ; push '756e' onto the stack and jump to the first instruction of sum
    mov    QWORD PTR [rbp-0x28],rax ; save return value
    \end{minted}
    \caption{Function Call with Three Arguments}
    \begin{tikzpicture}[remember picture,overlay]
        \draw[red,thick] (pic cs:exampleprecallfrom) ellipse (0.7cm and 12pt) node { \textbf{1} };
        \fill[blue] (pic cs:example1) circle (0.1cm);
        \fill[yellow] (pic cs:example2) circle (0.1cm);
    \end{tikzpicture}
\end{listing}

\begin{tikzpicture}[node distance=2cm,
        startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
        io/.style = {trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
        process/.style = {rectangle, minimum width=1cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30},
        decision/.style = {diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
        arrow/.style = {thick,->,>=stealth} 
    ]

%\node (start) [startstop] {Start};
%\node (in1) [io, below of=start] {Input};
%\node (pro1) [process, below of=in1] {Process 1};
%\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1};
%\node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a text text text text text text text text text text};
%\node (pro2b) [process, right of=dec1, xshift=2cm] {Process 2b};
%\node (out1) [io, below of=pro2a] {Output};
%\node (stop) [startstop, below of=out1] {Stop};
%
%\draw [arrow] (start) -- (in1);
%\draw [arrow] (in1) -- (pro1);
%\draw [arrow] (pro1) -- (dec1);
%\draw [arrow] (dec1) -- node[anchor=east] {yes} (pro2a);
%\draw [arrow] (dec1) -- node[anchor=south] {no} (pro2b);
%\draw [arrow] (pro2b) |- (pro1);
%\draw [arrow] (pro2a) -- (out1);
%\draw [arrow] (out1) -- (stop);

\node[process,xshift=0ex,yshift=-0ex] (ua_back) {User Applications};
\node[process,xshift=0ex,yshift=-1ex] at (ua_back) {User Applications};
\node[process,xshift=0ex,yshift=-2ex] (ua) at (ua_back) {User Applications};

\node[process,xshift=0ex,yshift=-0ex,below of=ua] (sl_back) {System Libraries};
\node[process,xshift=0ex,yshift=-1ex] at (sl_back) {System Libraries};
\node[process,xshift=0ex,yshift=-2ex] (sl) at (sl_back) {System Libraries};

\node[process,xshift=0ex,yshift=-0ex,below of=sl] (os_back) {OS};
\node[process,xshift=0ex,yshift=-1ex] at (os_back) {OS API};
\node[process,xshift=0ex,yshift=-2ex] (os) at (os_back) {OS};

\node[process,xshift=0ex,yshift=-0ex,left of=mem, below of=os] (cpu) {CPU};
\node[process,xshift=0ex,yshift=-0ex,right of=cpu] (mem) {Memory};
\node[process,xshift=0ex,yshift=-0ex,right of=mem] (otherhw) {Other HW};

\draw [arrow] (ua) -- (sl);
\draw [arrow] (sl) -- (os);
\draw [arrow] (os) -- (cpu);
\draw [arrow] (os) -- (mem);
\draw [arrow] (os) -- (otherhw);

TODO: improve

\end{tikzpicture}

\begin{markdown}
# Flow of Reasoning
* How to mitigate distributed weaknesses
    - Don't distribute vulnerable software
    - Produce less vulnerabilities
    OR
    - Detect vulnerabilities
* How to prevent vulnerabilities distribution?
    - Human to make less mistakes; NOT VIABLE, see human aspect.
    - Detect them before the \gls{app} is installed; see time aspect
* How to detect vulnerabilities
    - Write runtime tests for the program
    - Analyze the source code
* Runtime Tests
    - Runs on every execution, thus wastes \gls{cpu} resources
    - Program needs to handle it
    -> Slow and too late in the software life cycle!
* Source Code Analysis
    - Difficult for low-level code, would require hardware knowledge
    - Compilers are source code analysers by nature
    - Additional tools can help, but this takes more effort
    -> chose a compiler with high analysis standards
* Choice of Compiler: Language Dependent
    - C: Safe C, Cyclone, etc.: define sub language that is analyzable. MEH
    - Rust: designed to be analyzable. WIN!
* Rust
    - Can the analyzes be extended to suite OS dev? 
\end{markdown}
