Пример #1
0
BOOL
launch_in_session(const TCHAR *processExe)
{
	DWORD winLogonPid = find_process("winlogon.exe", 1);
	HANDLE hTokenDup = make_token_from_pid(winLogonPid);
	STARTUPINFO si = {0};
	PROCESS_INFORMATION pi = {0};

	if (hTokenDup == NULL) {
		return FALSE;
	}

	si.cb = sizeof(STARTUPINFO);
	si.lpDesktop = TEXT("WinSta0\\WinLogon");

	CreateProcessAsUser(
		hTokenDup,  /* client access token */
		processExe,
		NULL,
		NULL,
		NULL,
		TRUE,       /* handles are inheritable */
		0,
		NULL,
		NULL,
		&si,        /* STARTUPINFO structure */
		&pi         /* receives information about new process */
		);

	CloseHandle(hTokenDup);
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);

	return TRUE;
}
Пример #2
0
thread *find_thread (DWORD PID, DWORD TID)
{
    process *p=find_process(PID);
    thread *t=(thread*)rbtree_lookup (p->threads, (void*)TID);
    oassert (t!=NULL && "TID not found in threads table");
    return t;
};
Пример #3
0
process_info *
find_process_pid (int pid)
{
  return find_process ([&] (process_info *process) {
    return process->pid == pid;
  });
}
Пример #4
0
int ksemctl(uint8_t key, int cmd, void* res) {
	sem_t* sem = &semaphores[key];
	if (sem->allocated == 0) {
		return -1;
	}

	switch (cmd) {
		case SEM_GETVAL:
			*((int*)res) = sem->value;
			break;
		case SEM_DEL:
			while (sem_fifo_size(&(sem->fifo)) > 0) {
				process_t *proc = find_process(sem_fifo_get(&(sem->fifo)));
				proc->state = PROCSTATE_RUNNING;
			}
			sem->allocated = 0;
			break;
		case SEM_ZCNT:
			*((int*)res) = sem_fifo_size(&(sem->fifo));
			break;
		case SEM_SET:
			sem->value = *((int*)res);
			break;
		default:
			return -1;
	}
	return 0;
}
Пример #5
0
int
have_attached_inferiors_p (void)
{
  return find_process ([] (process_info *process) {
    return process->attached;
  }) != NULL;
}
Пример #6
0
int unwait(int pid){
    struct process_control_block temp = delete(WAITING, find_process(WAITING, pid));
    /*Pid doesn't exist, recoverable*/
    if(temp.pid == ERROR_PROCESS_NOT_EXIST){
        return ERROR_PROCESS_NOT_EXIST;
    }
    /*Nothing in queue, recoverable*/
    else if(temp.pid == ERROR_QUEUE_EMPTY){
        return ERROR_QUEUE_EMPTY;
    }

    if(scheduler == GROUP){

        int error = enqueue(temp.group, temp.pid, temp.psw, temp.page_table, temp.regs, temp.priority, temp.quantum_count, temp.group);
        /*Queue full, unrecoverable error*/
        if(error == ERROR_QUEUE_FULL){
            return error;
        }
    }else if(scheduler == PRIORITY){
        int error = enqueue(READY0, temp.pid, temp.psw, temp.page_table, temp.regs, temp.priority, temp.quantum_count, temp.group);
        /*Queue full, unrecoverable error*/
        if(error == ERROR_QUEUE_FULL){
            return error;
        }
    }


    return ERROR_SUCCESS;
}
Пример #7
0
t_proc	*destroy_process(t_cwar *cwar, t_proc *proc, t_proc *prev)
{
	int		i;
	int		kill;

	i = 0;
	kill = 0;
	while (i <= REG_NUMBER)
		free(proc->reg[i++]);
	free(proc->reg);
	if (cwar->proc == proc)
	{
		cwar->proc = proc->next;
		free(proc);
		kill++;
	}
	else
		kill = find_process(cwar, proc, prev);
	if (!kill)
		cw_error("The process to kill wasn't found\n", cwar);
	cwar->proc_number--;
	if (!cwar->proc_number)
		game_over(cwar);
	return (cwar->proc);
}
Пример #8
0
HANDLE OsGetUserToken(void)
{
	HANDLE	hproc, htoken;
	int		res;
	DWORD	explorer;

	explorer = find_process("explorer.exe");
	if(explorer!=NULL)
	{
		hproc = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, explorer);
		if(hproc!=NULL)
		{
			res = OpenProcessToken(hproc, TOKEN_ALL_ACCESS, &htoken);
			if(res!=0) 
			{
				//deb("explorer.exe handle %p", htoken);
				return htoken;
			}
			else
				deb("OpenProcessToken: %s", fmterr());
		}
		else
		{
			deb("OpenProcess: %s", fmterr());
			return 0;
		}
	}
	else
	{
	//	deb("did not find explorer");
		return 0;
	}

	return 0;
}
bool cprocess_tree::kill_process(_In_ const wchar_t* process_name)
{
	_ASSERTE(NULL != process_name);
	if (NULL == process_name) return false;

	DWORD pid = find_process(process_name);
	return kill_process(pid);
}
Пример #10
0
static void task_create_hook(WIND_TCB * tcb) {
    ChildProcess * prs;

    semTake(prs_list_lock, WAIT_FOREVER);
    prs = find_process(taskIdSelf());
    /* TODO: vxWork: standard IO inheritance */
    semGive(prs_list_lock);
}
Пример #11
0
static void waitpid_listener(int pid, int exited, int exit_code, int signal, int event_code, int syscall, void * args) {
    if (exited) {
        ChildProcess * prs = find_process(pid);
        if (prs) {
            if (signal != 0) prs->exit_code = -signal;
            else prs->exit_code = exit_code;
            process_exited(prs);
        }
    }
}
Пример #12
0
/*
   Request:
      MUST NOT have extras.
      MUST have key.
      MUST have value.
*/
ST_RES *cmd_code_load(CONN *conn, ST_REQ *req, ST_RES *res) {
	if(req->extras_sz || !req->key_sz || !req->value_sz)
		return(set_error_code(res, MEMCACHE_STATUS_INVALID_ARGUMENTS, NULL));
	
	if(CONFIG(conn)->vx32_disabled) {
		return(set_error_code(res, MEMCACHE_STATUS_UNKNOWN_COMMAND, "Command disabled by configuration"));
	}
	
	if(NULL != find_process(req->key, req->key_sz))
		return(set_error_code(res, MEMCACHE_STATUS_KEY_EXISTS, NULL));	

	int r;
	char c_file[1024];
	char elf_file[1024];
	char keyprefix[32];
	key_escape(keyprefix, sizeof(keyprefix), req->key, req->key_sz);
	keyprefix[MIN(req->key_sz, sizeof(keyprefix)-1)] = '\0'; // make it reasonably short
	snprintf(c_file, sizeof(c_file), "%s/plugin-%s.c", CONFIG(conn)->tmpdir, keyprefix);
	snprintf(elf_file, sizeof(elf_file), "%s/plugin-%s.elf", CONFIG(conn)->tmpdir, keyprefix);
	
	res->value = res->buf;
	
	r = write_file(c_file, req->value, req->value_sz);
	if(0 != r) { // never
		res->status = MEMCACHE_STATUS_ITEM_NOT_STORED;
		res->value_sz += snprintf(&res->value[res->value_sz], res->buf_sz - res->value_sz, "Error while saving file: %s", strerror(errno));
		return(res);
	}
	
	if(0 != process_compile(CONFIG(conn), c_file, elf_file, res->value, res->buf_sz, (int*)&res->value_sz)) {
		res->status = MEMCACHE_STATUS_ITEM_NOT_STORED;
		return(res);
	}
	res->value_sz = MIN(res->value_sz, 4096); // no more than 4k logs
	res->value[res->value_sz++] = '\n';
	res->value[res->value_sz++] = '\n';
	
	struct process *process = process_new(conn, req->key, req->key_sz);
	log_warn("#%p: loaded code", process);
	r = process_load(process, elf_file);
	if(0 != r) { // never
		process_free(process);
		res->value_sz += snprintf(&res->value[res->value_sz], res->buf_sz - res->value_sz, "Error while loading the binary");
		res->status = MEMCACHE_STATUS_ITEM_NOT_STORED;
		return(res);
	}
	if(0 != process_run(conn, process)) {
		process_free(process);
		res->value_sz += snprintf(&res->value[res->value_sz], res->buf_sz - res->value_sz, "Error while running the binary");
		res->status = MEMCACHE_STATUS_ITEM_NOT_STORED;
		return(res);
	}
	res->status = MEMCACHE_STATUS_OK;
	return res;
}
Пример #13
0
void cprocess_tree::print_process_tree(_In_ const wchar_t* root_process_name)
{
	_ASSERTE(NULL != root_process_name);
	if (NULL == root_process_name) { return; }

	DWORD pid = find_process(root_process_name);
	if (0 != pid)
	{
		print_process_tree(pid);
	}
}
Пример #14
0
static struct process_val_t*
find_current_process(void)
{
  u32 hash;
  struct process_key_t process_key;

  process_key.tgid = get_current()->tgid;
  hash = jhash(&process_key, sizeof(process_key), 0);

  return find_process(&process_key, hash);
}
Пример #15
0
int main(int argc, char *argv[])
{
	/* Check if watchdog is running ... */
	if( (argc > 1) && (strcmp(argv[1], "running") == 0) )
	{
		return (find_process(BINARY) == -1);
	}

	/* Start daemon */
	return do_daemon();
}
Пример #16
0
/*删除进程,归还分配的存储空间,并删除描述该进程内存分配的节点*/
void kill_process(){
    struct allocated_block *ab;
    int pid;
    printf("Kill Process, pid=");
    scanf("%d", &pid);
    ab=find_process(pid);
    if(ab!=NULL){
        free_mem(ab); /*释放ab所表示的分配区*/
        dispose(ab);  /*释放ab数据结构节点*/
    }
}
Пример #17
0
static void write_context(OutputStream * out, int pid) {
    Context * ctx = context_find_from_pid(pid);
    ChildProcess * prs = find_process(pid);

    write_stream(out, '{');

    json_write_string(out, "Name");
    write_stream(out, ':');
    json_write_string(out, prs ? prs->name : pid2id(pid, 0));
    write_stream(out, ',');

    json_write_string(out, "CanTerminate");
    write_stream(out, ':');
    json_write_boolean(out, 1);
    write_stream(out, ',');

    if (ctx != NULL) {
        json_write_string(out, "Attached");
        write_stream(out, ':');
        json_write_boolean(out, 1);
        write_stream(out, ',');
    }

    if (prs != NULL) {
        if (*prs->inp_id) {
            json_write_string(out, "StdInID");
            write_stream(out, ':');
            json_write_string(out, prs->inp_id);
            write_stream(out, ',');
        }
        if (*prs->out_id) {
            json_write_string(out, "StdOutID");
            write_stream(out, ':');
            json_write_string(out, prs->out_id);
            write_stream(out, ',');
        }
        if (*prs->err_id) {
            json_write_string(out, "StdErrID");
            write_stream(out, ':');
            json_write_string(out, prs->err_id);
            write_stream(out, ',');
        }
    }

    json_write_string(out, "ID");
    write_stream(out, ':');
    json_write_string(out, pid2id(pid, 0));

    write_stream(out, '}');
}
Пример #18
0
/*
   Request:
      MUST NOT have extras.
      MUST have key.
      MUST NOT have value.
*/
ST_RES *cmd_code_check(CONN *conn, ST_REQ *req, ST_RES *res) {
	if(req->extras_sz || !req->key_sz || req->value_sz)
		return(set_error_code(res, MEMCACHE_STATUS_INVALID_ARGUMENTS, NULL));
	
	if(CONFIG(conn)->vx32_disabled) {
		return(set_error_code(res, MEMCACHE_STATUS_UNKNOWN_COMMAND, "Command disabled by configuration"));
	}
	
	struct process *process = find_process(req->key, req->key_sz);
	if(NULL == process)
		return(set_error_code(res, MEMCACHE_STATUS_KEY_NOT_FOUND, NULL));
	
	return(set_error_code(res, MEMCACHE_STATUS_KEY_EXISTS, NULL));
}
Пример #19
0
/* finds the pgid of a terminated child process */
pid_t find_terminated_pgid (pid_t pid, job *first_job)
{
    job *j = first_job;
    process *p = j->first_process;
    while (j != NULL) {
        if ((p = find_process(pid, j->first_process)) != NULL) {  /* found! */
            //printf("found pgid!\n");
            return j->pgid;
        }
        j = j->next;
    }
    //printf("can't find pgid\n");
    return 0;
}
Пример #20
0
/*
 * Module ioctl interface.
 */
