Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
23
Task/Machine-code/Pluto/machine-code-1.pluto
Normal file
23
Task/Machine-code/Pluto/machine-code-1.pluto
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* mclib.c */
|
||||
|
||||
// gcc -c -fpic mclib.c
|
||||
// gcc -shared -o mclib.so mclib.o
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
||||
extern uchar run_machine_code(const char *code, uchar a, uchar b, int len) {
|
||||
void *buf;
|
||||
uchar c;
|
||||
/* copy code to executable buffer */
|
||||
buf = mmap (0, len, PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
memcpy (buf, code, len);
|
||||
/* run code */
|
||||
c = ((uchar (*) (uchar, uchar))buf)(a, b);
|
||||
/* free buffer */
|
||||
munmap (buf, len);
|
||||
return c;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue