示例#1
0
int main(int argc, char *argv[]) {
	int ret;
	workspace_t w;
	workspace_t w1;
	unsigned int *pdata;
	int i;
	pid_t pid;
	
	ret = init_workspace(&w, PA_SIZE, TEST_VM_TYPE_FILE);
	if (ret < 0) {
		printf("init_workspace w error!\n");
		return -1;
	}	
	memset(w.data, 0, w.size);
	
	ret = init_workspace(&w1, PA_SIZE, TEST_VM_TYPE_MEM);
	if (ret < 0) {	
		close(w.fd);	
		printf("init_workspace w1 error!\n");
		return -1;
	}	
	memset(w1.data, 0, w1.size);

	sprintf(w.data, "test");
	sprintf(w1.data, "test");
		
	pid = fork();
	if (pid == 0) {
		printf("\n=========== Child R ==========\n");
		printf("[%-4s]: %s\n", g_vm_type_name[w.type], (char *)w.data);
		printf("[%-4s]: %s\n", g_vm_type_name[w1.type], (char *)w1.data);
		sprintf(w.data, "hello world");
		sprintf(w1.data, "hello world");
		printf("\n=========== Child W ==========\n");
		printf("[%-4s]: %s\n", g_vm_type_name[w.type], (char *)w.data);
		printf("[%-4s]: %s\n", g_vm_type_name[w1.type], (char *)w1.data);
	} else {
		wait(NULL);
		printf("\n========== Parent R ==========\n");
		printf("[%-4s]: %s\n", g_vm_type_name[w.type], (char *)w.data);
		printf("[%-4s]: %s\n", g_vm_type_name[w1.type], (char *)w1.data);
		printf("\n");
	}
	
	if (w.fd) {
		close(w.fd);
	}
	
	if (w1.data > 0) {
		free(w1.data);
	}
	 	
	return 0;
}
示例#2
0
/*
** 'exec_new' clears away the program currently in memory. It can also be
** used to alter the amount of memory used by the interpreter in which
** to store and run programs
*/
static void exec_new(void) {
  int32 oldsize, newsize;
  boolean ok;
  if (basicvars.runflags.running) error(ERR_COMMAND);	/* Cannot edit a running program */
  basicvars.current++;
  if (!isateol(basicvars.current)) {	/* New workspace size supplied */
    newsize = get_number();
    check_ateol();
    oldsize = basicvars.worksize;
    release_workspace();	/* Discard horrible, rusty old Basic workspace */
    ok = init_workspace(ALIGN(newsize));	/* Obtain nice, shiny new one */
    if (!ok) {	/* Allocation failed - Should still be a block of the old size available */
      (void) init_workspace(oldsize);
      error(ERR_NOMEMORY);
    }
    error(WARN_NEWSIZE, basicvars.worksize);
  }
  clear_program();
  init_expressions();
}
示例#3
0
static int init_property_area(void)
{
    if (property_area_inited)
        return -1;

    if(__system_property_area_init())
        return -1;

    if(init_workspace(&pa_workspace, 0))
        return -1;

    fcntl(pa_workspace.fd, F_SETFD, FD_CLOEXEC);

    property_area_inited = 1;
    return 0;
}
示例#4
0
static int init_property_area(void)
{
    // 如果已经初始化了就直接返回
    if (property_area_inited)
        return -1;

    if(__system_property_area_init())
        return -1;

    // 初始化workspace,得到shared memory的fd, size, data
    if(init_workspace(&pa_workspace, 0))
        return -1;

    // pa指向shared memory的头,实际就是头信息,并初始化
    fcntl(pa_workspace.fd, F_SETFD, FD_CLOEXEC);

    property_area_inited = 1;
    return 0;
}
示例#5
0
static int init_property_area(void)
{
    prop_area *pa;

    if(pa_info_array)
        return -1;

    if(init_workspace(&pa_workspace, PA_SIZE))
        return -1;

    fcntl(pa_workspace.fd, F_SETFD, FD_CLOEXEC);

    pa_info_array = (void*) (((char*) pa_workspace.data) + PA_INFO_START);

    pa = pa_workspace.data;
    memset(pa, 0, PA_SIZE);
    pa->magic = PROP_AREA_MAGIC;
    pa->version = PROP_AREA_VERSION;

        /* plug into the lib property services */
    __system_property_area__ = pa;
    property_area_inited = 1;
    return 0;
}