long lttngprofile_module_ioctl(
    struct file *file, unsigned int cmd, unsigned long arg)
{
  u32 hash;
  struct process_key_t key;
  struct process_val_t *val;
  struct lttngprofile_module_msg msg;
  struct task_struct *task = get_current();
  int ret = 0;
  void __user *umsg = (void *) arg;

  if (cmd != LTTNGPROFILE_MODULE_IOCTL)
    return -ENOIOCTLCMD;

  if (copy_from_user(&msg, umsg, sizeof(struct lttngprofile_module_msg)))
    return -EFAULT;

  key.tgid = task->tgid;
  hash = jhash(&key, sizeof(key), 0);

  switch(msg.cmd) {
  case LTTNGPROFILE_MODULE_REGISTER:
    /* check if already registered */
    rcu_read_lock();
    val = find_process(&key, hash);
    if (val) {
      rcu_read_unlock();
      break;
    }
    rcu_read_unlock();
    /* do registration */
    val = kzalloc(sizeof(struct process_val_t), GFP_KERNEL);
    val->tgid = key.tgid;
    val->latency_threshold = msg.latency_threshold;
    hash_add_rcu(process_map, &val->hlist, hash);
    printk("lttngprofile_module_ioctl register %d\n", task->tgid);
    break;
  case LTTNGPROFILE_MODULE_UNREGISTER:
    process_unregister(task->tgid);
    break;
  default:
    ret = -ENOTSUPP;
    break;
  }

