/* InterpreterPlugin>>#positiveMachineIntegerFor: */ static sqInt positiveMachineIntegerFor(usqIntptr_t value) { return (BytesPerWord == 8 ? positive64BitIntegerFor(value) : positive32BitIntegerFor(value)); }
primitiveDLSym(void) { void *addr; sqInt i; char *name; sqInt nameObj; char *namePtr; sqInt sz; nameObj = stackValue(0); if (!(isBytes(nameObj))) { return primitiveFailFor(PrimErrBadArgument); } sz = byteSizeOf(nameObj); name = malloc(sz + 1); namePtr = firstIndexableField(nameObj); for (i = 0; i < sz; i += 1) { name[i] = (namePtr[i]); } name[sz] = 0; addr = dlsym(RTLD_SELF,name); free(name); return methodReturnValue((addr == 0 ? nilObject() : (/* begin positiveMachineIntegerFor: */ (BytesPerWord == 8 ? positive64BitIntegerFor(((usqIntptr_t)addr)) : positive32BitIntegerFor(((usqIntptr_t)addr)))))); }
static sqInt makeDirEntryNamesizecreateDatemodDateisDirfileSizeposixPermissionsisSymlink(char *entryName, sqInt entryNameSize, sqInt createDate, sqInt modifiedDate, sqInt dirFlag, squeakFileOffsetType fileSize, sqInt posixPermissions, sqInt symlinkFlag) { // FilePlugin>>#makeDirEntryName:size:createDate:modDate:isDir:fileSize:posixPermissions:isSymlink: sqInt createDateOop; sqInt fileSizeOop; sqInt i; sqInt modDateOop; sqInt nameString; sqInt posixPermissionsOop; sqInt results; char *stringPtr; /* allocate storage for results, remapping newly allocated oops in case GC happens during allocation */ pushRemappableOop(instantiateClassindexableSize(classArray(), 7)); pushRemappableOop(instantiateClassindexableSize(classString(), entryNameSize)); pushRemappableOop(positive32BitIntegerFor(createDate)); pushRemappableOop(positive32BitIntegerFor(modifiedDate)); pushRemappableOop(positive64BitIntegerFor(fileSize)); pushRemappableOop(positive32BitIntegerFor(posixPermissions)); posixPermissionsOop = popRemappableOop(); fileSizeOop = popRemappableOop(); modDateOop = popRemappableOop(); createDateOop = popRemappableOop(); nameString = popRemappableOop(); /* copy name into Smalltalk string */ results = popRemappableOop(); stringPtr = firstIndexableField(nameString); for (i = 0; i < entryNameSize; i += 1) { stringPtr[i] = (entryName[i]); } storePointerofObjectwithValue(0, results, nameString); storePointerofObjectwithValue(1, results, createDateOop); storePointerofObjectwithValue(2, results, modDateOop); if (dirFlag) { storePointerofObjectwithValue(3, results, trueObject()); } else { storePointerofObjectwithValue(3, results, falseObject()); } storePointerofObjectwithValue(4, results, fileSizeOop); storePointerofObjectwithValue(5, results, posixPermissionsOop); if (symlinkFlag) { storePointerofObjectwithValue(6, results, trueObject()); } else { storePointerofObjectwithValue(6, results, falseObject()); } return results; }
primitiveNewCPU(void) { void *cpu; cpu = newCPU(); if (cpu == 0) { primitiveFail(); return null; } popthenPush(1, (BytesPerWord == 8 ? positive64BitIntegerFor(((usqIntptr_t) cpu)) : positive32BitIntegerFor(((usqIntptr_t) cpu)))); if (failed()) { return null; } return null; }
primitiveFileGetPosition(void) { // FilePlugin>>#primitiveFileGetPosition SQFile *file; sqInt objectPointer; squeakFileOffsetType position; /* begin fileValueOf: */ objectPointer = stackValue(0); if (!((isBytes(objectPointer)) && ((byteSizeOf(objectPointer)) == (sizeof(SQFile))))) { primitiveFail(); file = null; goto l1; } file = firstIndexableField(objectPointer); l1: /* end fileValueOf: */; if (!(failed())) { position = sqFileGetPosition(file); } if (!(failed())) { popthenPush(2, positive64BitIntegerFor(position)); } }
primitiveExecutableModulesAndOffsets(void) { const struct mach_header *h; const struct mach_header_64 *h64; sqInt i; const char *name; char *nameObjData; sqInt nimages; sqInt resultObj; const struct section *s; const struct section_64 *s64; usqIntptr_t size; usqIntptr_t slide; usqIntptr_t start; sqInt valueObj; # if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 /* _dyld_present was deprecated in 10.5 */ if (!(_dyld_present())) { return primitiveFail(); } # endif /* MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 */ nimages = _dyld_image_count(); resultObj = instantiateClassindexableSize(classArray(), nimages * 4); if (resultObj == 0) { return primitiveFail(); } pushRemappableOop(resultObj); for (i = 0; i < nimages; i += 1) { /* impossible start & size */ start = (size = -1); name = _dyld_get_image_name(i); slide = _dyld_get_image_vmaddr_slide(i); # if __x86_64__ h64 = (const struct mach_header_64 *)_dyld_get_image_header(i); if (!(h64 == null)) { s64 = getsectbynamefromheader_64(h64,SEG_TEXT,SECT_TEXT); if (!(s64 == null)) { start = s64->addr; size = s64->size; } } # else /* __x86_64__ */ h = _dyld_get_image_header(i); if (!(h == null)) { s = getsectbynamefromheader(h,SEG_TEXT,SECT_TEXT); if (!(s == null)) { start = s->addr; size = s->size; } } # endif /* __x86_64__ */ valueObj = instantiateClassindexableSize(classString(), strlen(name)); if (failed()) { popRemappableOop(); return primitiveFail(); } storePointerofObjectwithValue(i * 4, topRemappableOop(), valueObj); nameObjData = arrayValueOf(valueObj); memcpy(nameObjData, name, strlen(name)); valueObj = (BytesPerWord == 8 ? signed64BitIntegerFor(slide) : signed32BitIntegerFor(slide)); if (failed()) { popRemappableOop(); return primitiveFail(); } storePointerofObjectwithValue((i * 4) + 1, topRemappableOop(), valueObj); /* begin positiveMachineIntegerFor: */ valueObj = (BytesPerWord == 8 ? positive64BitIntegerFor(start) : positive32BitIntegerFor(start)); if (failed()) { popRemappableOop(); return primitiveFail(); } storePointerofObjectwithValue((i * 4) + 2, topRemappableOop(), valueObj); /* begin positiveMachineIntegerFor: */ valueObj = (BytesPerWord == 8 ? positive64BitIntegerFor(size) : positive32BitIntegerFor(size)); if (failed()) { popRemappableOop(); return primitiveFail(); } storePointerofObjectwithValue((i * 4) + 3, topRemappableOop(), valueObj); } resultObj = popRemappableOop(); return popthenPush(1, resultObj); }