Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Machine-code/PARI-GP/machine-code.parigp
Normal file
29
Task/Machine-code/PARI-GP/machine-code.parigp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <pari/pari.h>
|
||||
|
||||
int
|
||||
test(int a, int b)
|
||||
{
|
||||
char code[] = {0x8B, 0x44, 0x24, 0x4, 0x3, 0x44, 0x24, 0x8, 0xC3};
|
||||
void *buf;
|
||||
int c;
|
||||
/* copy code to executable buffer */
|
||||
buf = mmap (0,sizeof(code),PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||
MAP_PRIVATE|MAP_ANON,-1,0);
|
||||
|
||||
memcpy (buf, code, sizeof(code));
|
||||
/* run code */
|
||||
c = ((int (*) (int, int))buf)(a, b);
|
||||
/* free buffer */
|
||||
munmap (buf, sizeof(code));
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
init_auto(void)
|
||||
{
|
||||
pari_printf("%d\n", test(7,12));
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue