long sys_clone(unsigned long clone_flags, unsigned long newsp,
	       int __user *parent_tid, void *newtls, int __user *child_tid)
{
	long ret;

	if (!newsp)
		newsp = UPT_SP(&current->thread.regs.regs);

	current->thread.forking = 1;
	ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
		      child_tid);
	current->thread.forking = 0;
	return ret;
}
예제 #2
0
/*
 * Create a kernel thread
 */
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

        /* Don't use r10 since that is set to 0 in copy_thread */
	regs.r11 = (unsigned long)fn;
	regs.r12 = (unsigned long)arg;
	regs.irp = (unsigned long)kernel_thread_helper;

	/* Ok, create the new process.. */
        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
예제 #3
0
int sys_clone(struct pt_regs *regs)
{
	unsigned long clone_flags;
	unsigned long newsp;
	int __user *parent_tidptr, *child_tidptr;

	clone_flags = regs->bx;
	newsp = regs->cx;
	parent_tidptr = (int __user *)regs->dx;
	child_tidptr = (int __user *)regs->di;
	if (!newsp)
		newsp = regs->sp;
	return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
}
예제 #4
0
asmlinkage int sys_clone(struct pt_regs regs)
{
    unsigned long clone_flags;
    unsigned long newsp;
    int __user *parent_tidptr, *child_tidptr;

    clone_flags = regs.ebx;
    newsp = regs.ecx;
    parent_tidptr = (int __user *)regs.edx;
    child_tidptr = (int __user *)regs.edi;
    if (!newsp)
        newsp = regs.esp;
    return do_fork(clone_flags, newsp, &regs, 0, parent_tidptr, child_tidptr);
}
      int daemon(int nochdir, int noclose, boost::system::error_code &ec)
      {
         int status = 0;

         //openlog("daemonize", LOG_PID, LOG_DAEMON);

         // fork once to go into the background.
         if((status = do_fork()) < 0 )
            ;
         // create new session
         else if(setsid() < 0)              // shouldn't fail 
            status = -1;
         // fork again to ensure that daemon never reacquires a control terminal. 
         else if((status = do_fork()) < 0 )
            ;
         else
         {
            // clear any inherited umask(2) value 

            umask(0);

            // we're there.

            if(!nochdir)
            {
               // go to a neutral corner. 
               chdir("/");
            }

            if(!noclose)
            {
               redirect_fds(ec);
            }
         }

         return status;
      }
예제 #6
0
파일: process.c 프로젝트: CSCLOG/beaglebone
/*
 * Create a kernel thread.
 */
long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

	regs.regs[6] = (unsigned long) arg;
	regs.regs[5] = (unsigned long) fn;
	regs.cp0_epc = (unsigned long) kernel_thread_helper;
	regs.cp0_psr = (regs.cp0_psr & ~(0x1|0x4|0x8)) | \
			((regs.cp0_psr & 0x3) << 2);

	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, \
			0, &regs, 0, NULL, NULL);
}
예제 #7
0
pid_t kernel_thread(int (*fn) (void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

	regs.r1 = (unsigned long)arg;
	regs.p1 = (unsigned long)fn;
	regs.pc = (unsigned long)kernel_thread_helper;
	regs.orig_p0 = -1;
	regs.ipend = 0x8002;
	__asm__ __volatile__("%0 = syscfg;":"=da"(regs.syscfg):);
	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
		       NULL);
}
예제 #8
0
파일: boot.c 프로젝트: duskast/learning
void plat_boot(void) {
    int i;
    for (i=0; init[i]; i++) {
        init[i]();
    }
    init_sys_mmu();
    start_mmu();
    task_init();
    timer_init();

    init_page_map();
    kmalloc_init();
    ramdisk_driver_init();
    romfs_init();
    
    i = do_fork(test_process, (void *)0x1);
    i = do_fork(test_process, (void *)0x2);

    while (1) {
        delay ();
        printk("this is the original process\n");
    }

}
예제 #9
0
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

        
	regs.r11 = (unsigned long)fn;
	regs.r12 = (unsigned long)arg;
	regs.irp = (unsigned long)kernel_thread_helper;
	regs.dccr = 1 << I_DCCR_BITNR;

	
        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
