/** * meta_stack_tracker_get_stack: * @tracker: a #MetaStackTracker * @windows: location to store list of windows, or %NULL * @n_windows: location to store count of windows, or %NULL * * @windows will contain the most current view we have of the stacking order * of the children of the root window. The returned array contains * everything: InputOnly windows, override-redirect windows, * hidden windows, etc. Some of these will correspond to MetaWindow * objects, others won't. * * Assuming that no other clients have made requests that change * the stacking order since we last received a notification, the * returned list of windows is exactly that you'd get as the * children when calling XQueryTree() on the root window. */ void meta_stack_tracker_get_stack (MetaStackTracker *tracker, Window **windows, int *n_windows) { GArray *stack; if (tracker->queued_requests->length == 0) { stack = tracker->server_stack; } else { if (tracker->predicted_stack == NULL) { GList *l; tracker->predicted_stack = copy_stack ((Window *)tracker->server_stack->data, tracker->server_stack->len); for (l = tracker->queued_requests->head; l; l = l->next) { MetaStackOp *op = l->data; meta_stack_op_apply (op, tracker->predicted_stack); } } stack = tracker->predicted_stack; } if (windows) *windows = (Window *)stack->data; if (n_windows) *n_windows = stack->len; }
void do_fork(){ process_num++; PCB_queue[ process_num].f_pid = w_is_r; //sub -> father PCB_queue[ process_num].process_id = process_num; //copy_fa_Tss update_fa(); restore_flags(); //to fix some stack bug __asm__("pop %cx"); // update fa end PCB_queue[ process_num].tss = PCB_queue[ w_is_r].tss; PCB_queue[ process_num].tss.SP = _sp + 0x1000; PCB_queue[ process_num].tss.AX = 0; PCB_queue[ process_num].tss.Stack_END = PCB_queue[ w_is_r].tss.Stack_END+0x1000; sub_stack = (PCB_queue[ process_num].tss.Stack_END-0x200)/16; fa_stack = (PCB_queue[ w_is_r].tss.Stack_END-0x200)/16; __asm__("mov $0x104,%cx"); copy_stack(); __asm__("pop %cx"); PCB_queue[ process_num].process_status = READY; restore_ax_pid(); __asm__("pop %bx"); __asm__("pop %bx"); __asm__("pop %bx"); __asm__("pop %bx"); __asm__("jmp *%bx"); }
static pid_t do_fork(process_t *parent) { // YOUR CODE HERE! // First, find an empty process descriptor. If there is no empty // process descriptor, return -1. Remember not to use proc_array[0]. // Then, initialize that process descriptor as a running process // by copying the parent process's registers and stack into the // child. Copying the registers is simple: they are stored in the // process descriptor in the 'p_registers' field. Copying the stack // is a little more involved; see the copy_stack function, below. // The child process's registers will be equal to the parent's, with // two differences: // * reg_esp The child process's stack pointer will point into // its stack, rather than the parent's. copy_stack // should arrange this. // * ??????? There is one other difference. What is it? (Hint: // What should sys_fork() return to the child process?) // You need to set one other process descriptor field as well. // Finally, return the child's process ID to the parent. int i; for (i=1; i<16; i++) { if (proc_array[i].p_state==P_EMPTY) { break; } if(i == 15) return -1; } process_t *childproc = &proc_array[i]; childproc->p_state=P_RUNNABLE; childproc->p_registers=parent->p_registers; copy_stack(childproc, parent); childproc->p_registers.reg_eax = 0; childproc->wait_queue=0; return i; }
static pid_t do_fork(process_t *parent) { // YOUR CODE HERE! // First, find an empty process descriptor. If there is no empty // process descriptor, return -1. Remember not to use proc_array[0]. // Then, initialize that process descriptor as a running process // by copying the parent process's registers and stack into the // child. Copying the registers is simple: they are stored in the // process descriptor in the 'p_registers' field. Copying the stack // is a little more involved; see the copy_stack function, below. // The child process's registers will be equal to the parent's, with // two differences: // * reg_esp The child process's stack pointer will point into // its stack, rather than the parent's. copy_stack // should arrange this. // * ??????? There is one other difference. What is it? (Hint: // What should sys_fork() return to the child process?) // You need to set one other process descriptor field as well. // Finally, return the child's process ID to the parent. pid_t pid; for (pid = 1; pid < NPROCS; pid++) { if (proc_array[pid].p_state == P_EMPTY) { memcpy(&(proc_array[pid].p_registers), &(parent->p_registers), sizeof(registers_t)); copy_stack(&(proc_array[pid]), parent); proc_array[pid].p_pid = pid; proc_array[pid].p_registers.reg_eax = 0; proc_array[pid].p_state = P_RUNNABLE; return pid; } } return -1; }
u8 fork() { u8 i; u16 stack; for(i = 0; i < MAX_THREADS; i++) { if(thread_id[i] == TH_ID_UNUSED) break; } if(i == MAX_THREADS) { // thread table is full write_to(SERIAL); printf("\r\ncouldn't fork from thread %c", (u8)thread_id[thread_index]); halt(); } //write_to(SERIAL_DIRECT); //printf("forking from %u to %u\n", thread_index, i); stack = copy_stack(i); // <- new thread starts here... if(i == thread_index) return /*child*/ 1; thread_stack[i] = stack; // ...because of this line thread_id[i] = TH_ID_SOMETHING; return /*parent*/ 0; }
uint64_t change_stack() { uint64_t offset = copy_stack(); // Перемещаем стек asm volatile("add %0, %%rsp\n \ add %0, %%rbp\n" :: "r" (offset)); return offset; }
/* Copy inputs to the internal stack. * This is a shallow copy, no buffers are duplicated here! */ static void group_copy_inputs(bNode *node, bNodeStack **in, bNodeStack *gstack) { bNodeSocket *sock; bNodeStack *ns; int a; for (sock=node->inputs.first, a=0; sock; sock=sock->next, ++a) { if (sock->groupsock) { ns = node_get_socket_stack(gstack, sock->groupsock); copy_stack(ns, in[a]); } } }
/* Copy internal results to the external outputs. */ static void group_copy_outputs(bNode *node, bNodeStack **out, bNodeStack *gstack) { bNodeSocket *sock; bNodeStack *ns; int a; for (sock=node->outputs.first, a=0; sock; sock=sock->next, ++a) { if (sock->groupsock) { ns = node_get_socket_stack(gstack, sock->groupsock); copy_stack(out[a], ns); } } }
static pid_t do_fork(process_t *parent) { // First, find an empty process descriptor. If there is no empty // process descriptor, return -1. Remember not to use proc_array[0]. pid_t index; int stop = 0; for (index = 1; index < NPROCS; index++) { if(proc_array[index].p_state == P_EMPTY) { stop = 1; break; } } if(stop == 0) return -1; // Then, initialize that process descriptor as a running process proc_array[index].p_state = P_RUNNABLE; // by copying the parent process's registers proc_array[index].p_registers = parent-> p_registers; // and stack into the child. copy_stack(&proc_array[index], parent); proc_array[index].p_registers.reg_eax = 0; // Copying the registers is simple: they are stored in the // process descriptor in the 'p_registers' field. Copying the stack // is a little more involved; see the copy_stack function, below. // The child process's registers will be equal to the parent's, with // two differences: // * reg_esp The child process's stack pointer will point into // its stack, rather than the parent's. copy_stack // should arrange this. // * ??????? There is one other difference. What is it? (Hint: // What should sys_fork() return to the child process?) // You need to set one other process descriptor field as well. // Finally, return the child's process ID to the parent. return index; }
static pid_t do_fork(process_t *parent) { // YOUR CODE HERE! // First, find an empty process descriptor. If there is no empty // process descriptor, return -1. Remember not to use proc_array[0]. // Then, initialize that process descriptor as a running process // by copying the parent process's registers and stack into the // child. Copying the registers is simple: they are stored in the // process descriptor in the 'p_registers' field. Copying the stack // is a little more involved; see the copy_stack function, below. // The child process's registers will be equal to the parent's, with // two differences: // * reg_esp The child process's stack pointer will point into // its stack, rather than the parent's. copy_stack // should arrange this. // * ??????? There is one other difference. What is it? (Hint: // What should sys_fork() return to the child process?) // You need to set one other process descriptor field as well. // Finally, return the child's process ID to the parent. int i; int flag = 0; pid_t child_pid; for(i = 1;i<NPROCS;i++) { if(proc_array[i].p_state == P_EMPTY) { //Empty proc found, flag = 1; //set flag and stop iterating. child_pid = i; break; } } if(flag == 0) return -1; proc_array[child_pid].p_registers = parent->p_registers; // set child regs copy_stack(&proc_array[child_pid],parent); // set child stack proc_array[child_pid].p_registers.reg_eax = 0; // set exit code proc_array[child_pid].p_state = P_RUNNABLE; return child_pid; }
static pid_t do_fork(process_t *parent) { // find first open pid, if cycles through to pid=0 then none // are available, return -1 pid_t pid = 1; while (proc_array[pid].p_state != P_EMPTY) { pid = (pid + 1) % NPROCS; if (pid == 0) return -1; } //copy parent process's registers to child proc_array[pid].p_registers = current->p_registers; // copy the parent's stack to the child copy_stack(&proc_array[pid], current); // change eax to be 0 for child process, it will return 0. proc_array[pid].p_registers.reg_eax = 0; // change procstate to runnable for child process proc_array[pid].p_state = P_RUNNABLE; // return child's pid to parent return pid; // YOUR CODE HERE! // First, find an empty process descriptor. If there is no empty // process descriptor, return -1. Remember not to use proc_array[0]. // Then, initialize that process descriptor as a running process // by copying the parent process's registers and stack into the // child. Copying the registers is simple: they are stored in the // process descriptor in the 'p_registers' field. Copying the stack // is a little more involved; see the copy_stack function, below. // The child process's registers will be equal to the parent's, with // two differences: // * reg_esp The child process's stack pointer will point into // its stack, rather than the parent's. copy_stack // should arrange this. // * ??????? There is one other difference. What is it? (Hint: // What should sys_fork() return to the child process?) // You need to set one other process descriptor field as well. // Finally, return the child's process ID to the parent. return -1; }
static pid_t do_fork(process_t *parent) { // YOUR CODE HERE! // First, find an empty process descriptor. If there is no empty // process descriptor, return -1. Remember not to use proc_array[0]. // Then, initialize that process descriptor as a running process // by copying the parent process's registers and stack into the // child. Copying the registers is simple: they are stored in the // process descriptor in the 'p_registers' field. Copying the stack // is a little more involved; see the copy_stack function, below. // The child process's registers will be equal to the parent's, with // two differences: // * reg_esp The child process's stack pointer will point into // its stack, rather than the parent's. copy_stack // should arrange this. // * ??????? There is one other difference. What is it? (Hint: // What should sys_fork() return to the child process?) // You need to set one other process descriptor field as well. // Finally, return the child's process ID to the parent. int pos = 1; for(; pos < NPROCS; pos++) { if(proc_array[pos].p_state == P_EMPTY) break; } if(pos == NPROCS) return -1; proc_array[pos].p_pid = pos; proc_array[pos].p_registers = current->p_registers; proc_array[pos].p_state = P_RUNNABLE; copy_stack(&proc_array[pos], current); int stackSize = ((PROC1_STACK_ADDR + parent->p_pid*PROC_STACK_SIZE) - parent->p_registers.reg_esp); proc_array[pos].p_registers.reg_esp = ((PROC1_STACK_ADDR + proc_array[pos].p_pid*PROC_STACK_SIZE) - stackSize); proc_array[pos].p_registers.reg_eax = 0; return proc_array[pos].p_pid; }
/* Copy inputs to the internal stack. * This is a shallow copy, no buffers are duplicated here! */ static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack) { bNodeTree *ngroup = (bNodeTree*)gnode->id; bNode *node; bNodeSocket *sock; bNodeStack *ns; int a; for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_INPUT) { for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { ns = node_get_socket_stack(gstack, sock); if (ns) copy_stack(ns, in[a]); } } } }
/* Copy internal results to the external outputs. */ static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack) { bNodeTree *ngroup = (bNodeTree*)gnode->id; bNode *node; bNodeSocket *sock; bNodeStack *ns; int a; for (node = ngroup->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { ns = node_get_socket_stack(gstack, sock); if (ns) copy_stack(out[a], ns); } break; /* only one active output node */ } } }
void filter(STACK *stream,STACK *integral,STACK *decimal) { STACK temp; init_stack(&temp); while(!is_empty(stream) && (int) peek(stream)!=DECIMAL_PT) push(&temp,pop(stream)); if(is_empty(stream)) copy_stack(&temp,integral); else { pour(decimal,&temp); pop(stream); if(is_empty(stream)) push(integral,0); else while(!is_empty(stream)) push(integral,pop(stream)); } }
static pid_t do_fork(process_t *parent) { // YOUR CODE HERE! // First, find an empty process descriptor. If there is no empty // process descriptor, return -1. Remember not to use proc_array[0]. // Then, initialize that process descriptor as a running process // by copying the parent process's registers and stack into the // child. Copying the registers is simple: they are stored in the // process descriptor in the 'p_registers' field. Copying the stack // is a little more involved; see the copy_stack function, below. // The child process's registers will be equal to the parent's, with // two differences: // * reg_esp The child process's stack pointer will point into // its stack, rather than the parent's. copy_stack // should arrange this. // * ??????? There is one other difference. What is it? (Hint: // What should sys_fork() return to the child process?) // You need to set one other process descriptor field as well. // Finally, return the child's process ID to the parent. //finding availability of processes process_t* avail; int offset=1; while(1){ if(offset==NPROCS) return -1; avail=&(proc_array[offset]); if(avail->p_state==P_EMPTY) break; offset++; } avail->p_registers=parent->p_registers; copy_stack(avail,parent); avail->p_state = P_RUNNABLE; avail->p_registers.reg_eax=0; //avail is a child, reg_eax is the return value of the child return avail->p_pid; }
MetaStackTracker * meta_stack_tracker_new (MetaScreen *screen) { MetaStackTracker *tracker; Window ignored1, ignored2; Window *children; guint n_children; tracker = g_new0 (MetaStackTracker, 1); tracker->screen = screen; tracker->server_serial = XNextRequest (screen->display->xdisplay); XQueryTree (screen->display->xdisplay, screen->xroot, &ignored1, &ignored2, &children, &n_children); tracker->server_stack = copy_stack (children, n_children); XFree (children); tracker->queued_requests = g_queue_new (); return tracker; }