Exemple #1
0
/* Send signal SIG to process number PID.  If PID is zero,
   send SIG to all processes in the current process's process group.
   If PID is < -1, send SIG to all processes in process group - PID.
   If SIG is SIGKILL, kill the process. */
int __kill (int pid, int sig)
{
	struct event_msg local_msg = {0};
	if (pid <= 0) {
		errno = ENOSYS;
		return -1;
	}
	if (sig == SIGKILL)
		return ros_syscall(SYS_proc_destroy, pid, 0, 0, 0, 0, 0);
	local_msg.ev_type = EV_POSIX_SIGNAL;
	local_msg.ev_arg1 = sig;
	return ros_syscall(SYS_notify, pid, EV_POSIX_SIGNAL, &local_msg, 0, 0, 0);
}
Exemple #2
0
/* Yield the processor.  */
int
__sched_yield (void)
{
  /* TRUE tells the kernel we simply want to let someone else process, and not
   * that we are waiting on an event. */
  return ros_syscall(SYS_yield, TRUE, 0, 0, 0, 0, 0);
}
Exemple #3
0
/* Seek to OFFSET on FD, starting from WHENCE.  */
off64_t
__libc_lseek64 (int fd, off64_t offset, int whence)
{
	off64_t retoff = 0;
	off_t hi = 0;
	off_t lo = 0;
	int ret;
	if (fd < 0) {
		__set_errno (EBADF);
		return -1;
	}
	switch (whence) {
		case SEEK_SET:
		case SEEK_CUR:
		case SEEK_END:
			break;
		default:
			__set_errno (EINVAL);
			return -1;
	}
	hi = offset >> 32;
	lo = offset & 0xffffffff;
	ret = ros_syscall(SYS_llseek, fd, hi, lo, &retoff, whence, 0);
	if (ret) {
		assert(ret == -1);	/* catch odd bugs */
		return ret;
	}
	return retoff;
}
Exemple #4
0
ssize_t sys_shared_page_alloc(void** addr, pid_t p2, 
                              int p1_flags, int p2_flags
                             ) 
{
	return ros_syscall(SYS_shared_page_alloc, addr, 
	               p2, p1_flags, p2_flags, 0, 0);
}
Exemple #5
0
/* Get the pathname of the current working directory,
   and put it in SIZE bytes of BUF.  Returns NULL if the
   directory couldn't be determined or SIZE was too small.
   If successful, returns BUF.  In GNU, if BUF is NULL,
   an array is allocated with `malloc'; the array is SIZE
   bytes long, unless SIZE <= 0, in which case it is as
   big as necessary.  */
char *
__getcwd (char *buf, size_t size)
{
  int allocated = 0;
  if(buf == NULL)
  {
    // Linux ABI requires we allocate a buffer if NULL is passed.
    // If size is passed as 0, it means "as big as necessary"
    if(size == 0)
      size = PGSIZE;

    buf = (char*)malloc(size);
    if(buf == NULL)
    {
      errno = ENOMEM;
      return NULL;
    }
    allocated = 1;
  }

  int ret = ros_syscall(SYS_getcwd, buf, size, 0, 0, 0, 0);

  if(ret == -1 && allocated)
  {
    free(buf);
    return NULL;
  }

  return buf;
}
Exemple #6
0
void *timer_thread(void *arg)
{
	while (1) {
		set_posted_interrupt(0xef);
		ros_syscall(SYS_vmm_poke_guest, 0, 0, 0, 0, 0, 0);
		uthread_usleep(100000);
	}
	fprintf(stderr, "SENDING TIMER\n");
}
Exemple #7
0
/* Create a one-way communication channel (__pipe).  If successful,
   two file descriptors are stored in PIPEDES; bytes written on
   PIPEDES[1] can be read from PIPEDES[0].  Apply FLAGS to the new
   file descriptors.  Returns 0 if successful, -1 if not.  */
int __pipe2(int pipedes[2], int flags)
{
	if (pipedes == NULL) {
		__set_errno (EINVAL);
		return -1;
	}

	__set_errno (ENOSYS);
	return ros_syscall(SYS_pipe, pipedes, flags, 0, 0, 0, 0);
}
Exemple #8
0
/* Get file information about FILE in BUF.  */
int
__lxstat (int vers, const char *file, struct stat *buf)
{
  if (vers != _STAT_VER || file == NULL || buf == NULL)
  {
    __set_errno (EINVAL);
    return -1;
  }

  int ret = (int)ros_syscall(SYS_lstat, file, strlen(file), buf, 0, 0, 0);
  return ret;
}
Exemple #9
0
int sys_proc_create(char *path, size_t path_l, char *argv[], char *envp[],
                    int flags)
{
	struct serialized_data *sd = serialize_argv_envp(argv, envp);
	if (!sd) {
		errno = ENOMEM;
		return -1;
	}
	int ret = ros_syscall(SYS_proc_create, path, path_l,
	                      sd->buf, sd->len, flags, 0);
	free_serialized_data(sd);
	return ret;
}
Exemple #10
0
int fcntl(int fd, int cmd, ...)
{
	int ret, arg;
	va_list vl;
	va_start(vl, cmd);
	switch (cmd) {
		case F_GETFL:
			ret = ros_syscall(SYS_fcntl, fd, cmd, 0, 0, 0, 0);
			if (ret != -1)
				ret |= get_nonblock_status(fd);
			break;
		case F_SETFL:
			arg = va_arg(vl, int);
			if ((ret = set_nonblock_status(fd, &arg)))
				return ret;
			ret = ros_syscall(SYS_fcntl, fd, cmd, arg, 0, 0, 0);
			break;
		default:
			ret = __vfcntl(fd, cmd, vl);
	}
	va_end(vl);
	return ret;
}
Exemple #11
0
long int syscall(long int num, ...)
{
	va_list vl;
	va_start(vl, num);
	long int a0 = va_arg(vl, long int);
	long int a1 = va_arg(vl, long int);
	long int a2 = va_arg(vl, long int);
	long int a3 = va_arg(vl, long int);
	long int a4 = va_arg(vl, long int);
	long int a5 = va_arg(vl, long int);
	va_end(vl);
	
	return ros_syscall(num, a0, a1, a2, a3, a4, a5);
}
Exemple #12
0
/* Change the protections of FILE to MODE.  */
int
__chmod (const char* file, mode_t mode)
{
  struct dir dir;
  size_t mlen;
  char mbuf[STATFIXLEN];
  int ret;

  if (file == NULL)
  {
    __set_errno (EINVAL);
    return -1;
  }

  init_empty_dir(&dir);
  dir.mode = mode;
  mlen = convD2M(&dir, mbuf, STATFIXLEN);
  ret = ros_syscall(SYS_wstat, file, strlen(file), mbuf, mlen, WSTAT_MODE, 0);
  return (ret == mlen ? 0 : -1);
}
Exemple #13
0
/* Perform file control operations on FD.  */
int
__fcntl(int fd, int cmd, ...)
{
  va_list vl;
  va_start(vl,cmd);
  int arg = va_arg(vl,int);
  va_end(vl);

  switch(cmd)
  {
    case F_DUPFD:
    case F_GETFD:
    case F_SETFD:
    case F_GETFL:
    case F_SETFL:
      return ros_syscall(SYS_fcntl, fd, cmd, arg, 0, 0, 0);
    default:
      errno = ENOSYS;
      return -1;
  }
}
Exemple #14
0
/* Clone the calling process, creating an exact copy.
   Return -1 for errors, 0 to the new process,
   and the process ID of the new process to the old process.  */