예제 #10
0
static void daemonize()
{
  int fd, fdlimit;
  const char *chdir_root = "/";

  do_fork();
  if ( setsid() < 0 )
    {
      exit(EXIT_FAILURE);
    }
  do_fork();

  umask(0);
  if ( chdir(chdir_root) < 0)
    {
      exit(EXIT_FAILURE);
    }

  /* Close all open files. */
  fdlimit = sysconf (_SC_OPEN_MAX);
  for ( fd=0; fd<fdlimit; ++fd )
    {
      close(fd);
    }

  /* Open 0, 1 and 2. */
  open("/dev/null", O_RDWR);
  if ( dup(0) != 1 )
    {
      exit(EXIT_FAILURE);
    }
  if ( dup(0) != 2 )
    {
      exit(EXIT_FAILURE);
    }
}
예제 #11
0
파일: process.c 프로젝트: AllenDou/linux
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));
	/*
	 * Yes, we're exploting illicit knowledge of the ABI here.
	 */
	regs.r00 = (unsigned long) arg;
	regs.r01 = (unsigned long) fn;
	pt_set_elr(&regs, (unsigned long)kernel_thread_helper);
	pt_set_kmode(&regs);

	return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
예제 #12
0
파일: process.c 프로젝트: 7L/pi_plus
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));
	/* store them in non-volatile registers */
	regs.r5 = (unsigned long)fn;
	regs.r6 = (unsigned long)arg;
	local_save_flags(regs.msr);
	regs.pc = (unsigned long)kernel_thread_helper;
	regs.pt_mode = 1;

	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
			&regs, 0, NULL, NULL);
}
예제 #13
0
static_unused int _sys_clone(nabi_no_regargs struct pt_regs regs)
{
	unsigned long clone_flags;
	unsigned long newsp;
	int *parent_tidptr, *child_tidptr;

	clone_flags = regs.regs[4];
	newsp = regs.regs[5];
	if (!newsp)
		newsp = regs.regs[29];
	parent_tidptr = (int *) regs.regs[6];
	child_tidptr = (int *) regs.regs[7];
	return do_fork(clone_flags & ~CLONE_IDLETASK, newsp, &regs, 0,
	               parent_tidptr, child_tidptr);
}
예제 #14
0
파일: lat_proc.c 프로젝트: ash9211/graphene
int
main(int ac, char **av)
{
	if (ac < 2) goto usage;

	if (!strcmp("procedure", av[1])) {
		BENCH(do_procedure(ac), 0);
		micro("Procedure call", get_n());
	} else if (!strcmp("fork", av[1])) {
		BENCH(do_fork(), 0);
#ifdef STATIC
		micro("Static Process fork+exit", get_n());
#else
		micro("Process fork+exit", get_n());
#endif
	} else if (!strcmp("dfork", av[1])) {
		BENCH(do_dfork(), 0);
#ifdef STATIC
		micro("Static Process double fork+exit", get_n());
#else
		micro("Process double fork+exit", get_n());
#endif
	} else if (!strcmp("exec", av[1])) {
		BENCH(do_forkexec(), 0);
#ifdef STATIC
		micro("Static Process fork+execve", get_n());
#else
		micro("Process fork+execve", get_n());
#endif
	} else if (!strcmp("dforkexec", av[1])) {
		BENCH(do_dforkexec(), 0);
#ifdef STATIC
		micro("Static Process double fork+execve", get_n());
#else
		micro("Process double fork+execve", get_n());
#endif
	} else if (!strcmp("shell", av[1])) {
		BENCH(do_shell(), 0);
#ifdef STATIC
		micro("Static Process fork+/bin/sh -c", get_n());
#else
		micro("Process fork+/bin/sh -c", get_n());
#endif
	} else {
usage:		printf("Usage: %s fork|exec|shell|dfork|dforkexec\n", av[0]);
	}
	return(0);
}
예제 #15
0
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

	regs.r0 = (unsigned long)arg;
	regs.r1 = (unsigned long)fn;
	regs.r2 = (unsigned long)do_exit;
	regs.lr = (unsigned long)kernel_thread_helper;
	regs.pc = (unsigned long)kernel_thread_helper;
	regs.sr = MODE_SUPERVISOR;

	return do_fork(flags | CLONE_VM | CLONE_UNTRACED,
		       0, &regs, 0, NULL, NULL);
}
예제 #16
0
파일: sys_or32.c 프로젝트: 08opt/linux
asmlinkage long _sys_clone(unsigned long clone_flags, unsigned long newsp,
			   int __user *parent_tid, int __user *child_tid,
			   struct pt_regs *regs)
{
	long ret;

	/* FIXME: Is alignment necessary? */
	/* newsp = ALIGN(newsp, 4); */

	if (!newsp)
		newsp = regs->sp;

	ret = do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);

	return ret;
}
예제 #17
0
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof (regs));
	regs.r1 = (unsigned long)fn;
	regs.r2 = (unsigned long)arg;

	regs.bpc = (unsigned long)kernel_thread_helper;

	regs.psw = M32R_PSW_BIE;

	/* Ok, create the new process. */
	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
		NULL);
}
예제 #18
0
/* We don't want to use generic sys_clone because Nios II passes all arguments
 * on stack. And we need to save all these registers, which means we need
 * push all these registers on top of pt_regs. So, it is better to pass in
 * pt_regs* and extract the arguments for do_fork() from here.
 */
asmlinkage int nios2_clone(struct pt_regs *regs)
{
    unsigned long flags;
    unsigned long newsp;
    int __user *parent_tidptr, *child_tidptr;

    flags = regs->r4;
    newsp = regs->r5;
    if (newsp == 0)
        newsp = regs->sp;

    parent_tidptr = (int __user *) regs->r6;
    child_tidptr = (int __user *) regs->r8;

    return do_fork(flags, newsp, 0, parent_tidptr, child_tidptr);
}
예제 #19
0
asmlinkage long _sys_clone(unsigned long clone_flags, unsigned long newsp,
			   int __user *parent_tid, int __user *child_tid,
			   struct pt_regs *regs)
{
	long ret;

	
	

	if (!newsp)
		newsp = regs->sp;

	ret = do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);

	return ret;
}
예제 #20
0
/*
 * create a kernel thread
 */
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

	regs.a2 = (unsigned long) fn;
	regs.d2 = (unsigned long) arg;
	regs.pc = (unsigned long) kernel_thread_helper;
	local_save_flags(regs.epsw);
	regs.epsw |= EPSW_IE | EPSW_IM_7;

	/* Ok, create the new process.. */
	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0,
		       NULL, NULL);
}
예제 #21
0
static void
run_lock_blocks_other_process(void)
{
    /* Making this static prevents a memory leak warning from valgrind for the
     * parent process, which cannot easily unlock (and free) 'lockfile' because
     * it can only do so after the child has exited, and it's the caller of
     * this function that does the wait() call. */
    static struct lockfile *lockfile;

    CHECK(lockfile_lock("file", &lockfile), 0);
    if (do_fork() == CHILD) {
        lockfile_unlock(lockfile);
        CHECK(lockfile_lock("file", &lockfile), EAGAIN);
        exit(11);
    }
}
예제 #22
0
/*
 * Clone a task - this clones the calling program thread.
 * This is called indirectly via a small wrapper
 */
asmlinkage long
score_clone(struct pt_regs *regs)
{
	unsigned long clone_flags;
	unsigned long newsp;
	int __user *parent_tidptr, *child_tidptr;

	clone_flags = regs->regs[4];
	newsp = regs->regs[5];
	if (!newsp)
		newsp = regs->regs[0];
	parent_tidptr = (int __user *)regs->regs[6];
	child_tidptr = (int __user *)regs->regs[8];

	return do_fork(clone_flags, newsp, regs, 0,
			parent_tidptr, child_tidptr);
}
예제 #23
0
/*
 * Create a kernel thread
 */
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
	/* prepare registers from which a child task switch frame will be copied */
	struct pt_regs regs;

	set_fs(KERNEL_DS);

	memset(&regs, 0, sizeof(regs));

	//printk("kernel_thread fn=%x arg=%x regs=%x\n", fn, arg, &regs);

	regs.r11 = (unsigned long)fn;
	regs.r12 = (unsigned long)arg;
	regs.r13 = (unsigned long)kernel_thread_helper;
	regs.pt_mode = PT_MODE_KERNEL;
	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
