primitiveErrorAndLog(void) { char *log; sqInt logLen; sqInt logObj; char *logObjData; sqInt resultObj; logLen = 0; log = getlog((&logLen)); resultObj = instantiateClassindexableSize(classArray(), 2); if (resultObj == 0) { primitiveFailFor(PrimErrNoMemory); return null; } storePointerofObjectwithValue(0, resultObj, integerObjectOf(errorAcorn())); if (logLen > 0) { pushRemappableOop(resultObj); logObj = instantiateClassindexableSize(classString(), logLen); if (failed()) { popRemappableOop(); primitiveFailFor(PrimErrNoMemory); return null; } resultObj = popRemappableOop(); logObjData = arrayValueOf(logObj); memcpy(logObjData, log, logLen); storePointerofObjectwithValue(1, resultObj, logObj); } popthenPush(1, resultObj); if (failed()) { return null; } return null; }
primitiveDisassembleAtInMemory(void) { usqIntptr_t address; void *cpu; sqInt cpuAlien; sqInt instrLenOrErr; sqInt log; sqInt logLen; sqInt logObj; sqInt logObjData; char *memory; sqInt resultObj; logLen = 0; address = (BytesPerOop == 4 ? positive32BitValueOf(stackValue(1)) : positive64BitValueOf(stackValue(1))); success(isWordsOrBytes(stackValue(0))); memory = ((char *) (firstIndexableField(stackValue(0)))); cpuAlien = stackValue(2); if (failed()) { return null; } if (((cpu = ((longAt(cpuAlien + BaseHeaderSize)) > 0 ? (cpuAlien + BaseHeaderSize) + BytesPerOop : longAt((cpuAlien + BaseHeaderSize) + BytesPerOop)))) == 0) { primitiveFailFor(PrimErrBadReceiver); return null; } instrLenOrErr = disassembleForAtInSize(cpu, address, memory, byteSizeOf(((sqInt)(sqIntptr_t)(memory) - BaseHeaderSize))); if (instrLenOrErr < 0) { primitiveFailFor(PrimErrInappropriate); return null; } log = getlog((&logLen)); resultObj = instantiateClassindexableSize(classArray(), 2); if (resultObj == 0) { primitiveFailFor(PrimErrNoMemory); return null; } pushRemappableOop(resultObj); logObj = instantiateClassindexableSize(classString(), logLen); if (failed()) { popRemappableOop(); primitiveFailFor(PrimErrNoMemory); return null; } logObjData = arrayValueOf(logObj); memcpy(logObjData, log, logLen); resultObj = popRemappableOop(); storePointerofObjectwithValue(0, resultObj, integerObjectOf(instrLenOrErr)); storePointerofObjectwithValue(1, resultObj, logObj); if (failed()) { return null; } popthenPush(3, resultObj); return null; }
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; }
primitiveGetMacintoshFileTypeAndCreatorFrom(void) { char *aFileName; char creator[8]; sqInt i; sqInt keyLength; sqInt oop; char *ptr; success(isBytes(stackValue(0))); aFileName = ((char *) (firstIndexableField(stackValue(0)))); if (failed()) { return null; } keyLength = byteSizeOf(((sqInt)(sqIntptr_t)(aFileName) - BaseHeaderSize)); sqInternetGetMacintoshFileTypeAndCreatorFromkeySizeinto(aFileName, keyLength, creator); oop = instantiateClassindexableSize(classString(), 8); ptr = firstIndexableField(oop); for (i = 0; i <= 7; i += 1) { ptr[i] = (creator[i]); } if (failed()) { return null; } popthenPush(2, oop); return null; }
primitiveGetStringKeyedBy(void) { char *aKey; char aString[1025]; sqInt i; sqInt keyLength; sqInt oop; char *ptr; sqInt size; success(isBytes(stackValue(0))); aKey = ((char *) (firstIndexableField(stackValue(0)))); if (failed()) { return null; } keyLength = byteSizeOf(((sqInt)(sqIntptr_t)(aKey) - BaseHeaderSize)); size = sqInternetConfigurationGetStringKeyedBykeySizeinto(aKey, keyLength, aString); oop = instantiateClassindexableSize(classString(), size); ptr = firstIndexableField(oop); for (i = 0; i < size; i += 1) { ptr[i] = (aString[i]); } if (failed()) { return null; } popthenPush(2, oop); return null; }
primitiveGetUntrustedUserDirectory(void) { sqInt dirLen; char *dirName; sqInt dirOop; char *dirPtr; sqInt i; dirName = ioGetUntrustedUserDirectory(); if ((dirName == null) || (failed())) { return primitiveFail(); } dirLen = strlen(dirName); dirOop = instantiateClassindexableSize(classString(), dirLen); if (failed()) { return null; } dirPtr = firstIndexableField(dirOop); for (i = 0; i < dirLen; i += 1) { dirPtr[i] = (dirName[i]); } popthenPush(1, dirOop); return 0; }
primitiveDropRequestFileName(void) { sqInt dropIndex; char *dropName; sqInt i; sqInt nameLength; sqInt nameOop; char *namePtr; if (!((methodArgumentCount()) == 1)) { return primitiveFail(); } dropIndex = stackIntegerValue(0); /* dropRequestFileName returns name or NULL on error */ dropName = dropRequestFileName(dropIndex); if (dropName == null) { return primitiveFail(); } nameLength = strlen(dropName); nameOop = instantiateClassindexableSize(classString(), nameLength); namePtr = firstIndexableField(nameOop); for (i = 0; i < nameLength; i += 1) { namePtr[i] = (dropName[i]); } pop(2); push(nameOop); return 0; }
primitiveGSMNewState(void) { sqInt state; state = instantiateClassindexableSize(classByteArray(), gsmStateBytes()); gsmInitState(state + BaseHeaderSize); popthenPush(1, state); return 0; }
primitiveFileStdioHandles(void) { // FilePlugin>>#primitiveFileStdioHandles SQFile fileRecords[3]; sqInt index; sqInt result; sqInt validMask; if (sHFAfn != 0) { if (!( ((sqInt (*)(void))sHFAfn)())) { return primitiveFailFor(PrimErrUnsupported); } } validMask = sqFileStdioHandlesInto(fileRecords); if (validMask == 0) { return primitiveFailFor(PrimErrUnsupported); } result = instantiateClassindexableSize(classArray(), 3); if (result == null) { return primitiveFailFor(PrimErrNoMemory); } pushRemappableOop(result); for (index = 0; index <= 2; index += 1) { if ((validMask & (1 << index)) != 0) { result = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); if (result == null) { popRemappableOop(); return primitiveFailFor(PrimErrNoMemory); } storePointerofObjectwithValue(index, topRemappableOop(), result); memcpy(firstIndexableField(result), (&(fileRecords[index])), sizeof(SQFile)); } } # if COGMTVM fullGC(); # endif /* COGMTVM */ result = popRemappableOop(); popthenPush(1, result); }
/* AioPlugin>>#stringFromCString: */ static sqInt stringFromCString(const char *aCString) { sqInt len; sqInt newString; len = strlen(aCString); newString = instantiateClassindexableSize(classString(), len); strncpy(arrayValueOf(newString), aCString, len); return newString; }
int dropRequestFileHandle(int dropIndex) { int fileHandle, wasBrowserMode; char *dropName = dropRequestFileName(dropIndex); if(!dropName) return interpreterProxy->nilObject(); fileHandle = instantiateClassindexableSize(classByteArray(), fileRecordSize()); wasBrowserMode = fBrowserMode; fBrowserMode = false; sqFileOpen(fileValueOf(fileHandle),(int)dropName, strlen(dropName), 0); fBrowserMode = wasBrowserMode; return fileHandle; }
primitiveLanguage(void) { sqInt oop; oop = instantiateClassindexableSize(classString(), 3); sqLocGetLanguageInto(firstIndexableField(oop)); if (failed()) { return null; } popthenPush(1, oop); return null; }
primitiveDigitGroupingSymbol(void) { sqInt oop; oop = instantiateClassindexableSize(classString(), 1); sqLocGetDigitGroupingSymbolInto(firstIndexableField(oop)); if (failed()) { return null; } popthenPush(1, oop); return null; }
int dropRequestFileHandle(int dropIndex) { char *path= dropRequestFileName(dropIndex); if (path) { // you cannot be serious? int handle= instantiateClassindexableSize(classByteArray(), fileRecordSize()); sqFileOpen((SQFile *)fileValueOf(handle), path, strlen(path), 0); return handle; } return interpreterProxy->nilObject(); }
primitiveDecimalSymbol(void) { // LocalePlugin>>#primitiveDecimalSymbol sqInt oop; oop = instantiateClassindexableSize(classString(), 1); sqLocGetDecimalSymbolInto(firstIndexableField(oop)); if (failed()) { return null; } popthenPush(1, oop); return null; }
primitiveCountry(void) { // LocalePlugin>>#primitiveCountry sqInt oop; oop = instantiateClassindexableSize(classString(), 3); sqLocGetCountryInto(firstIndexableField(oop)); if (failed()) { return null; } popthenPush(1, oop); return null; }
primitiveTimeFormat(void) { sqInt length; sqInt oop; length = sqLocTimeFormatSize(); oop = instantiateClassindexableSize(classString(), length); sqLocGetTimeFormatInto(firstIndexableField(oop)); if (failed()) { return null; } popthenPush(1, oop); return null; }
primitiveCurrencySymbol(void) { sqInt length; sqInt oop; length = sqLocCurrencySymbolSize(); oop = instantiateClassindexableSize(classString(), length); sqLocGetCurrencySymbolInto(firstIndexableField(oop)); if (failed()) { return null; } popthenPush(1, oop); return null; }
primitiveShortDateFormat(void) { // LocalePlugin>>#primitiveShortDateFormat sqInt length; sqInt oop; length = sqLocShortDateFormatSize(); oop = instantiateClassindexableSize(classString(), length); sqLocGetShortDateFormatInto(firstIndexableField(oop)); if (failed()) { return null; } popthenPush(1, oop); return null; }
/* RePlugin>>#allocateByteArrayAndSetRcvrPCREPtrFromPCRE: */ static sqInt allocateByteArrayAndSetRcvrPCREPtrFromPCRE(sqInt aPCREPtr) { void *patByteArrayPtr; sqInt patObject; /* Allocate a Smalltalk ByteArray -- lastAlloc contains the length */ patObject = instantiateClassindexableSize(classByteArray(), lastAlloc); /* begin loadRcvrFromStackAt: */ rcvr = stackObjectValue(0); patByteArrayPtr = arrayValueOf(patObject); memcpy(patByteArrayPtr, (void *) aPCREPtr, lastAlloc); /* begin rcvrPCREBufferFrom: */ storePointerofObjectwithValue(2, rcvr, patObject); return patObject; }
/* RePlugin>>#allocateStringAndSetRcvrErrorStrFromCStr: */ static sqInt allocateStringAndSetRcvrErrorStrFromCStr(const char *aCStrBuffer) { sqInt errorStrObj; void *errorStrObjPtr; sqInt length; /* Allocate errorStrObj */ length = strlen(aCStrBuffer); errorStrObj = instantiateClassindexableSize(classString(), length); /* begin loadRcvrFromStackAt: */ rcvr = stackObjectValue(0); errorStrObjPtr = arrayValueOf(errorStrObj); memcpy(errorStrObjPtr,aCStrBuffer,length); /* begin rcvrErrorStrFrom: */ storePointerofObjectwithValue(4, rcvr, errorStrObj); return errorStrObj; }
primitiveAsyncFileOpen(void) { // AsynchFilePlugin>>#primitiveAsyncFileOpen AsyncFile *f; char *fileName; sqInt fileNameSize; sqInt fOop; sqInt okToOpen; sqInt semaIndex; sqInt writeFlag; success(isBytes(stackValue(2))); fileName = ((char *) (firstIndexableField(stackValue(2)))); writeFlag = booleanValueOf(stackValue(1)); semaIndex = stackIntegerValue(0); if (failed()) { return null; } /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ fileNameSize = slotSizeOf(((int) fileName) - 4); if (sCOAFfn != 0) { okToOpen = ((sqInt (*) (char *, sqInt, sqInt)) sCOAFfn)(fileName, fileNameSize, writeFlag); if (!okToOpen) { primitiveFail(); return null; } } fOop = instantiateClassindexableSize(classByteArray(), sizeof(AsyncFile)); f = asyncFileValueOf(fOop); if (!(failed())) { asyncFileOpen(f, (int)fileName, fileNameSize, writeFlag, semaIndex); } if (failed()) { return null; } popthenPush(4, fOop); return null; }
primitiveReadTablet(void) { sqInt cursorIndex; sqInt result; int * resultPtr; sqInt resultSize; cursorIndex = stackIntegerValue(0); if (failed()) { return null; } resultSize = tabletResultSize(); result = instantiateClassindexableSize(classBitmap(), resultSize); resultPtr = ((int *)firstIndexableField(result)); success(tabletRead(cursorIndex, resultPtr)); if (failed()) { return null; } popthenPush(2, result); return null; }
fileOpenNamesizewritesecure(char *nameIndex, sqInt nameSize, sqInt writeFlag, sqInt secureFlag) { // FilePlugin>>#fileOpenName:size:write:secure: SQFile *file; sqInt fileOop; sqInt okToOpen; fileOop = instantiateClassindexableSize(classByteArray(), sizeof(SQFile)); /* begin fileValueOf: */ if (!((isBytes(fileOop)) && ((byteSizeOf(fileOop)) == (sizeof(SQFile))))) { primitiveFail(); file = null; goto l1; } file = firstIndexableField(fileOop); l1: /* end fileValueOf: */; if (!(failed())) { if (secureFlag) { /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ if (sCOFfn != 0) { /* If the security plugin can be loaded, use it to check for permission. If not, assume it's ok */ okToOpen = ((sqInt (*) (char *, sqInt, sqInt)) sCOFfn)(nameIndex, nameSize, writeFlag); if (!okToOpen) { primitiveFail(); } } } } if (!(failed())) { sqFileOpen(file, nameIndex, nameSize, writeFlag); } return fileOop; }
primitiveSoundGetVolume(void) { // SoundPlugin>>#primitiveSoundGetVolume double left; sqInt results; double right; left = 0; right = 0; snd_Volume((double *) &left,(double *) &right); pushRemappableOop(floatObjectOf(right)); pushRemappableOop(floatObjectOf(left)); pushRemappableOop(instantiateClassindexableSize(classArray(), 2)); results = popRemappableOop(); storePointerofObjectwithValue(0, results, popRemappableOop()); storePointerofObjectwithValue(1, results, popRemappableOop()); if (failed()) { return null; } popthenPush(1, results); return null; }
/* RePlugin>>#allocateByteArrayAndSetRcvrExtraPtrFrom: */ static sqInt allocateByteArrayAndSetRcvrExtraPtrFrom(sqInt anExtraPtr) { void *extraByteArrayPtr; sqInt extraObject; extraByteArrayPtr = 0; if (anExtraPtr) { /* Allocate a Smalltalk ByteArray -- lastAlloc contains the length */ extraObject = instantiateClassindexableSize(classByteArray(), sizeof(real_pcre_extra)); /* begin loadRcvrFromStackAt: */ rcvr = stackObjectValue(0); extraByteArrayPtr = arrayValueOf(extraObject); memcpy(extraByteArrayPtr, (void *) anExtraPtr, sizeof(real_pcre_extra)); } else { extraObject = nilObject(); } /* begin rcvrExtraPtrFrom: */ storePointerofObjectwithValue(3, rcvr, extraObject); return extraObject; }
primitiveGetStringProperty(void) { sqInt handle; sqInt i; char *oopPtr; sqInt propID; sqInt stringLen; sqInt stringOop; char *stringPtr; if (!((methodArgumentCount()) == 2)) { return primitiveFail(); } propID = stackIntegerValue(0); handle = stackIntegerValue(1); if (failed()) { return null; } stringPtr = sqGetStringPropertySSL(handle, propID); if (failed()) { return null; } if (stringPtr == null) { stringOop = nilObject(); } else { stringLen = strlen(stringPtr); stringOop = instantiateClassindexableSize(classString(), stringLen); oopPtr = firstIndexableField(stringOop); for (i = 0; i < stringLen; i += 1) { oopPtr[i] = (stringPtr[i]); } } popthenPush((methodArgumentCount()) + 1, stringOop); return 0; }
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); }