int
__fork ()
{
  int ret = -1;
  __libc_lock_lock(__fork_lock);

  if(child_list_size == child_list_capacity)
  {
    int newcap = child_list_capacity ? 2*child_list_capacity : 1;
    int* tmp = realloc(child_list,newcap*sizeof(int));
    if(!tmp)
      goto out;
    child_list_capacity = newcap;
    child_list = tmp;
  }

  ret = ros_syscall(SYS_fork,0,0,0,0,0);
  if(ret > 0)
    child_list[child_list_size++] = ret;

out:
  __libc_lock_unlock(__fork_lock);
  return ret;
}
Exemple #15
0
/* Write NBYTES of BUF to FD.  Return the number written, or -1.  */
int
__close (int fd)
{
  return ros_syscall(SYS_close,fd,0,0,0,0);
}
Exemple #16
0
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
	return ros_syscall(SYS_accept, sockfd, addr, addrlen, 0, 0, 0);
}
Exemple #17
0
/* Wait for a child matching PID to die.
   If PID is greater than 0, match any process whose process ID is PID.
   If PID is (pid_t) -1, match any process.
   If PID is (pid_t) 0, match any process with the
   same process group as the current process.
   If PID is less than -1, match any process whose
   process group is the absolute value of PID.
   If the WNOHANG bit is set in OPTIONS, and that child
   is not already dead, return (pid_t) 0.  If successful,
   return PID and store the dead child's status in STAT_LOC.
   Return (pid_t) -1 for errors.  If the WUNTRACED bit is set in OPTIONS,
   return status for stopped children; otherwise don't.  */
pid_t __libc_waitpid(pid_t pid, int *stat_loc, int options)
{
	return ros_syscall(SYS_waitpid, pid, stat_loc, options, 0, 0, 0);
}
Exemple #18
0
/* These are the default handlers for each posix signal.  They are listed in
 * SIGNAL(7) of the Linux Programmer's Manual.  We run them as default
 * sigactions, instead of the older handlers, so that we have access to the
 * faulting context.
 *
 * Exit codes are set as suggested in the following link.  I wish I could find
 * the definitive source, but this will have to do for now.
 * http://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated
 * */
