omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / modules / tests / caller.c
| 1 | /* Independent test oracle, not a production dependency. */ |
| 2 | #include <stdint.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <sys/mman.h> |
| 6 | #include <sys/stat.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <unistd.h> |
| 9 | extern uint64_t invoke(void*,void*,void*,uint64_t,uint64_t,uint64_t); |
| 10 | extern void trap_entry(void); |
| 11 | int main(int argc,char **argv) { |
| 12 | if(argc!=3)return 90; |
| 13 | int fd=open(argv[1],O_RDONLY); struct stat st; |
| 14 | if(fd<0||fstat(fd,&st))return 91; |
| 15 | void *code=mmap(0,st.st_size,PROT_READ|PROT_EXEC,MAP_PRIVATE,fd,0); |
| 16 | void *stack=mmap(0,8*1024*1024,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); |
| 17 | if(code==MAP_FAILED||stack==MAP_FAILED)return 92; |
| 18 | uint64_t context[32]={0};context[2]=(uintptr_t)trap_entry; |
| 19 | uint64_t data[4]={3,5,7,11}; |
| 20 | uint64_t arg=strtoull(argv[2],0,10); |
| 21 | uint64_t r=invoke(code,(char*)stack+8*1024*1024,context,arg==999?(uintptr_t)data:arg,4,0); |
| 22 | printf("%llu\n",(unsigned long long)r);return 0; |
| 23 | } |