/* * Test for internal_flush() for the case when: * - secure_write returns 0 (send failed) * - errno is set to EINTR */ void test__internal_flush_failedSendEINTR(void **state) { int result; /* * In the case secure_write gets interrupted, we loop around and * try the send again. * In this test we simulate that, and secure_write will be called twice. * * First call to secure_write: returns 0 and sets errno to EINTR. */ expect_any(secure_write, port); expect_any(secure_write, ptr); expect_any(secure_write, len); static int errval = EINTR; will_return_with_sideeffect(secure_write, 0, _set_errno, &errval); /* Second call to secure_write: returns TEST_NUM_BYTES, i.e. success */ expect_any(secure_write, port); expect_any(secure_write, ptr); expect_any(secure_write, len); will_return(secure_write, TEST_NUM_BYTES); PqSendPointer = TEST_NUM_BYTES; /* Call function under test */ result = internal_flush(); assert_int_equal(result,0); assert_int_equal(ClientConnectionLost, 0); assert_int_equal(InterruptPending, 0); }
/* * Test for internal_flush() for the case when: * - secure_write returns 0 (send failed) * - errno is set to EPIPE */ void test__internal_flush_failedSendEPIPE(void **state) { int result; /* Simulating that secure_write will fail, and set the errno to EPIPE */ expect_any(secure_write, port); expect_any(secure_write, ptr); expect_any(secure_write, len); static int errval = EPIPE; will_return_with_sideeffect(secure_write, 0, _set_errno, &errval); /* In that case, we expect ereport(COMERROR, ...) to be called */ expect_value(errstart, elevel, COMMERROR); expect_any(errstart, filename); expect_any(errstart, lineno); expect_any(errstart, funcname); expect_any(errstart, domain); will_return(errstart, false); PqSendPointer = TEST_NUM_BYTES; /* Call function under test */ result = internal_flush(); assert_int_equal(result,EOF); assert_int_equal(ClientConnectionLost, 1); assert_int_equal(InterruptPending, 1); }
bool protected_fs_file::flush(/*bool mc*/) { bool result = false; int32_t result32 = sgx_thread_mutex_lock(&mutex); if (result32 != 0) { last_error = result32; file_status = SGX_FILE_STATUS_MEMORY_CORRUPTED; return false; } if (file_status != SGX_FILE_STATUS_OK) { last_error = SGX_ERROR_FILE_BAD_STATUS; sgx_thread_mutex_unlock(&mutex); return false; } result = internal_flush(/*mc,*/ true); if (result == false) { assert(file_status != SGX_FILE_STATUS_OK); if (file_status == SGX_FILE_STATUS_OK) file_status = SGX_FILE_STATUS_FLUSH_ERROR; // for release set this anyway } sgx_thread_mutex_unlock(&mutex); return result; }
/* -------------------------------- * pq_flush - flush pending output * * returns 0 if OK, EOF if trouble * -------------------------------- */ int pq_flush(void) { int res; /* No-op if reentrant call */ if (PqCommBusy) return 0; PqCommBusy = true; res = internal_flush(); PqCommBusy = false; return res; }
/* * Test for internal_flush() for the case when: * - requesting to send TEST_NUM_BYTES bytes * - secure_write returns TEST_NUM_BYTES (send successful) * - errno is not changed */ void test__internal_flush_succesfulSend(void **state) { int result; expect_any(secure_write, port); expect_any(secure_write, ptr); expect_any(secure_write, len); will_return(secure_write, TEST_NUM_BYTES); PqSendPointer = TEST_NUM_BYTES; result = internal_flush(); assert_int_equal(result,0); assert_int_equal(ClientConnectionLost, 0); assert_int_equal(InterruptPending, 0); }
/* -------------------------------- * pq_flush - flush pending output * * returns 0 if OK, EOF if trouble * -------------------------------- */ int pq_flush(void) { int res; if ((Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_DISPATCHAGENT) && IsUnderPostmaster) { if (!pq_send_mutex_lock()) { return EOF; } } pq_set_nonblocking(false); res = internal_flush(); if ((Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_DISPATCHAGENT) && IsUnderPostmaster) pthread_mutex_unlock(&send_mutex); return res; }
static int internal_putbytes(const char *s, size_t len) { size_t amount; while (len > 0) { /* If buffer is full, then flush it out */ if (PqSendPointer >= PQ_BUFFER_SIZE) if (internal_flush()) return EOF; amount = PQ_BUFFER_SIZE - PqSendPointer; if (amount > len) amount = len; memcpy(PqSendBuffer + PqSendPointer, s, amount); PqSendPointer += amount; s += amount; len -= amount; } return 0; }
/* -------------------------------- * pq_flush_if_writable - flush pending output if writable without blocking * * Returns 0 if OK, or EOF if trouble. * -------------------------------- */ int pq_flush_if_writable(void) { int res; /* Quick exit if nothing to do */ if (PqSendPointer == PqSendStart) return 0; /* No-op if reentrant call */ if (PqCommBusy) return 0; /* Temporarily put the socket into non-blocking mode */ pq_set_nonblocking(true); PqCommBusy = true; res = internal_flush(); PqCommBusy = false; return res; }
/* -------------------------------- * pq_flush_if_writable - flush pending output if writable without blocking * * Returns 0 if OK, or EOF if trouble. * -------------------------------- */ int pq_flush_if_writable(void) { int res; /* Quick exit if nothing to do */ if (PqSendPointer == PqSendStart) return 0; if ((Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_DISPATCHAGENT) && IsUnderPostmaster) { if (!pq_send_mutex_lock()) { return EOF; } } /* Temporarily put the socket into non-blocking mode */ pq_set_nonblocking(true); res = internal_flush(); if ((Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_DISPATCHAGENT) && IsUnderPostmaster) pthread_mutex_unlock(&send_mutex); return res; }
static int internal_putbytes(const char *s, size_t len) { size_t amount; while (len > 0) { /* If buffer is full, then flush it out */ if (PqSendPointer >= PqSendBufferSize) { pq_set_nonblocking(false); if (internal_flush()) return EOF; } amount = PqSendBufferSize - PqSendPointer; if (amount > len) amount = len; memcpy(PqSendBuffer + PqSendPointer, s, amount); PqSendPointer += amount; s += amount; len -= amount; } return 0; }
err pcd8544< Spi, Cs_gpio, Mode_gpio, Rst_gpio >::flush() { return internal_flush(); }
file_data_node_t* protected_fs_file::get_data_node() { file_data_node_t* file_data_node = NULL; if (offset < MD_USER_DATA_SIZE) { last_error = SGX_ERROR_UNEXPECTED; return NULL; } if ((offset - MD_USER_DATA_SIZE) % NODE_SIZE == 0 && offset == encrypted_part_plain.size) {// new node file_data_node = append_data_node(); } else {// existing node file_data_node = read_data_node(); } // bump all the parents mht to reside before the data node in the cache if (file_data_node != NULL) { file_mht_node_t* file_mht_node = file_data_node->parent; while (file_mht_node->mht_node_number != 0) { cache.get(file_mht_node->physical_node_number); // bump the mht node to the head of the lru file_mht_node = file_mht_node->parent; } } // even if we didn't get the required data_node, we might have read other nodes in the process while (cache.size() > MAX_PAGES_IN_CACHE) { void* data = cache.get_last(); assert(data != NULL); // for production - if (data == NULL) { last_error = SGX_ERROR_UNEXPECTED; return NULL; } if (((file_data_node_t*)data)->need_writing == false) // need_writing is in the same offset in both node types { cache.remove_last(); // before deleting the memory, need to scrub the plain secrets if (((file_data_node_t*)data)->type == FILE_DATA_NODE_TYPE) // type is in the same offset in both node types { file_data_node_t* file_data_node1 = (file_data_node_t*)data; memset_s(&file_data_node1->plain, sizeof(data_node_t), 0, sizeof(data_node_t)); delete file_data_node1; } else { file_mht_node_t* file_mht_node = (file_mht_node_t*)data; memset_s(&file_mht_node->plain, sizeof(mht_node_t), 0, sizeof(mht_node_t)); delete file_mht_node; } } else { if (internal_flush(/*false,*/ false) == false) // error, can't flush cache, file status changed to error { assert(file_status != SGX_FILE_STATUS_OK); if (file_status == SGX_FILE_STATUS_OK) file_status = SGX_FILE_STATUS_FLUSH_ERROR; // for release set this anyway return NULL; // even if we got the data_node! } } } return file_data_node; }