예제 #24
0
static void		manage_multi_cmd(t_lst *list, char **cmd)
{
	char **paths_tmp;
	char *cmd_path;

	cmd_path = NULL;
	paths_tmp = parse_path(list);
	cmd_path = get_cmd_path(cmd[3], paths_tmp);
	if (cmd_is_in_path(cmd[3], paths_tmp))
		do_fork(list, cmd + 3, cmd_path);
	else
	{
		ft_putstr_fd("env: ", 2);
		ft_putstr_fd(cmd[3], 2);
		ft_putendl_fd(": No such file or directory", 2);
	}
}
예제 #25
0
파일: attach.c 프로젝트: nelhage/reptyr
int do_setsid(struct ptrace_child *child) {
    int err = 0;
    struct ptrace_child dummy;

    err = do_fork(child);
    if (err < 0)
        return err;

    debug("Forked a child: %ld", child->forked_pid);

    err = ptrace_finish_attach(&dummy, child->forked_pid);
    if (err < 0)
        goto out_kill;

    dummy.state = ptrace_after_syscall;
    copy_user(&dummy, child);
    if (ptrace_restore_regs(&dummy)) {
        err = dummy.error;
        goto out_kill;
    }

    err = do_syscall(&dummy, setpgid, 0, 0, 0, 0, 0, 0);
    if (err < 0) {
        error("Failed to setpgid: %s", strerror(-err));
        goto out_kill;
    }

    move_process_group(child, child->pid, dummy.pid);

    err = do_syscall(child, setsid, 0, 0, 0, 0, 0, 0);
    if (err < 0) {
        error("Failed to setsid: %s", strerror(-err));
        move_process_group(child, dummy.pid, child->pid);
        goto out_kill;
    }

    debug("Did setsid()");

out_kill:
    kill(dummy.pid, SIGKILL);
    ptrace_wait(&dummy);
    ptrace_detach_child(&dummy);
    do_syscall(child, wait4, dummy.pid, 0, WNOHANG, 0, 0, 0);
    return err;
}
예제 #26
0
파일: pipe.c 프로젝트: AnupBansod/SS-Rsync
pid_t piped_child_http(char **command)
{
    pid_t pid;
    pid = do_fork();
    if (pid == -1) {
        rsyserr(FERROR, errno, "fork");
        exit_cleanup(RERR_IPC);
    }

    if (pid == 0) {
        set_blocking(STDIN_FILENO);
        execvp(command[0], command);
        rsyserr(FERROR, errno, "Failed to exec %s", command[0]);
        exit_cleanup(RERR_IPC);
    }

    return pid;
}
asmlinkage int bfin_clone(struct pt_regs *regs)
{
	unsigned long clone_flags;
	unsigned long newsp;

#ifdef __ARCH_SYNC_CORE_DCACHE
	if (current->nr_cpus_allowed == num_possible_cpus())
		set_cpus_allowed_ptr(current, cpumask_of(smp_processor_id()));
#endif

	/* syscall2 puts clone_flags in r0 and usp in r1 */
	clone_flags = regs->r0;
	newsp = regs->r1;
	if (!newsp)
		newsp = rdusp();
	else
		newsp -= 12;
	return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
}
예제 #28
0
파일: main.c 프로젝트: aclark4life/CS
main()
{
	char **tokenv;
	char *s;
	int tokenc;
	int i;

	prompt();
	for ( s=read_long(); s!=NULL; s=read_long() )
	{
		tokenv=tokenize(s,&tokenc);
		if (!no_token(tokenv)) /* if there is a token */
		{
			check_for_exit(tokenv); 
			do_fork(tokenv,&tokenc);
		}
		prompt();
	}
}
예제 #29
0
/*
 * Create a kernel thread
 */
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

	regs.ebx = (unsigned long) fn;
	regs.edx = (unsigned long) arg;

	regs.xds = __USER_DS;
	regs.xes = __USER_DS;
	regs.orig_eax = -1;
	regs.eip = (unsigned long) kernel_thread_helper;
	regs.xcs = GET_KERNEL_CS();
	regs.eflags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2;

	/* Ok, create the new process.. */
	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
예제 #30
0
long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
	struct pt_regs regs;

	memset(&regs, 0, sizeof(regs));

	regs.regs[4] = (unsigned long) arg;
	regs.regs[5] = (unsigned long) fn;
	regs.cp0_epc = (unsigned long) kernel_thread_helper;
	regs.cp0_status = read_c0_status();
#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
	regs.cp0_status = (regs.cp0_status & ~(ST0_KUP | ST0_IEP | ST0_IEC)) |
			  ((regs.cp0_status & (ST0_KUC | ST0_IEC)) << 2);
#else
	regs.cp0_status |= ST0_EXL;
#endif

	/* Ok, create the new process.. */
	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}