summary refs log tree commit diff stats
path: root/compiler/nimpaths.nim
blob: 7b2216080be98801d369d769a72a4abc8ee73bb3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
##[
Represents absolute paths, but using a symbolic variables (eg $nimr) which can be
resolved at runtime; this avoids hardcoding at compile time absolute paths so
that the project root can be relocated.

xxx consider some refactoring with $nim/testament/lib/stdtest/specialpaths.nim;
specialpaths is simpler because it doesn't need variables to be relocatable at
runtime (eg for use in testament)

interpolation variables:
  $nimr: such that `$nimr/lib/system.nim` exists (avoids confusion with $nim binary)
         in compiler, it's obtainable via getPrefixDir(); for other tools (eg koch),
        this could be getCurrentDir() or getAppFilename().parentDir.parentDir,
        depending on use case

Unstable API
]##

import std/[os,strutils]

const
  docCss* = "$nimr/doc/nimdoc.css"
  docHackNim* = "$nimr/tools/dochack/dochack.nim"
  docHackJs* = docHackNim.changeFileExt("js")
  docHackJsFname* = docHackJs.lastPathPart
  theindexFname* = "theindex.html"
  nimdocOutCss* = "nimdoc.out.css"
    # `out` to make it easier to use with gitignore in user's repos
  htmldocsDirname* = "htmldocs"
  dotdotMangle* = "_._"  ## refs #13223
    # if this changes, make sure it's consistent with `esc` and `escapeLink`
    # lots of other obvious options won't work, see #14454; `_` could work too

proc interp*(path: string, nimr: string): string =
  result = path % ["nimr", nimr]
  doAssert '$' notin result, $(path, nimr, result) # avoids un-interpolated variables in output

proc getDocHacksJs*(nimr: string, nim = getCurrentCompilerExe(), forceRebuild = false): string =
  ## return absolute path to dochack.js, rebuilding if it doesn't exist or if
  ## `forceRebuild`.
  let docHackJs2 = docHackJs.interp(nimr = nimr)
  if forceRebuild or not docHackJs2.fileExists:
    let cmd =  "$nim js -d:release $file" % ["nim", nim.quoteShell, "file", docHackNim.interp(nimr = nimr).quoteShell]
    echo "getDocHacksJs: cmd: " & cmd
    doAssert execShellCmd(cmd) == 0, $(cmd)
  doAssert docHackJs2.fileExists
  result = docHackJs2