static void default_term_handler(int signr, siginfo_t *info, void *ctx)
{
	ros_syscall(SYS_proc_destroy, __procinfo.pid, signr, 0, 0, 0, 0);
}
Exemple #19
0
/* Write NBYTES of BUF to FD.  Return the number written, or -1.  */
ssize_t
__libc_read (int fd, void *buf, size_t nbytes)
{
  return ros_syscall(SYS_read,fd,buf,nbytes,0,0);
}
Exemple #20
0
void *consin(void *arg)
{
	struct virtio_threadarg *a = arg;
	char *line, *outline;
	static char consline[128];
	static struct scatterlist iov[32];
	static struct scatterlist out[] = { {NULL, sizeof(outline)}, };
	static struct scatterlist in[] = { {NULL, sizeof(line)}, };

	static unsigned int inlen, outlen, conslen;
	struct virtqueue *v = a->arg->virtio;
	fprintf(stderr, "consin thread ..\n");
	uint16_t head, gaveit = 0, gotitback = 0;
	uint32_t vv;
	int i;
	int num;
	//char c[1];

	if (debug) fprintf(stderr, "Spin on console being read, print num queues, halt\n");

	for(num = 0;! quit;num++) {
		//int debug = 1;
		/* host: use any buffers we should have been sent. */
		head = wait_for_vq_desc(v, iov, &outlen, &inlen);
		if (debug)
			fprintf(stderr, "vq desc head %d, gaveit %d gotitback %d\n", head, gaveit, gotitback);
		for(i = 0; debug && i < outlen + inlen; i++)
			fprintf(stderr, "v[%d/%d] v %p len %d\n", i, outlen + inlen, iov[i].v, iov[i].length);
		if (debug)
			fprintf(stderr, "outlen is %d; inlen is %d\n", outlen, inlen);
		/* host: fill in the writeable buffers. */
		for (i = outlen; i < outlen + inlen; i++) {
			/* host: read a line. */
			memset(consline, 0, 128);
			if (read(0, consline, 1) < 0) {
				exit(0);
			}
			if (debug) fprintf(stderr, "CONSIN: GOT A LINE:%s:\n", consline);
			if (debug) fprintf(stderr, "CONSIN: OUTLEN:%d:\n", outlen);
			if (strlen(consline) < 3 && consline[0] == 'q' ) {
				quit = 1;
				break;
			}

			memmove(iov[i].v, consline, strlen(consline)+ 1);
			iov[i].length = strlen(consline) + 1;
		}
		if (debug) fprintf(stderr, "call add_used\n");
		/* host: now ack that we used them all. */
		add_used(v, head, outlen+inlen);
		/* turn off consdata - the IRQ injection isn't right */
		//consdata = 1;
		if (debug) fprintf(stderr, "DONE call add_used\n");

		// Send spurious for testing (Gan)
		set_posted_interrupt(0xE5);
		virtio_mmio_set_vring_irq();

		ros_syscall(SYS_vmm_poke_guest, 0, 0, 0, 0, 0, 0);
	}
	fprintf(stderr, "All done\n");
	return NULL;
}
Exemple #21
0
int sys_self_notify(uint32_t vcoreid, unsigned int ev_type,
                    struct event_msg *u_msg, bool priv)
{
	return ros_syscall(SYS_self_notify, vcoreid, ev_type, u_msg, priv, 0, 0);
}
Exemple #22
0
ssize_t
readlink (const char* path, char* buf, size_t len)
{
  return ros_syscall(SYS_readlink, path, strlen(path), buf, len, 0, 0);
}
Exemple #23
0
/* Put the state of FD into *TERMIOS_P.  */
int
__tcgetattr (int fd, struct termios* termios_p)
{
  return ros_syscall(SYS_tcgetattr, fd, termios_p, 0, 0, 0, 0);
}
Exemple #24
0
int main(int argc, char **argv)
{
	int i, amt;
	int nr_gpcs = 1;
	uint64_t entry;
	int fd = open("#c/sysctl", O_RDWR), ret;
	int kfd = -1;
	bool smallkernel = false;
	void * x;
	static char cmd[512];
	if (fd < 0) {
		perror("#c/sysctl");
		exit(1);
	}
	argc--,argv++;
	if (argc != 2) {
		fprintf(stderr, "Usage: %s vmimage entrypoint\n", argv[0]);
		exit(1);
	}
	entry = strtoull(argv[1], 0, 0);
	kfd = open(argv[0], O_RDONLY);
	if (kfd < 0) {
		perror(argv[0]);
		exit(1);
	}
	if (ros_syscall(SYS_setup_vmm, nr_gpcs, 0, 0, 0, 0, 0) != nr_gpcs) {
		perror("Guest pcore setup failed");
		exit(1);
	}
		my_threads = malloc(sizeof(pthread_t) * nr_threads);
		my_retvals = malloc(sizeof(void*) * nr_threads);
		if (!(my_retvals && my_threads))
			perror("Init threads/malloc");

		pthread_can_vcore_request(FALSE);	/* 2LS won't manage vcores */
		pthread_need_tls(FALSE);
		pthread_mcp_init();					/* gives us one vcore */
		vcore_request(nr_threads - 1);		/* ghetto incremental interface */
		for (int i = 0; i < nr_threads; i++) {
			x = __procinfo.vcoremap;
			printf("%p\n", __procinfo.vcoremap);
			printf("Vcore %d mapped to pcore %d\n", i,
			    	__procinfo.vcoremap[i].pcoreid);
		}
		if (pthread_create(&my_threads[0], NULL, &talk_thread, NULL))
			perror("pth_create failed");
//		if (pthread_create(&my_threads[1], NULL, &fail, NULL))
//			perror("pth_create failed");
	printf("threads started\n");

	if (0) for (int i = 0; i < nr_threads-1; i++) {
		int ret;
		if (pthread_join(my_threads[i], &my_retvals[i]))
			perror("pth_join failed");
		printf("%d %d\n", i, ret);
	}
	

	ret = syscall(33, 1);
	if (ret < 0) {
		perror("vm setup");
		exit(1);
	}
	/* blob that is faulted in from the EPT first.  we need this to be in low
	 * memory (not above the normal mmap_break), so the EPT can look it up.
	 * Note that we won't get 4096.  The min is 1MB now, and ld is there. */

	mmap_blob = mmap((int*)(15*1048576), 16 * 1048576, PROT_EXEC | PROT_READ | PROT_WRITE,
	                 MAP_ANONYMOUS, -1, 0);
	if (mmap_blob == MAP_FAILED) {
		perror("Unable to mmap");
		exit(1);
	}

	memset(mmap_blob, 0, 16*1048576);
	// read in the kernel.
	x = mmap_blob + 0x1000000;
	for(;;) {
		amt = read(kfd, x, 1048576);
		if (amt < 0) {
			perror("read");
			exit(1);
		}
		if (amt == 0) {
			break;
		}
		x += amt;
	}
	fprintf(stderr, "Read in %d bytes\n", x-mmap_blob);

	p512 = mmap_blob;
	p1 = &p512[512];
	p2m = &p512[1024];
	
	// We had thought to enter the kernel at the high address. But
	// there's just too much state the kernel has to clean up to
	// make this really work -- consider all the segment
	// descriptors that have to move, etc.  So we will enter the
	// kernel in the low part of the address space, and let it
	// work up its page tables and the other good fun.  Map the
	// kernel address space at low virtual, for 1G.  It's ok to
	// map memory we have no access to.
#define _2MiB 0x200000
	p512[0] = (unsigned long long)p1 | 7;
	// if only we could guarantee 1G pages everywhere!
	p1[0] = /*0x87; */(unsigned long long)p2m | 7;
	for(i = 0; i < 16; i++) {
		p2m[i] = 0x87 | i * _2MiB;
		printf("pwm[%d] = 0x%llx\n", i, p2m[i]);
	}
	printf("p512 %p p512[0] is 0x%lx p1 %p p1[0] is 0x%x\n", p512, p512[0], p1, p1[0]);
	sprintf(cmd, "V 0x%llx 0x%llx 0x%llx", entry, (unsigned long long) &stack[1024], (unsigned long long) p512);
	printf("Writing command :%s:\n", cmd);
	ret = write(fd, cmd, strlen(cmd));
	if (ret != strlen(cmd)) {
		perror(cmd);
	}

	sprintf(cmd, "V 0 0 0");
	while (! done) {
		char c[1];
		printf("hit return\n"); read(0, c, 1);
		if (debug)
			fprintf(stderr, "RESUME\n");
		ret = write(fd, cmd, strlen(cmd));
		if (ret != strlen(cmd)) {
			perror(cmd);
		}
	}
	return 0;
}
Exemple #25
0
int __socket(int socket_family, int socket_type, int protocol) {
	return ros_syscall(SYS_socket, socket_family, socket_type, protocol, 0,0,0);
}
Exemple #26
0
int
__mprotect (__ptr_t addr, size_t len, int prot)
{
  return ros_syscall(SYS_mprotect, addr, len, prot, 0, 0, 0);
}
Exemple #27
0
int sys_provision(int pid, unsigned int res_type, long res_val)
{
	return ros_syscall(SYS_provision, pid, res_type, res_val, 0, 0, 0);
}
Exemple #28
0
int sys_notify(int pid, unsigned int ev_type, struct event_msg *u_msg)
{
	return ros_syscall(SYS_notify, pid, ev_type, u_msg, 0, 0, 0);
}
Exemple #29
0
/* Set the state of FD to *TERMIOS_P.  */
int
tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
{
  return ros_syscall(SYS_tcsetattr,fd,optional_actions,termios_p,0,0);
}
Exemple #30
0
int __connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
	return ros_syscall(SYS_connect, sockfd, addr, addrlen, 0, 0, 0);
}