about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--dev/c/basic.html4
-rw-r--r--dev/c/datatypes.html6
-rw-r--r--dev/c/debugging.html47
-rw-r--r--dev/c/elements.html6
-rw-r--r--dev/c/hello.html4
-rw-r--r--dev/c/index.html6
-rw-r--r--dev/c/lib.html6
-rw-r--r--dev/c/system.html6
8 files changed, 62 insertions, 23 deletions
diff --git a/dev/c/basic.html b/dev/c/basic.html
index 104e59a..a2009fc 100644
--- a/dev/c/basic.html
+++ b/dev/c/basic.html
@@ -5,7 +5,7 @@
 	<title>C - Basic</title>
     </head>
     <body>
-        <a href="../index.html">C &amp; GDB Index</a>
+        <a href="index.html">C Index</a>
 
 	<h1>C - Basic</h1>
 
@@ -48,7 +48,7 @@
 	$ gcc -Wall main.c hello.c -o hello
 	</pre>
 
-	<a href="../index.html">C &amp; GDB Index</a>
+	<a href="index.html">C Index</a>
 	<p>
 	This is part of the Hive System Documentation.
 	Copyright (C) 2019
diff --git a/dev/c/datatypes.html b/dev/c/datatypes.html
index 77b5dbb..a5e1efd 100644
--- a/dev/c/datatypes.html
+++ b/dev/c/datatypes.html
@@ -5,7 +5,7 @@
         <title>Datatypes</title>
     </head>
     <body>
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C index</a>
 
         <h1>Datatypes</h1>
 
@@ -172,9 +172,9 @@
             <dd>Pointer address</dd>
         </dl>
 
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C Index</a>
         <p>This is part of the Hive System Documentation.
-        Copyright (C) 2018
+        Copyright (C) 2019
         Hive Team.
         See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
         for copying conditions.</p>
diff --git a/dev/c/debugging.html b/dev/c/debugging.html
index c68fbc1..90dca1b 100644
--- a/dev/c/debugging.html
+++ b/dev/c/debugging.html
@@ -5,10 +5,43 @@
         <title>Debugging</title>
     </head>
     <body>
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C Index</a>
 
         <h1>Debugging</h1>
 
+        <p>Check if the system have restrictions to attach to other processes or other hardening measures, check <a href=../../core/sysctl.html>sysctl settings</a> such as; kernel.yama.ptrace_scope;</p>
+
+	<dl>
+            <dt>kernel.yama.ptrace_scope=0</dt>
+            <dd>All processes can be debugged, they must have same uid.</dd>
+            <dt>kernel.yama.ptrace_scope=1</dt>
+            <dd>Only a parent process can be debugged.</dd>
+
+            <dt>kernel.yama.ptrace_scope=2</dt>
+            <dd>Require user privileges to use ptrace  CAP_SYS_PTRACE capability.</dd>
+
+            <dt>kernel.yama.ptrace_scope=3</dt>
+            <dd>No processes may be traced with ptrace.</dd>
+
+        </dl>
+
+        <p>Before debug;</p>
+
+        <pre>
+        # echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
+        # sysctl -w kernel.yama.ptrace_scope=0
+
+        </pre>
+
+        <p>After debug;</p>
+
+        <pre>
+        # echo 1 | sudo tee /proc/sys/kernel/yama/ptrace_scope
+        # sysctl -w kernel.yama.ptrace_scope=1
+        </pre>
+
+        <h2 id="gdb">GDB</h2>
+
         <p>If the program needs arguments you can set it;</p>
 
         <pre>
@@ -74,8 +107,14 @@
         break linespec thread threadno
         </pre>
 
+        <h2 id="strace">Strace</h2>
+
+        <pre>
+        $ strace -c ./program -o ~/program.strace
+        </pre>
+
         <pre>
-        strace -c ./program
+        $ strace -p 1337 -o ~/program.strace
         </pre>
 
 