#nntiv[For example, in finding the modulus and phase angle (amplitude or argument) of a complex number.] + Write a Python program to take two numbers from the user and show their the sum, product, difference and the GCD. + Write a Python program to demonstrate the use of _regular expressions_ using `re.split`, `re.join`, `re.search` and `re.match` methods from `re` module. + Write a program to take two floating point numbers as input from the user. Concatenate the integral parts of the two numbers and display them, also display the sum of the input floating point numbers rounded upto 2 decimal places. + Write a program to divide two numbers and check if the digits at one’s place of the quotient and remainder are equal. = Decision Control Statements + Write a Python program to calculate the sum a list of number of (i) even length and then (ii) any length, using `while` loop: at each step, add $k$th number from the start and end of the list and display it, for $k$ from $0$ to half the length the list. #nntiv[For example: if the list is `[1, 2, 3, 4, 5, 6]`, the program should output `1 + 6`, `2 + 5`, and `3 + 4` in separate lines, and the result of the addition `21`.] + Write a Python program to sperate prime numbers from a given list of numbers and store them in another list. + Write a Python program to demonstrate keyword argument `key` of `sum()`, `min()`, `max()`, and `sort()` functions using `lambda`s. + Write a Python program to design the following random number guessing game. A random number from 1 to 10 (inclusive) is selected as a secret number, then the user is prompted to guess the number. If the user’s guess matches the secret number, the game ends with an appropriate message, otherwise the user is asked to try again. After 3 unsuccessful guesses, the user loses and the game ends with an appropriate message revealing the secret number. At the end of the game, ask the user whether to play again. (Use the `random` module to obtain the secret number.) + Write a Python program to generate the calendar of a month given the start day (`1` for Sunday, `2` for Monday, ... `7` is Saturday) and the number of days in the month. #nntiv[An example:] #[ #show raw: block.with(inset: 0pt, fill: white, width: 20em, outset: 0pt) #show: it => align(center, it) ```text Enter the starting day: 5 Enter the number of days in the month: 30 Calender for this month: SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ```] + Write a Python program to take input from user as a string and count the lowercase characters, uppercase characters and digits in it. + #table( columns: (1fr, 4em), stroke: none, inset: 0pt, gutter: 0pt, column-gutter: 5pt, [Write a Python program to print the following star pattern of the given size. \ #nntiv[Example (with size 4):]], [ #set par(leading: 0em) #set block(inset: 0pt, width: 4em, outset: 0pt) ```text **** * * * * **** ``` ]) = Strings + Write a Python program to ask the user for two strings, print a new string where the first string is reversed, and the second string is converted to upper case, only using string slicing and `+` operator. #nntiv[Sample strings: `Pets`, `party`, output: `steP PARTY`.] + Write a Python program to from a list of words, join all the words in the odd and even indices to form two strings using list slicing and `join` method. #nntiv[Example: for a list `['abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']`, the result are: `'abcghimnotuv'` and `'defjklpqrswxyz'`.] + #text(fill: red, sym.convolve) Write a Python program to input your name in a string, separate the first name and last name using the slice operator with negative indexing, and display your name in reverse using a formatted string. + Write a Python program to implement a function that works like `str.count()` method. + Write a Python program to take input a string and display it after removing all the vowels. + Write a Python program that take a plain text string and generate cyphertext by using $k$th next character with wrap around for each character for a given constant key value $k$. #nntiv[Also known as _Caesar Cipher_. \ Example: for key $k = 23$, the message `"The quick brown fox jumps over the lazy dog."` encrypts to `"Qeb nrfzh yoltk clu grjmp lsbo qeb ixwv ald."`.] + Write a Python program to sperate the username and domain name of an email address. #{ /* + Write a Python program to separate the `local-part` and `domain` of an email address given as per RFC 5322 format for `addr-spec` (§3.4.1): ```text addr-spec = local-part "@" domain local-part = dot-atom / quoted-string / obs-local-part domain = dot-atom / domain-literal / obs-domain dtext = %d33-90 / ; Printable US-ASCII %d94-126 / ; characters not including obs-dtext ; "[", "]", or "\" FWS = ([*WSP CRLF] 1*WSP) / obs-FW ; Folding white space ctext = %d33-39 / ; Printable US-ASCII %d42-91 / ; characters not including %d93-126 / ; "(", ")", or "\" obs-ctext ccontent = ctext / quoted-pair / comment comment = "(" *([FWS] ccontent) [FWS] ")" CFWS = (1*([FWS] comment) [FWS]) / FWS atext = ALPHA / DIGIT / ; Printable US-ASCII "!" / "#" / ; characters not including "$" / "%" / ; specials. Used for atoms. "&" / "'" / "*" / "+" / "-" / "/" / "=" / "?" / "^" / "_" / "`" / "{" / "|" / "}" / "~" atom = [CFWS] 1*atext [CFWS] dot-atom-text = 1*atext *("." 1*atext) dot-atom = [CFWS] dot-atom-text [CFWS] qtext = %d33 / ; Printable US-ASCII %d35-91 / ; characters not including %d93-126 / ; "\" or the quote character obs-qtext quoted-pair = ("\" (VCHAR / WSP)) / obs-qp obs-qp = "\" (%d0 / obs-NO-WS-CTL / LF / CR) qcontent = qtext / quoted-pair quoted-string = [CFWS] DQUOTE *([FWS] qcontent) [FWS] DQUOTE [CFWS] word = atom / quoted-string obs-local-part = word *("." word) obs-domain = atom *("." atom) obs-dtext = obs-NO-WS-CTL / quoted-pair obs-NO-WS-CTL = %d1-8 / ; US-ASCII control %d11 / ; characters that do not %d12 / ; include the carriage %d14-31 / ; return, line feed, and %d127 ; white space characters ``` */} = Lists + Write a Python program to simulate a stack and a queue using lists. #nntiv[Note that the queue deletion operation won’t run in $O(1)$ time.] + Write a Python program to find all the odd numbers and numbers divisible by 3 from a list of numbers using list comprehension. + Write a Python program to find the second largest number in a list of numbers. + Write a Python program to generate a list of numbers `items` using list comprehension as per the following description: $ "items"[ i ] = cases( i^2 quad "if " i "is even", i^3 quad "if " i "is odd", ) $ where $i$ denotes the index of the list. + Write a Python program to use the `map()` method to square each number in a list. + Write a Python program to remove all duplicate items in a list. = Tuples + Write a Python program that, given sequences of first and last names, generate a tuple of tuples each of which contains the full name of a person, using the `zip()` function. + Write a Python program to create and modify tuples in various ways. + Write a Python program to take a nested tuple with the name, Roll No. and marks of some students and find the name of the student having highest marks. + Write a Python program to take a list of numbers (both positive and negative) and make a new tuple out from this list with only the positive values. + Write a Python program to demonstrate the definition and use of a function taking variable length arguments (scatter and gather) using the `*` symbol. = Sets + Write a Python program to remove duplicate items of a list of numbers and duplicate characters in a string using sets. + Write a Python program to implement the Jaccard and cosine similarity of two sets using the set union and intersection operations. + Write a Python program to show the difference between `set.remove()` and `set.discard()` methods. + Write a Python program that creates two sets of even numbers in the range 1 to 10 and composite numbers in the range 1 to 20 to demonstrate the use of `all()`, `issuperset()`, `len()`, `sum()` methods on the sets. + Write a Python program that generates a set of prime numbers and another set of odd numbers. Demonstrate the result of union, intersection, difference, symmetric difference operations on these sets. + Write a Python program that creates two sets: squares and cubes in the range 1 to 10 to demonstrate the use of `update()`, `pop()`, `remove()`, `add()` and `clear()` methods. + Write a Python program to demonstrate the use of frozensets. = Dictionaries + Write a Python program to count the word and letter occurrences in a long string of text using dictionaries. + Write a Python program to invert a dictionary such the previous keys become values and values become keys. #nntiv[For example: if the initial and inverted dictionaries are `d1` and `d2`, where `d1 = {1: 'a', 2: 'b', 3: 120}`, then `d2 = {'a': 1, 2: 'b', 120: 3}`.] + What if the values in 2 are not immutable? Use frozensets, For repeated values, use lists. For example: if `d1 = {1: 'a', 2: 'a', 4: [1, 2]}`, then `d2 = {'a': [1, 2], frozenset([1, 2]): 4}`. + Write a Python program with a function to generate the Fibonacci numbers in + Exponential time using the naïve algorithm. + Linear time using dynamic programming (memoization) with a dictionary. + Write a Python program to generate a dictionary where each key is a number and the corresponding value is the number’s square using dictionary comprehensions. + Write a Python program to store a sparse matrix as a dictionary. + Write a Python program that combines lists of keys and values into a dictionary. = User-Defined Functions + Write a Python program to implement quick sort and merge sort algorithms to sort lists of numbers. + Write a Python program that displays the Pascal’s triangle of a given size. + Three positive integers $a$, $b$, and $c$ are Pythagorean triples if $a^2 + b^2 = c^2$. Write a Python program with a function to generate all Pythagorean triples in a certain range. + Write two functions that simulate the toss of a fair coin, and the roll of an unbiased $n$ sided die using the `random` module. + Modify the previous assignment. Now the coin and the die are not fair, with each outcome having a given probability. = File Handling; `sys`, `pickle` and `csv` modules + Basic file operations. Explore the different file modes. + Emulate the unix `cp`, `grep`, `cat` programs in Python. In each case, the user should pass the arguments to the program as command line arguments. + Use pickle for persistent storage of variables. = Object Oriented Programming + Create a `Graph` class to store and manipulate graphs. It should have the following functions: + Read an edge list file, where each edge `(u, v)` appears exactly once in the file as space separated values. + Add and remove nodes and edges. + Print nodes, and edges in a user readable format. + Computes basic statistics of the graph like degree distribution, clustering coefficient, and the number of connected components. + Finding all the neighbors of a node. + Finding all the connected components and storing them as individual Graph objects inside the class. + Finding single source shortest paths using Breadth First Search. + Make a `DiGraph` class to handle directed graphs which inherits from the `Graph` class. In addition to all of the functionalities of 1, it should support the following operations + Finding the predecessors and successors of a node. + Creating a new `DiGraph` object where all the edges are reversed. + Finding the strongly connected components. + Extend 1 and 2 to handle weighted graphs, and implement Dijkstra’s and Floyd-Warshall algorithms to compute the single source and all pairs shortest paths. + Use the graph containers in 1, 2, and 3 to implement additional graph algorithms. span>span id="L6" class="LineNr"> 6 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;syscall&quot;</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L7" class="LineNr"> 7 </span> <span class="Normal">uint8_t</span> code = <a href='010vm.cc.html#L338'>next</a><span class="Delimiter">();</span> <span id="L8" class="LineNr"> 8 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>code != <span class="Constant">0x80</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L9" class="LineNr"> 9 </span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;Unimplemented interrupt code &quot;</span> &lt;&lt; <a href='010vm.cc.html#L407'>HEXBYTE</a> &lt;&lt; code &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L10" class="LineNr"> 10 </span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot; Only `int 80h` supported for now.\n&quot;</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L11" class="LineNr"> 11 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L12" class="LineNr"> 12 </span> <span class="Delimiter">}</span> <span id="L13" class="LineNr"> 13 </span> <a href='020syscalls.cc.html#L18'>process_int80</a><span class="Delimiter">();</span> <span id="L14" class="LineNr"> 14 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L15" class="LineNr"> 15 </span><span class="Delimiter">}</span> <span id="L16" class="LineNr"> 16 </span> <span id="L17" class="LineNr"> 17 </span><span class="Delimiter">:(code)</span> <span id="L18" class="LineNr"> 18 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L18'>process_int80</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> <span id="L19" class="LineNr"> 19 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L20" class="LineNr"> 20 </span> <span class="Normal">case</span> <span class="Constant">1</span>: <span id="L21" class="LineNr"> 21 </span> exit<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">exit code</span><span class="Comment">*/</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L22" class="LineNr"> 22 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L23" class="LineNr"> 23 </span> <span class="Normal">case</span> <span class="Constant">3</span>: <span id="L24" class="LineNr"> 24 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;read: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">' '</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">' '</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L25" class="LineNr"> 25 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = read<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L26" class="LineNr"> 26 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i &lt;&lt; end<span class="Delimiter">();</span> <span id="L27" class="LineNr"> 27 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;read: &quot;</span> &lt;&lt; strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L28" class="LineNr"> 28 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L29" class="LineNr"> 29 </span> <span class="Normal">case</span> <span class="Constant">4</span>: <span id="L30" class="LineNr"> 30 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;write: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">' '</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">' '</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L31" class="LineNr"> 31 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; <a href='010vm.cc.html#L237'>mem_addr_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L32" class="LineNr"> 32 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = write<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010vm.cc.html#L192'>mem_addr_u8</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L33" class="LineNr"> 33 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i &lt;&lt; end<span class="Delimiter">();</span> <span id="L34" class="LineNr"> 34 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;write: &quot;</span> &lt;&lt; strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L35" class="LineNr"> 35 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L36" class="LineNr"> 36 </span> <span class="Normal">case</span> <span class="Constant">5</span>: <span class="Delimiter">{</span> <span id="L37" class="LineNr"> 37 </span> <a href='020syscalls.cc.html#L92'>check_flags</a><span class="Delimiter">(</span><a href='010vm.cc.html#L11'>ECX</a><span class="Delimiter">);</span> <span id="L38" class="LineNr"> 38 </span> <a href='020syscalls.cc.html#L104'>check_mode</a><span class="Delimiter">(</span><a href='010vm.cc.html#L12'>EDX</a><span class="Delimiter">);</span> <span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;open: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">' '</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L40" class="LineNr"> 40 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L41" class="LineNr"> 41 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = open<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">flags</span><span class="Comment">*/</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> <span id="L42" class="LineNr"> 42 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i &lt;&lt; end<span class="Delimiter">();</span> <span id="L43" class="LineNr"> 43 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;open: &quot;</span> &lt;&lt; strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L44" class="LineNr"> 44 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L45" class="LineNr"> 45 </span> <span class="Delimiter">}</span> <span id="L46" class="LineNr"> 46 </span> <span class="Normal">case</span> <span class="Constant">6</span>: <span id="L47" class="LineNr"> 47 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;close: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L48" class="LineNr"> 48 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = close<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i &lt;&lt; end<span class="Delimiter">();</span> <span id="L50" class="LineNr"> 50 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;close: &quot;</span> &lt;&lt; strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L51" class="LineNr"> 51 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L52" class="LineNr"> 52 </span> <span class="Normal">case</span> <span class="Constant">8</span>: <span id="L53" class="LineNr"> 53 </span> <a href='020syscalls.cc.html#L104'>check_mode</a><span class="Delimiter">(</span><a href='010vm.cc.html#L11'>ECX</a><span class="Delimiter">);</span> <span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;creat: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L56" class="LineNr"> 56 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = creat<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> <span id="L57" class="LineNr"> 57 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i &lt;&lt; end<span class="Delimiter">();</span> <span id="L58" class="LineNr"> 58 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;creat: &quot;</span> &lt;&lt; strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L59" class="LineNr"> 59 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L60" class="LineNr"> 60 </span> <span class="Normal">case</span> <span class="Constant">10</span>: <span id="L61" class="LineNr"> 61 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;unlink: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L62" class="LineNr"> 62 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L63" class="LineNr"> 63 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = unlink<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> <span id="L64" class="LineNr"> 64 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i &lt;&lt; end<span class="Delimiter">();</span> <span id="L65" class="LineNr"> 65 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;unlink: &quot;</span> &lt;&lt; strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L66" class="LineNr"> 66 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L67" class="LineNr"> 67 </span> <span class="Normal">case</span> <span class="Constant">38</span>: <span id="L68" class="LineNr"> 68 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;rename: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">&quot; -&gt; &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L69" class="LineNr"> 69 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L70" class="LineNr"> 70 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u &lt;&lt; <span class="Constant">&quot; =&gt; &quot;</span> &lt;&lt; <a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L71" class="LineNr"> 71 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = rename<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">old filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">new filename</span><span class="Comment">*/</span><a href='010vm.cc.html#L234'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> <span id="L72" class="LineNr"> 72 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i &lt;&lt; end<span class="Delimiter">();</span> <span id="L73" class="LineNr"> 73 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;rename: &quot;</span> &lt;&lt; strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L74" class="LineNr"> 74 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L75" class="LineNr"> 75 </span> <span class="Normal">case</span> <span class="Constant">90</span>: <span class="Comment">// mmap: allocate memory outside existing segment allocations</span> <span id="L76" class="LineNr"> 76 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;mmap: allocate new segment&quot;</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L77" class="LineNr"> 77 </span> <span class="Comment">// Ignore most arguments for now: address hint, protection flags, sharing flags, fd, offset.</span> <span id="L78" class="LineNr"> 78 </span> <span class="Comment">// We only support anonymous maps.</span> <span id="L79" class="LineNr"> 79 </span> <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u = <a href='020syscalls.cc.html#L116'>new_segment</a><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">length</span><span class="Comment">*/</span><a href='010vm.cc.html#L181'>read_mem_u32</a><span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u+<span class="Constant">0x4</span><span class="Delimiter">));</span> <span id="L80" class="LineNr"> 80 </span> <a href='003trace.cc.html#L96'>trace</a><span class="Delimiter">(</span><span class="SpecialChar">Callstack_depth</span>+<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;result: &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u &lt;&lt; end<span class="Delimiter">();</span> <span id="L81" class="LineNr"> 81 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L82" class="LineNr"> 82 </span> <span class="Normal">case</span> <span class="Constant">0xa2</span>: <span class="Comment">// nanosleep</span> <span id="L83" class="LineNr"> 83 </span> cerr &lt;&lt; <span class="Constant">&quot;not sleeping\n&quot;</span><span class="Delimiter">;</span> <span id="L84" class="LineNr"> 84 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L85" class="LineNr"> 85 </span> <span class="Normal">default</span>: <span id="L86" class="LineNr"> 86 </span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <a href='010vm.cc.html#L408'>HEXWORD</a> &lt;&lt; <a href='010vm.cc.html#L26'>EIP</a> &lt;&lt; <span class="Constant">&quot;: unimplemented syscall &quot;</span> &lt;&lt; <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span> <span id="L87" class="LineNr"> 87 </span> <span class="Delimiter">}</span> <span id="L88" class="LineNr"> 88 </span><span class="Delimiter">}</span> <span id="L89" class="LineNr"> 89 </span> <span id="L90" class="LineNr"> 90 </span><span class="Comment">// SubX is oblivious to file permissions, directories, symbolic links, terminals, and much else besides.</span> <span id="L91" class="LineNr"> 91 </span><span class="Comment">// Also ignoring any concurrency considerations for now.</span> <span id="L92" class="LineNr"> 92 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L92'>check_flags</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L93" class="LineNr"> 93 </span> <span class="Normal">uint32_t</span> flags = <span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> <span id="L94" class="LineNr"> 94 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>flags != <span class="Delimiter">((</span>flags &amp; O_RDONLY<span class="Delimiter">)</span> | <span class="Delimiter">(</span>flags &amp; O_WRONLY<span class="Delimiter">)))</span> <span class="Delimiter">{</span> <span id="L95" class="LineNr"> 95 </span> cerr &lt;&lt; <a href='010vm.cc.html#L408'>HEXWORD</a> &lt;&lt; <a href='010vm.cc.html#L26'>EIP</a> &lt;&lt; <span class="Constant">&quot;: most POSIX flags to the open() syscall are not supported. Just O_RDONLY and O_WRONLY for now. Zero concurrent access support.\n&quot;</span><span class="Delimiter">;</span> <span id="L96" class="LineNr"> 96 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L97" class="LineNr"> 97 </span> <span class="Delimiter">}</span> <span id="L98" class="LineNr"> 98 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>flags &amp; O_RDONLY<span class="Delimiter">)</span> &amp;&amp; <span class="Delimiter">(</span>flags &amp; O_WRONLY<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L99" class="LineNr"> 99 </span> cerr &lt;&lt; <a href='010vm.cc.html#L408'>HEXWORD</a> &lt;&lt; <a href='010vm.cc.html#L26'>EIP</a> &lt;&lt; <span class="Constant">&quot;: can't open a file for both reading and writing at once. See <a href="http://man7.org/linux/man-pages/man2/open.2.html">http://man7.org/linux/man-pages/man2/open.2.html</a>.\n&quot;</span><span class="Delimiter">;</span> <span id="L100" class="LineNr">100 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L101" class="LineNr">101 </span> <span class="Delimiter">}</span> <span id="L102" class="LineNr">102 </span><span class="Delimiter">}</span> <span id="L103" class="LineNr">103 </span> <span id="L104" class="LineNr">104 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L104'>check_mode</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010vm.cc.html#L20'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L105" class="LineNr">105 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="SpecialChar"><a href='010vm.cc.html#L25'>Reg</a></span>[reg]<span class="Delimiter">.</span>u != <span class="PreProc">0</span><span class="Constant">600</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L106" class="LineNr">106 </span> cerr &lt;&lt; <a href='010vm.cc.html#L408'>HEXWORD</a> &lt;&lt; <a href='010vm.cc.html#L26'>EIP</a> &lt;&lt; <span class="Constant">&quot;: SubX is oblivious to file permissions; register &quot;</span> &lt;&lt; <a href='010vm.cc.html#L20'>reg</a> &lt;&lt; <span class="Constant">&quot; must be 0x180.\n&quot;</span><span class="Delimiter">;</span> <span id="L107" class="LineNr">107 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L108" class="LineNr">108 </span> <span class="Delimiter">}</span> <span id="L109" class="LineNr">109 </span><span class="Delimiter">}</span> <span id="L110" class="LineNr">110 </span> <span id="L111" class="LineNr">111 </span><span class="Delimiter">:(before &quot;End Globals&quot;)</span> <span id="L112" class="LineNr">112 </span><span class="Comment">// Very primitive/fixed/insecure mmap segments for now.</span> <span id="L113" class="LineNr">113 </span><span class="Normal">uint32_t</span> <span class="SpecialChar"><a href='020syscalls.cc.html#L113'>Segments_allocated_above</a></span> = <a href='012elf.cc.html#L151'>END_HEAP</a><span class="Delimiter">;</span> <span id="L114" class="LineNr">114 </span><span class="Delimiter">:(code)</span> <span id="L115" class="LineNr">115 </span><span class="Comment">// always allocate multiples of the segment size</span> <span id="L116" class="LineNr">116 </span><span class="Normal">uint32_t</span> <a href='020syscalls.cc.html#L116'>new_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> length<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L117" class="LineNr">117 </span> assert<span class="Delimiter">(</span>length &gt; <span class="Constant">0</span><span class="Delimiter">);</span> <span id="L118" class="LineNr">118 </span> <span class="Normal">uint32_t</span> result = <span class="Delimiter">(</span><span class="SpecialChar"><a href='020syscalls.cc.html#L113'>Segments_allocated_above</a></span> - length<span class="Delimiter">)</span> &amp; <span class="Constant">0xff000000</span><span class="Delimiter">;</span> <span class="Comment">// same number of zeroes as SEGMENT_ALIGNMENT</span> <span id="L119" class="LineNr">119 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result &lt;= <a href='012elf.cc.html#L150'>START_HEAP</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L120" class="LineNr">120 </span> <a href='003trace.cc.html#L226'>raise</a> &lt;&lt; <span class="Constant">&quot;Allocated too many segments; the VM ran out of memory. &quot;</span> <span id="L121" class="LineNr">121 </span> &lt;&lt; <span class="Constant">&quot;Maybe <a href='010vm.cc.html#L98'>SEGMENT_ALIGNMENT</a> can be smaller?\n&quot;</span> &lt;&lt; <a href='003trace.cc.html#L173'>die</a><span class="Delimiter">();</span> <span id="L122" class="LineNr">122 </span> <span class="Delimiter">}</span> <span id="L123" class="LineNr">123 </span> <span class="SpecialChar"><a href='010vm.cc.html#L163'>Mem</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>result<span class="Delimiter">,</span> result+length<span class="Delimiter">));</span> <span id="L124" class="LineNr">124 </span> <span class="SpecialChar"><a href='020syscalls.cc.html#L113'>Segments_allocated_above</a></span> = result<span class="Delimiter">;</span> <span id="L125" class="LineNr">125 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span id="L126" class="LineNr">126 </span><span class="Delimiter">}</span> </pre> </body> </html> <!-- vim: set foldmethod=manual : -->