// zapis do pamieci pod adres (mem_ptr + 2), w segmencie ograniczonym przez // segment_end // zwraca: 1 - nastapilo kasowanie pamieci; 0 - kasowanie nie nastapilo int save_to_memory(unsigned int int_to_save, unsigned int **mem_ptr, unsigned int segment_start, unsigned int segment_end) { int retval = 0; unsigned short wdog_state; *mem_ptr += 1; if(*mem_ptr > (unsigned int*)segment_end) { retval = 1; clear_memory((unsigned int*)segment_start);//kasuj pamiec *mem_ptr = (unsigned int*)segment_start; } wdog_state = WDTCTL; // zachowaj stan watchdoga WDTCTL = WDTPW + WDTCNTCL; // zresetuj watchdoga WDTCTL = WDTPW + WDTHOLD; // wylacz watch-doga istate_t state = __get_interrupt_state(); __disable_interrupt(); FCTL3 = FWKEY; // wyczysc LOCK FCTL1 = FWKEY + WRT; // wlacz zapis **mem_ptr = int_to_save; // zapis FCTL1 = FWKEY; // wylacz zapis FCTL3 = FWKEY + LOCK; // ustaw LOCK if ((WATCHDOG_ON) && !(wdog_state & WDTHOLD)) WDTCTL = WDTPW; // wlacz watchdoga __set_interrupt_state(state); return retval; }
int main() { int T, tc, i, j; freopen("cultures_info.txt", "r", stdin); setbuf(stdout, NULL); scanf("%d", &T); for (tc = 1; tc <= T; tc++) { scanf("%d %d", &N, &M); for (i = 1; i <= M; i++) { for (j = 1; j <= N; j++) { scanf(" %c", &a[i][j]); if (a[i][j] == 'W') W[j]++; else E[j]++; WN[0] += W[j]; } } //printf("Accumulation of W Number = %d\n", WN[0]); int min = WN[0]; int divided_idx = 0; for (i = 1; i <= N; i++) { EN[i] = EN[i - 1] + E[i]; WN[i] = WN[i - 1] - W[i]; if ((EN[i] + WN[i]) < min) { min = EN[i] + WN[i]; divided_idx = i; } } printf("#%d %d | %d\n", tc, divided_idx, divided_idx + 1); clear_memory(); } return 0; }
Configure& Configure::operator=(const Configure &co) { //std::cout << "Configure assignment operator is called" << std::endl; if (this == &co) return *this; opcount = co.opcount; max_size = co.max_size; opname_size = co.opname_size; opchoice_size = co.opchoice_size; opvalue_size = co.opvalue_size; clear_memory(); preallocate_memory(); memcpy(opid, co.opid, opcount * sizeof(int)); memcpy(opname_store, co.opname_store, opname_size * sizeof(char)); memcpy(opchoice_store, co.opchoice_store, opchoice_size * sizeof(char)); memcpy(opvalue_store, co.opvalue_store, opvalue_size * sizeof(char)); for (int i = 0; i < opcount; i++) { opname[i] = opname_store + int(co.opname[i] - co.opname[0]); opchoice[i] = opchoice_store + int(co.opchoice[i] - co.opchoice[0]); opvalue[i] = opvalue_store + int(co.opvalue[i] - co.opvalue[0]); } return *this; }
static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UChar *needle, Match *match_results, int32_t *final_positions, int32_t needle_char_len, UChar *level1, UChar *level2, UChar *level3) { Stack stack = {0}; int32_t i = 0, maxhl = 0; int32_t r = 0, *positions = NULL; MatchInfo *matches = NULL; bool ok = FALSE; MemoryItem ***memo = NULL; int32_t needle_len = u_strlen(needle); if (needle_len <= 0 || item_count <= 0) { for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0; ok = TRUE; goto end; } matches = (MatchInfo*)calloc(item_count, sizeof(MatchInfo)); positions = (int32_t*)calloc(2*needle_len, sizeof(int32_t)); // One set of positions is the final answer and one set is working space if (matches == NULL || positions == NULL) {PyErr_NoMemory(); goto end;} for (i = 0; i < (int32_t)item_count; i++) { matches[i].haystack = items[i]; matches[i].haystack_len = item_lengths[i]; matches[i].needle = needle; matches[i].needle_len = needle_len; matches[i].max_score_per_char = (1.0 / matches[i].haystack_len + 1.0 / needle_len) / 2.0; matches[i].level1 = level1; matches[i].level2 = level2; matches[i].level3 = level3; maxhl = MAX(maxhl, matches[i].haystack_len); } if (maxhl <= 0) { for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0; ok = TRUE; goto end; } alloc_stack(&stack, needle_len, maxhl); memo = alloc_memory(needle_len, maxhl); if (stack.items == NULL || memo == NULL) {PyErr_NoMemory(); goto end;} for (i = 0; i < (int32_t)item_count; i++) { for (r = 0; r < needle_len; r++) { positions[r] = -1; } stack_clear(&stack); clear_memory(memo, needle_len, matches[i].haystack_len); matches[i].memo = memo; match_results[i].score = process_item(&matches[i], &stack, positions); convert_positions(positions, final_positions + i, matches[i].haystack, needle_char_len, needle_len, match_results[i].score); } ok = TRUE; end: nullfree(positions); nullfree(stack.items); nullfree(matches); nullfree(memo); return ok; }
void free(void *ptr) { if (ptr != NULL && list != NULL) { if (modif_list2(ptr) != 0) check_last_element(ptr); clear_memory(); } else if (list == NULL) { brk(start); end = sbrk(0); } }
int main(int argc, char **argv) { FILE* fp; // file pointer to input file char move = '\0'; // character depicting next move int direction[2]; // direction of the move in cartesian plane Position* head = NULL; // head of set (linked list) Position santa_position; // current santa position santa_position.x = 0; santa_position.y = 0; Position robot_position; // current robot position robot_position.x = 0; robot_position.y = 0; mark_position_visited(&head, santa_position); // Since Santa goes first, // Robot would have been the one before that. // Current member will hold whoever is moving currently. Position* current_member = &robot_position; fp = fopen("./input.txt", "r"); // Read the file one character at a time while((move=fgetc(fp)) != EOF) { // Get the next move parse_direction(move, direction); // Get position of currently active member current_member = switcher(current_member, &santa_position, &robot_position); // Add the next move to current position current_member->x += direction[0]; current_member->y += direction[1]; // Check if position has been previously visited. // If it hasn't been, mark it as visited. if (!position_was_visited(head, *current_member)) { mark_position_visited(&head, *current_member); } } printf("%ld\n", list_length(head)); // Free the list and close the file. clear_memory(&head); fclose(fp); return 0; }
void fill_bus_entry(struct bus_entry *entry, long bus) { OSErr status; SCSIBusInquiryPB pb; long len; long result; long x, y; if (!AsyncSCSIPresent()) { entry->sort_value = 0; entry->max_id = 7; entry->master_id = 7; return; } len = sizeof(SCSIBusInquiryPB); clear_memory((Ptr) &pb, len); pb.scsiPBLength = len; pb.scsiFunctionCode = SCSIBusInquiry; pb.scsiDevice.bus = bus; status = SCSIAction((SCSI_PB *) &pb); if (status != noErr) { result = 6; } else { switch (pb.scsiHBAslotType) { case scsiMotherboardBus: x = 0; break; case scsiPDSBus: x = 1; break; case scsiNuBus: x = 2; break; case scsiPCIBus: x = 3; break; case scsiFireWireBridgeBus: x = 4; break; case scsiPCMCIABus: x = 5; break; default: x = 7 + pb.scsiHBAslotType; break; }; switch (pb.scsiFeatureFlags & scsiBusInternalExternalMask) { case scsiBusInternal: y = 0; break; case scsiBusInternalExternal: y = 1; break; case scsiBusExternal: y = 2; break; default: case scsiBusInternalExternalUnknown: y = 3; break; }; result = x * 4 + y; } entry->sort_value = result; entry->max_id = pb.scsiMaxLUN; entry->master_id = pb.scsiInitiatorID; }
int stat (const char * file_name, struct stat * file_stat) { _kernel_osfile_block osfile_blk; int rc; int unix_time; // printf ("Statting %s", file_name); clear_memory ((unsigned int *) file_stat, sizeof(struct stat)); rc = _kernel_osfile (17, file_name, &osfile_blk); if ((rc >= 1) && (rc <= 3)) { file_stat -> st_size = osfile_blk.start; if (osfile_blk.end & 0x01) file_stat -> st_mode |= S_IREAD; if (osfile_blk.end & 0x02) file_stat -> st_mode |= S_IWRITE; if (osfile_blk.end & 0x10) file_stat -> st_mode |= 0044; if (osfile_blk.end & 0x20) file_stat -> st_mode |= 0022; if (rc == 1) file_stat -> st_mode |= S_IFREG; else file_stat -> st_mode |= S_IFDIR; unix_time = conv_arctime_to_unixtime (osfile_blk.load & 0xFF, osfile_blk.exec); file_stat -> st_atime = unix_time; file_stat -> st_mtime = unix_time; file_stat -> st_ctime = unix_time; file_stat -> st_nlink = 1; file_stat -> st_uid = 200; file_stat -> st_gid = 21; file_stat -> st_blksize = 512; /* file_stat -> st_blocks = osfile_blk.start / 512; */ //errno = 0; rc = 0; } else { //errno = ENOENT; rc = 1; } // printf (" and returned %d (%X)\n", rc, file_stat -> st_mode); return (rc); }
MEDIA SCSI_FindDevice(long dRefNum) { SCSIDriverPB pb; OSErr status; short targetID; status = nsvErr; if (AsyncSCSIPresent()) { clear_memory((Ptr) &pb, sizeof pb); pb.scsiPBLength = sizeof (SCSIDriverPB); pb.scsiCompletion = NULL; pb.scsiFlags = 0; pb.scsiFunctionCode = SCSILookupRefNumXref; pb.scsiDevice.bus = kNoDevice; /* was *((long *) &pb.scsiDevice) = 0xFFFFFFFFL; */ do { status = SCSIAction((SCSI_PB *) &pb); if (status != noErr) { break; } else if (pb.scsiDriver == dRefNum && pb.scsiDevice.bus != kNoDevice) { return open_scsi_as_media(pb.scsiDevice.bus, pb.scsiDevice.targetID); } else { pb.scsiDevice = pb.scsiNextDevice; } } while (pb.scsiDevice.bus != kNoDevice); } if (status == nsvErr) { /* * The asynchronous SCSI Manager is missing or the * driver didn't register with the SCSI Manager.*/ targetID = DriverRefNumToSCSI(dRefNum); if (targetID >= 0 && targetID <= 6) { return open_old_scsi_as_media(targetID); } } return 0; }
/* * Do one SCSI Command. If the device returns Check Condition, issue Request Sense * (original SCSI Manager only) and interpret the sense data. The original SCSI * command status is in SCB.status. If it is statusErr or scsiNonZeroStatus, * the sense data is in SCB.sense and the Request Sense status is in * SCB.requestSenseStatus. * * If sensePtr[0] is non-zero, there is a message. */ OSErr DoSCSICommand( DeviceIdent scsiDevice, ConstStr255Param currentAction, const SCSI_CommandPtr callerSCSICommand, Ptr dataBuffer, ByteCount dataLength, UInt32 scsiFlags, ByteCount *actualTransferCount, SCSI_Sense_Data *sensePtr, StringPtr senseMessage ) { OSErr status; SCSI_Command theSCSICommand; unsigned short cmdBlockLength; // SpinSpinner(&gCurrentInfoPtr->spinnerRecord); // ShowProgressAction(currentAction); /* * Store the LUN information in the command block - this is needed * for devices that only examine the command block for LUN values. * (On SCSI-II, the asynchronous SCSI Manager also includes the * LUN in the identify message). */ theSCSICommand = *callerSCSICommand; theSCSICommand.scsi[1] &= ~0xE0; theSCSICommand.scsi[1] |= (scsiDevice.LUN & 0x03) << 5; cmdBlockLength = GetCommandLength(&theSCSICommand); if (senseMessage != NULL) senseMessage[0] = 0; if (sensePtr != NULL) sensePtr->errorCode = 0; if (scsiDevice.bus == kOriginalSCSIBusAdaptor) { status = DoOriginalSCSICommand( scsiDevice, &theSCSICommand, cmdBlockLength, dataBuffer, dataLength, scsiFlags, actualTransferCount, sensePtr ); } else { clear_memory(gSCSIExecIOPBPtr, gSCSIExecIOPBPtrLen); #define PB (*gSCSIExecIOPBPtr) PB.scsiPBLength = gSCSIExecIOPBPtrLen; PB.scsiFunctionCode = SCSIExecIO; PB.scsiDevice = scsiDevice; PB.scsiTimeout = kSCSICommandTimeout; /* * Fiddle the flags so they're the least disruptive possible. */ PB.scsiFlags = scsiFlags | (scsiSIMQNoFreeze | scsiDontDisconnect); if (sensePtr != NULL) { PB.scsiSensePtr = (UInt8 *) sensePtr; PB.scsiSenseLength = sizeof *sensePtr; } BlockMoveData(&theSCSICommand, &PB.scsiCDB.cdbBytes[0], cmdBlockLength); PB.scsiCDBLength = cmdBlockLength; if (dataBuffer != NULL) { PB.scsiDataPtr = (UInt8 *) dataBuffer; PB.scsiDataLength = dataLength; PB.scsiDataType = scsiDataBuffer; PB.scsiTransferType = scsiTransferPolled; } status = SCSIAction((SCSI_PB *) &PB); if (status == noErr) status = PB.scsiResult; if (status == scsiSelectTimeout) status = scsiDeviceNotThere; if (actualTransferCount != NULL) { /* * Make sure that the actual transfer count does not exceed * the allocation count (some devices spit extra data at us!) */ *actualTransferCount = dataLength - PB.scsiDataResidual; if (*actualTransferCount > dataLength) *actualTransferCount = dataLength; } #undef PB } if (status == scsiNonZeroStatus && sensePtr != NULL && sensePtr->errorCode != 0 && senseMessage != NULL) { // FormatSenseMessage(sensePtr, senseMessage); // ShowProgressAction(senseMessage); } return (status); }
CSparseCholeskyInterface::~CSparseCholeskyInterface() { clear_memory(); }
BonminInterface::~BonminInterface() { clear_memory(); }
IdasInterface::~IdasInterface() { clear_memory(); }
static int load_object (struct linux_binprm * bprm, struct pt_regs *regs, int lib_ok) { COFF_FILHDR *coff_hdr = (COFF_FILHDR *) bprm->buf; /* COFF Header */ COFF_SCNHDR *sect_bufr; /* Pointer to section table */ COFF_SCNHDR *text_sect; /* Pointer to the text section */ COFF_SCNHDR *data_sect; /* Pointer to the data section */ COFF_SCNHDR *bss_sect; /* Pointer to the bss section */ int text_count; /* Number of text sections */ int data_count; /* Number of data sections */ int bss_count; /* Number of bss sections */ int lib_count; /* Number of lib sections */ unsigned int start_addr = 0;/* Starting location for program */ int status = 0; /* Result status register */ int fd = -1; /* Open file descriptor */ struct file *fp = NULL; /* Pointer to the file at "fd" */ short int sections = 0; /* Number of sections in the file */ short int aout_size = 0; /* Size of the a.out header area */ short int flags; /* Flag bits from the COFF header */ #ifdef COFF_DEBUG printk ("binfmt_coff entry: %s\n", bprm->filename); #endif /* * Validate the magic value for the object file. */ do { if (COFF_I386BADMAG (*coff_hdr)) { #ifdef COFF_DEBUG printk ("bad filehdr magic\n"); #endif status = -ENOEXEC; break; } /* * The object file should have 32 BIT little endian format. Do not allow * it to have the 16 bit object file flag set as Linux is not able to run * on the 80286/80186/8086. */ flags = COFF_SHORT (coff_hdr->f_flags); if ((flags & (COFF_F_AR32WR | COFF_F_AR16WR)) != COFF_F_AR32WR) { #ifdef COFF_DEBUG printk ("invalid f_flags bits\n"); #endif status = -ENOEXEC; break; } /* * Extract the header information which we need. */ sections = COFF_SHORT (coff_hdr->f_nscns); /* Number of sections */ aout_size = COFF_SHORT (coff_hdr->f_opthdr); /* Size of opt. headr */ /* * If the file is not executable then reject the execution. This means * that there must not be external references. */ if ((flags & COFF_F_EXEC) == 0) { #ifdef COFF_DEBUG printk ("not executable bit\n"); #endif status = -ENOEXEC; break; } /* * There must be at least one section. */ if (sections == 0) { #ifdef COFF_DEBUG printk ("no sections\n"); #endif status = -ENOEXEC; break; } /* * Do some additional consistency checks. * The system requires mapping for this loader. If you try * to use a file system with no mapping, the format is not valid. */ if (!bprm->inode->i_op || !bprm->inode->i_op->default_file_ops->mmap) { #ifdef COFF_DEBUG printk ("no mmap in fs\n"); #endif status = -ENOEXEC; } } while (0); /* * Allocate a buffer to hold the entire coff section list. */ if (status >= 0) { int nbytes = sections * COFF_SCNHSZ; sect_bufr = (COFF_SCNHDR *) kmalloc (nbytes, GFP_KERNEL); if (0 == sect_bufr) { #ifdef COFF_DEBUG printk ("kmalloc failed\n"); #endif status = -ENOEXEC; } /* * Read the section list from the disk file. */ else { int old_fs = get_fs (); set_fs (get_ds ()); /* Make it point to the proper location */ status = read_exec (bprm->inode, /* INODE for file */ aout_size + COFF_FILHSZ, /* Offset in the file */ (char *) sect_bufr, /* Buffer for read */ nbytes); /* Byte count reqd. */ set_fs (old_fs); /* Restore the selector */ #ifdef COFF_DEBUG if (status < 0) printk ("read aout hdr, status = %d\n", status); #endif } } else sect_bufr = NULL; /* Errors do not have a section buffer */ /* * Count the number of sections for the required types and store the location * of the last section for the three primary types. */ text_count = 0; data_count = 0; bss_count = 0; lib_count = 0; text_sect = NULL; data_sect = NULL; bss_sect = NULL; /* * Loop through the sections and find the various types */ if (status >= 0) { int nIndex; COFF_SCNHDR *sect_ptr = sect_bufr; for (nIndex = 0; nIndex < sections; ++nIndex) { long int sect_flags = COFF_LONG (sect_ptr->s_flags); switch (sect_flags) { case COFF_STYP_TEXT: text_sect = sect_ptr; ++text_count; status = is_properly_aligned (sect_ptr); break; case COFF_STYP_DATA: data_sect = sect_ptr; ++data_count; status = is_properly_aligned (sect_ptr); break; case COFF_STYP_BSS: bss_sect = sect_ptr; ++bss_count; break; case COFF_STYP_LIB: #ifdef COFF_DEBUG printk (".lib section found\n"); #endif ++lib_count; break; default: break; } sect_ptr = (COFF_SCNHDR *) & ((char *) sect_ptr)[COFF_SCNHSZ]; } /* * Ensure that there are the required sections. There must be one text * sections and one each of the data and bss sections for an executable. * A library may or may not have a data / bss section. */ if (text_count != 1) { status = -ENOEXEC; #ifdef COFF_DEBUG printk ("no text sections\n"); #endif } else { if (lib_ok) { if (data_count != 1 || bss_count != 1) { status = -ENOEXEC; #ifdef COFF_DEBUG printk ("no .data nor .bss sections\n"); #endif } } } } /* * If there is no additional header then assume the file starts at * the first byte of the text section. This may not be the proper place, * so the best solution is to include the optional header. A shared library * __MUST__ have an optional header to indicate that it is a shared library. */ if (status >= 0) { if (aout_size == 0) { if (!lib_ok) { status = -ENOEXEC; #ifdef COFF_DEBUG printk ("no header in library\n"); #endif } start_addr = COFF_LONG (text_sect->s_vaddr); } /* * There is some header. Ensure that it is sufficient. */ else { if (aout_size < COFF_AOUTSZ) { status = -ENOEXEC; #ifdef COFF_DEBUG printk ("header too small\n"); #endif } else { COFF_AOUTHDR *aout_hdr = /* Pointer to a.out header */ (COFF_AOUTHDR *) & ((char *) coff_hdr)[COFF_FILHSZ]; short int aout_magic = COFF_SHORT (aout_hdr->magic); /* id */ /* * Validate the magic number in the a.out header. If it is valid then * update the starting symbol location. Do not accept these file formats * when loading a shared library. */ switch (aout_magic) { case COFF_OMAGIC: case COFF_ZMAGIC: case COFF_STMAGIC: if (!lib_ok) { status = -ENOEXEC; #ifdef COFF_DEBUG printk ("wrong a.out header magic\n"); #endif } start_addr = (unsigned int) COFF_LONG (aout_hdr->entry); break; /* * Magic value for a shared library. This is valid only when loading a * shared library. (There is no need for a start_addr. It won't be used.) */ case COFF_SHMAGIC: if (lib_ok) { #ifdef COFF_DEBUG printk ("wrong a.out header magic\n"); #endif status = -ENOEXEC; } break; default: #ifdef COFF_DEBUG printk ("wrong a.out header magic\n"); #endif status = -ENOEXEC; break; } } } } /* * Fetch a file pointer to the executable. */ if (status >= 0) { fd = open_inode (bprm->inode, O_RDONLY); if (fd < 0) { #ifdef COFF_DEBUG printk ("can not open inode, result = %d\n", fd); #endif status = fd; } else fp = current->files->fd[fd]; } else fd = -1; /* Invalidate the open file descriptor */ /* * Generate the proper values for the text fields * * THIS IS THE POINT OF NO RETURN. THE NEW PROCESS WILL TRAP OUT SHOULD * SOMETHING FAIL IN THE LOAD SEQUENCE FROM THIS POINT ONWARD. */ if (status >= 0) { long text_scnptr = COFF_LONG (text_sect->s_scnptr); long text_size = COFF_LONG (text_sect->s_size); long text_vaddr = COFF_LONG (text_sect->s_vaddr); long data_scnptr; long data_size; long data_vaddr; long bss_size; long bss_vaddr; /* * Generate the proper values for the data fields */ if (data_sect != NULL) { data_scnptr = COFF_LONG (data_sect->s_scnptr); data_size = COFF_LONG (data_sect->s_size); data_vaddr = COFF_LONG (data_sect->s_vaddr); } else { data_scnptr = 0; data_size = 0; data_vaddr = 0; } /* * Generate the proper values for the bss fields */ if (bss_sect != NULL) { bss_size = COFF_LONG (bss_sect->s_size); bss_vaddr = COFF_LONG (bss_sect->s_vaddr); } else { bss_size = 0; bss_vaddr = 0; } /* * Flush the executable from memory. At this point the executable is * committed to being defined or a segmentation violation will occur. */ if (lib_ok) { #ifdef COFF_DEBUG printk ("flushing executable\n"); #endif flush_old_exec (bprm); /* * Define the initial locations for the various items in the new process */ current->mm->mmap = NULL; current->mm->rss = 0; /* * Construct the parameter and environment string table entries. */ bprm->p += change_ldt (0, bprm->page); bprm->p -= MAX_ARG_PAGES*PAGE_SIZE; bprm->p = (unsigned long) create_tables ((char *) bprm->p, bprm->argc, bprm->envc, 1); /* * Do the end processing once the stack has been constructed */ current->mm->start_code = text_vaddr & PAGE_MASK; current->mm->end_code = text_vaddr + text_size; current->mm->end_data = data_vaddr + data_size; current->mm->start_brk = current->mm->brk = bss_vaddr + bss_size; current->suid = current->euid = bprm->e_uid; current->sgid = current->egid = bprm->e_gid; current->executable = bprm->inode; /* Store inode for file */ ++bprm->inode->i_count; /* Count the open inode */ regs->eip = start_addr; /* Current EIP register */ regs->esp = current->mm->start_stack = bprm->p; } /* * Map the text pages */ #ifdef COFF_DEBUG printk (".text: vaddr = %d, size = %d, scnptr = %d\n", text_vaddr, text_size, text_scnptr); #endif status = do_mmap (fp, text_vaddr & PAGE_MASK, text_size + (text_vaddr & ~PAGE_MASK), PROT_READ | PROT_EXEC, MAP_FIXED | MAP_SHARED, text_scnptr & PAGE_MASK); status = (status == (text_vaddr & PAGE_MASK)) ? 0 : -ENOEXEC; /* * Map the data pages */ if (status >= 0 && data_size != 0) { #ifdef COFF_DEBUG printk (".data: vaddr = %d, size = %d, scnptr = %d\n", data_vaddr, data_size, data_scnptr); #endif status = do_mmap (fp, data_vaddr & PAGE_MASK, data_size + (data_vaddr & ~PAGE_MASK), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, data_scnptr & PAGE_MASK); status = (status == (data_vaddr & PAGE_MASK)) ? 0 : -ENOEXEC; } /* * Construct the bss data for the process. The bss ranges from the * end of the data (which may not be on a page boundary) to the end * of the bss section. Allocate any necessary pages for the data. */ if (status >= 0 && bss_size != 0) { #ifdef COFF_DEBUG printk (".bss: vaddr = %d, size = %d\n", bss_vaddr, bss_size); #endif zeromap_page_range (PAGE_ALIGN (bss_vaddr), PAGE_ALIGN (bss_size), PAGE_COPY); status = clear_memory (bss_vaddr, bss_size); } /* * Load any shared library for the executable. */ if (status >= 0 && lib_ok && lib_count != 0) { int nIndex; COFF_SCNHDR *sect_ptr = sect_bufr; /* * Find the library sections. (There should be at least one. It was counted * earlier.) This will eventually recurse to our code and load the shared * library with our own procedures. */ for (nIndex = 0; nIndex < sections; ++nIndex) { long int sect_flags = COFF_LONG (sect_ptr->s_flags); if (sect_flags == COFF_STYP_LIB) { status = preload_library (bprm, sect_ptr, fp); if (status != 0) break; } sect_ptr = (COFF_SCNHDR *) &((char *) sect_ptr) [COFF_SCNHSZ]; } } /* * Generate any needed trap for this process. If an error occurred then * generate a segmentation violation. If the process is being debugged * then generate the load trap. (Note: If this is a library load then * do not generate the trap here. Pass the error to the caller who * will do it for the process in the outer lay of this procedure call.) */ if (lib_ok) { if (status < 0) send_sig (SIGSEGV, current, 0); /* Generate the error trap */ else { if (current->flags & PF_PTRACED) send_sig (SIGTRAP, current, 0); } status = 0; /* We are committed. It can't fail */ } } /* * Do any cleanup processing */ if (fd >= 0) sys_close (fd); /* Close unused code file */ if (sect_bufr != NULL) kfree (sect_bufr); /* Release section list buffer */ /* * Return the completion status. */ #ifdef COFF_DEBUG printk ("binfmt_coff: result = %d\n", status); #endif return (status); }
SnoptInterface::~SnoptInterface() { clear_memory(); }
Newton::~Newton() { clear_memory(); }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // wylacz watchdoga // ile razy nalezy sprawdzic wartosc WE podczas eliminacji drgan const int ELIM_CHECKS = DCO_FQ / ELIM_TIME_DIV; int i = 0; int elim_state = 0; // stan eliminacji drgan : // 0 - czekamy na 0, 1 - czekamy na 1 int state = S_NORMAL; // stan ukladu - normalny int stations_index = 0; // indeks aktualnie wybranej stacji unsigned int control_sum = 0; // suma kontrolna segmentu licznikow int seg_clear = 0; // czy w operacji zapisu nastapilo kasowanie? // wskaznik do pamieci - adres licznika stacji unsigned int *mem_ptr = 0; // adres sumy kontrolnej segmentu licznika stacji unsigned int *cs_mem_ptr = 0; // czy powiodlo sie policzenie sumy kontrolnej? int ctrl_sum_check1_succeeded = 0; // timer A TACTL |= TASSEL_1; TACCTL0 |= CCIE; // Wyjscie danych na LCD P1DIR = 0xFF; P1OUT = 0x00; // Wyjscie sterujace LCD // pin 1 = wyjscie strobujace E // pin 2 = wyjscie RS P3DIR = 0xFF; P3OUT = 0x00; // Uruchomienie wyswietlacza delay_us(30000); // Duzy delay, zeby LCD wstal poprawnie po resecie P1OUT = 0x38; // Function set (8bit, 1 line) strobe_e(); P1OUT = 0x0C; // Display on/off control strobe_e(); P1OUT = 0x06; // Entry mode set (increments DDRAM address) strobe_e(); delay_us(1000); P1OUT = LCD_CLEAR; strobe_e(); delay_us(3000); /* // test pokazujacy blad sumy kontrolnej mem_ptr = (unsigned int*)SEGMENT_START; save_to_memory(5, &mem_ptr, SEGMENT_START, SEGMENT_END); cs_mem_ptr = (unsigned int*)CS_SEG_START; save_to_memory(6, &cs_mem_ptr, CS_SEG_START, CS_SEG_END); // koniec testu */ /* // test pokazujacy reakcje na przepelnienie segmentu pamieci clear_memory((unsigned int*)SEGMENT_START); clear_memory((unsigned int*)CS_SEG_START); cs_mem_ptr = (unsigned int*)(CS_SEG_START - 2); stations_index = stations_num; for (mem_ptr = (unsigned int*)(SEGMENT_START - 2); mem_ptr < (unsigned int*)(SEGMENT_END - 4);) { save_to_memory(stations_index, &mem_ptr, SEGMENT_START, SEGMENT_END); control_sum += stations_num; save_to_memory(control_sum, &cs_mem_ptr, CS_SEG_START, CS_SEG_END); } for (i = 0; i < 4; i++) { save_to_memory(stations_index, &mem_ptr, SEGMENT_START, SEGMENT_END); control_sum += stations_num; save_to_memory(control_sum, &cs_mem_ptr, CS_SEG_START, CS_SEG_END); } stations_index = 0; control_sum = 0; // koniec testu */ // znajdz ostatnia legalna wartosc licznika w pamieci mem_ptr = find_address(SEGMENT_START, SEGMENT_END); if (mem_ptr >= (unsigned int*)SEGMENT_START) { stations_index = *mem_ptr; // pobierz z pamieci wartosc licznika, // o ile istnieje (wpp 0) } // znajdz ostatnia legalna wartosc sumy kontrolnej w pamieci cs_mem_ptr = find_address(CS_SEG_START, CS_SEG_END); if (cs_mem_ptr >= (unsigned int*)CS_SEG_START) { control_sum = *cs_mem_ptr; // pobierz z pamieci wartosc sumy kontrolnej, // o ile istnieje (wpp 0) } // sprawdz sume kontrolna1 if ((CS_SEG_END - (unsigned int)cs_mem_ptr) == (SEGMENT_END - (unsigned int)mem_ptr)) { if (control_sum == calculate_ctrl_sum(SEGMENT_START, SEGMENT_END)) { ctrl_sum_check1_succeeded = 1; // spr sumy kontrolnej - sukces! } } // przy braku dualBIOSa jesli suma kontrolna sie nie zgadza, zresetuj licznik if (ctrl_sum_check1_succeeded == 0) { state = S_CTRL_SUM_ERROR; clear_memory((unsigned int*)SEGMENT_START); clear_memory((unsigned int*)CS_SEG_START); mem_ptr = (unsigned int*)SEGMENT_START; cs_mem_ptr = (unsigned int*)CS_SEG_START; stations_index = 0; control_sum = 0; } // sprawdz stan ukladu i wyswietl odpowiedni komunikat if (IFG1 & WDTIFG) // uklad zostal zresetowany przez watchdoga { IFG1 &= 0xFE; // wyczyszczenie znacznika przerwania state = S_WDOG_RESET; // zostalismy zresetowani przez wdoga display_string(wdog_error); } else if (state == S_CTRL_SUM_ERROR) // wystapil blad sumy kontrolnej { display_string(ctrl_sum_error); } else // uklad dziala poprawnie { display_string(stations[stations_index]); } WDTCTL = WDTPW + WDTHOLD; // wylacz watchdoga przed wejsciem do petli g_flags = 0; // przyciski P2IES = 0xFF; // przerwanie wyzwalane 1->0 P2IE = BIT0 + BIT1; // przyciski wyboru stacji //petla glowna programu while(1) { /***** spr, czy nie przyszlo kolejne przerwanie w trakcie petli glownej *****/ __disable_interrupt(); if (g_flags != 0) { __enable_interrupt(); goto mainloop_internal; } //else : zasypiajac odblokujemy przerwania //zasypiamy _BIS_SR(LPM0_bits + GIE); __no_operation(); mainloop_internal: /******* eliminacja drgan - wcisniecie przycisku (1->0) *******/ if ((elim_state == 0) && ((g_flags & BIT0)|| (g_flags & BIT1))) { /* // test dzialania watchdoga if (g_flags & BIT0) while(1); // koniec testu */ i = 0; while ((i < ELIM_CHECKS) && (g_curr_input == P2IN)) { i++; } if (WATCHDOG_ON) { WDTCTL = WDTPW + WDTCNTCL; // wyczysc licznik watchdoga WDTCTL = WDTPW + WDTHOLD; // wylacz watchdoga } if (i == ELIM_CHECKS) // jesli rzeczywiscie wcisniety { if (state != S_NORMAL)// ustawiamy normalny stan poczatkowy ukladu { state = S_NORMAL; display_string(stations[stations_index]); } // nic wiecej nie robimy else { if (g_flags & BIT1) stations_index = (stations_index + 1) % stations_num; else if (g_flags & BIT0) stations_index = (stations_index == 0) ? (stations_num - 1): stations_index - 1; display_string(stations[stations_index]); seg_clear = save_to_memory(stations_index, &mem_ptr, SEGMENT_START, SEGMENT_END); if (seg_clear == 1) // jesli skasowano segment, suma sie resetuje control_sum = stations_index; else control_sum += stations_index; save_to_memory(control_sum, &cs_mem_ptr, CS_SEG_START, CS_SEG_END); } __disable_interrupt(); P2IES = 0; // przelacz zbocze, ktorym wyzwalane jest INT P2IFG = 0; // wyczysc ew. smieci __enable_interrupt(); elim_state = 1; } g_flags = 0; P2IE = BIT0 + BIT1; // przyciski wyboru stacji } /******* eliminacja drgan - zwolnienie przycisku (0->1) *******/ else if ((elim_state == 1) && ((g_flags & BIT0)|| (g_flags & BIT1))) { i = 0; while ((i < ELIM_CHECKS) && (g_curr_input == P2IN)) { i++; } if (WATCHDOG_ON) { WDTCTL = WDTPW + WDTCNTCL; // wyczysc licznik watchdoga WDTCTL = WDTPW + WDTHOLD; // wylacz watchdoga } if (i == ELIM_CHECKS) // jesli rzeczywiscie wycisniety { __disable_interrupt(); P2IES = 0xFF; // przelacz zbocze, ktorym wyzwalane jest INT P2IFG = 0; // wyczysc ew. smieci __enable_interrupt(); elim_state = 0; } g_flags = 0; P2IE = BIT0 + BIT1; // przyciski wyboru stacji } } return 0; }
GurobiInterface::~GurobiInterface() { clear_memory(); }
static int xout_amen(struct file *fp, struct xseg *sp, int pageable, u_long *addrp, struct xexec *xexec, struct pt_regs *regs, int impure) { u_long bss_size, bss_base, ce; int err = 0; ce = cap_mmap(0); cap_mmap(1); bss_size = sp->xs_vsize - sp->xs_psize; bss_base = sp->xs_rbase + sp->xs_psize; /* * If it is a text segment update the code boundary * markers. If it is a data segment update the data * boundary markers. */ if (sp->xs_type == XS_TTEXT || sp->xs_type == XS_TDATA) { if ((sp->xs_rbase + sp->xs_psize) > current->mm->end_code) current->mm->end_code = (sp->xs_rbase + sp->xs_psize); } if ((sp->xs_rbase + sp->xs_vsize) > current->mm->brk) { current->mm->start_brk = current->mm->brk = PAGE_ALIGN(sp->xs_rbase + sp->xs_vsize); } if (!pageable) { dprintk(KERN_DEBUG "xout: Null map 0x%08lx, length 0x%08lx\n", sp->xs_rbase, sp->xs_vsize); down_write(¤t->mm->mmap_sem); err = do_mmap(NULL, sp->xs_rbase, sp->xs_vsize, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED|MAP_PRIVATE|MAP_32BIT, 0); up_write(¤t->mm->mmap_sem); goto out; } dprintk(KERN_DEBUG "xout: mmap to 0x%08lx from 0x%08lx, length 0x%08lx\n", sp->xs_rbase, sp->xs_filpos, sp->xs_psize); if (sp->xs_attr & XS_APURE) { down_write(¤t->mm->mmap_sem); err = do_mmap(fp, sp->xs_rbase, sp->xs_psize, PROT_READ|PROT_EXEC, MAP_FIXED|MAP_SHARED|MAP_32BIT, sp->xs_filpos); up_write(¤t->mm->mmap_sem); } else { down_write(¤t->mm->mmap_sem); err = do_mmap(fp, sp->xs_rbase, sp->xs_psize, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED|MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE | MAP_32BIT, sp->xs_filpos); up_write(¤t->mm->mmap_sem); } if (err < 0) goto out; /* * Map uninitialised data. */ if (bss_size) { if (bss_base & PAGE_MASK) { clear_memory(bss_base, PAGE_ALIGN(bss_base)-bss_base); bss_size -= (PAGE_ALIGN(bss_base) - bss_base); bss_base = PAGE_ALIGN(bss_base); } dprintk(KERN_DEBUG "xout: Null map 0x%08lx, length 0x%08lx\n", bss_base, bss_size); down_write(¤t->mm->mmap_sem); err = do_mmap(NULL, bss_base, bss_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_32BIT, 0); up_write(¤t->mm->mmap_sem); } out: if (!ce) cap_mmap(2); return (err); }
Configure::~Configure() { //std::cout << "Configure destructor is called" << std::endl; clear_memory(); }