@@ -87,11 +126,11 @@
         <a href="http://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_39.html#SEC40">Stopping and Starting</a>
         multi-thread programs</p>
 
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C Index</a>
 
         <p>
         This is part of the Hive System Documentation.
-        Copyright (C) 2018
+        Copyright (C) 2019
         Hive Team.
         See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
         for copying conditions.</p>
diff --git a/dev/c/elements.html b/dev/c/elements.html
index 9e31adb..49871db 100644
--- a/dev/c/elements.html
+++ b/dev/c/elements.html
@@ -5,7 +5,7 @@
         <title>Elements</title>
     </head>
     <body>
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C Index</a>
 
         <h1>Elements</h1>
 
@@ -51,11 +51,11 @@
 
         <p>White space is ignored except when separating elements.</p>
 
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C Index</a>
 
         <p>
         This is part of the Hive System Documentation.
-        Copyright (C) 2018
+        Copyright (C) 2019
         Hive Team.
         See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
         for copying conditions.</p>
diff --git a/dev/c/hello.html b/dev/c/hello.html
index ff31bc9..14c65e9 100644
--- a/dev/c/hello.html
+++ b/dev/c/hello.html
@@ -5,7 +5,7 @@
 	<title>C &amp; GDB</title>
     </head>
     <body>
-        <a href="../index.html">C &amp; GDB Index</a>
+        <a href="index.html">C Index</a>
 
 	<h1>Hello World</h1>
 
@@ -123,7 +123,7 @@
 	(gdb) n
 	</pre>
 
-        <a href="../index.html">C &amp; GDB Index</a>
+        <a href="index.html">C Index</a>
 	<p>
 	This is part of the Hive System Documentation.
 	Copyright (C) 2019
diff --git a/dev/c/index.html b/dev/c/index.html
index 3c48776..0e54a13 100644
--- a/dev/c/index.html
+++ b/dev/c/index.html
@@ -70,8 +70,8 @@
 
 
 	    </li>
-	    <li><a href="c/debugging.html">Debugging</a></li>
-	    <li><a href="c/system.html">System Development</a></li>
+	    <li><a href="debugging.html">Debugging</a></li>
+	    <li><a href="system.html">System Development</a></li>
 	</ul>
 
 	<ul>
@@ -233,7 +233,7 @@
 	<a href="../index.html">Development Index</a>
 	<p>
 	This is part of the Hive System Documentation.
-	Copyright (C) 2018
+	Copyright (C) 2019
 	Hive Team.
 	See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
 	for copying conditions.</p>
diff --git a/dev/c/lib.html b/dev/c/lib.html
index 4531d7a..5e3f1f7 100644
--- a/dev/c/lib.html
+++ b/dev/c/lib.html
@@ -5,7 +5,7 @@
         <title>Libraries</title>
     </head>
     <body>
-        <a href="../index.html">C &amp; GDB Index</a>
+        <a href="index.html">C Index</a>
 
 
         <h1>Libraries</h1>
@@ -243,11 +243,11 @@
         void pthread_exit(void *value_ptr);
         </pre>
 
-        <a href="../index.html">C &amp; GDB Index</a>
+        <a href="index.html">C Index</a>
 
         <p>
         This is part of the Hive System Documentation.
-        Copyright (C) 2018
+        Copyright (C) 2019
         Hive Team.
         See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
         for copying conditions.</p>
diff --git a/dev/c/system.html b/dev/c/system.html
index 5312151..d2a7d1f 100644
--- a/dev/c/system.html
+++ b/dev/c/system.html
@@ -5,7 +5,7 @@
         <title>System Development &amp; GDB</title>
     </head>
     <body>
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C Index</a>
 
         <h1>System Development</h1>
 
@@ -169,10 +169,10 @@
 	(gdb)
 	</pre>
 
-        <a href="../index.html">Development Index</a>
+        <a href="index.html">C Index</a>
         <p>
         This is part of the Hive System Documentation.
-        Copyright (C) 2018
+        Copyright (C) 2019
         Hive Team.
         See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
         for copying conditions.</p>
