/* **++ ** ROUTINE: netlib___alloc_dnsreq ** ** FUNCTIONAL DESCRIPTION: ** ** Allocates some memory. ** ** RETURNS: cond_value ** ** PROTOTYPE: ** ** netlib___alloc_dnsreq(unsigned int size, void *ptr) ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: None. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib___alloc_dnsreq (struct DNSREQ **dnsreqp) { struct DNSREQ *dnsreq; unsigned int status, fullsize, aststat; BLOCK_ASTS(aststat); if (dnsreqzone == 0) { unsigned int algorithm=LIB$K_VM_FIXED; unsigned int flags=LIB$M_VM_GET_FILL0|LIB$M_VM_EXTEND_AREA; status = lib$create_vm_zone(&dnsreqzone, &algorithm, &DNSREQ_S_DNSREQDEF, &flags); if (!OK(status)) { UNBLOCK_ASTS(aststat); return status; } } if (queue_remove(dnsreqque.head, &dnsreq)) { memset(dnsreq, 0, DNSREQ_S_DNSREQDEF); status = SS$_NORMAL; } else status = lib$get_vm(&DNSREQ_S_DNSREQDEF, &dnsreq, &dnsreqzone); if (OK(status)) *dnsreqp = dnsreq; UNBLOCK_ASTS(aststat); return status; } /* netlib___alloc_dnsreq */
// arr.push(v); bool push(value value) { pinned pv(get_vm(),value); assert(is_set()); unsigned l = length(); val = ni()->set_array_size(vm,val,l + 1); return ni()->set_elem(vm,val,l,pv); }
static void *sqlite3MemMalloc(int nByte){ long *pNew, szNew = nByte + sizeof(int); if( $VMS_STATUS_SUCCESS(lib$get_vm(&szNew, &pNew, &_sqliteZone_)) ){ *pNew = nByte; return ++pNew; } return 0; }
/* **++ ** ROUTINE: netlib___get_nameservers ** ** FUNCTIONAL DESCRIPTION: ** ** Obtains the list of DNS servers configured for this TCP/IP package. ** ** RETURNS: int ** ** PROTOTYPE: ** ** NETLIB___GET_NAMESERVERS nsq ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: ** ** ** SIDE EFFECTS: None. ** **-- */ int netlib___get_nameservers (QUEUE *nsq) { struct NAMESERVER *ns; struct INADDRDEF a; struct CTX *tmpctx; struct dsc$descriptor dsc, lognamdsc; ITMLST lnmlst[2]; char name[256], lognam[256], *cp, *anchor; unsigned int status, size, maxidx; unsigned short namlen; int index, i, remain; int v5, count; static unsigned int one = 1; tmpctx = 0; count = 0; ITMLST_INIT(lnmlst[0], LNM$_STRING, sizeof(name), name, &namlen); ITMLST_INIT(lnmlst[1], 0, 0, 0, 0); INIT_SDESC(lognamdsc, 0, lognam); for (v5 = 1; (count == 0) && (v5 >= 0); v5--) { for (index = 0; index <= 16; index++) { lognamdsc.dsc$w_length = sprintf(lognam, (v5 == 0 ? "UCX$BIND_SERVER%03d" : "TCPIP$BIND_SERVER%03d"), index); status = sys$trnlnm(0, &nameserver_tabnam, &lognamdsc, 0, lnmlst); if (!OK(status) || namlen == 0) continue; for (anchor = name, remain = namlen; remain > 0; remain -= i+1, anchor = cp+1) { cp = memchr(anchor, ',', remain); if (cp == 0) i = remain; else i = cp - anchor; INIT_SDESC(dsc, i, anchor); if (!OK(netlib_strtoaddr(&dsc, &a))) { if (tmpctx == 0) { if (!OK(netlib_socket(&tmpctx, 0, 0))) continue; } if (!OK(netlib_name_to_address(&tmpctx, 0, &dsc, &a, &one, 0, 0, 0, 0))) continue; } size = sizeof(struct NAMESERVER); status = lib$get_vm(&size, &ns); if (!OK(status)) break; ns->addr = a; queue_insert(ns, nsq->tail); count += 1; } } } if (tmpctx != 0) netlib_close(&tmpctx); return count; } /* netlib___get_nameservers */
/* **++ ** ROUTINE: get_spd ** ** FUNCTIONAL DESCRIPTION: ** ** Allocates an SPD data cell. ** ** RETURNS: pointer to SPD structure. ** ** PROTOTYPE: ** ** get_spd(int bufsize) ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: ** non-0: Success. ** 0: Allocation failed. ** ** SIDE EFFECTS: None. ** **-- */ static struct SPD *get_spd (int bufsize) { unsigned int cellsize, status; struct SPD *spd; cellsize = bufsize + sizeof(struct SPD); status = lib$get_vm(&cellsize, &spd); if (!OK(status)) return 0; spd->len = bufsize; return spd; } /* get_spd */
/* **++ ** ROUTINE: netlib___alloc_ior ** ** FUNCTIONAL DESCRIPTION: ** ** Allocates some memory. ** ** RETURNS: cond_value ** ** PROTOTYPE: ** ** netlib___alloc_ior(unsigned int size, void *ptr) ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: None. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib___alloc_ior (struct IOR **iorp) { struct IOR *ior; unsigned int status, fullsize, aststat; BLOCK_ASTS(aststat); if (iorzone == 0) { unsigned int algorithm=LIB$K_VM_FIXED; unsigned int flags=LIB$M_VM_GET_FILL0|LIB$M_VM_EXTEND_AREA; int i; status = lib$create_vm_zone(&iorzone, &algorithm, &IOR_S_IORDEF, &flags); if (!OK(status)) { UNBLOCK_ASTS(aststat); return status; } for (i = 0; i < 8; i++) { if (!OK(lib$get_vm(&IOR_S_IORDEF, &ior))) break; queue_insert(ior, iorque.tail); } } if (queue_remove(iorque.head, &ior)) { memset(ior, 0, IOR_S_IORDEF); *iorp = ior; status = SS$_NORMAL; } else status = lib$get_vm(&IOR_S_IORDEF, &ior, &iorzone); if (OK(status)) *iorp = ior; UNBLOCK_ASTS(aststat); return status; } /* netlib___alloc_ior */
/* **++ ** ROUTINE: netlib___alloc_ctx ** ** FUNCTIONAL DESCRIPTION: ** ** Allocates some memory. ** ** RETURNS: cond_value ** ** PROTOTYPE: ** ** netlib___alloc_ctx(unsigned int size, void *ptr) ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: None. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib___alloc_ctx (struct CTX **ctxp, unsigned int specsize) { struct CTX *ctx; unsigned int status, fullsize, aststat; BLOCK_ASTS(aststat); if (netlib_synch_efn == 0xffffffff) { status = lib$get_ef(&netlib_synch_efn); if (!OK(status)) { UNBLOCK_ASTS(aststat); return status; } } if (netlib_asynch_efn == 0xffffffff) { status = lib$get_ef(&netlib_asynch_efn); if (!OK(status)) { UNBLOCK_ASTS(aststat); return status; } } fullsize = specsize + CTX_S_CTXDEF; if (ctxzone == 0) { unsigned int algorithm=LIB$K_VM_FIXED; unsigned int flags=LIB$M_VM_GET_FILL0|LIB$M_VM_EXTEND_AREA; status = lib$create_vm_zone(&ctxzone, &algorithm, &fullsize, &flags); if (!OK(status)) { UNBLOCK_ASTS(aststat); return status; } } status = lib$get_vm(&fullsize, &ctx, &ctxzone); if (OK(status)) { ctx->specctx = ctx + 1; ctx->specctx_size = specsize; if (!OK(status)) lib$free_vm(&fullsize, &ctx, &ctxzone); *ctxp = ctx; } UNBLOCK_ASTS(aststat); return status; } /* netlib___alloc_ctx */
/* **++ ** ROUTINE: netlib_connect_by_name ** ** FUNCTIONAL DESCRIPTION: ** ** Connects to a remote host/port by name. The name is looked up, ** then a connection is tried to each address until a connection is ** established, or we run out of addresses. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** NETLIB_CONNECT_BY_NAME ctxptr, namdsc, port [,iosb] [,astadr] [,astprm] ** ** ctxptr: NETLIB context, longword (unsigned), read only, by reference ** namdsc: char_string, character string, read only, by descriptor ** port: word_unsigned, word (unsigned), read only, by reference ** iosb: io_status_block, quadword (unsigned), write only, by reference ** astadr: ast_procedure, procedure value, call, by reference ** astprm: user_arg, longword (unsigned), read only, by value ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: ** SS$_NORMAL: normal successful completion ** SS$_INSFARG: not enough arguments ** SS$_BADPARAM: invalid argument ** Codes from LIB$GET_VM, LIB$ANALYZE_SDESC, and ** other NETLIB network status codes. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib_connect_by_name (struct CTX **xctx, struct dsc$descriptor *dsc, unsigned short *port, struct NETLIBIOSBDEF *iosb, void (*astadr)(), void *astprm) { struct Connect_Context *con; struct CTX *ctx; struct INADDRDEF addr; unsigned int status, size; unsigned short namlen; char *namp; int argc; /* ** Verify the arguments */ VERIFY_CTX(xctx, ctx); SETARGCOUNT(argc); if (argc < 3) return SS$_INSFARG; if (dsc == 0 || port == 0) return SS$_BADPARAM; /* ** Allocate and fill in the connection context */ status = lib$analyze_sdesc(dsc, &namlen, &namp); if (!OK(status)) return status; size = namlen + sizeof(struct Connect_Context); status = lib$get_vm(&size, &con); if (!OK(status)) return status; memset(con, 0, size); con->name = (char *) (con + 1); memcpy(con->name, namp, namlen); INIT_SDESC(con->dsc, namlen, con->name); con->ctx = ctx; con->sin.sin_w_family = NETLIB_K_AF_INET; con->sin.sin_w_port = netlib_word_swap(*port); con->ctxsize = size; size = sizeof(con->htadrlst)/sizeof(con->htadrlst[0]); if (argc > 3 && iosb != 0) con->user_iosb = iosb; if (argc > 4 && astadr != 0) { con->astadr = astadr; if (argc > 5) con->astprm = astprm; } /* ** If they provided us with a dotted-decimal IP address, fake ** out do_connect to make it look like we looked up the address ** via DNS. */ if (OK(netlib_strtoaddr(&con->dsc, &addr))) { con->iosb.iosb_w_status = SS$_NORMAL; con->nsadrcnt = 1; con->nsadrlst[0] = addr; if (con->astadr != 0) return sys$dclast(do_connect, con, 0); return do_connect(con); } /* ** Make lookup via host table synchronous and in main-line thread ** because we can't call it from AST level for all packages */ status = netlib_name_to_address(&con->ctx, &useht, &con->dsc, con->htadrlst, &size, &con->htadrcnt, &con->iosb); if (!OK(status)) con->htadrcnt = 0; size = sizeof(con->nsadrlst)/sizeof(con->nsadrlst[0]); /* ** For an asynch call, do the DNS lookup and have DO_CONNECT invoked ** as the AST routine */ if (argc > 4 && astadr != 0) { status = netlib_name_to_address(&con->ctx, &usedns, &con->dsc, con->nsadrlst, &size, &con->nsadrcnt, &con->iosb, do_connect, con); if (!OK(status)) lib$free_vm(&con->ctxsize, &con); return status; } /* ** Synchronous call: do the DNS lookup... */ status = netlib_name_to_address(&con->ctx, &usedns, &con->dsc, con->nsadrlst, &size, &con->nsadrcnt, &con->iosb); /* ** ... if it failed, fall back on the host table lookup info we got */ if (!OK(status)) { con->iosb.iosb_w_status = SS$_ENDOFFILE; con->nsadrcnt = 0; } /* ** Just call DO_CONNECT to complete this for us */ return do_connect(con); } /* netlib_connect_by_name */
// var v = obj["key"]; obj["key"] = v; bool set(const WCHAR* key, value v) { assert(is_set()); pinned pv(get_vm(),v); value k = v_string(get_vm(),key); return ni()->set_prop(vm,val,k,pv); }
/* **++ ** ROUTINE: netlib___dns_init ** ** FUNCTIONAL DESCRIPTION: ** ** Initializes an internal DNS resolver context. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** netlib___dns_init(struct CTX *ctx) ** ** ctx: NETLIB context, modify, by reference. ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: See code. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib___dns_init (struct CTX *ctx) { struct DOMAIN *dom; unsigned int status; ITMLST lnmlst[3]; int i, maxidx; unsigned int size; unsigned short buflen; char buf[256]; int did_tmo; static unsigned int socktype = NETLIB_K_TYPE_DGRAM; static unsigned int ctxsize = sizeof(struct DNSCTX); static $DESCRIPTOR(tabnam, "LNM$FILE_DEV"); static $DESCRIPTOR(lognam, "NETLIB_SEARCH_DOMAIN"); static $DESCRIPTOR(tmolnm, "NETLIB_DNS_QUERY_TIMEOUT"); /* ** Allocate the DNS resolver context */ status = lib$get_vm(&ctxsize, &ctx->dnsctx); if (!OK(status)) return status; INIT_QUEUE(ctx->dnsctx->nsq); INIT_QUEUE(ctx->dnsctx->domq); /* ** Get the list of name servers we're supposed to contact */ if (netlib___get_nameservers(&ctx->dnsctx->nsq) == 0) { lib$free_vm(&ctxsize, &ctx->dnsctx); ctx->dnsctx = 0; ctx->flags |= CTX_M_NO_DNS; return SS$_UNSUPPORTED; } /* ** Get the list of NETLIB search domains, or the package-specific ** ones. */ ITMLST_INIT(lnmlst[0], LNM$_MAX_INDEX, sizeof(maxidx), &maxidx, 0); ITMLST_INIT(lnmlst[1], 0, 0, 0, 0); if (OK(sys$trnlnm(0, &tabnam, &lognam, 0, lnmlst))) { ITMLST_INIT(lnmlst[0], LNM$_INDEX, sizeof(i), &i, 0); ITMLST_INIT(lnmlst[1], LNM$_STRING, sizeof(buf), buf, &buflen); ITMLST_INIT(lnmlst[2], 0, 0, 0, 0); for (i = 0; i <= maxidx; i++) { if (OK(sys$trnlnm(0, &tabnam, &lognam, 0, lnmlst)) && buflen != 0) { size = buflen + sizeof(struct DOMAIN); if (OK(lib$get_vm(&size, &dom))) { dom->length = buflen; memcpy(dom->name, buf, buflen); dom->name[buflen] = '\0'; queue_insert(dom, ctx->dnsctx->domq.tail); } } } } else if (netlib___get_domain(buf, sizeof(buf), &buflen)) { char *cp, *cp1; int remain; cp = buf; remain = buflen; /* ** A search domain must have at least two parts, to avoid the ".com.edu" ** problem, which is why we check to make sure that the remaining domain ** string has at least one dot. */ while (remain > 0) { cp1 = memchr(cp, '.', remain); if (cp1 == 0) break; size = remain + sizeof(struct DOMAIN); if (OK(lib$get_vm(&size, &dom))) { dom->length = remain; memcpy(dom->name, cp, remain); dom->name[remain] = '\0'; queue_insert(dom, ctx->dnsctx->domq.tail); } remain -= (cp1 - cp) + 1; cp = cp1 + 1; } } did_tmo = 0; ITMLST_INIT(lnmlst[0], LNM$_STRING, sizeof(buf), buf, &buflen); ITMLST_INIT(lnmlst[1], 0, 0, 0, 0); if (OK(sys$trnlnm(0, &tabnam, &tmolnm, 0, lnmlst))) { struct dsc$descriptor dsc; INIT_SDESC(dsc, buflen, buf); /* * Make sure it's a delta time value */ if (OK(sys$bintim(&dsc, &ctx->dnsctx->timeout))) did_tmo = (int) ctx->dnsctx->timeout.long2 < 0; } if (!did_tmo) sys$bintim(&default_timeout, &ctx->dnsctx->timeout); ctx->dnsctx->retry_count = 4; return SS$_NORMAL; } /* netlib___dns_init */
/* * Construct a striped mapping. * <number of stripes> <chunk size> [<dev_path> <offset>]+ */ static int vm_ctr(struct dm_target *ti, unsigned int argc, char **argv) { struct vm_c *vc; sector_t width, tmp_len; uint32_t vms; uint32_t chunk_size; int r; unsigned long long i; if (argc < 2) { ti->error = "Not enough arguments"; return -EINVAL; } if (kstrtouint(argv[0], 10, &vms) || !vms) { ti->error = "Invalid stripe count"; return -EINVAL; } if (kstrtouint(argv[1], 10, &chunk_size) || !chunk_size) { ti->error = "Invalid chunk_size"; return -EINVAL; } width = ti->len; if (sector_div(width, vms)) { ti->error = "Target length not divisible by " "number of stripes"; return -EINVAL; } tmp_len = width; if (sector_div(tmp_len, chunk_size)) { ti->error = "Target length not divisible by " "chunk size"; return -EINVAL; } /* * Do we have enough arguments for that many stripes ? */ if (argc != (2 + 2 * vms)) { ti->error = "Not enough destinations " "specified"; return -EINVAL; } vc = alloc_context(vms); if (!vc) { ti->error = "Memory allocation for striped context " "failed"; return -ENOMEM; } INIT_WORK(&vc->trigger_event, trigger_event); /* Set pointer to dm target; used in trigger_event */ vc->ti = ti; vc->vms = vms; vc->vm_width = width; if (vms & (vms - 1)) vc->vms_shift = -1; else vc->vms_shift = __ffs(vms); r = dm_set_target_max_io_len(ti, chunk_size); if (r) { kfree(vc); return r; } ti->num_flush_bios = vms; ti->num_discard_bios = vms; ti->num_write_same_bios = vms; vc->chunk_size = chunk_size; if (chunk_size & (chunk_size - 1)) vc->chunk_size_shift = -1; else vc->chunk_size_shift = __ffs(chunk_size); /* * Get the stripe destinations. */ for (i = 0; i < vms; i++) { argv += 2; r = get_vm(ti, vc, i, argv); if (r < 0) { ti->error = "Couldn't parse stripe destination"; while (i--) dm_put_device(ti, vc->vm[i].dev); kfree(vc); return r; } atomic_set(&(vc->vm[i].error_count), 0); } /*volume manager initialize*/ vc->wp = 0;//////current 0 is NVMe //vc->wp = 1; vc->ws = kmalloc(sizeof(unsigned long long) * vc->vms, GFP_KERNEL); for(i = 0; i<vc->vms; i++) vc->ws[i] = 0; vc->gp_list = kmalloc(sizeof(char) * vc->vms, GFP_KERNEL); vc->num_gp = 0; vc->io_client = dm_io_client_create(); vc->gs = NULL; vc->overload = 0; for(i=0; i<vc->vms; i++) vc->gp_list[i] = Clean_Weight;//0 is clean { unsigned long long tem, disk_size; tem = 0; for(i = 0; i<vms; i++){ struct block_device *cur_bdev = vc->vm[i].dev->bdev; vc->vm[i].end_sector = i_size_read(cur_bdev->bd_inode)>>9;//unit of sector printk("vm%llu start_sector %llu, end_sector %llu, target_offset %llu\n", i, (unsigned long long) vc->vm[i].physical_start, (unsigned long long) vc->vm[i].end_sector, (unsigned long long)dm_target_offset(ti, vc->ws[i])); disk_size = vc->vm[i].end_sector * 512; do_div(disk_size, (unsigned long long) vc->vm[i].dev->bdev->bd_block_size); tem += disk_size; } vc->num_entry = tem;//num entry is blk num } printk("num entry is %llu, node size is %lu, req mem is %llu\n", vc->num_entry, sizeof(struct flag_nodes), sizeof(struct flag_nodes) * vc->num_entry); //flag set initialize vc->fs = (struct flag_set *) kmalloc(sizeof(struct flag_set), GFP_KERNEL); vc->fs->node_buf = kmem_cache_create("dirty_data_buf", sizeof(struct flag_nodes), 0, (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD), NULL); vc->fs->table = (struct flag_nodes **)vmalloc(sizeof(struct flag_nodes*) * vc->num_entry); for(i=0; i<vc->num_entry; i++){ //vc->fs->table[i] = NULL;//late alloc code vc->fs->table[i] = kmem_cache_alloc(vc->fs->node_buf, GFP_KERNEL);//pre alloc start vc->fs->table[i]->msector = -1; vc->fs->table[i]->wp = -1;//pre alloc end } vc->num_map_block = 0;//vc->num_entry * sizeof(struct flag_nodes) / 4096; //vc->ws[0] += vc->num_map_block; vc->fs->reverse_table = vmalloc(sizeof(struct reverse_nodes*) * vc->vms); vc->d_num = kmalloc(sizeof(unsigned long long) * vc->vms, GFP_KERNEL); for(i=0; i<vc->vms; i++){ unsigned long long j; unsigned long long r_table_size = (vc->vm[i].end_sector + 7); unsigned long long phy_sect = vc->vm[i].physical_start; do_div(phy_sect, 8); do_div(r_table_size, 8); printk("r_table_size = %llu\n", r_table_size); vc->vm[i].num_dirty = r_table_size - phy_sect; vc->d_num[i] = vc->vm[i].num_dirty; vc->fs->reverse_table[i] = vmalloc(sizeof(struct reverse_nodes) * r_table_size); for(j=0; j<r_table_size; j++){ vc->fs->reverse_table[i][j].index = -1; vc->fs->reverse_table[i][j].dirty = 1; vc->fs->reverse_table[i][j].size = -1; } //printk("%u's first ptr is %p, final ptr is %p\n", i, &(vc->fs->reverse_table[i][0]), &(vc->fs->reverse_table[i][j])); } for(i=0; i<vc->vms; i++){ unsigned int minor = atom(vc->vm[i].dev->name); unsigned int major = atoj(vc->vm[i].dev->name); printk("dev name is %s\t", vc->vm[i].dev->name); if(major != 2600) vc->vm[i].main_dev = minor >> minor_shift; else vc->vm[i].main_dev = minor - 1; vc->vm[i].maj_dev = major; printk("main %u, maj %u\n", vc->vm[i].main_dev, vc->vm[i].maj_dev); }
/* **++ ** ROUTINE: netlib_name_to_address ** ** FUNCTIONAL DESCRIPTION: ** ** Uses the UCX IO$_ACPCONTROL $QIO function to translate a host ** name into one or more IP addresses. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** NETLIB_NAME_TO_ADDRESS ctx, which, namdsc, addrlist, listsize [,count] [,iosb] [,astadr] [,astprm] ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: ** ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib_name_to_address (struct CTX **xctx, unsigned int *whichp, struct dsc$descriptor *namdsc, struct INADDRDEF *addrlist, unsigned int *listsize, unsigned int *count, struct NETLIBIOSBDEF *iosb, void (*astadr)(), void *astprm) { struct CTX *ctx; struct INADDRDEF addr; struct NETLIBIOSBDEF myiosb; struct HOSTENT hostent; unsigned int status, subfunction; ITMLST2 subfdsc; ITMLST2 entdsc; unsigned short helen; int argc; VERIFY_CTX(xctx, ctx); SETARGCOUNT(argc); if (argc < 5) return SS$_INSFARG; if (namdsc == 0 || addrlist == 0 || listsize == 0) return SS$_BADPARAM; if (OK(netlib_strtoaddr(namdsc, &addr))) { addrlist[0] = addr; if (argc > 5 && count != 0) *count = 1; if (argc > 6 && iosb != 0) { iosb->iosb_w_status = SS$_NORMAL; iosb->iosb_w_count = 1; iosb->iosb_l_unused = 0; } if (argc > 7 && astadr != 0) { return sys$dclast(astadr, (argc > 8) ? astprm : 0, 0); } else { return SS$_NORMAL; } } if (argc > 7 && astadr != 0) { struct IOR *ior; GET_IOR(ior, ctx, iosb, astadr, (argc > 8) ? astprm : 0); status = lib$get_vm(&hostent_size, &ior->spec_hostent); if (!OK(status)) { FREE_IOR(ior); return status; } ior->specior.subfunction = (INETACP$C_HOSTENT_OFFSET << 8) | INETACP_FUNC$C_GETHOSTBYNAME; ITMLST2_INIT(subfdsc, 0, sizeof(ior->specior.subfunction), &ior->specior.subfunction); ITMLST2_INIT(entdsc, 0, hostent_size, ior->spec_hostent); ior->spec_useralist = addrlist; ior->spec_length = *listsize; ior->spec_retlen = count; ior->iorflags = IOR_M_COPY_ADDRS; status = sys$qio(netlib_asynch_efn, ctx->chan, IO$_ACPCONTROL, &ior->iosb, io_completion, ior, &subfdsc, namdsc, &ior->specior.fromlen, &entdsc, 0, 0); if (!OK(status)) FREE_IOR(ior); return status; } subfunction = (INETACP$C_HOSTENT_OFFSET << 8) | INETACP_FUNC$C_GETHOSTBYNAME; ITMLST2_INIT(subfdsc, 0, sizeof(subfunction), &subfunction); ITMLST2_INIT(entdsc, 0, hostent_size, &hostent); status = sys$qiow(netlib_synch_efn, ctx->chan, IO$_ACPCONTROL, &myiosb, 0, 0, &subfdsc, namdsc, &helen, &entdsc, 0, 0); if (OK(status)) status = netlib___cvt_status(&myiosb); if (argc > 6 && iosb != 0) netlib___cvt_iosb(iosb, &myiosb); if (OK(status)) { char *base; unsigned int *offlst; int i; base = (char *) &hostent; i = 0; if (hostent.addrlist_offset != 0) { offlst = (unsigned int *) (base+hostent.addrlist_offset); while (i < *listsize && offlst[i] != 0) { addrlist[i] = *(struct INADDRDEF *) (base + offlst[i]); i++; } } if (argc > 5 && count != 0) *count = i; } return status; } /* netlib_name_to_address */
/* **++ ** ROUTINE: sp_open ** ** FUNCTIONAL DESCRIPTION: ** ** Spawns a subprocess, possibly passing it an initial command. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** sp_open(SPHANDLE *ctxpp, struct dsc$descriptor *inicmd, ** unsigned int (*rcvast)(void *), void *rcvastprm); ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: ** SS$_NORMAL: Normal successful completion. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int sp_open (SPHANDLE *ctxpp, void *inicmd, unsigned int (*rcvast)(void *), void *rcvastprm) { SPHANDLE ctx; unsigned int dvi_devnam = DVI$_DEVNAM, dvi_devbufsiz = DVI$_DEVBUFSIZ; unsigned int spawn_flags = CLI$M_NOWAIT|CLI$M_NOKEYPAD; unsigned int status; struct dsc$descriptor inbox, outbox; status = lib$get_vm(&spb_size, &ctx); if (!OK(status)) return status; /* ** Assign the SPHANDLE address for the caller immediately to avoid timing issues with ** WRTATTN AST that passes the ctx as rcvastprm (which sp_once does). */ *ctxpp = ctx; ctx->sendque.head = ctx->sendque.tail = &ctx->sendque; ctx->ok_to_send = 0; /* ** Create the mailboxes we'll be using for I/O with the subprocess */ status = sys$crembx(0, &ctx->inchn, 1024, 1024, 0xff00, 0, 0, 0); if (!OK(status)) { lib$free_vm(&spb_size, &ctx); return status; } status = sys$crembx(0, &ctx->outchn, 1024, 1024, 0xff00, 0, 0, 0); if (!OK(status)) { sys$dassgn(ctx->inchn); lib$free_vm(&spb_size, &ctx); return status; } /* ** Now that they're created, let's find out what they're called so we ** can tell LIB$SPAWN */ INIT_DYNDESC(inbox); INIT_DYNDESC(outbox); lib$getdvi(&dvi_devnam, &ctx->inchn, 0, 0, &inbox); lib$getdvi(&dvi_devnam, &ctx->outchn, 0, 0, &outbox); lib$getdvi(&dvi_devbufsiz, &ctx->outchn, 0, &ctx->bufsiz); /* ** Create the output buffer for the subprocess. */ status = lib$get_vm(&ctx->bufsiz, &ctx->bufptr); if (!OK(status)) { sys$dassgn(ctx->outchn); sys$dassgn(ctx->inchn); str$free1_dx(&inbox); str$free1_dx(&outbox); lib$free_vm(&spb_size, &ctx); return status; } /* ** Set the "receive AST" routine to be invoked by SP_WRTATTN_AST */ ctx->rcvast = rcvast; ctx->astprm = rcvastprm; sys$qiow(0, ctx->outchn, IO$_SETMODE|IO$M_WRTATTN, 0, 0, 0, sp_wrtattn_ast, ctx, 0, 0, 0, 0); sys$qiow(0, ctx->inchn, IO$_SETMODE|IO$M_READATTN, 0, 0, 0, sp_readattn_ast, ctx, 0, 0, 0, 0); /* ** Get us a termination event flag */ status = lib$get_ef(&ctx->termefn); if (OK(status)) lib$get_ef(&ctx->inefn); if (OK(status)) lib$get_ef(&ctx->outefn); if (!OK(status)) { sys$dassgn(ctx->outchn); sys$dassgn(ctx->inchn); str$free1_dx(&inbox); str$free1_dx(&outbox); lib$free_vm(&ctx->bufsiz, &ctx->bufptr); lib$free_vm(&spb_size, &ctx); return status; } /* ** Now create the subprocess */ status = lib$spawn(inicmd, &inbox, &outbox, &spawn_flags, 0, &ctx->pid, 0, &ctx->termefn); if (!OK(status)) { lib$free_ef(&ctx->termefn); lib$free_ef(&ctx->outefn); lib$free_ef(&ctx->inefn); sys$dassgn(ctx->outchn); sys$dassgn(ctx->inchn); str$free1_dx(&inbox); str$free1_dx(&outbox); lib$free_vm(&ctx->bufsiz, &ctx->bufptr); lib$free_vm(&spb_size, &ctx); return status; } /* ** Set up the exit handler, if we haven't done so already */ status = sys$setast(0); if (!exh_declared) { sys$dclexh(&exhblk); exh_declared = 1; } if (status == SS$_WASSET) sys$setast(1); /* ** Save the SPB in our private queue */ queue_insert(ctx, spque.tail); /* ** Clean up and return */ str$free1_dx(&inbox); str$free1_dx(&outbox); return SS$_NORMAL; } /* sp_open */
array_ref& operator = (value v) { assert(get_vm()); assign(v); return *this; }
// create new array void create(unsigned num_elements = 0) { val = ni()->create_array(get_vm(), num_elements); }
value get(const WCHAR* key) { assert(is_set()); value k = v_string(get_vm(),key); return ni()->get_prop(vm,val,k); }
void DCPUToolchain::SendStatus() { vm_t* vm = get_vm(); AddStatusMessage(vm); }
void create(const char* class_path ) { value cls = value_by_path(get_vm(), class_path); assert( is_class(vm,cls) ); val = ni()->create_object(get_vm(), cls); }
// create new object [of class] void create(value of_class = 0) { val = ni()->create_object(get_vm(), of_class); }
/* **++ ** ROUTINE: netlib_address_to_name ** ** FUNCTIONAL DESCRIPTION: ** ** Uses the UCX IO$_ACPCONTROL $QIO function to translate an ** IP address into a host name. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** NETLIB_ADDRESS_TO_NAME ctx, which, addr, addrsize, namdsc [,retlen] [,iosb] [,astadr] [,astprm] ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: ** ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib_address_to_name (struct CTX **xctx, unsigned int *whichp, struct INADDRDEF *addr, unsigned int *addrsize, struct dsc$descriptor *namdsc, unsigned short *retlen, struct NETLIBIOSBDEF *iosb, void (*astadr)(), void *astprm) { struct CTX *ctx; struct NETLIBIOSBDEF myiosb; ITMLST2 subfdsc, entdsc, adrdsc; unsigned int status, subfunction; char buf[1024]; #ifdef TCPWARE char tmp[64]; struct dsc$descriptor tmpdsc; #endif /* TCPWARE */ unsigned short length; int argc; VERIFY_CTX(xctx, ctx); SETARGCOUNT(argc); if (argc < 5) return SS$_INSFARG; if (addr == 0 || addrsize == 0 || namdsc == 0) return SS$_BADPARAM; if (*addrsize != sizeof(struct INADDRDEF)) return SS$_BADPARAM; #ifdef TCPWARE INIT_SDESC (tmpdsc, sizeof(tmp), tmp); status = netlib_addrtostr(addr, &tmpdsc, &tmpdsc.dsc$w_length); if (!OK(status)) return status; #else ITMLST2_INIT(adrdsc, 0, *addrsize, addr); #endif /* TCPWARE */ if (argc > 7 && astadr != 0) { struct IOR *ior; struct HOSTENT *h; GET_IOR(ior, ctx, iosb, astadr, (argc > 8) ? astprm : 0); status = lib$get_vm(&hostent_size, &h); if (!OK(status)) { FREE_IOR(ior); return status; } ior->spec_usrdsc = namdsc; ior->spec_retlen = retlen; ior->specior.subfunction = #ifndef TCPWARE (INETACP$C_TRANS << 8) | #endif /* not TCPWARE */ INETACP_FUNC$C_GETHOSTBYADDR; ITMLST2_INIT(subfdsc, 0, sizeof(ior->specior.subfunction), &ior->specior.subfunction); ITMLST2_INIT(entdsc, 0, sizeof(h->buffer), h->buffer); ior->spec_hostent = h; ior->iorflags = IOR_M_COPY_HOSTNAME; status = sys$qio(netlib_asynch_efn, ctx->chan, IO$_ACPCONTROL, &ior->iosb, io_completion, ior, &subfdsc, #ifdef TCPWARE &tmpdsc, #else &adrdsc, #endif /* TCPWARE */ &ior->specior.fromlen, &entdsc, 0, 0); if (!OK(status)) FREE_IOR(ior); return status; } subfunction = #ifndef TCPWARE (INETACP$C_TRANS << 8) | #endif INETACP_FUNC$C_GETHOSTBYADDR; ITMLST2_INIT(subfdsc, 0, sizeof(subfunction), &subfunction); ITMLST2_INIT(entdsc, 0, sizeof(buf), buf); status = sys$qiow(netlib_synch_efn, ctx->chan, IO$_ACPCONTROL, &myiosb, 0, 0, &subfdsc, #ifdef TCPWARE &tmpdsc, #else &adrdsc, #endif /* TCPWARE */ &length, &entdsc, 0, 0); if (OK(status)) status = netlib___cvt_status(&myiosb); if (argc > 6 && iosb != 0) netlib___cvt_iosb(iosb, &myiosb); if (OK(status)) { str$copy_r(namdsc, &length, buf); if (argc > 5 && retlen != 0) *retlen = length; } return status; } /* netlib_address_to_name */