void scanf(char* str, void* buf) { char temp_buf[100]; __syscall1(11, (uint64_t)temp_buf); if(strcmp1(str, "%s") == 0) { buf = (char *)buf; // printf("----- %c", temp_buf[0]); // printf("in"); //buf = temp_buf; int i = 0; while(temp_buf[i] != '\0') *(char *)buf++ = temp_buf[i++]; *(char *)buf = '\0'; // printf("%d", i); } else if(strcmp1(str, "%d") == 0) { *(int *)buf = stoi(temp_buf); } else if(strcmp1(str, "%x") == 0) { //buf = temp_buf; } }
void child() { char* argv[] = { "server", 0 }; int pid = __syscall0(__NR_fork); if (pid == 0) { __syscall3(__NR_execve, (long) "./sslserver", (long) argv, (long) envp); myerror("exec"); __syscall1(__NR_exit, 1); } else if (pid < 0) { errno = -pid; myerror("fork"); __syscall1(__NR_exit, 1); } }
void execve(char *filename) { // __syscall3(SYSCALL_EXECVE,(uint64_t)filename, (uint64_t)argv, (uint64_t)envp); __syscall1(SYSCALL_EXECVE, (uint64_t) filename); }
void STARTFUNC () { struct sysreq r; int fd; long n, s; uint64_t id[] = IDENT; __syscall1(__NR_close, 3); acceptloop: fd = __syscall3(__NR_accept, 0, 0, 0); if (fd < 0) { myerror("accept"); __syscall1(__NR_exit, 1); } if (fd != 3) { __syscall2(__NR_dup2, fd, 3); __syscall1(__NR_close, fd); fd = 3; } __syscall3 (__NR_write, fd, (long) id, sizeof(id)); while (__syscall3(__NR_read, fd, (long) &r, sizeof(r)) > 0) { // fprintf (stderr, "(%x, %x, %x, %x, %x, %x, %x);\n", r.snr, r.sa, r.sb, r.sc, r.sd, r.se, r.sf); if (r.snr == 0 && r.sa == fd) { for (s = 0; r.sc && (n = __syscall3(__NR_read, fd, r.sb, r.sc)) > 0; s += n) { r.sb += n; r.sc -= n; } __syscall3(__NR_write, fd, (long) &s, sizeof(s)); } else if (r.snr == 1 && r.sa == fd) { for (s = 0; r.sc && (n = __syscall3(__NR_write, fd, r.sb, r.sc)) > 0; s += n) { r.sb += n; r.sc -= n; } __syscall3(__NR_write, fd, (long) &s, sizeof(s)); } else { r.sa = __syscall6(r.snr, r.sa, r.sb, r.sc, r.sd, r.se, r.sf); __syscall3(__NR_write, fd, (long) &r.sa, sizeof(r.sa)); } } goto acceptloop; }
/** * malloc does a system call to allocate memory on the user heap * * @param size of the block of memory allocated * @param uint32_t size > 0 * @return returns a pointer to the allocated block of memory returns 0 if size is less than 1 */ void* malloc(uint32_t size) { if (size <= 0) { return 0; } //size will be passed into R0 for the syscall. long retval = __syscall1(SYSCALL_MALLOC,(long) size); //returns a pointer to begginning of allocated block(s) return (void*)retval; }
/** * free does a system call to free an allocated block of memory on the heap * * @param pointer to a block of memeory on the heap, does nothing if pointer is null * @param void* ptr * @return nothing returned */ void free(void* ptr) { //if null pointer, do nothing if (ptr == 0) { return 0; } //pointer of allocated block passed into R0 long retval = __syscall1(SYSCALL_FREE,(long)ptr); //nothing returned }
int close(int fd) { int * file_desc = (int *)0xfffffe0000000000; file_desc[0] = fd; __syscall1(7,(uint64_t)file_desc[0]); return ((int)file_desc[0]); }
void exit(int status) { __syscall1(EXIT, status); }
/* allocate virtual memory */ void* sys_virtmem_alloc(ulong size) { return (void*)__syscall1(SYSCALL_VIRTMEM_ALLOC, (ulong)size); }
void hw_disable_irq (int irq) { long __res; __syscall1 (irq, hw_disable_irq_nr, __res); }
void hw_restore_flags (int flags) { long __res; __syscall1 (flags, hw_restore_flags_nr, __res); }
void do_exit(uint32_t status) { __syscall1(SYS_EXIT, status); }
#include <stdio.h> #include <stdarg.h> #include "../arch/arm/syscall_arch.h" int printf(const char *restrict fmt, ...) { //int ret; //va_list ap; //va_start(ap, fmt); //ret = vfprintf(stdout, fmt, ap); //va_end(ap); //return ret; long error = __syscall1(SYSCALL_PRINTF, (long)fmt); return error; }
/* delete semaphore */ status_t sys_sem_delete(sem_id id) { return __syscall1(SYSCALL_SEM_DELETE, (ulong)id); }
/* terminate current thread */ void sys_thread_exit(int exitcode) { __syscall1(SYSCALL_THREAD_EXIT, (ulong)exitcode); }
/* put thread into temporary sleep */ void sys_thread_sleep(unsigned msec) { __syscall1(SYSCALL_THREAD_SLEEP, (ulong)msec); }
/* resume thread */ status_t sys_thread_resume(thread_id tid) { return __syscall1(SYSCALL_THREAD_RESUME, (ulong)tid); }
/* suspend thread */ status_t sys_thread_suspend(thread_id tid) { return __syscall1(SYSCALL_THREAD_SUSPEND, (ulong)tid); }
/* free virtual memory */ status_t sys_virtmem_free(void *ptr) { return __syscall1(SYSCALL_VIRTMEM_FREE, (ulong)ptr); }
int64_t wait(){ /* Will wait for a child to wakeup itself */ uint64_t pid = get_pid(); return __syscall1(WAITPID, pid); }
uint64_t closedir(char* name) { return __syscall1(CLOSEDIR,(uint64_t)name); }
void xm_exit_domain (int status) { int res; __syscall1(status, exit_domain_nr, res); }
int nanosleep(int sec) { return __syscall1(SLEEP, sec); }
int64_t wait_pid(uint64_t pid){ return __syscall1(WAITPID, pid); }
void hw_save_flags_and_cli (int *flags) { long __res; __syscall1 (flags, hw_save_flags_and_cli_nr, __res); }
void* sbrk(intptr_t incr) { return (void*)__syscall1(SYS_SBRK, (uint32_t)incr); }
void hw_end_irq (int irq) { long __res; __syscall1 (irq, hw_end_irq_nr, __res); }
pid_t wait(int* status) { return __syscall1(WAIT, (uint64_t)status); }
void xm_pass_event (int event) { int res; __syscall1(event, pass_event_nr, res); }
int brk(void* addr) { return (int)__syscall1(SYS_BRK, (uint32_t)addr); }