lass="w"> if z[0] == 254: pResult = (((uint64)x) shl 24) + (z[5].uint64 shl 16) + (z[6].uint64 shl 8) + z[7].uint64 return 8 pResult = (((uint64)x) shl 32) + (0xffffffff'u64 and ((z[5].uint64 shl 24) + (z[6].uint64 shl 16) + (z[7].uint64 shl 8) + z[8].uint64)) return 9 proc varintWrite32(z: var openArray[byte]; y: uint32) = z[0] = uint8(y shr 24) z[1] = uint8(y shr 16) z[2] = uint8(y shr 8) z[3] = uint8(y) proc writeVu64*(z: var openArray[byte], x: uint64): int = ## Write a varint into z. The buffer z must be at least 9 characters ## long to accommodate the largest possible varint. Returns the number of ## bytes used. if x <= 240: z[0] = uint8 x return 1 if x <= 2287: let y = uint32(x - 240) z[0] = uint8(y shr 8 + 241) z[1] = uint8(y and 255) return 2 if x <= 67823: let y = uint32(x - 2288) z[0] = 249 z[1] = uint8(y shr 8) z[2] = uint8(y and 255) return 3 let y = uint32 x let w = uint32(x shr 32) if w == 0: if y <= 16777215: z[0] = 250 z[1] = uint8(y shr 16) z[2] = uint8(y shr 8) z[3] = uint8(y) return 4 z[0] = 251 varintWrite32(toOpenArray(z, 1, z.high-1), y) return 5 if w <= 255: z[0] = 252 z[1] = uint8 w varintWrite32(toOpenArray(z, 2, z.high-2), y) return 6 if w <= 65535: z[0] = 253 z[1] = uint8(w shr 8) z[2] = uint8 w varintWrite32(toOpenArray(z, 3, z.high-3), y) return 7 if w <= 16777215: z[0] = 254 z[1] = uint8(w shr 16) z[2] = uint8(w shr 8) z[3] = uint8 w varintWrite32(toOpenArray(z, 4, z.high-4), y) return 8 z[0] = 255 varintWrite32(toOpenArray(z, 1, z.high-1), w) varintWrite32(toOpenArray(z, 5, z.high-5), y) return 9 proc sar(a, b: int64): int64 = {.emit: [result, " = ", a, " >> ", b, ";"].} proc sal(a, b: int64): int64 = {.emit: [result, " = ", a, " << ", b, ";"].} proc encodeZigzag*(x: int64): uint64 {.inline.} = uint64(sal(x, 1)) xor uint64(sar(x, 63)) proc decodeZigzag*(x: uint64): int64 {.inline.} = let casted = cast[int64](x) result = (`shr`(casted, 1)) xor (-(casted and 1)) when isMainModule: #import random var dest: array[50, byte] var got: uint64 for test in [0xFFFF_FFFF_FFFFF_FFFFu64, 77u64, 0u64, 10_000_000u64, uint64(high(int64)), uint64(high(int32)),uint64(low(int32)),uint64(low(int64))]: let wrLen = writeVu64(dest, test) let rdLen = readVu64(dest, got) assert wrLen == rdLen echo(if got == test: "YES" else: "NO") echo "number is ", got if encodeZigzag(decodeZigzag(test)) != test: echo "Failure for ", test, " ", encodeZigzag(decodeZigzag(test)), " ", decodeZigzag(test) for test in 0u64..300u64: let wrLen = writeVu64(dest, test) let rdLen = readVu64(dest, got) assert wrLen == rdLen if got != test: echo "BUG! expected: ", test, " got: ", got, " z0: ", dest[0] # check this also works for floats: for test in [0.0, 0.1, 2.0, +Inf, Nan, NegInf]: let t = cast[uint64](test) let wrLenB = writeVu64(dest, t) let rdLenB = readVu64(dest, got) assert wrLenB == rdLenB echo rdLenB echo(if cast[float64](got) == test: "YES" else: "NO")