Token *newToken(int type, int dup, char *pre, char *tok) { Token *ret; SF(ret, malloc, NULL, (sizeof(Token))); ret->type = type; ret->idx = ret->l = ret->c = 0; ret->f = -1; if (pre == NULL) { SF(ret->pre, strdup, NULL, ("")); } else if (dup) { SF(ret->pre, strdup, NULL, (pre)); } else { ret->pre = pre; } if (tok == NULL) { SF(ret->tok, strdup, NULL, ("")); } else if (dup) { SF(ret->tok, strdup, NULL, (tok)); } else { ret->tok = tok; } return ret; }
static void setup_blend_function(NVPtr pNv, PicturePtr pdpict, int alu) { struct nouveau_pushbuf *push = pNv->pushbuf; struct pict_op *op = &nv10_pict_op[alu]; int src_factor = op->src; int dst_factor = op->dst; if (src_factor == SF(ONE_MINUS_DST_ALPHA) && !PICT_FORMAT_A(pdpict->format)) /* ONE_MINUS_DST_ALPHA doesn't always do the right thing for * framebuffers without alpha channel. But it's the same as * ZERO in that case. */ src_factor = SF(ZERO); if (effective_component_alpha(pNv->pmpict)) { if (dst_factor == DF(SRC_ALPHA)) dst_factor = DF(SRC_COLOR); else if (dst_factor == DF(ONE_MINUS_SRC_ALPHA)) dst_factor = DF(ONE_MINUS_SRC_COLOR); } BEGIN_NV04(push, NV10_3D(BLEND_FUNC_SRC), 2); PUSH_DATA (push, src_factor); PUSH_DATA (push, dst_factor); BEGIN_NV04(push, NV10_3D(BLEND_FUNC_ENABLE), 1); PUSH_DATA (push, 1); }
static orafce_lexnode * compose(orafce_lexnode *a, orafce_lexnode *b) { orafce_lexnode *result; StringInfo sinfo; sinfo = makeStringInfo(); result = NEWNODE(IDENT); result->lloc = a->lloc; if (strcmp(SF(mod(a)), "dq") == 0) appendStringInfo(sinfo, "\"%s\".", a->str); else { appendStringInfoString(sinfo, a->str); appendStringInfoChar(sinfo, '.'); } if (strcmp(SF(mod(b)), "dq") == 0) appendStringInfo(sinfo, "\"%s\"", b->str); else appendStringInfoString(sinfo, b->str); result->str = sinfo->data; return result; }
/* create a new named UNIXL */ static Socket *newUNIXL(char **saveptr) { SocketUNIXL *ret; char *path; int fd, tmpi; struct sockaddr_un sun; /* get the path */ path = strtok_r(NULL, "", saveptr); /* make the socket */ SF(fd, socket, -1, (AF_UNIX, SOCK_STREAM, 0)); sun.sun_family = AF_UNIX; strncpy(sun.sun_path, path, sizeof(sun.sun_path)); SF(tmpi, bind, -1, (fd, (struct sockaddr *) &sun, sizeof(sun))); /* and set it up to listen */ SF(tmpi, listen, -1, (fd, 32)); /* then make the return */ ret = (SocketUNIXL *) newSocket(sizeof(SocketUNIXL)); ret->ssuper.vtbl = &unixlVTbl; ret->fd = fd; return (Socket *) ret; }
static void setup_blend_function(NVPtr pNv) { struct nouveau_channel *chan = pNv->chan; struct nouveau_grobj *celsius = pNv->Nv3D; struct pict_op *op = &nv10_pict_op[pNv->alu]; int src_factor = op->src; int dst_factor = op->dst; if (src_factor == SF(ONE_MINUS_DST_ALPHA) && !PICT_FORMAT_A(pNv->pdpict->format)) /* ONE_MINUS_DST_ALPHA doesn't always do the right thing for * framebuffers without alpha channel. But it's the same as * ZERO in that case. */ src_factor = SF(ZERO); if (effective_component_alpha(pNv->pmpict)) { if (dst_factor == DF(SRC_ALPHA)) dst_factor = DF(SRC_COLOR); else if (dst_factor == DF(ONE_MINUS_SRC_ALPHA)) dst_factor = DF(ONE_MINUS_SRC_COLOR); } BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_SRC, 2); OUT_RING (chan, src_factor); OUT_RING (chan, dst_factor); BEGIN_RING(chan, celsius, NV10TCL_BLEND_FUNC_ENABLE, 1); OUT_RING (chan, 1); }
static int internal_rayHitsAABB(vec3f *abp, vec3f *p_ray, float *dist) { #define ap &abp[0] #define bp &abp[1] #define p_pos &p_ray[0] #define p_dir &p_ray[1] #define SF(VAR) (*(v4sf*) VAR) float dirprod = X(SF(p_dir)) * Y(SF(p_dir)) * Z(SF(p_dir)); #undef SF v4si mask = (v4si) FOUR(1<<31); v4si signs = mask & *(v4si*)p_dir; v4sf a = (v4sf) (V4SI(*ap) ^ signs); v4sf b = (v4sf) (V4SI(*bp) ^ signs); v4sf pos = (v4sf) (V4SI(*p_pos) ^ signs); v4sf dir = (v4sf) (V4SI(*p_dir) ^ signs); v4sf b_ = b; // pretend ray starts at origin: -pos b = __builtin_ia32_maxps(a, b) - pos; // if (X(b) < 0 || Y(b) < 0 || Z(b) < 0) return 0; // ray is pointed away from aabb. v4si bsign = mask & *(v4si*)&b; if (IX(bsign) | IY(bsign) | IZ(bsign)) return 0; a = __builtin_ia32_minps(a, b_) - pos; // multiply every component with dir.(x*y*z) // vec3f dista = a / dir, distb = b / dir; vec3f *_vdir = (vec3f*) &dir; vec3f *_dista = (vec3f*) &a, *_distb = (vec3f*) &b; #define vdir (*_vdir) #define dista (*_dista) #define distb (*_distb) if (LIKELY(vdir.x != 0 && vdir.y != 0 && vdir.z != 0)) { // vdir += (v4sf) {0, 0, 0, 1}; *(v4si*) &dir &= (v4si) {-1, -1, -1, 0}; dir += (v4sf) {0, 0, 0, 1}; a /= dir; b /= dir; } else { if (LIKELY(vdir.x != 0)) { dista.x /= vdir.x; distb.x /= vdir.x; } else { dista.x = copysignf(INFINITY, dista.x); distb.x = copysignf(INFINITY, distb.x); } if (LIKELY(vdir.y != 0)) { dista.y /= vdir.y; distb.y /= vdir.y; } else { dista.y = copysignf(INFINITY, dista.y); distb.y = copysignf(INFINITY, distb.y); } if (LIKELY(vdir.z != 0)) { dista.z /= vdir.z; distb.z /= vdir.z; } else { dista.z = copysignf(INFINITY, dista.z); distb.z = copysignf(INFINITY, distb.z); } } float entry = fmaxf(dista.x, fmaxf(dista.y, dista.z)); float exit = fminf(distb.x, fminf(distb.y, distb.z)); if (dist) { *dist = entry; } return entry <= exit; #undef dista #undef vdir #undef ap #undef bp #undef p_pos #undef p_dir }
void write_vertices(FILE* fd) { const char* const dataType = "float"; pr("DATASET POLYDATA\n"); pr("POINTS %d %s\n", nv, dataType); int ib, iv; for (iv=0, ib=0; iv<nv; ++iv) { SF(xx[iv]); SF(yy[iv]); SF(zz[iv]); } fwrite(buf, ib, sizeof(float), fd); }
/** Get cluster from the first FAT. * * @param bs Buffer holding the boot sector for the file system. * @param service_id Service ID for the file system. * @param clst Cluster which to get. * @param value Output argument holding the value of the cluster. * * @return EOK or a negative error code. */ static int fat_get_cluster_fat12(fat_bs_t *bs, service_id_t service_id, unsigned fatno, fat_cluster_t clst, fat_cluster_t *value) { block_t *b, *b1; uint16_t byte1, byte2; aoff64_t offset; int rc; offset = (clst + clst / 2); if (offset / BPS(bs) >= SF(bs)) return ERANGE; rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); if (rc != EOK) return rc; byte1 = ((uint8_t *) b->data)[offset % BPS(bs)]; /* This cluster access spans a sector boundary. Check only for FAT12 */ if ((offset % BPS(bs)) + 1 == BPS(bs)) { /* Is this the last sector of FAT? */ if (offset / BPS(bs) < SF(bs)) { /* No, read the next sector */ rc = block_get(&b1, service_id, 1 + RSCNT(bs) + SF(bs) * fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); if (rc != EOK) { block_put(b); return rc; } /* * Combining value with last byte of current sector and * first byte of next sector */ byte2 = ((uint8_t*) b1->data)[0]; rc = block_put(b1); if (rc != EOK) { block_put(b); return rc; } } else { /* Yes. This is the last sector of FAT */ block_put(b); return ERANGE; } } else byte2 = ((uint8_t *) b->data)[(offset % BPS(bs)) + 1]; *value = uint16_t_le2host(byte1 | (byte2 << 8)); if (IS_ODD(clst)) *value = (*value) >> 4; else
int main(int argc, char **argv) { FILE *f; PmError perr; MfFile *pf; int ti; MfTrack *track; MfEvent *cur; int redux; if (argc < 4) { fprintf(stderr, "Use: hreducevel <file> <output file> <range reduction>\n"); return 1; } redux = atoi(argv[3]); PSF(perr, Mf_Initialize, ()); /* open it for input */ SF(f, fopen, NULL, (argv[1], "rb")); /* and read it */ PSF(perr, Mf_ReadMidiFile, (&pf, f)); fclose(f); /* redux it */ for (ti = 0; ti < pf->trackCt; ti++) { track = pf->tracks[ti]; cur = track->head; while (cur) { if (Pm_MessageType(cur->e.message) == MIDI_NOTE_ON) { uint8_t vel = Pm_MessageData2(cur->e.message); vel = 127 - (127-vel)/redux; cur->e.message = Pm_Message( Pm_MessageStatus(cur->e.message), Pm_MessageData1(cur->e.message), vel); } cur = cur->next; } } /* write it out */ SF(f, fopen, NULL, (argv[2], "wb")); PSF(perr, Mf_WriteMidiFile, (f, pf)); fclose(f); return 0; }
NodeSpecial *nodeAddSpecial(Node *node, const char *type) { NodeSpecial *ret; SF(ret, malloc, NULL, (sizeof(NodeSpecial))); ret->next = node->specials; node->specials = ret; SF(ret->type, strdup, NULL, (type)); ret->val = NULL; ret->free = NULL; return ret; }
Bool NV40EXACheckComposite(int op, PicturePtr psPict, PicturePtr pmPict, PicturePtr pdPict) { nv_pict_surface_format_t *fmt; nv_pict_op_t *opr; opr = NV40_GetPictOpRec(op); if (!opr) NOUVEAU_FALLBACK("unsupported blend op 0x%x\n", op); fmt = NV40_GetPictSurfaceFormat(pdPict->format); if (!fmt) NOUVEAU_FALLBACK("dst picture format 0x%08x not supported\n", pdPict->format); if (!NV40EXACheckCompositeTexture(psPict, pdPict, op)) NOUVEAU_FALLBACK("src picture\n"); if (pmPict) { if (pmPict->componentAlpha && PICT_FORMAT_RGB(pmPict->format) && opr->src_alpha && opr->src_card_op != SF(ZERO)) NOUVEAU_FALLBACK("mask CA + SA\n"); if (!NV40EXACheckCompositeTexture(pmPict, pdPict, op)) NOUVEAU_FALLBACK("mask picture\n"); } return TRUE; }
/* try/catch. Use this to initialize a try/catch block. Make sure to pop iff * nothing is caught. Returns 0 on try, 1 on catch. */ int fytheCatch(struct FytheValue *catchInto) { struct FytheExceptionFrame *ef; /* create our exception frame */ SF(ef, malloc, NULL, (sizeof(struct FytheExceptionFrame))); ef->fytheStackTop = GGGGC_fytheStackTop; ef->catchInto = catchInto; /* link it to the current one */ #if defined(TLS) ef->next = fytheExceptionStack; fytheExceptionStack = ef; #elif defined(TLS_PTHREAD) { struct FytheExceptionFrame *efo; efo = pthread_getspecific(fytheExceptionStackKey); ef->next = efo; pthread_setspecific(fytheExceptionStackKey, ef); } #endif /* now do the setjmp */ return setjmp(ef->jmp); }
BufferOffset Assembler::LogicalImmediate(const Register& rd, const Register& rn, unsigned n, unsigned imm_s, unsigned imm_r, LogicalOp op) { unsigned reg_size = rd.size(); Instr dest_reg = (op == ANDS) ? Rd(rd) : RdSP(rd); return Emit(SF(rd) | LogicalImmediateFixed | op | BitN(n, reg_size) | ImmSetBits(imm_s, reg_size) | ImmRotate(imm_r, reg_size) | dest_reg | Rn(rn)); }
static void unparsePrime(struct Buffer_char *buf, struct Buffer_charp *filenames, size_t *lastFile, Node *node) { size_t i; if (node->tok) { Token *tok = node->tok; if (tok->f != *lastFile) { /* first get out any comments that come before the final newline */ char *fnl; fnl = tok->pre ? strrchr(tok->pre, '\n') : NULL; if (fnl) WRITE_BUFFER(*buf, tok->pre, fnl - tok->pre); /* we're in a different file, write a #line directive */ if ((tok->f != (size_t) -1) && filenames) { char *lnum; SF(lnum, malloc, NULL, (4*sizeof(int) + 1)); sprintf(lnum, "%d", (int) tok->l); WRITE_BUFFER(*buf, "\n#line ", 7); WRITE_BUFFER(*buf, lnum, strlen(lnum)); free(lnum); WRITE_BUFFER(*buf, " \"", 2); if (tok->f < filenames->bufused) { WRITE_BUFFER(*buf, filenames->buf[tok->f], strlen(filenames->buf[tok->f])); } else { WRITE_BUFFER(*buf, "???", 3); } WRITE_BUFFER(*buf, "\"\n", 2); } else if (fnl) { WRITE_ONE_BUFFER(*buf, '\n'); } *lastFile = tok->f; /* now write out the remainder of the comment */ if (fnl) { WRITE_BUFFER(*buf, fnl + 1, strlen(fnl + 1)); } else if (tok->pre) { WRITE_BUFFER(*buf, tok->pre, strlen(tok->pre)); } } else if (tok->pre) { WRITE_BUFFER(*buf, tok->pre, strlen(tok->pre)); } if (tok->tok) WRITE_BUFFER(*buf, tok->tok, strlen(tok->tok)); } for (i = 0; node->children[i]; i++) { unparsePrime(buf, filenames, lastFile, node->children[i]); } }
Node *newNode(Node *parent, int type, Token *tok, size_t children) { Node *ret; SF(ret, calloc, NULL, (sizeof(Node) + children * sizeof(Node *), 1)); ret->parent = parent; ret->type = type; ret->tok = tok; return ret; }
FreeModule *FreeModule::symm(int n) const // n th symmetric power { FreeModule_symm SF(this, n); FreeModule *result = SF.value(); if (schreyer != NULL) result->schreyer = schreyer->symm(n); return result; }
BufferOffset Assembler::DataProcShiftedRegister(const Register& rd, const Register& rn, const Operand& operand, FlagsUpdate S, Instr op) { VIXL_ASSERT(operand.IsShiftedRegister()); VIXL_ASSERT(rn.Is64Bits() || (rn.Is32Bits() && is_uint5(operand.shift_amount()))); return Emit(SF(rd) | op | Flags(S) | ShiftDP(operand.shift()) | ImmDPShift(operand.shift_amount()) | Rm(operand.reg()) | Rn(rn) | Rd(rd)); }
static void NV40_SetupBlend(ScrnInfoPtr pScrn, nv_pict_op_t *blend, PictFormatShort dest_format, Bool component_alpha) { NVPtr pNv = NVPTR(pScrn); struct nouveau_channel *chan = pNv->chan; struct nouveau_grobj *curie = pNv->Nv3D; uint32_t sblend, dblend; sblend = blend->src_card_op; dblend = blend->dst_card_op; if (blend->dst_alpha) { if (!PICT_FORMAT_A(dest_format)) { if (sblend == SF(DST_ALPHA)) { sblend = SF(ONE); } else if (sblend == SF(ONE_MINUS_DST_ALPHA)) { sblend = SF(ZERO); } } else if (dest_format == PICT_a8) { if (sblend == SF(DST_ALPHA)) { sblend = SF(DST_COLOR); } else if (sblend == SF(ONE_MINUS_DST_ALPHA)) { sblend = SF(ONE_MINUS_DST_COLOR); } } } if (blend->src_alpha && (component_alpha || dest_format == PICT_a8)) { if (dblend == DF(SRC_ALPHA)) { dblend = DF(SRC_COLOR); } else if (dblend == DF(ONE_MINUS_SRC_ALPHA)) { dblend = DF(ONE_MINUS_SRC_COLOR); } } if (sblend == SF(ONE) && dblend == DF(ZERO)) { BEGIN_RING(chan, curie, NV40TCL_BLEND_ENABLE, 1); OUT_RING (chan, 0); } else { BEGIN_RING(chan, curie, NV40TCL_BLEND_ENABLE, 5); OUT_RING (chan, 1); OUT_RING (chan, sblend); OUT_RING (chan, dblend); OUT_RING (chan, 0x00000000); OUT_RING (chan, NV40TCL_BLEND_EQUATION_ALPHA_FUNC_ADD | NV40TCL_BLEND_EQUATION_RGB_FUNC_ADD); } }
static void NV40_SetupBlend(ScrnInfoPtr pScrn, nv_pict_op_t *blend, PictFormatShort dest_format, Bool component_alpha) { NVPtr pNv = NVPTR(pScrn); struct nouveau_pushbuf *push = pNv->pushbuf; uint32_t sblend, dblend; sblend = blend->src_card_op; dblend = blend->dst_card_op; if (blend->dst_alpha) { if (!PICT_FORMAT_A(dest_format)) { if (sblend == SF(DST_ALPHA)) { sblend = SF(ONE); } else if (sblend == SF(ONE_MINUS_DST_ALPHA)) { sblend = SF(ZERO); } } else if (dest_format == PICT_a8) { if (sblend == SF(DST_ALPHA)) { sblend = SF(DST_COLOR); } else if (sblend == SF(ONE_MINUS_DST_ALPHA)) { sblend = SF(ONE_MINUS_DST_COLOR); } } } if (blend->src_alpha && (component_alpha || dest_format == PICT_a8)) { if (dblend == DF(SRC_ALPHA)) { dblend = DF(SRC_COLOR); } else if (dblend == DF(ONE_MINUS_SRC_ALPHA)) { dblend = DF(ONE_MINUS_SRC_COLOR); } } if (sblend == SF(ONE) && dblend == DF(ZERO)) { BEGIN_NV04(push, NV30_3D(BLEND_FUNC_ENABLE), 1); PUSH_DATA (push, 0); } else { BEGIN_NV04(push, NV30_3D(BLEND_FUNC_ENABLE), 5); PUSH_DATA (push, 1); PUSH_DATA (push, sblend); PUSH_DATA (push, dblend); PUSH_DATA (push, 0x00000000); PUSH_DATA (push, NV40_3D_BLEND_EQUATION_ALPHA_FUNC_ADD | NV40_3D_BLEND_EQUATION_RGB_FUNC_ADD); } }
int init(HS) { struct NoteTapperState *pstate; SF(pstate, calloc, NULL, (1, sizeof(struct NoteTapperState))); pstate->track = -1; pstate->velocity = pstate->lastVelocity = 100; pstate->lastExpressionModVal = 64; hstate->pstate[pnum] = (void *) pstate; return 1; }
scalar sasfit_ff_sphere_with_3_shells_f(scalar q, sasfit_param * param) { SASFIT_ASSERT_PTR(param); // assert pointer param is valid return (ETA_CORE-ETA_SOL)* SF(q,R_CORE) + (ETA_SH1-ETA_SOL) *(SF(q,R_CORE+T_SH1) -SF(q,R_CORE)) + (ETA_SH2-ETA_SOL) *(SF(q,R_CORE+T_SH1+T_SH2) -SF(q,R_CORE+T_SH1)) + (ETA_SH3-ETA_SOL) *(SF(q,R_CORE+T_SH1+T_SH2+T_SH3)-SF(q,R_CORE+T_SH1+T_SH2)); }
void ui_temp_status_display(void) { if (SF(FLAG_FORCE_LCD_REFRESH)) { lcd_temp_sensor(0); lcd_temp_sensor(1); hd44780_goto(2,1); lcd_temp_sensor(2); lcd_temp_sensor(3); } else { lcd_clear_temp_indicators(); } }
void ProgNmaAlignment::preProcess() { MetaData SF(fnModeList); SF.removeDisabled(); numberOfModes = SF.size(); // Get the size of the images in the selfile imgSize = xdimOut; // Set the pointer of the program to this object global_nma_prog = this; //create some neededs files createWorkFiles(); }
void write_cells_attributes(FILE* fd) { int ifa, ib; const char* const dataType = "float"; const char* const dataName = "s"; pr("\n"); pr("CELL_DATA %d\n", nf); pr("SCALARS %s %s\n", dataName, dataType); pr("LOOKUP_TABLE default\n"); for (ifa = ib = 0; ifa < nf; ++ifa) SF(ifa); fwrite(buf, ib, sizeof(float), fd); }
void ECRYPT_Trivium::TRIVIUM_process_bytes( int action, void* ctxa, const u8* input, u8* output, u32 msglen) { TRIVIUM_ctx* ctx = (TRIVIUM_ctx*)ctxa; m64 s11, s12; m64 s21, s22; m64 s31, s32; LOAD(ctx->state); for (; (int)(msglen -= 16) >= 0; output += 16, input += 16) { m64 t1, t2, t3, z[2]; UPDATE(); z[0] = XOR(XOR(s12, s22), s32); ROTATE(); UPDATE(); z[1] = XOR(XOR(s12, s22), s32); ROTATE(); M64TO64_CONVERT(z[0]); ((m64*)output)[0] = XOR(((m64*)input)[0], z[0]); M64TO64_CONVERT(z[1]); ((m64*)output)[1] = XOR(((m64*)input)[1], z[1]); } for (msglen += 16; (int)msglen > 0; msglen -= 8, output += 8, input += 8) { m64 t1, t2, t3, z; UPDATE(); z = XOR(XOR(s12, s22), s32); if (msglen >= 8) { M64TO64_CONVERT(z); ((m64*)output)[0] = XOR(((m64*)input)[0], z); } else { u32 i; for (i = 0; i < msglen; ++i, z = SF(z, 8)) output[i] = input[i] ^ M8V(z); } ROTATE(); } STORE(ctx->state); EMPTY(); }
gp_Pnt cadmbtb_FacePoint(const TopoDS_Face &face,Standard_Real u, Standard_Real v) { // get bounds of face /* Standard_Real umin, umax, vmin, vmax; BRepTools::UVBounds(face, umin, umax, vmin, vmax); // create surface if (u < umin) u = umin; if (v < vmin) v = vmin; if (u > umax) u = umax; if (v > vmax) v = vmax;*/ BRepAdaptor_Surface SF(face); // gp_Vec VecU,VecV; gp_Pnt aPaux; SF.D0(u,v,aPaux);//,VecU,VecV);// compute point on surface return aPaux; }
void ui_outputs_status_display(void) { if (SF(FLAG_FORCE_LCD_REFRESH)) { if (alarms_is_active() && alarms_notification_enabled()) { hd44780_outstrn_P(PSTR(" ! ALARM ! ")); } else { lcd_clock(); } hd44780_goto(2,1); lcd_outputs_status(); } else { if (alarms_is_active() && alarms_notification_enabled()) { hd44780_outstrn_P(PSTR(" ALARM ")); } else { hd44780_goto(1,3); hd44780_outstrn_P(SPACE_S); } } }
/* create a new named UNIXC */ static Socket *newUNIXC(char **saveptr) { SocketUNIXC *ret; char *path; struct sockaddr_un *sun; /* get the path */ path = strtok_r(NULL, "", saveptr); /* make the return */ ret = (SocketUNIXC *) newSocket(sizeof(SocketUNIXC)); ret->ssuper.vtbl = &unixcVTbl; SF(sun, malloc, NULL, (sizeof(struct sockaddr_un))); sun->sun_family = AF_UNIX; strncpy(sun->sun_path, path, sizeof(sun->sun_path)); ret->addr = (struct sockaddr *) sun; ret->addrlen = sizeof(*sun); return (Socket *) ret; }
/* connection function for UNIXC */ static Socket *unixcConnect(Socket *self) { SocketUNIXC *sockc = (SocketUNIXC *) self; SocketUNIX *ret; int fd, tmpi; /* make the socket */ SF(fd, socket, -1, (AF_UNIX, SOCK_STREAM, 0)); tmpi = connect(fd, sockc->addr, sockc->addrlen); if (tmpi < 0) { close(fd); return NULL; } /* then make the return */ ret = (SocketUNIX *) newSocket(sizeof(SocketUNIX)); newSocketWritable(ret, fd); ret->ssuper.vtbl = &unixVTbl; return (Socket *) ret; }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ GLOBAL VOID check_SS IFN4( IU16, selector, /* (I) 16-bit selector to stack segment */ ISM32, privilege, /* (I) privilege level to check against */ IU32 *, descr_addr, /* (O) address of stack segment descriptor */ CPU_DESCR *, entry /* (O) the decoded descriptor */ ) { /* must be within GDT or LDT */ if ( selector_outside_GDT_LDT(selector, descr_addr) ) GP(selector, FAULT_CHECKSS_SELECTOR); read_descriptor_linear(*descr_addr, entry); /* must be writable data */ switch ( descriptor_super_type(entry->AR) ) { case EXPANDUP_WRITEABLE_DATA: case EXPANDDOWN_WRITEABLE_DATA: break; /* good type */ default: GP(selector, FAULT_CHECKSS_BAD_SEG_TYPE); /* bad type */ } /* access check requires RPL == DPL == privilege */ if ( GET_SELECTOR_RPL(selector) != privilege || GET_AR_DPL(entry->AR) != privilege ) GP(selector, FAULT_CHECKSS_ACCESS); /* finally it must be present */ if ( GET_AR_P(entry->AR) == NOT_PRESENT ) SF(selector, FAULT_CHECKSS_NOTPRESENT); }