Skip to content

Commit

Permalink
feat: constants and sigaction() method
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jan 9, 2018
1 parent 3cbfc42 commit 06b2606
Show file tree
Hide file tree
Showing 22 changed files with 581 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.associations": {
"__config": "cpp",
"__nullptr": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"new": "cpp",
"stdexcept": "cpp",
"typeinfo": "cpp"
}
}
62 changes: 62 additions & 0 deletions c++/darwin/SA.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// g++ ./c++/darwin/SA.cc -o ./build/SA && ./build/SA
#include <iostream>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/time.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/dir.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <signal.h>


using namespace std;

int main() {
std::cout << "const SA = {" << endl;
std::cout << " NOCLDSTOP: " << SA_NOCLDSTOP << "," << endl;
std::cout << "};" << endl;
std::cout << endl;
std::cout << "export default SA;" << endl;

return 0;
}

99 changes: 99 additions & 0 deletions c++/darwin/SIG.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// g++ ./c++/darwin/SIG.cc -o ./build/SIG && ./build/SIG
#include <iostream>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/time.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/dir.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <signal.h>

using namespace std;

typedef void (*callback)(int);

int main() {

std::cout << "const SIG = {" << endl;
std::cout << " HUP: " << SIGHUP << ", /* hangup */" << endl;
std::cout << " INT: " << SIGINT << ", /* interrupt */" << endl;
std::cout << " ILL: " << SIGILL << ", /* illegal instruction (not reset when caught) */" << endl;
std::cout << " TRAP: " << SIGTRAP << ", /* trace trap (not reset when caught) */" << endl;
std::cout << " ABRT: " << SIGABRT << ", /* abort() */" << endl;
std::cout << " IOT: " << SIGIOT << ", /* compatibility */" << endl;
std::cout << " EMT: " << SIGEMT << ", /* EMT instruction */" << endl;
std::cout << " FPE: " << SIGFPE << ", /* floating point exception */" << endl;
std::cout << " KILL: " << SIGKILL << ", /* kill (cannot be caught or ignored) */" << endl;
std::cout << " BUS: " << SIGBUS << ", /* bus error */" << endl;
std::cout << " SEGV: " << SIGSEGV << ", /* segmentation violation */" << endl;
std::cout << " SYS: " << SIGSYS << ", /* bad argument to system call */" << endl;
std::cout << " PIPE: " << SIGPIPE << ", /* write on a pipe with no one to read it */" << endl;
std::cout << " ALRM: " << SIGALRM << ", /* alarm clock */" << endl;
std::cout << " TERM: " << SIGTERM << ", /* software termination signal from kill */" << endl;
std::cout << " URG: " << SIGURG << ", /* urgent condition on IO channel */" << endl;
std::cout << " STOP: " << SIGSTOP << ", /* sendable stop signal not from tty */" << endl;
std::cout << " TSTP: " << SIGTSTP << ", /* stop signal from tty */" << endl;
std::cout << " CONT: " << SIGCONT << ", /* continue a stopped process */" << endl;
std::cout << " CHLD: " << SIGCHLD << ", /* to parent on child stop or exit */" << endl;
std::cout << " TTIN: " << SIGTTIN << ", /* to readers pgrp upon background tty read */" << endl;
std::cout << " TTOU: " << SIGTTOU << ", /* like TTIN for output if (tp->t_local&LTOSTOP) */" << endl;
std::cout << " IO: " << SIGIO << ", /* input/output possible signal */" << endl;
std::cout << " XCPU: " << SIGXCPU << ", /* exceeded CPU time limit */" << endl;
std::cout << " XFSZ: " << SIGXFSZ << ", /* exceeded file size limit */" << endl;
std::cout << " VTALRM: " << SIGVTALRM << ", /* virtual time alarm */" << endl;
std::cout << " PROF: " << SIGPROF << ", /* profiling time alarm */" << endl;
std::cout << " WINCH: " << SIGWINCH << ", /* window size changes */" << endl;
std::cout << " INFO: " << SIGINFO << ", /* information request */" << endl;
std::cout << " USR1: " << SIGUSR1 << ", /* user defined signal 1 */" << endl;
std::cout << " USR2: " << SIGUSR2 << ", /* user defined signal 2 */" << endl;

std::cout << " DFL: " << SIG_DFL << "," << endl;
std::cout << " IGN: " << SIG_IGN << "," << endl;
std::cout << " HOLD: " << SIG_HOLD << "," << endl;
std::cout << " ERR: " << SIG_ERR << "," << endl;

std::cout << "};" << endl;
std::cout << endl;
std::cout << "export default SIG;" << endl;

return 0;
}
79 changes: 79 additions & 0 deletions c++/darwin/sigaction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// g++ ./c++/darwin/sigaction.cc -o ./build/sigaction && ./build/sigaction
#include <iostream>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/time.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/dir.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <signal.h>

using namespace std;

typedef void (*callback)(int);

int main() {

struct sigaction sa;
int offset = 0;
int size = 0;

std::cout << "const sigaction = Struct.define(" << sizeof(sa) << ", [" << endl;

size = sizeof(sa.sa_handler);
std::cout << " [" << offset << ", " << "uintXX" << ", " << "'handler'], // " << size << endl;

offset += size;

size = sizeof(sa.sa_mask);
std::cout << " [" << offset << ", " << "uintXX" << ", " << "'mask'], // " << size << endl;

offset += size;

size = sizeof(sa.sa_flags);
std::cout << " [" << offset << ", " << "uintXX" << ", " << "'flags'], // " << size << endl;

std::cout << "]);" << endl << endl;
std::cout << "export default sigaction;\n" << endl;

return 0;
}
69 changes: 69 additions & 0 deletions c++/error.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// g++ ./c++/error.cc -o ./build/error && ./build/error
#include <iostream>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/time.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/dir.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>

using namespace std;


int main() {
long SYS_WRITE = 0x2000004;
long STDOUT = 1;

long result;
char* str = "Hello world";

__asm__ __volatile__ (
"syscall;\n"
: "=a" (result)
: "a" (SYS_WRITE), "D" (STDOUT), "S" (str), "d" (10)
:
);

std::cout << result << endl;

return 0;
}
60 changes: 60 additions & 0 deletions c++/jump.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// g++ ./c++/jump.cc -o ./build/jump
#include <iostream>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/time.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/dir.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>

using namespace std;

typedef long (*callback)();

int main() {

long addr = 0xBABE;

((callback) addr)();

return 0;
}
Loading

0 comments on commit 06b2606

Please sign in to comment.