static void grow_stack() { int i, space[256]; for(i = 0; i < 256; i++) { space[i] = 0; } if ((char *) &i > stack_lo_addr) { grow_stack(); } }
/* Reads 'size' bytes from file open as fd into buffer. Returns number of bytes actually read - 0 at end of file, or -1 if file could not be read. fd = 0 reads from the keyboard. */ static int sys_read(int fd, void *buffer, unsigned size, struct intr_frame *f) { /* Cannot read from stdout. */ if (fd == STDOUT_FILENO) sys_exit(ERROR); int bytes; void *buf_iter = pg_round_down(buffer); check_fd(fd); check_buffer(buffer, size); lock_acquire(&secure_file); for (; buf_iter <= buffer + size; buf_iter += PGSIZE) { struct spt_entry *entry = get_spt_entry(&thread_current()->supp_pt, buf_iter); if (entry == NULL && should_stack_grow(buf_iter, f->esp)) { grow_stack(buf_iter); } } /* fd = 0 corresponds to reading from stdin. */ if (fd == STDIN_FILENO) { unsigned i; uint8_t keys[size]; /* Make an array of keys pressed. */ for (i = 0; i < size; i++) { keys[i] = input_getc(); } /* Put these keys pressed into the buffer. */ memcpy(buffer, (const void *) keys, size); /* Must have successfully read all bytes we were told to. */ bytes = size; } else { struct file *f = get_file(fd); if (!f) { lock_release(&secure_file); return ERROR; } bytes = file_read(f, buffer, size); } lock_release(&secure_file); return bytes; }
void ensure_stack(JVMState* jvms, uint stk_size) { assert(verify_jvms(jvms), "jvms must match"); int grow_by = (int)stk_size - (int)jvms->stk_size(); if (grow_by > 0) grow_stack(jvms, grow_by); }