void mono_sgen_nursery_allocator_prepare_for_pinning (void) { Fragment *frag; /* * The code below starts the search from an entry in scan_starts, which might point into a nursery * fragment containing random data. Clearing the nursery fragments takes a lot of time, and searching * though them too, so lay arrays at each location inside a fragment where a search can start: * - scan_locations[i] * - start_nursery * - the start of each fragment (the last_obj + last_obj case) * The third encompasses the first two, since scan_locations [i] can't point inside a nursery fragment. */ for (frag = unmask (nursery_fragments); frag; frag = unmask (frag->next)) { MonoArray *o; g_assert (frag->fragment_end - frag->fragment_next >= sizeof (MonoArray)); o = (MonoArray*)frag->fragment_next; memset (o, 0, sizeof (MonoArray)); g_assert (mono_sgen_get_array_fill_vtable ()); o->obj.vtable = mono_sgen_get_array_fill_vtable (); /* Mark this as not a real object */ o->obj.synchronisation = GINT_TO_POINTER (-1); o->max_length = (frag->fragment_end - frag->fragment_next) - sizeof (MonoArray); g_assert (frag->fragment_next + mono_sgen_safe_object_get_size ((MonoObject*)o) == frag->fragment_end); } }
void* mono_sgen_nursery_alloc (size_t size) { Fragment *frag; DEBUG (4, fprintf (gc_debug_file, "Searching nursery for size: %zd\n", size)); size = SGEN_ALIGN_UP (size); HEAVY_STAT (InterlockedIncrement (&stat_nursery_alloc_requests)); #ifdef NALLOC_DEBUG InterlockedIncrement (&alloc_count); #endif restart: for (frag = unmask (nursery_fragments); frag; frag = unmask (frag->next)) { HEAVY_STAT (InterlockedIncrement (&stat_alloc_iterations)); if (size <= (frag->fragment_end - frag->fragment_next)) { void *p = alloc_from_fragment (frag, size); if (!p) { HEAVY_STAT (InterlockedIncrement (&stat_alloc_retries)); goto restart; } #ifdef NALLOC_DEBUG add_alloc_record (p, size, FIXED_ALLOC); #endif return p; } } return NULL; }
void* sgen_fragment_allocator_par_alloc (SgenFragmentAllocator *allocator, size_t size) { SgenFragment *frag; #ifdef NALLOC_DEBUG InterlockedIncrement (&alloc_count); #endif restart: for (frag = (SgenFragment *)unmask (allocator->alloc_head); unmask (frag); frag = (SgenFragment *)unmask (frag->next)) { HEAVY_STAT (++stat_alloc_iterations); if (size <= (size_t)(frag->fragment_end - frag->fragment_next)) { void *p = par_alloc_from_fragment (allocator, frag, size); if (!p) { HEAVY_STAT (++stat_alloc_retries); goto restart; } #ifdef NALLOC_DEBUG add_alloc_record (p, size, FIXED_ALLOC); #endif return p; } } return NULL; }
void Battle::playActionOver(cocostudio::Armature *armature, cocostudio::MovementEventType type, const char *name) { if (armature == m_pReadygo) { if (type == COMPLETE) { removeChild(armature); m_pReadygo = NULL; unmask(); BIND(BUND_ID_GLOBAL_TOUCH_MOVED, this, Battle::globalTouchMoved); g_pEventEngine->BundlerCall(BUND_ID_PLANE_FIRE, this, sizeof(this)); } } if (armature == m_pBossIn) { if (type == COMPLETE) { removeChild(armature); m_pBossIn = NULL; unmask(); const BossConfig * pconfig = g_pGameConfig->getBossConfig(m_pConfig->boss); m_pBoss = Boss::create(pconfig); addChild(m_pBoss, GRADE_ENEMY); if (m_pConfig->boss != "chisezhilang") { m_pBoss->setScale(g_pGameConfig->scaleEleMin); } else { m_pBoss->setScale(g_pGameConfig->scaleEleMin * 1.5); } m_pBoss->setPosition(Vec2(pconfig->pos.x * g_pGameConfig->scaleEleX, pconfig->pos.y * g_pGameConfig->scaleEleY)); m_pBoss->setRotation(pconfig->rotate); ActionInterval * action = MoveBy::create(2, Vec2(0, -500 * g_pGameConfig->scaleEleY)); m_pBoss->runAction(Sequence::create(action, CallFuncN::create(this, callfuncN_selector(Battle::playbossAi)), NULL)); } } if (armature == m_pMissionVictory) { if (type == COMPLETE) { Node * icon = g_pGameConfig->getIcon(m_equip.model, m_equip.type); icon->setPosition(Vec2(-200, -275)); icon->setScale(g_pGameConfig->scaleEleMin * 5); m_pMissionVictory->addChild(icon, GRADE_UI); icon->setOpacity(0); ActionInterval * scale = ScaleTo::create(.5f, g_pGameConfig->scaleEleMin * 1.5); ActionInterval * fadein = FadeIn::create(.5f); icon->runAction(Spawn::create(scale, fadein, NULL)); UNBIND(BUND_ID_GLOBAL_TOUCH_MOVED, this, Battle::globalTouchMoved); scheduleOnce(schedule_selector(Battle::returnMission), 2.0f); } } if (armature == m_pMissionFaild) { if (type == COMPLETE) { UNBIND(BUND_ID_GLOBAL_TOUCH_MOVED, this, Battle::globalTouchMoved); scheduleOnce(schedule_selector(Battle::returnMission), 2.0f); } } }
char * mono_sgen_nursery_alloc_get_upper_alloc_bound (void) { char *p = NULL; Fragment *frag; for (frag = unmask (nursery_fragments); frag; frag = unmask (frag->next)) p = MAX (p, frag->fragment_next); return MAX (p, nursery_last_pinned_end); }
gboolean mono_sgen_can_alloc_size (size_t size) { Fragment *frag; size = SGEN_ALIGN_UP (size); for (frag = unmask (nursery_fragments); frag; frag = unmask (frag->next)) { if ((frag->fragment_end - frag->fragment_next) >= size) return TRUE; } return FALSE; }
mword mono_sgen_build_nursery_fragments (GCMemSection *nursery_section, void **start, int num_entries) { char *frag_start, *frag_end; size_t frag_size; int i; #ifdef NALLOC_DEBUG reset_alloc_records (); #endif while (unmask (nursery_fragments)) { Fragment *nf = unmask (nursery_fragments); Fragment *next = unmask (nf->next); nf->next_free = fragment_freelist; fragment_freelist = nf; nursery_fragments = next; } frag_start = nursery_start; fragment_total = 0; /* clear scan starts */ memset (nursery_section->scan_starts, 0, nursery_section->num_scan_start * sizeof (gpointer)); for (i = 0; i < num_entries; ++i) { frag_end = start [i]; /* remove the pin bit from pinned objects */ SGEN_UNPIN_OBJECT (frag_end); nursery_section->scan_starts [((char*)frag_end - (char*)nursery_section->data)/SGEN_SCAN_START_SIZE] = frag_end; frag_size = frag_end - frag_start; if (frag_size) add_nursery_frag (frag_size, frag_start, frag_end); frag_size = SGEN_ALIGN_UP (mono_sgen_safe_object_get_size ((MonoObject*)start [i])); #ifdef NALLOC_DEBUG add_alloc_record (start [i], frag_size, PINNING); #endif frag_start = (char*)start [i] + frag_size; } nursery_last_pinned_end = frag_start; frag_end = nursery_end; frag_size = frag_end - frag_start; if (frag_size) add_nursery_frag (frag_size, frag_start, frag_end); if (!unmask (nursery_fragments)) { DEBUG (1, fprintf (gc_debug_file, "Nursery fully pinned (%d)\n", num_entries)); for (i = 0; i < num_entries; ++i) { DEBUG (3, fprintf (gc_debug_file, "Bastard pinning obj %p (%s), size: %d\n", start [i], mono_sgen_safe_name (start [i]), mono_sgen_safe_object_get_size (start [i]))); } } return fragment_total; }
void sgen_clear_allocator_fragments (SgenFragmentAllocator *allocator) { SgenFragment *frag; for (frag = unmask (allocator->alloc_head); frag; frag = unmask (frag->next)) { SGEN_LOG (4, "Clear nursery frag %p-%p", frag->fragment_next, frag->fragment_end); sgen_clear_range (frag->fragment_next, frag->fragment_end); #ifdef NALLOC_DEBUG add_alloc_record (frag->fragment_next, frag->fragment_end - frag->fragment_next, CLEAR_NURSERY_FRAGS); #endif } }
void print_addr(struct pf_addr_wrap *addr, sa_family_t af, int verbose) { switch (addr->type) { case PF_ADDR_DYNIFTL: printf("(%s", addr->v.ifname); if (addr->iflags & PFI_AFLAG_NETWORK) printf(":network"); if (addr->iflags & PFI_AFLAG_BROADCAST) printf(":broadcast"); if (addr->iflags & PFI_AFLAG_PEER) printf(":peer"); if (addr->iflags & PFI_AFLAG_NOALIAS) printf(":0"); if (verbose) { if (addr->p.dyncnt <= 0) printf(":*"); else printf(":%d", addr->p.dyncnt); } printf(")"); break; case PF_ADDR_TABLE: if (verbose) if (addr->p.tblcnt == -1) printf("<%s:*>", addr->v.tblname); else printf("<%s:%d>", addr->v.tblname, addr->p.tblcnt); else printf("<%s>", addr->v.tblname); return; case PF_ADDR_ADDRMASK: if (PF_AZERO(&addr->v.a.addr, AF_INET6) && PF_AZERO(&addr->v.a.mask, AF_INET6)) printf("any"); else { char buf[48]; if (inet_ntop(af, &addr->v.a.addr, buf, sizeof(buf)) == NULL) printf("?"); else printf("%s", buf); } break; case PF_ADDR_NOROUTE: printf("no-route"); return; default: printf("?"); return; } if (! PF_AZERO(&addr->v.a.mask, af)) { int bits = unmask(&addr->v.a.mask, af); if (bits != (af == AF_INET ? 32 : 128)) printf("/%d", bits); } }
gboolean sgen_can_alloc_size (size_t size) { SgenFragment *frag; if (!SGEN_CAN_ALIGN_UP (size)) return FALSE; size = SGEN_ALIGN_UP (size); for (frag = unmask (mutator_allocator.alloc_head); frag; frag = unmask (frag->next)) { if ((size_t)(frag->fragment_end - frag->fragment_next) >= size) return TRUE; } return FALSE; }
int main(int argc, char** argv) { register_handlers(); sscanf(argv[0], "%d", &parent_pid); sscanf(argv[1], "%d", &fid); sscanf(argv[2], "%d", &mem_size); #ifdef DEBUG printf("KBD: %d %d %d\n", parent_pid, mem_size, fid); #endif mem_ptr = mmap((caddr_t)0, mem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fid, (off_t)0); mem_buffer *buffer = (mem_buffer*) mem_ptr; char local_buffer[MEMBLOCK_SIZE]; int index = 0; char kbd_in = '\0'; unmask(); while(1) { kbd_in = getchar(); putc(kbd_in, stdout); //echo back if (kbd_in != '\r' && index < MEMBLOCK_SIZE-1) { local_buffer[index++] = kbd_in; } else { local_buffer[index++] = '\0'; while (buffer->flag != MEM_DONE) sleep(1); //1-sec polling strcpy(buffer->data, local_buffer); buffer->flag = MEM_READY; buffer->length = index; index = 0; kill(parent_pid, SIGUSR1); } } return 0; }
/* Clear all remaining nursery fragments */ void mono_sgen_clear_nursery_fragments (void) { Fragment *frag; if (mono_sgen_get_nursery_clear_policy () == CLEAR_AT_TLAB_CREATION) { mono_sgen_clear_current_nursery_fragment (); for (frag = unmask (nursery_fragments); frag; frag = unmask (frag->next)) { DEBUG (4, fprintf (gc_debug_file, "Clear nursery frag %p-%p\n", frag->fragment_next, frag->fragment_end)); memset (frag->fragment_next, 0, frag->fragment_end - frag->fragment_next); #ifdef NALLOC_DEBUG add_alloc_record (frag->fragment_next, frag->fragment_end - frag->fragment_next, CLEAR_NURSERY_FRAGS); #endif } } }
static void add_fragment (char *start, char *end) { Fragment *fragment; fragment = alloc_fragment (); fragment->fragment_start = start; fragment->fragment_next = start; fragment->fragment_end = end; fragment->next = unmask (nursery_fragments); nursery_fragments = fragment; }
static inline void consumeIncompleteMessage(int length, const int headerLength, T fullPayloadLength, SocketData *socketData, char *src, frameFormat &frame, void *socket) { socketData->spillLength = 0; socketData->state = READ_MESSAGE; socketData->remainingBytes = fullPayloadLength - length + headerLength; socketData->mask = *(uint32_t *) &src[headerLength - 4]; rotate_mask(4 - (length - headerLength) % 4, &socketData->mask); unmask(src, src, headerLength - 4, headerLength, length); socketData->server->fragmentCallback(socket, src, length - headerLength, socketData->opCode[socketData->opStack], socketData->fin, socketData->remainingBytes); }
void print_addr(struct pf_addr *addr, struct pf_addr *mask, u_int8_t af) { char buf[48]; const char *bf; bf = inet_ntop(af, addr, buf, sizeof(buf)); printf("%s", bf); if (mask != NULL) { if (!PF_AZERO(mask, af)) printf("/%u", unmask(mask, af)); } }
// Decrypt the supplied data bool SecureDataManager::decrypt(const ByteString& encrypted, ByteString& plaintext) { // Check the object logged in state if ((!userLoggedIn && !soLoggedIn) || (maskedKey.size() != 32)) { return false; } // Do not attempt decryption of empty byte strings if (encrypted.size() == 0) { plaintext = ByteString(""); return true; } AESKey theKey(256); ByteString unmaskedKey; { MutexLocker lock(dataMgrMutex); unmask(unmaskedKey); theKey.setKeyBits(unmaskedKey); remask(unmaskedKey); } // Take the IV from the input data ByteString IV = encrypted.substr(0, aes->getBlockSize()); if (IV.size() != aes->getBlockSize()) { ERROR_MSG("Invalid IV in encrypted data"); return false; } ByteString finalBlock; if (!aes->decryptInit(&theKey, SymMode::CBC, IV) || !aes->decryptUpdate(encrypted.substr(aes->getBlockSize()), plaintext) || !aes->decryptFinal(finalBlock)) { return false; } plaintext += finalBlock; return true; }
void sgen_fragment_allocator_add (SgenFragmentAllocator *allocator, char *start, char *end) { SgenFragment *fragment; fragment = sgen_fragment_allocator_alloc (); fragment->fragment_start = start; fragment->fragment_next = start; fragment->fragment_end = end; fragment->next_in_order = fragment->next = (SgenFragment *)unmask (allocator->region_head); allocator->region_head = allocator->alloc_head = fragment; g_assert (fragment->fragment_end > fragment->fragment_start); }
void only_in_row(Sudoku &sudoku, int row) { int cols_who_contain[9]; sudoku.digit_to_column_map(row, cols_who_contain); for (int num = 0; num < 9; ++num) { int cols = cols_who_contain[num]; if (1 == num_ones(cols)) { int col = unmask(cols); sudoku.set(row, col, mask(num)); } } }
Smword Irq_sender::consume() { Smword old; do { old = _queued; } while (!mp_cas (&_queued, old, old - 1)); if (old == 2 && hit_func == &hit_edge_irq) unmask(); return old - 1; }
// Encrypt the supplied data bool SecureDataManager::encrypt(const ByteString& plaintext, ByteString& encrypted) { // Check the object logged in state if ((!userLoggedIn && !soLoggedIn) || (maskedKey.size() != 32)) { return false; } AESKey theKey(256); ByteString unmaskedKey; { MutexLocker lock(dataMgrMutex); unmask(unmaskedKey); theKey.setKeyBits(unmaskedKey); remask(unmaskedKey); } // Wipe encrypted data block encrypted.wipe(); // Generate random IV ByteString IV; if (!rng->generateRandom(IV, aes->getBlockSize())) return false; ByteString finalBlock; if (!aes->encryptInit(&theKey, SymMode::CBC, IV) || !aes->encryptUpdate(plaintext, encrypted) || !aes->encryptFinal(finalBlock)) { return false; } encrypted += finalBlock; // Add IV to output data encrypted = IV + encrypted; return true; }
static inline int consumeCompleteMessage(int &length, const int headerLength, T fullPayloadLength, SocketData *socketData, char **src, frameFormat &frame, void *socket) { unmask(*src, *src, headerLength - 4, headerLength, fullPayloadLength); socketData->server->fragmentCallback(socket, *src, fullPayloadLength, socketData->opCode[socketData->opStack], socketData->fin, 0); // did we close the socket using Socket.fail()? if (uv_is_closing((uv_handle_t *) socket)) { return 1; } if (frame.fin) { socketData->opStack--; } *src += fullPayloadLength + headerLength; length -= fullPayloadLength + headerLength; socketData->spillLength = 0; return 0; }
/*! * This function is used to subscribe on an event. * * @param event_sub structure of event, it contains type of event and callback * * @return This function returns 0 if successful. */ int mc13783_event_subscribe_internal(type_event_notification event_sub) { notify_event *new_notify_event; void *pmem = kmalloc(sizeof(notify_event), GFP_KERNEL); /*check? */ TRACEMSG(_K_D("event subscribe\n")); down_interruptible(&sem_event); new_notify_event = notify_event_tab[event_sub.event]; if (new_notify_event == NULL) { notify_event_tab[event_sub.event] = (notify_event *) pmem; new_notify_event = notify_event_tab[event_sub.event]; new_notify_event->callback = NULL; new_notify_event->callback_p = NULL; new_notify_event->param = (void *)NO_PARAM; } else { while (new_notify_event->next_notify_event != NULL) { new_notify_event = (notify_event *) new_notify_event->next_notify_event; } new_notify_event->next_notify_event = (notify_event *) pmem; new_notify_event = (notify_event *) new_notify_event->next_notify_event; new_notify_event->callback = NULL; new_notify_event->callback_p = NULL; new_notify_event->param = (void *)NO_PARAM; } if (event_sub.param != (void *)NO_PARAM) { new_notify_event->callback_p = event_sub.callback_p; new_notify_event->param = event_sub.param; } else { new_notify_event->callback = event_sub.callback; } new_notify_event->next_notify_event = NULL; up(&sem_event); CHECK_ERROR(unmask(event_sub.event)); /* test if event is not available */ mc13783_wq_handler(NULL); return 0; }
PUBLIC L4_msg_tag Irq_sender::kinvoke(L4_obj_ref, L4_fpage::Rights /*rights*/, Syscall_frame *f, Utcb const *utcb, Utcb *) { register Context *const c_thread = ::current(); assert_opt (c_thread); register Space *const c_space = c_thread->space(); assert_opt (c_space); L4_msg_tag tag = f->tag(); if (EXPECT_FALSE(tag.proto() != L4_msg_tag::Label_irq)) return commit_result(-L4_err::EBadproto); if (EXPECT_FALSE(tag.words() < 1)) return commit_result(-L4_err::EInval); switch ((utcb->values[0] & 0xffff)) { case Op_eoi_1: case Op_eoi_2: if (_queued < 1) unmask(); return no_reply(); case Op_attach: /* ATTACH, DETACH */ return sys_attach(tag, utcb, f, c_space); case Op_trigger: log(); hit(0); return no_reply(); default: return commit_result(-L4_err::EInval); } }
void row_box(Sudoku &sudoku, int row) { int boxes_who_contain[9] = { 0 }; for (int col = 0; col < 9; ++col) { int cell = sudoku(row, col); for (int num = 0; num < 9; ++num) { int mask_num = mask(num); if (cell & mask_num) { boxes_who_contain[num] |= mask(col / 3); } } } for (int num = 0; num < 9; ++num) { int boxes = boxes_who_contain[num]; if (1 == num_ones(boxes)) { int box = unmask(boxes); // figure out the other two rows we need to deal with int row_base = (row / 3) * 3; int other_rows_mask = 0x7 << row_base; int other_row_1; int other_row_2; int other_rows = subtract(other_rows_mask, mask(row)); lowest_two_set(other_rows, other_row_1, other_row_2); box_row_eliminate(sudoku, other_row_1, box, mask(num)); box_row_eliminate(sudoku, other_row_2, box, mask(num)); } } }
mword sgen_build_nursery_fragments (GCMemSection *nursery_section, SgenGrayQueue *unpin_queue) { char *frag_start, *frag_end; size_t frag_size; SgenFragment *frags_ranges; void **pin_start, **pin_entry, **pin_end; #ifdef NALLOC_DEBUG reset_alloc_records (); #endif /*The mutator fragments are done. We no longer need them. */ sgen_fragment_allocator_release (&mutator_allocator); frag_start = sgen_nursery_start; fragment_total = 0; /* The current nursery might give us a fragment list to exclude [start, next[*/ frags_ranges = sgen_minor_collector.build_fragments_get_exclude_head (); /* clear scan starts */ memset (nursery_section->scan_starts, 0, nursery_section->num_scan_start * sizeof (gpointer)); pin_start = pin_entry = sgen_pinning_get_entry (nursery_section->pin_queue_first_entry); pin_end = sgen_pinning_get_entry (nursery_section->pin_queue_last_entry); while (pin_entry < pin_end || frags_ranges) { char *addr0, *addr1; size_t size; addr0 = addr1 = sgen_nursery_end; if (pin_entry < pin_end) addr0 = (char *)*pin_entry; if (frags_ranges) addr1 = frags_ranges->fragment_start; if (addr0 < addr1) { if (unpin_queue) GRAY_OBJECT_ENQUEUE (unpin_queue, (GCObject*)addr0, sgen_obj_get_descriptor_safe ((GCObject*)addr0)); else SGEN_UNPIN_OBJECT (addr0); size = SGEN_ALIGN_UP (sgen_safe_object_get_size ((GCObject*)addr0)); CANARIFY_SIZE (size); sgen_set_nursery_scan_start (addr0); frag_end = addr0; ++pin_entry; } else { frag_end = addr1; size = frags_ranges->fragment_next - addr1; frags_ranges = frags_ranges->next_in_order; } frag_size = frag_end - frag_start; if (size == 0) continue; g_assert (frag_size >= 0); g_assert (size > 0); if (frag_size && size) add_nursery_frag (&mutator_allocator, frag_size, frag_start, frag_end); frag_size = size; #ifdef NALLOC_DEBUG add_alloc_record (*pin_entry, frag_size, PINNING); #endif frag_start = frag_end + frag_size; } nursery_last_pinned_end = frag_start; frag_end = sgen_nursery_end; frag_size = frag_end - frag_start; if (frag_size) add_nursery_frag (&mutator_allocator, frag_size, frag_start, frag_end); /* Now it's safe to release the fragments exclude list. */ sgen_minor_collector.build_fragments_release_exclude_head (); /* First we reorder the fragment list to be in ascending address order. This makes H/W prefetchers happier. */ fragment_list_reverse (&mutator_allocator); /*The collector might want to do something with the final nursery fragment list.*/ sgen_minor_collector.build_fragments_finish (&mutator_allocator); if (!unmask (mutator_allocator.alloc_head)) { SGEN_LOG (1, "Nursery fully pinned"); for (pin_entry = pin_start; pin_entry < pin_end; ++pin_entry) { GCObject *p = (GCObject *)*pin_entry; SGEN_LOG (3, "Bastard pinning obj %p (%s), size: %zd", p, sgen_client_vtable_get_name (SGEN_LOAD_VTABLE (p)), sgen_safe_object_get_size (p)); } } return fragment_total; }
void* sgen_fragment_allocator_par_range_alloc (SgenFragmentAllocator *allocator, size_t desired_size, size_t minimum_size, size_t *out_alloc_size) { SgenFragment *frag, *min_frag; size_t current_minimum; restart: min_frag = NULL; current_minimum = minimum_size; #ifdef NALLOC_DEBUG InterlockedIncrement (&alloc_count); #endif for (frag = (SgenFragment *)unmask (allocator->alloc_head); frag; frag = (SgenFragment *)unmask (frag->next)) { size_t frag_size = frag->fragment_end - frag->fragment_next; HEAVY_STAT (++stat_alloc_range_iterations); if (desired_size <= frag_size) { void *p; *out_alloc_size = desired_size; p = par_alloc_from_fragment (allocator, frag, desired_size); if (!p) { HEAVY_STAT (++stat_alloc_range_retries); goto restart; } #ifdef NALLOC_DEBUG add_alloc_record (p, desired_size, RANGE_ALLOC); #endif return p; } if (current_minimum <= frag_size) { min_frag = frag; current_minimum = frag_size; } } /* The second fragment_next read should be ordered in respect to the first code block */ mono_memory_barrier (); if (min_frag) { void *p; size_t frag_size; frag_size = min_frag->fragment_end - min_frag->fragment_next; if (frag_size < minimum_size) goto restart; *out_alloc_size = frag_size; mono_memory_barrier (); p = par_alloc_from_fragment (allocator, min_frag, frag_size); /*XXX restarting here is quite dubious given this is already second chance allocation. */ if (!p) { HEAVY_STAT (++stat_alloc_retries); goto restart; } #ifdef NALLOC_DEBUG add_alloc_record (p, frag_size, RANGE_ALLOC); #endif return p; } return NULL; }
static void* par_alloc_from_fragment (SgenFragmentAllocator *allocator, SgenFragment *frag, size_t size) { char *p = frag->fragment_next; char *end = p + size; if (end > frag->fragment_end) return NULL; /* p = frag->fragment_next must happen before */ mono_memory_barrier (); if (InterlockedCompareExchangePointer ((volatile gpointer*)&frag->fragment_next, end, p) != p) return NULL; if (frag->fragment_end - end < SGEN_MAX_NURSERY_WASTE) { SgenFragment *next, **prev_ptr; /* * Before we clean the remaining nursery, we must claim the remaining space * as it could end up been used by the range allocator since it can end up * allocating from this dying fragment as it doesn't respect SGEN_MAX_NURSERY_WASTE * when doing second chance allocation. */ if ((sgen_get_nursery_clear_policy () == CLEAR_AT_TLAB_CREATION || sgen_get_nursery_clear_policy () == CLEAR_AT_TLAB_CREATION_DEBUG) && claim_remaining_size (frag, end)) { sgen_clear_range (end, frag->fragment_end); HEAVY_STAT (stat_wasted_bytes_trailer += frag->fragment_end - end); #ifdef NALLOC_DEBUG add_alloc_record (end, frag->fragment_end - end, BLOCK_ZEROING); #endif } prev_ptr = find_previous_pointer_fragment (allocator, frag); /*Use Michaels linked list remove*/ /*prev_ptr will be null if the fragment was removed concurrently */ while (prev_ptr) { next = frag->next; /*already deleted*/ if (!get_mark (next)) { /*frag->next read must happen before the first CAS*/ mono_memory_write_barrier (); /*Fail if the next node is removed concurrently and its CAS wins */ if (InterlockedCompareExchangePointer ((volatile gpointer*)&frag->next, mask (next, 1), next) != next) { continue; } } /* The second CAS must happen after the first CAS or frag->next. */ mono_memory_write_barrier (); /* Fail if the previous node was deleted and its CAS wins */ if (InterlockedCompareExchangePointer ((volatile gpointer*)prev_ptr, unmask (next), frag) != frag) { prev_ptr = find_previous_pointer_fragment (allocator, frag); continue; } break; } } return p; }
void print_addr(struct pf_addr_wrap *addr, sa_family_t af, int verbose) { switch (addr->type) { case PF_ADDR_DYNIFTL: printf("(%s", addr->v.ifname); if (addr->iflags & PFI_AFLAG_NETWORK) printf(":network"); if (addr->iflags & PFI_AFLAG_BROADCAST) printf(":broadcast"); if (addr->iflags & PFI_AFLAG_PEER) printf(":peer"); if (addr->iflags & PFI_AFLAG_NOALIAS) printf(":0"); if (verbose) { if (addr->p.dyncnt <= 0) printf(":*"); else printf(":%d", addr->p.dyncnt); } printf(")"); break; case PF_ADDR_TABLE: if (verbose) if (addr->p.tblcnt == -1) printf("<%s:*>", addr->v.tblname); else printf("<%s:%d>", addr->v.tblname, addr->p.tblcnt); else printf("<%s>", addr->v.tblname); return; case PF_ADDR_RANGE: { char buf[48]; if (inet_ntop(af, &addr->v.a.addr, buf, sizeof(buf)) == NULL) printf("?"); else printf("%s", buf); if (inet_ntop(af, &addr->v.a.mask, buf, sizeof(buf)) == NULL) printf(" - ?"); else printf(" - %s", buf); break; } case PF_ADDR_ADDRMASK: if (PF_AZERO(&addr->v.a.addr, AF_INET6) && PF_AZERO(&addr->v.a.mask, AF_INET6)) printf("any"); else { char buf[48]; if (inet_ntop(af, &addr->v.a.addr, buf, sizeof(buf)) == NULL) printf("?"); else printf("%s", buf); } break; case PF_ADDR_NOROUTE: printf("no-route"); return; case PF_ADDR_URPFFAILED: printf("urpf-failed"); return; case PF_ADDR_RTLABEL: printf("route \"%s\"", addr->v.rtlabelname); return; default: printf("?"); return; } /* mask if not _both_ address and mask are zero */ if (addr->type != PF_ADDR_RANGE && !(PF_AZERO(&addr->v.a.addr, AF_INET6) && PF_AZERO(&addr->v.a.mask, AF_INET6))) { int bits = unmask(&addr->v.a.mask, af); if (bits < (af == AF_INET ? 32 : 128)) printf("/%d", bits); } }
// Generic function for creating an encrypted version of the key from the specified passphrase bool SecureDataManager::pbeEncryptKey(const ByteString& passphrase, ByteString& encryptedKey) { // Generate salt ByteString salt; if (!rng->generateRandom(salt, 8)) return false; // Derive the key using RFC4880 PBE AESKey* pbeKey = NULL; if (!RFC4880::PBEDeriveKey(passphrase, salt, &pbeKey)) { return false; } // Add the salt encryptedKey.wipe(); encryptedKey += salt; // Generate random IV ByteString IV; if (!rng->generateRandom(IV, aes->getBlockSize())) return false; // Add the IV encryptedKey += IV; // Encrypt the data ByteString block; if (!aes->encryptInit(pbeKey, SymMode::CBC, IV)) { delete pbeKey; return false; } // First, add the magic if (!aes->encryptUpdate(magic, block)) { delete pbeKey; return false; } encryptedKey += block; // Then, add the key itself ByteString key; { MutexLocker lock(dataMgrMutex); unmask(key); bool rv = aes->encryptUpdate(key, block); remask(key); if (!rv) { delete pbeKey; return false; } } encryptedKey += block; // And finalise encryption if (!aes->encryptFinal(block)) { delete pbeKey; return false; } encryptedKey += block; delete pbeKey; return true; }
int main(int argc, char **argv) { int clocks[MAXCLOCKS*4], lit[4]; int P, p, K, N, n, i, *cl, *now; int d1, d2, d3, d4; int answer; i = 0; /* First digit can only be blank or 1 */ for (d1 = 10; d1 != -1; d1 = (d1 == 10 ? 1 : -1)) { /* * Second digit can be 0-9 UNLESS first digit is 1, * in which case, it can only be 0-2. */ for (d2 = (d1 == 10 ? 1 : 0); (d1 == 10 && d2 <= 9) || (d1 == 1 && d2 <= 2); d2++) { /* Third digit can be anything 0-5 */ for (d3 = 0; d3 <= 5; d3++) { /* Fourth digit can be anything 0-9 */ for (d4 = 0; d4 <= 9; d4++) { CLOCKS[i++] = digits[d1]; CLOCKS[i++] = digits[d2]; CLOCKS[i++] = digits[d3]; CLOCKS[i++] = digits[d4]; } } } } /* P: Number of data set 1 <= P <= 1000 */ scanf("%d", &P); for (p = 1; p <= P; p++) { /* K: Data set number */ /* N: Number of previous displays seen 1 <= N <= 10 */ scanf("%d %d", &K, &N); /* Reset the lit segments we have seen */ lit[0] = lit[1] = lit[2] = lit[3] = 0; /* Read in the N clock faces- last clock face is the current time */ for (n = 0; n < N; n++) { cl = &clocks[n*4]; read_clock(cl); /* Accumulate the lit segments */ unmask(lit, cl); } /* Pointer to the last clock face- the current time */ now = &clocks[(N-1)*4]; answer = -1; /* Check against all possible clocks for 'now' */ for (i = 0; i < NUMCLOCKS * 4; i += 4) { cl = &CLOCKS[i]; if ((cl[0] & lit[0]) != now[0] || (cl[1] & lit[1]) != now[1] || (cl[2] & lit[2]) != now[2] || (cl[3] & lit[3]) != now[3]) { continue; } if (answer == -1) { /* We found an answer; mark it */ answer = i; } else { /* We found another answer; then we're not 100% certain */ answer = -1; break; } } printf("%d ", K); if (answer != -1) { print_clock(&CLOCKS[answer]); } else { printf("?\n"); } } return 0; }