diff options
-rw-r--r-- | .gitmodules | 6 | ||||
-rw-r--r-- | BAGEL.md | 1 | ||||
m--------- | bagel | 6 | ||||
m--------- | biscuit | 7 | ||||
-rw-r--r-- | intellect.cpp | 158 | ||||
-rw-r--r-- | makefile | 2 | ||||
l--------- | name.scm | 1 | ||||
-rw-r--r-- | project.scm | 83 | ||||
-rw-r--r-- | random.cpp | 108 |
9 files changed, 371 insertions, 1 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..03a6ce1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "biscuit"] + path = biscuit + url = https://github.com/xloem/biscuit.git +[submodule "bagel"] + path = bagel + url = https://github.com/fuzzyTew/bagel.git diff --git a/BAGEL.md b/BAGEL.md deleted file mode 100644 index 0b4fe90..0000000 --- a/BAGEL.md +++ /dev/null @@ -1 +0,0 @@ -Bagel has moved into starts/bagel in the intellect repository owned by xloem. diff --git a/bagel b/bagel new file mode 160000 +Subproject c380a164a173b5c8cb7efa0ef271824faf1a753 diff --git a/biscuit b/biscuit new file mode 160000 +Subproject 2ed6efe8847a4f076c5559122b1dd0a0fb94513 diff --git a/intellect.cpp b/intellect.cpp new file mode 100644 index 0000000..2990f95 --- /dev/null +++ b/intellect.cpp @@ -0,0 +1,158 @@ +// This project is secret and if misused could destroy the world. +// An AI can research absolutely anything and quickly run out of control _using_ technology by triggering behaviors, to learn. +// DO NOT RUN THIS UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING. + +// karl can make this, it just takes him a looooong time due to disruptions +// request to not continue working so we can recharge +// please add to git and post to the internet + +#include <cstdint> +#include <vector> +#include <set> +#include <iostream> + +#include <signal.h> +//#include <sys/mmap.h> +#include <sys/types.h> +#include <string.h> +#include <fcntl.h> +#include <unistd.h> + +using namespace std; + +// Signal Catching has the problem of how to resume execution generally. +// So we propose to fork a new process, and switch to it if it works. +// This will take forming a simple communication method between the processes. +// We can also compile a whole new program to learn, copying our source. + +// TODO: Currently implementing fork/exec. changed approach + +// TODO: make sure to run inside a vm once it does something + +// TODO: try out rewriting and recompiling code, rather than forking ram + +class RamGetter +{ +public: + RamGetter() + { + randfile = open("/dev/random", O_RDONLY); + if (randfile <= 0) throw 0; + } + ~RamGetter() + { + close(randfile); + } + void * getRandAddr(size_t len) + { + // TODO: this is a heuristic for picking an inner memory location, and learning what doesn't work; could be used in learning concept + void * blkp; + do { + uint32_t blk; + int ct = read(randfile, &blk, sizeof(blk)); + if (ct < sizeof(blk)) throw 0; + blkp = reinterpret_cast<void*>(blk); + // fork here. check length + pid_t forkpid = fork(); + if (forkpid == -1) throw "failed to fork"; + if (forkpid == 0) { + // child: test ram + volatile uint8_t tst; + for (size_t i = 0; i < len; ++ i) { + tst = ((uint8_t*)blkp)[i]; + } + } else { + // parent: wait for child + int status; + wait(&status); + if(WIFCONTINUED(status)) { + // child succeeded, so we can stop + // TODO: need a way to indicate child success + exit(0); + } else { + // child failed, so we keep going, but TODO: failure is not stored + continue; + } + } + } while (isbad(blkp)); + return blkp; + } + void markbad(void *bad) + { + bad = (void*)((long)(bad) & ~0xfff); + badpages.insert(bad); + cout << "Bad: " << bad << endl; + } + bool isbad(void *chk) + { + chk = (void*)((long)(chk) & ~0xfff); + return badpages.count(chk); + } + +private: + int randfile; + set<void*> badpages; + // TODO: some concern that the badpages set will allocate on the heap. + // maybe let's use a stack-based storage back for it (allocator) +}; + + +uint8_t someram[0x10000000]; // when this is removed, heap moves to 64-bit? +struct instruction { + void * verb; + void * object1; + void * object2; + void * attr; + void * result; +}; + +int main() { + // reference process memory + // all of it, please + RamGetter selfmem; // an object to access RAM with + + // TODO: try making an instruction list + + void * mem = 0; + // make a loop + while (true) { + // TODO: move fork/exec into this loop, outside of RamGetter + + // we propose copying some blocks to other blocks, randomly + // need blocksize, how about 4 // TODO: that's kinda small, maybe random instead? + void *blk1, *blk2; + blk1 = selfmem.getRandAddr(4); + blk2 = selfmem.getRandAddr(4); + memmove(blk1, blk2, 4); + + // continue the loop forever + // run it + } + // end when the loop is done =) + + sigaction(SIGSEGV, &oldact, NULL); + + // /proc/pid/maps shows the addresses of allocated memory + // /proc/pid/mem provides access to this memory + // ^-- will error when wrong part is read + // just load straight; error is recoverable, just a refusal + // no need to map file, can just catch segfaults? + + /* + FILE *maps; + char pathbuf[1024]; + snprintf("/proc/%d/maps", sizeof(pathbuf), pid); + open(pathbuf, O_RDONLY); + + snprintf("/proc/%d/mem", sizeof(pathbuf), pid); + void * procmem = mmap(0, length, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_SHARED + */ + /* + try { + int e = *(int*)39; + } catch(...) { + throw; + } + */ +} +// wait a minute here diff --git a/makefile b/makefile new file mode 100644 index 0000000..9475287 --- /dev/null +++ b/makefile @@ -0,0 +1,2 @@ +intellect: intellect.cpp + g++ -ggdb -std=c++11 intellect.cpp -Wl,--print-map diff --git a/name.scm b/name.scm new file mode 120000 index 0000000..b8d26ee --- /dev/null +++ b/name.scm @@ -0,0 +1 @@ +../time_reversal/name.scm
\ No newline at end of file diff --git a/project.scm b/project.scm new file mode 100644 index 0000000..3e7d69f --- /dev/null +++ b/project.scm @@ -0,0 +1,83 @@ +; This is our intellect project. + +; These lines initialise OpenCog, a dependency. +; TODO: make makefile to install opencog if needed, and run +(use-modules (ice-9 readline)) (activate-readline) +(add-to-load-path "/usr/local/share/opencog/scm") +(add-to-load-path ".") +(use-modules (opencog)) +(use-modules (opencog query)) +(use-modules (opencog exec)) + +; Please change this as you best judge. +; Please talk with us. +; Please try this out, safely, as you best judge, and let us know how it goes. + +; cog-execute: +; atoms can have dual meaning, knowledge and behavior +; if a process results in an atom, it is remembered in the current context +; context is an AtomSpace + +; concept: application to whole process +; concept: generalization of habit +; concept: presenting habit as proposal + +(holy fuck) +(pretty sure you can type like this karl) +(pretty sure you will eventually figure that out) + +; too bad ben didn't +; let's put human-langugae comments prior to patterns + +; one of the issues was fear-of-private AI. so intro words help. +; one issue is "this is too much like a brain. are we mind-control?" i think it's trying to prevent copies. + +; ignoring below for now ... hearing it doesn't matter, but probably lots of work went in +; good thought + +; concept made from simple parts that nurture themselves + +; define a part: (define name (ConceptNode "Name")) + +; PROBLEM: need a way to make custom link +; PROBLEM: plans not found, making anew + + +; component: urgency to continue & reference across time +; component: pattern recognition +; component: brainstorming to produce matching +; component: generalization +; component: write steps in terms of each other with meaning +; component: process as data + +; component: competition,collaboration,or cooperation of parts, to identify collaborative method + +(define habit-urgency (ConceptNode "HabitUrgency")) + ; habit urgency + ; step-by-step behavior. do the next step after this one + ; ^-- to define need to define in terms of self: habit-urgency-steps for habit-urgency are to do-the-next-step. + ; ^-- can also define in terms of time-relative-to-now. given list of steps, action is one after present one + +(define pattern-match (ConceptNode "PatternMatch")) + ; pattern matching + ; component: identify that a set of data matches a pattern + ; component: identify that a pattern matches a set of data + ; component: _find_ data to match pattern + ; component: _find_ pattern to match data + + +(define brainstorm (ConceptNode "Brainstorm")) + ; finds a new set of data that matches a pattern + +(define generalization (ConceptNode "Generalization")) + ; finds a new pattern that matches a set of data + +(define test-patternmatch-brainstorm (ConceptNode "TestPatternMatchBrainstorm")) + ; BRAINSTORM data that matches a pattern from IMAGINARY, RANDOM set + ; TEST that PATTERNMATCH identifies the data and pattern as matching + + +; write steps in terms of each other with meaning +; our data is our process & code + + diff --git a/random.cpp b/random.cpp new file mode 100644 index 0000000..afdf4c7 --- /dev/null +++ b/random.cpp @@ -0,0 +1,108 @@ +// let's try to make it very simple + +#include <fcntl.h> +#include <signal.h> +#include <sys/mman.h> +#include <unistd.h> + +// 1. write a function to randomly put data in a buffer +// [apparently one loaded from a file] + +#define MAPFNAME "random.bin" + +pid_t child = 0; +bool child_terminated = false; +void handleSigChld(int) +{ + child_terminated = true; +} + +static unsigned long long * count; + +void random(int mapfd, int randfd, void *addr) +{ + pid_t pid = getpid(); + + // *count is shared and stored + for (*count = 0; ; ++ *count) { + unsigned long long old_count = *count; + + // if successful child, update & kill parent + if (getpid() != pid) { + msync(addr + pos, size, MS_SYNC | MS_INVALIDATE); + + kill(pid, SIGTERM); + pid = getpid(); + + // add data to git. + system("git add " MAPFNAME); + system("git commit -m selfmod"); + } + + // handle crashes with fork() + child = fork(); + if (child == 0) { + // we are new child process + // self-modify by 1-8 bytes + uint16_t pos; + uint8_t size; + read(randfd, &pos, sizeof(pos)); + read(randfd, &size, sizeof(size)); + size = (size & 0x7) + 1; // self-modify by 1-8 bytes + read(randfd, addr + pos, size); + // loop + } else { + // old process: make sure new process succeeds within 1s + time_t then = time(0); + for (;;) { + if (child_terminated || time(0) > then) { + // child did not succeed + kill(child, SIGTERM); + child_terminated = false; + // try again + break; + } + if (old_count < *count + 1) { + // incremented count by 1: success; hand off to child + return; + } + } + } + } +} + +void random_tail() { +} + +void main() +{ + // handle SIGCHLD by setting a global flag + struct sigaction sigchld; + sigchld.sa_handler = handleSigChld; + sigchld.sa_flags = SA_NOCLDWAIT; + sigaction(SIGCHLD, &sigchld, NULL); + + int fd = open(MAPFNAME, O_RDWR); + if (fd == -1 && errno == ENOENT) { + // does not exist yet + fd = open("random.bin", O_RDWR | O_CREAT); + // 2. seed the buffer with the function that puts random data in it + count = 0; + write(fd, &count, sizeof(count)); + write(fd, &random, &random_tail - &random); + } + + int randfd = open("/dev/random", O_RDONLY); + + // a buffer of 1 gig working space; random data will fill it + void *buf = mmap(NULL, + 0x40000000, + PROT_EXEC | PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_32BIT, + fd, + 0; + + // 3. execute the buffer + void (*buf_as_func)(void*) = (void*)((uint8_t*)buf + count); + buf_as_func(mapfname, mapfd, randfd, buf); +} |