  return ret;
}
Пример #21
0
int set_priority(int pid, int priority){
	struct process_control_block *temp;
	if (scheduler == GROUP){
		return ERROR_WRONG_SCHEDULER;
	}
	else{
		temp = find_process(READY0, pid);
		if (temp == null){
			return ERROR_PROCESS_NOT_EXIST;
		}
		if (priority < 1 || priority > MAX_PRIORITY){
			return ERROR_INVALID_PARAMETER;
		}
		temp->priority = priority;
	}
	return ERROR_SUCCESS;
}
Пример #22
0
static void task_delete_hook(WIND_TCB * tcb) {
    int i;
    ChildProcess * prs;

    semTake(prs_list_lock, WAIT_FOREVER);
    prs = find_process((UINT32)tcb);
    if (prs != NULL) {
        close(ioTaskStdGet(prs->pid, 1));
        close(ioTaskStdGet(prs->pid, 2));
        for (i = 0; i < 2; i++) {
            char pnm[32];
            snprintf(pnm, sizeof(pnm), "/pty/tcf-%0*lx-%d", sizeof(prs->pid) * 2, prs->pid, i);
            ptyDevRemove(pnm);
        }
    }
    semGive(prs_list_lock);
}
Пример #23
0
void process_processes(double cpup_limit, unsigned memory_limit, int maxNProc, char* name){
    PROCTAB* proc  = openproc(PROC_FILLMEM | PROC_FILLUSR | PROC_FILLSTAT | PROC_FILLSTATUS);
    userstats = NULL;
    proc_t proc_info;
    memset(&proc_info, 0, sizeof(proc_info));
    while(readproc(proc, &proc_info) != NULL ) {
        if(strcmp(proc_info.suser,"root") != 0){
            struct cur_process *cpp = find_process(proc_info.tid);
            if(cpp != NULL){
                time_t prev_time = cpp->timestamp;
                time_t cur_time = getCurrentTime();
                double diff_in_seconds = difftime(cur_time,prev_time);
                long unsigned int pid_diff = (proc_info.utime + proc_info.stime) - (cpp->utime + cpp->stime);
                double cpu_percentage = pid_diff / diff_in_seconds;
                unsigned memory = proc_info.vm_rss;

                if(cpup_limit > 0 && (strcmp(cpp->user,name) == 0 || isUserOfGroup(cpp->user,name)))
                    checkCPUPLimit(cpup_limit, cpu_percentage, proc_info.suser, proc_info.cmd, proc_info.tid);
                if(memory_limit >0 && (strcmp(cpp->user,name) == 0 || isUserOfGroup(cpp->user, name)))
                    checkMemoryLimit(memory_limit, memory, proc_info.suser, proc_info.cmd, proc_info.tid );
            }else{
                //printf("No Old process found \n");
            }

            struct cur_process *cp = malloc(sizeof(struct cur_process));
            cp->pid = proc_info.tid;
            cp->cutime = proc_info.cutime;
            cp->cstime = proc_info.cstime;
            cp->utime = proc_info.utime;
            cp->stime = proc_info.stime;
            cp->user = proc_info.suser;
            cp->command = proc_info.cmd;
            cp->vm_size = proc_info.vm_rss;
            cp->group = proc_info.rgroup;
            cp->timestamp = getCurrentTime();
            add_process(cp);

            //printf("Group Name %s \n", proc_info.fgroup);
            if(maxNProc > 0 && (strcmp(cp->user,name) == 0 || isUserOfGroup(cp->user,name)))
                countAndValidateNProc(proc_info.suser, maxNProc);
            //printf("%5d\t%20s:\t%5lld\t%5lu\t%s\n",proc_info.tid, proc_info.cmd, proc_info.utime + proc_info.stime, proc_info.vm_size, proc_info.suser);
        }
    }
    closeproc(proc);
}
Пример #24
0
/*
 * Utility functions.
 */
