static void buildfuncs(void) { extern byte etext[]; if(func != nil) return; // count funcs, fnames nfunc = 0; nfname = 0; walksymtab(dofunc); // initialize tables func = mal((nfunc+1)*sizeof func[0]); func[nfunc].entry = (uint64)etext; fname = mal(nfname*sizeof fname[0]); nfunc = 0; walksymtab(dofunc); // split pc/ln table by func splitpcln(); // record src file and line info for each func walksymtab(dosrcline); }
static int macholoadrel(MachoObj *m, MachoSect *sect) { MachoRel *rel, *r; uchar *buf, *p; int i, n; uint32 v; if(sect->rel != nil || sect->nreloc == 0) return 0; rel = mal(sect->nreloc * sizeof r[0]); n = sect->nreloc * 8; buf = mal(n); if(Bseek(m->f, m->base + sect->reloff, 0) < 0 || Bread(m->f, buf, n) != n) return -1; for(i=0; i<sect->nreloc; i++) { r = &rel[i]; p = buf+i*8; r->addr = m->e->e32(p); // TODO(rsc): Wrong interpretation for big-endian bitfields? if(r->addr & 0x80000000) { // scatterbrained relocation r->scattered = 1; v = r->addr >> 24; r->addr &= 0xFFFFFF; r->type = v & 0xF; v >>= 4; r->length = 1<<(v&3); v >>= 2; r->pcrel = v & 1; r->value = m->e->e32(p+4); } else {
static void buildfuncs(void) { extern byte etext[]; if(func != nil) return; // Memory profiling uses this code; // can deadlock if the profiler ends // up back here. m->nomemprof++; // count funcs, fnames nfunc = 0; nfname = 0; walksymtab(dofunc); // initialize tables func = runtime·mal((nfunc+1)*sizeof func[0]); func[nfunc].entry = (uint64)etext; fname = runtime·mal(nfname*sizeof fname[0]); nfunc = 0; walksymtab(dofunc); // split pc/ln table by func splitpcln(); // record src file and line info for each func walksymtab(dosrcline); m->nomemprof--; }
static void _cgo_allocate_internal(uintptr len, byte *ret) { CgoMal *c; ret = runtime·mal(len); c = runtime·mal(sizeof(*c)); c->next = m->cgomal; c->alloc = ret; m->cgomal = c; FLUSH(&ret); }
static void runfinq(void) { Finalizer *f, *next; byte *frame; for(;;) { // There's no need for a lock in this section // because it only conflicts with the garbage // collector, and the garbage collector only // runs when everyone else is stopped, and // runfinq only stops at the gosched() or // during the calls in the for loop. f = finq; finq = nil; if(f == nil) { fingwait = 1; g->status = Gwaiting; gosched(); continue; } for(; f; f=next) { next = f->next; frame = mal(sizeof(uintptr) + f->nret); *(void**)frame = f->arg; reflect·call((byte*)f->fn, frame, sizeof(uintptr) + f->nret); free(frame); f->fn = nil; f->arg = nil; f->next = nil; free(f); } gc(1); // trigger another gc to clean up the finalized objects, if possible } }
void checkwidth(Type *t) { TypeList *l; if(t == T) return; // function arg structs should not be checked // outside of the enclosing function. if(t->funarg) fatal("checkwidth %T", t); if(!defercalc) { dowidth(t); return; } if(t->deferwidth) return; t->deferwidth = 1; l = tlfree; if(l != nil) tlfree = l->next; else l = mal(sizeof *l); l->t = t; l->next = tlq; tlq = l; }
static void newselect(int32 size, Select **selp) { int32 n; Select *sel; n = 0; if(size > 1) n = size-1; // allocate all the memory we need in a single allocation // start with Select with size cases // then lockorder with size entries // then pollorder with size entries sel = runtime·mal(sizeof(*sel) + n*sizeof(sel->scase[0]) + size*sizeof(sel->lockorder[0]) + size*sizeof(sel->pollorder[0])); sel->tcase = size; sel->ncase = 0; sel->lockorder = (void*)(sel->scase + size); sel->pollorder = (void*)(sel->lockorder + size); *selp = sel; if(debug) runtime·printf("newselect s=%p size=%d\n", sel, size); }
// For reflect: // func chanrecv(c chan, nb bool) (val iword, selected, received bool) // where an iword is the same word an interface value would use: // the actual data if it fits, or else a pointer to the data. void reflect·chanrecv(ChanType *t, Hchan *c, bool nb, uintptr val, bool selected, bool received) { byte *vp; bool *sp; if(nb) { selected = false; sp = &selected; } else { selected = true; FLUSH(&selected); sp = nil; } received = false; FLUSH(&received); if(t->elem->size <= sizeof(val)) { val = 0; vp = (byte*)&val; } else { vp = runtime·mal(t->elem->size); val = (uintptr)vp; FLUSH(&val); } runtime·chanrecv(t, c, vp, sp, &received); }
// makeslice(nel int, cap int, width int) (ary []any); void runtime·makeslice(uint32 nel, uint32 cap, uint32 width, Slice ret) { uint64 size; if(cap < nel) cap = nel; size = cap*width; ret.len = nel; ret.cap = cap; ret.array = mal(size); FLUSH(&ret); if(debug) { prints("makeslice: nel="); runtime·printint(nel); prints("; cap="); runtime·printint(cap); prints("; width="); runtime·printint(width); prints("; ret="); runtime·printslice(ret); prints("\n"); } }
/* * Convert raw string to the prefix that will be used in the symbol table. * Invalid bytes turn into %xx. Right now the only bytes that need * escaping are %, ., and ", but we escape all control characters too. * * If you edit this, edit ../gc/subr.c:/^pathtoprefix too. * If you edit this, edit ../../pkg/debug/goobj/read.go:/importPathToPrefix too. */ static char* pathtoprefix(char *s) { static char hex[] = "0123456789abcdef"; char *p, *r, *w, *l; int n; // find first character past the last slash, if any. l = s; for(r=s; *r; r++) if(*r == '/') l = r+1; // check for chars that need escaping n = 0; for(r=s; *r; r++) if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f) n++; // quick exit if(n == 0) return s; // escape p = mal((r-s)+1+2*n); for(r=s, w=p; *r; r++) { if(*r <= ' ' || (*r == '.' && r >= l) || *r == '%' || *r == '"' || *r >= 0x7f) { *w++ = '%'; *w++ = hex[(*r>>4)&0xF]; *w++ = hex[*r&0xF]; } else
runtime·makechan_c(ChanType *t, int64 hint) { Hchan *c; int32 n; Type *elem; elem = t->elem; if(hint < 0 || (int32)hint != hint || (elem->size > 0 && hint > ((uintptr)-1) / elem->size)) runtime·panicstring("makechan: size out of range"); // calculate rounded size of Hchan n = sizeof(*c); while(n & MAXALIGN) n++; // allocate memory in one call c = (Hchan*)runtime·mal(n + hint*elem->size); c->elemsize = elem->size; c->elemalg = elem->alg; c->elemalign = elem->align; c->dataqsiz = hint; if(debug) runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; elemalign=%d; dataqsiz=%d\n", c, (int64)elem->size, elem->alg, elem->align, c->dataqsiz); return c; }
runtime·makechan_c(ChanType *t, int64 hint) { Hchan *c; uintptr n; Type *elem; elem = t->elem; // compiler checks this but be safe. if(elem->size >= (1<<16)) runtime·throw("makechan: invalid channel element type"); if(hint < 0 || (intgo)hint != hint || (elem->size > 0 && hint > MaxMem / elem->size)) runtime·panicstring("makechan: size out of range"); // calculate rounded size of Hchan n = sizeof(*c); while(n & MAXALIGN) n++; // allocate memory in one call c = (Hchan*)runtime·mal(n + hint*elem->size); c->elemsize = elem->size; c->elemalg = elem->alg; c->elemalign = elem->align; c->dataqsiz = hint; runtime·settype(c, (uintptr)t | TypeInfo_Chan); if(debug) runtime·printf("makechan: chan=%p; elemsize=%D; elemalg=%p; elemalign=%d; dataqsiz=%D\n", c, (int64)elem->size, elem->alg, elem->align, (int64)c->dataqsiz); return c; }
void loopit(Reg *r, int32 nr) { Reg *r1; int32 i, d, me; if(nr > maxnr) { rpo2r = mal(nr * sizeof(Reg*)); idom = mal(nr * sizeof(int32)); maxnr = nr; } d = postorder(r, rpo2r, 0); if(d > nr) fatal("too many reg nodes %d %d", d, nr); nr = d; for(i = 0; i < nr / 2; i++) { r1 = rpo2r[i]; rpo2r[i] = rpo2r[nr - 1 - i]; rpo2r[nr - 1 - i] = r1; } for(i = 0; i < nr; i++) rpo2r[i]->rpo = i; idom[0] = 0; for(i = 0; i < nr; i++) { r1 = rpo2r[i]; me = r1->rpo; d = -1; // rpo2r[r->rpo] == r protects against considering dead code, // which has r->rpo == 0. if(r1->p1 != R && rpo2r[r1->p1->rpo] == r1->p1 && r1->p1->rpo < me) d = r1->p1->rpo; for(r1 = r1->p2; r1 != nil; r1 = r1->p2link) if(rpo2r[r1->rpo] == r1 && r1->rpo < me) d = rpolca(idom, d, r1->rpo); idom[i] = d; } for(i = 0; i < nr; i++) { r1 = rpo2r[i]; r1->loop++; if(r1->p2 != R && loophead(idom, r1)) loopmark(rpo2r, i, r1); } }
static Dll* initdynimport(void) { Imp *m; Dll *d; LSym *s, *dynamic; dr = nil; m = nil; for(s = ctxt->allsym; s != S; s = s->allsym) { if(!s->reachable || s->type != SDYNIMPORT) continue; for(d = dr; d != nil; d = d->next) { if(strcmp(d->name,s->dynimplib) == 0) { m = mal(sizeof *m); break; } } if(d == nil) { d = mal(sizeof *d); d->name = s->dynimplib; d->next = dr; dr = d; m = mal(sizeof *m); } m->s = s; m->next = d->ms; d->ms = m; } dynamic = linklookup(ctxt, ".windynamic", 0); dynamic->reachable = 1; dynamic->type = SWINDOWS; for(d = dr; d != nil; d = d->next) { for(m = d->ms; m != nil; m = m->next) { m->s->type = SWINDOWS | SSUB; m->s->sub = dynamic->sub; dynamic->sub = m->s; m->s->value = dynamic->size; dynamic->size += PtrSize; } dynamic->size += PtrSize; } return dr; }
Prog* prg(void) { Prog *p; p = mal(sizeof(Prog)); *p = zprg; return p; }
void complete(int how, struct request *req) { struct timeval now, diff; int i, total; long milliseconds; struct event *timeoutev; evtimer_del(&req->timeoutev); switch(how){ case Success: gettimeofday(&now, nil); timersub(&now, &req->starttv, &diff); milliseconds = diff.tv_sec * 1000 + diff.tv_usec / 1000; for(i=0; params.buckets[i]<milliseconds && params.buckets[i]!=0; i++); counts.counters[i]++; counts.successes++; break; case Error: counts.errors++; break; case Timeout: counts.timeouts++; break; } total = counts.successes + counts.errors + counts.timeouts /*+ counts.closes*/; /* enqueue the next one */ if(params.count<0 || total<params.count){ if(params.rpc<0 || params.rpc>req->evcon_reqno){ dispatch(req->evcon, req->evcon_reqno+1); }else{ /* There seems to be a bug in libevent where the connection isn't really * freed until the event loop is unwound. We'll add ourselves back with a * 0-second timeout. */ evhttp_connection_free(req->evcon); timeoutev = mal(sizeof(*timeoutev)); evtimer_set(timeoutev, dispatchcb, (void *)timeoutev); evtimer_add(timeoutev, &zerotv); } }else{ /* We'll count this as a close. I guess that's ok. */ evhttp_connection_free(req->evcon); if(--params.concurrency == 0){ evtimer_del(&reportev); reportcb(0, 0, nil); /* issue a last report */ } } free(req); }
int run(cpu *pcpu) { char byte; pcpu->fl = CPU_CLEAN; if ((byte = get_byte(pcpu->ip)) < 0) { pcpu->fl = CPU_ERROR; pcpu->ip++; return -1; } //printf("Cel id-> %d, byte : 0x%x, at IP: %s\n",pcpu->pcel->id ,byte, decodificar(get_byte(pcpu->ip))); //show_regs(pcpu,0); switch(byte) { case 0X00 : nop0(pcpu); break; case 0X01 : nop1(pcpu); break; case 0X02 : pushax(pcpu); break; case 0X03 : pushbx(pcpu); break; case 0X04 : pushcx(pcpu); break; case 0X05 : pushdx(pcpu); break; case 0X06 : popax(pcpu); break; case 0X07 : popbx(pcpu); break; case 0X08 : popcx(pcpu); break; case 0X09 : popdx(pcpu); break; case 0X0a : movcd(pcpu); break; case 0X0b : movab(pcpu); break; case 0X0c : movii(pcpu); break; case 0X0d : sub_ab(pcpu); break; case 0X0e : sub_ac(pcpu); break; case 0X0f : inc_a(pcpu); break; case 0X10 : inc_b(pcpu); break; case 0X11 : dec_c(pcpu); break; case 0X12 : inc_c(pcpu); break; case 0X13 : zero(pcpu); break; case 0X14 : not0(pcpu); break; case 0X15 : shl(pcpu); break; case 0X16 : ifz(pcpu); break; case 0X17 : jmp(pcpu); break; case 0X18 : jmpb(pcpu); break; case 0X19 : call(pcpu); break; case 0X1a : ret(pcpu); break; case 0X1b : adr(pcpu); break; case 0X1c : adrb(pcpu); break; case 0x1d : adrf(pcpu); break; case 0X1e : mal(pcpu); break; case 0X1f : divide(pcpu); break; //default:printf("CPU: Instruccion No Encontrada!\n");break; } return 0; }
ElfShdr* newElfShdr(vlong name) { ElfShdr *e; e = mal(sizeof *e); e->name = name; if (hdr.shnum >= NSECT) { diag("too many shdrs"); } else { shdr[hdr.shnum++] = e; } return e; }
Sub* newsub(int n) { Sub *s; s = freesub; if(s != nil) freesub = (Sub*)s->sub[0]; else s = mal(sizeof *s); s->nsub = n; s->ref = 1; return s; }
Reg* rega(void) { Reg *r; r = freer; if(r == R) { r = mal(sizeof(*r)); } else freer = r->link; *r = zreg; return r; }
static void makeslice1(SliceType *t, int32 len, int32 cap, Slice *ret) { uintptr size; size = cap*t->elem->size; ret->len = len; ret->cap = cap; if((t->elem->kind&KindNoPointers)) ret->array = runtime·mallocgc(size, FlagNoPointers, 1, 1); else ret->array = runtime·mal(size); }
Elfaux* addelflib(Elflib **list, char *file, char *vers) { Elflib *lib; Elfaux *aux; for(lib=*list; lib; lib=lib->next) if(strcmp(lib->file, file) == 0) goto havelib; lib = mal(sizeof *lib); lib->next = *list; lib->file = file; *list = lib; havelib: for(aux=lib->aux; aux; aux=aux->next) if(strcmp(aux->vers, vers) == 0) goto haveaux; aux = mal(sizeof *aux); aux->next = lib->aux; aux->vers = vers; lib->aux = aux; haveaux: return aux; }
int dgostringptr(Sym *s, int off, char *str) { int n; Strlit *lit; if(str == nil) return duintptr(s, off, 0); n = strlen(str); lit = mal(sizeof *lit + n); strcpy(lit->s, str); lit->len = n; return dgostrlitptr(s, off, lit); }
Prog* compile(Regexp *r) { int n; Prog *p; n = count(r) + 1; p = mal(sizeof *p + n*sizeof p->start[0]); p->start = (Inst*)(p+1); pc = p->start; emit(r); pc->opcode = Match; pc++; p->len = pc - p->start; return p; }
void data(void) { gflag = debug['g']; debug['g'] = 0; if(estrdat == nil) { strdat = mal(sizeof(*pc)); clearp(strdat); estrdat = strdat; } if(savepc) fatal("data phase error"); savepc = pc; pc = estrdat; }
ElfPhdr* newElfPhdr(void) { ElfPhdr *e; e = mal(sizeof *e); if (hdr.phnum >= NSECT) diag("too many phdrs"); else phdr[hdr.phnum++] = e; if (elf64) hdr.shoff += ELF64PHDRSIZE; else hdr.shoff += ELF32PHDRSIZE; return e; }
static int map(PeObj *obj, PeSect *sect) { if(sect->base != nil) return 0; sect->base = mal(sect->sh.SizeOfRawData); if(sect->sh.PointerToRawData == 0) // .bss doesn't have data in object file return 0; werrstr("short read"); if(Bseek(obj->f, obj->base+sect->sh.PointerToRawData, 0) < 0 || Bread(obj->f, sect->base, sect->sh.SizeOfRawData) != sect->sh.SizeOfRawData) return -1; return 0; }
std::string* alm(int* maffia, std::string magasinering) { if (*maffia > 6 || magasinering == "magpumpning") return new std::string("majbrasa"); int magnetbandshantering = *maffia + 1; std::string* majolika = new std::string("make"); int* maka = alldeles(magnetbandshantering, majolika); std::string mal("mamma"); int mall = alltihopa(&magnetbandshantering, mal); std::string* man = new std::string("manipulering"); std::string maning = anmaning(magnetbandshantering, man); std::string* mapp = new std::string("marknadsandel"); int* markering = allra(magnetbandshantering, mapp); std::string mas("maskering"); std::string* maska = annonsering(&magnetbandshantering, mas); std::string* maskinskrivning = new std::string("maskinvara"); return maskinskrivning; } // alm
void libinit(void) { char *suffix, *suffixsep; fmtinstall('i', iconv); fmtinstall('Y', Yconv); fmtinstall('Z', Zconv); mywhatsys(); // get goroot, goarch, goos if(strcmp(goarch, thestring) != 0) print("goarch is not known: %s\n", goarch); // add goroot to the end of the libdir list. suffix = ""; suffixsep = ""; if(flag_installsuffix != nil) { suffixsep = "_"; suffix = flag_installsuffix; } else if(flag_race) { suffixsep = "_"; suffix = "race"; } Lflag(smprint("%s/pkg/%s_%s%s%s", goroot, goos, goarch, suffixsep, suffix)); // Unix doesn't like it when we write to a running (or, sometimes, // recently run) binary, so remove the output file before writing it. // On Windows 7, remove() can force the following create() to fail. #ifndef _WIN32 remove(outfile); #endif cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s: %r", outfile); errorexit(); } if(INITENTRY == nil) { INITENTRY = mal(strlen(goarch)+strlen(goos)+20); if(!flag_shared) { sprint(INITENTRY, "_rt0_%s_%s", goarch, goos); } else { sprint(INITENTRY, "_rt0_%s_%s_lib", goarch, goos); } } linklookup(ctxt, INITENTRY, 0)->type = SXREF; }
static Import * ilookup(char *name) { int h; Import *x; h = hashstr(name) % NIHASH; for(x=ihash[h]; x; x=x->hash) if(x->name[0] == name[0] && strcmp(x->name, name) == 0) return x; x = mal(sizeof *x); x->name = strdup(name); x->hash = ihash[h]; ihash[h] = x; nimport++; return x; }