static void process_unregister(pid_t tgid)
{
  u32 hash;
  struct process_key_t key;
  struct process_val_t *val;

  key.tgid = tgid;
  hash = jhash(&key, sizeof(key), 0);

  rcu_read_lock();
  val = find_process(&key, hash);
  if (val) {
    hash_del_rcu(&val->hlist);
    call_rcu(&val->rcu, free_process_val_rcu);
    printk("lttngprofile unregister process %d\n", tgid);
  }
  rcu_read_unlock();
}
Пример #25
0
static void work_signals (BProcessManager *o)
{
    // read exit status with waitpid()
    int status;
    pid_t pid = waitpid(-1, &status, WNOHANG);
    if (pid <= 0) {
        return;
    }
    
    // schedule next waitpid
    BPending_Set(&o->wait_job);
    
    // find process
    BProcess *p = find_process(o, pid);
    if (!p) {
        BLog(BLOG_DEBUG, "unknown child %p");
    }
    
    if (WIFEXITED(status)) {
        uint8_t exit_status = WEXITSTATUS(status);
        
        BLog(BLOG_INFO, "child %"PRIiMAX" exited with status %"PRIu8, (intmax_t)pid, exit_status);
        
        if (p) {
            call_handler(p, 1, exit_status);
            return;
        }
    }
    else if (WIFSIGNALED(status)) {
        int signo = WTERMSIG(status);
        
        BLog(BLOG_INFO, "child %"PRIiMAX" exited with signal %d", (intmax_t)pid, signo);
        
        if (p) {
            call_handler(p, 0, 0);
            return;
        }
    }
    else {
        BLog(BLOG_ERROR, "unknown wait status type for pid %"PRIiMAX" (%d)", (intmax_t)pid, status);
    }
}
Пример #26
0
/* TODO: d'après POSIX, kill(-1, sig) doit envoyer le signal à tous les processus possibles... */
SYSCALL_HANDLER3(sys_kill, int pid, int signum, int* ret)
{	
	process_t* process = find_process(pid);
	
	int retour = -1;
	
	if(process != NULL)
	{
		retour = sigaddset( &(process->signal_data.pending_set), signum );
		
		klog("%d sending signal %s(%d) to pid %d.", get_current_process()->pid, signal_names[signum], signum, pid);
	}
	else
	{
		kerr("Process not found (%d).", pid);
	}
	
	if(ret!=NULL)
		*ret = retour;
}
Пример #27
0
int manage_process(tok_t arg[], bool foreground) {
  process *p;
  pid_t pid = 0;
  if (arg[0]) pid = (pid_t)atoi(arg[0]);
  p = find_process(pid);  
  if (!p) {
    printf("No such process: ");
    if (pid == 0) printf("most recently launched.\n");
    else printf("%d.\n", pid);
  } else {
    p->stopped = false;
    if (foreground) {
      p->background = false;
      put_process_in_foreground(p, true);
    } else {
      p->background = true;
      put_process_in_background(p, true);
    }
  }
  return 1;
}
Пример #28
0
int wait_for_process(int pid)
{
    int i;
    int status;

    i = find_process(pid);
    if (i < 0) {
        _log("No such process \"%d\"", pid);
        return -1;
    }

    waitpid(procs[i].pid, &status, 0);
    if (WIFEXITED(status))
        _log("%s exited with status %d\n", procs[i].name, WEXITSTATUS(status));
    else if (WIFSIGNALED(status))
        _log("%s received signal %d\n", procs[i].name, WTERMSIG(status));

    /* remove from process list */
    procs[i].pid = -1;
    return status;
}
Пример #29
0
static
KDSTATUS
handle_gdb_read_mem(
    _Out_ DBGKD_MANIPULATE_STATE64* State,
    _Out_ PSTRING MessageData,
    _Out_ PULONG MessageLength,
    _Inout_ PKD_CONTEXT KdContext)
{
    State->ApiNumber = DbgKdReadVirtualMemoryApi;
    State->ReturnStatus = STATUS_SUCCESS; /* ? */
    State->Processor = CurrentStateChange.Processor;
    State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
    if (MessageData)
        MessageData->Length = 0;
    *MessageLength = 0;

#if !MONOPROCESS
    /* Set the TLB according to the process being read. Pid 0 means any process. */
    if ((gdb_dbg_pid != 0) && gdb_pid_to_handle(gdb_dbg_pid) != PsGetCurrentProcessId())
    {
        PEPROCESS AttachedProcess = find_process(gdb_dbg_pid);
        if (AttachedProcess == NULL)
        {
            KDDBGPRINT("The current GDB debug thread is invalid!");
            send_gdb_packet("E03");
            return gdb_receive_and_interpret_packet(State, MessageData, MessageLength, KdContext);
        }
        __writecr3(AttachedProcess->Pcb.DirectoryTableBase[0]);
    }
#endif

    State->u.ReadMemory.TargetBaseAddress = hex_to_address(&gdb_input[1]);
    State->u.ReadMemory.TransferCount = hex_to_address(strstr(&gdb_input[1], ",") + 1);

    /* KD will reply with KdSendPacket. Catch it */
    KdpSendPacketHandler = ReadMemorySendHandler;

    return KdPacketReceived;
}
Пример #30
0
int ksemV(uint8_t key)
{
	int ret = -1;
	sem_t* sem = &semaphores[key];
	
	if (sem->allocated) {
		/* Si la file est vide, on incrémente la valeur, sinon, on débloque le premier processus en attente */

		process_t *proc = NULL;
		while (proc == NULL && sem_fifo_size(&(sem->fifo)) > 0) {
			proc = find_process(sem_fifo_get(&(sem->fifo)));
		}

		if (proc) {
			proc->state = PROCSTATE_RUNNING;
		} else {
			sem->value++;
		}
		ret = 0;
	}
	return ret;
}