/* * Encode a sandesh into the buffer * * Returns the length of the encoded sandesh, -1 on error and set error */ int32_t sandesh_encode (void *sandesh, const char *sname, sandesh_find_info_fn sinfo_find_fn, u_int8_t *buf, u_int32_t buf_len, int *error) { ThriftBinaryProtocol protocol; ThriftMemoryBuffer transport; sandesh_info_t *sinfo; int32_t wxfer; /* First find the corresponding sandesh information */ sinfo = sinfo_find_fn(sname); if (sinfo == NULL) { os_log(OS_LOG_ERR, "Write: No information for sandesh %s", sname); *error = EINVAL; return -1; } /* Initialize the transport and protocol */ thrift_memory_buffer_init(&transport, buf, buf_len); thrift_protocol_init(&protocol, T_PROTOCOL_BINARY, (ThriftTransport *)&transport); /* Now, write the sandesh */ wxfer = sinfo->write(sandesh, &protocol, error); if (wxfer < 0) { #ifdef __KERNEL__ os_log(OS_LOG_DEBUG, "Write: Encode sandesh %s FAILED(%d)", sname, *error); #else os_log(OS_LOG_ERR, "Write: Encode sandesh %s FAILED(%d)", sname, *error); #endif return -1; } return wxfer; }
/* page write */ int eeprom_write(struct eeprom_priv_s *ee, uint8 *buf, uint32 offset, uint32 nb) { int ret; i2c_msg msg; if (nb > ee->page_size) { os_log(LOG_ERROR, "%s too large.\n", __func__); return -1; } os_log(LOG_INFO, "%s start...\n", __func__); _mm_dump(buf + ee->regaddr_size, nb, 0); msg.addr = ee->dev_addr; msg.flags = 0; msg.length = nb + ee->regaddr_size; msg.data = buf; ret = i2c_master_xfer(I2C1, &msg, 1, 0); if (ret != 0) { os_log(LOG_ERROR, "%s - ret = %d.\n", __func__, ret); return ret; } os_log(LOG_INFO, "%s done...\n", __func__); return 0; }
/* * Get the encoded length of a sandesh * * Returns the encoded length of a sandesh, -1 on error and set error */ int32_t sandesh_get_encoded_length (void *sandesh, const char *sname, sandesh_find_info_fn sinfo_find_fn, int *error) { ThriftBinaryProtocol protocol; ThriftFakeTransport transport; sandesh_info_t *sinfo; int32_t wxfer; /* First find the corresponding sandesh information */ sinfo = sinfo_find_fn(sname); if (sinfo == NULL) { os_log(OS_LOG_ERR, "Encode: No information for sandesh %s", sname); *error = EINVAL; return -1; } /* Initialize the transport and protocol */ thrift_fake_transport_init(&transport); thrift_protocol_init(&protocol, T_PROTOCOL_BINARY, (ThriftTransport *)&transport); /* Now, write the sandesh into the fake transport to get the encoded length */ wxfer = sinfo->write(sandesh, &protocol, error); if (wxfer < 0) { os_log(OS_LOG_ERR, "Encode: Encode sandesh %s FAILED(%d)", sname, *error); return -1; } return wxfer; }
/* page read */ int eeprom_read(struct eeprom_priv_s *ee, uint8 *buf, uint32 offset, uint32 nb) { int ret; i2c_msg msgs[2]; os_log(LOG_INFO, "%s start...\n", __func__); /* XXX 16 bit addr? */ msgs[0].addr = ee->dev_addr; msgs[0].flags = 0; msgs[0].length = 1; offset &= 0xFF; msgs[0].data = (uint8 *)&offset; msgs[1].addr = ee->dev_addr; msgs[1].flags = I2C_MSG_READ; msgs[1].length = nb; msgs[1].data = buf; ret = i2c_master_xfer(I2C1, msgs, 2, 0); if (ret != 0) os_log(LOG_ERROR, "%s - ret = %d.\n", __func__, ret); else { _mm_dump(buf, nb, 0); os_log(LOG_INFO, "%s done...\n", __func__); } return ret; }
int32_t thrift_binary_protocol_read_list_begin (ThriftProtocol *protocol, ThriftType *element_type, u_int32_t *size, int *error) { int32_t ret; int32_t xfer = 0; int8_t e; int32_t sizei; if ((ret = thrift_protocol_read_byte (protocol, &e, error)) < 0) { return -1; } xfer += ret; *element_type = (ThriftType) e; if ((ret = thrift_protocol_read_i32 (protocol, &sizei, error)) < 0) { return -1; } xfer += ret; if (sizei < 0) { *error = THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE; os_log(OS_LOG_ERR, "Got negative size of %d", sizei); return -1; } *size = (u_int32_t) sizei; return xfer; }
void DNSXRefDeAlloc(DNSXConnRef connRef) { if (connRef == NULL) { os_log(OS_LOG_DEFAULT, "dns_services: DNSXRefDeAlloc called with NULL DNSXConnRef"); return; } // Schedule this work on the internal library queue dispatch_sync(connRef->lib_q, ^{ xpc_connection_set_event_handler((connRef)->conn_ref, ^(__unused xpc_object_t event){}); // ignore any more events xpc_release(connRef->conn_ref); connRef->conn_ref = NULL; dispatch_release(connRef->lib_q); connRef->lib_q = NULL; connRef->AppCallBack = NULL; os_log_info(OS_LOG_DEFAULT, "dns_services: DNSXRefDeAlloc successfully DeAllocated conn_ref & lib_q"); dispatch_async((connRef)->client_q, ^{ dispatch_release(connRef->client_q); connRef->client_q = NULL; free(connRef); os_log_info(OS_LOG_DEFAULT, "dns_services: DNSXRefDeAlloc successfully DeAllocated client_q & freed connRef"); }); });
static void ps_button(void *args) { signal = 0; for (;;) { if (gpio_read_bit(USR_BUT_PORT, USR_BUT_PIN)) { os_log(LOG_INFO, "%s - pressed.\n", __func__); signal = 1; } os_process_sleep(100); } }
int main(int argc, char** argv) { os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); if (!logger_sub1 || !logger_sub2) return 1; // Note we cannot use the os_log() line as the breakpoint because, as of // the initial writing of this test, we get multiple breakpoints for that // line, which confuses the pexpect test logic. printf("About to log\n"); // break here os_log(logger_sub1, "log message sub%d-cat%d", 1, 1); os_log(logger_sub2, "log message sub%d-cat%d", 2, 2); // Sleep, as the darwin log reporting doesn't always happen until a bit // later. We need the message to come out before the process terminates. sleep(1); return 0; }
int main(int argc, char** argv) { os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); if (!logger_sub1 || !logger_sub2) return 1; // Note we cannot use the os_log() line as the breakpoint because, as of // the initial writing of this test, we get multiple breakpoints for that // line, which confuses the pexpect test logic. printf("About to log\n"); // break here os_activity_t parent_activity = os_activity_create("parent-activity", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); os_activity_apply(parent_activity, ^{ os_log(logger_sub1, "source-log-sub1-cat1"); os_activity_t child_activity = os_activity_create("child-activity", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); os_activity_apply(child_activity, ^{ os_log(logger_sub2, "source-log-sub2-cat2"); }); });
static inline i2c_dev* i2c_bus_to_dev(int id) { switch (id) { case 1: return I2C1; case 2: return I2C2; default: os_log(LOG_INFO, "Undefined bus id, use default I2C1.\n"); return I2C1; } }
static void i2c_recv_byte(uint8 slave, uint8 *pdata) { i2c_msg msg; int ret; msg.addr = slave; msg.flags = 0; msg.length = 1; msg.data = pdata; ret = i2c_master_xfer(I2C1, &msg, 1, 0); if (ret != 0) os_log(LOG_ERROR, "%s - ret = %d.\n", __func__, ret); }
static void eeprom_test(void) { int ret; eeprom_test_setup(); for (;;) { if (!signal) { os_process_sleep(50); continue; } else signal = 0; eeprom_erase(gee, 0, 16); eeprom_read(gee, buffer_r, 0, 16); eeprom_write(gee, buffer_w, 0, 16); ret = eeprom_verify(gee, buffer_w + gee->regaddr_size, 0, 16); if (ret != 0) os_log(LOG_ERROR, "Verify failed.\n"); else os_log(LOG_INFO, "Verify passed.\n"); } }
OS_DECLARE(os_status_t) _os_mutex_unlock(const char *file, int line, const char *func, os_mutex_t *mutex) { #ifdef OS_DEBUG_MUTEX int i = 0; if (mutex->reentrancy == 0) { os_log(file, func, line, OS_LOG_LEVEL_ERROR, "Cannot unlock something that is not locked!\n"); return OS_FAIL; } i = mutex->reentrancy - 1; /* I think this is a fair assumption when debugging */ if (func != mutex->lock_history[i].locked.func) { os_log(file, func, line, OS_LOG_LEVEL_WARNING, "Mutex %p was suspiciously locked at %s->%s:%d but unlocked at %s->%s:%d!\n", mutex, mutex->lock_history[i].locked.func, mutex->lock_history[i].locked.file, mutex->lock_history[i].locked.line, func, file, line); } mutex->lock_history[i].unlocked.file = file; mutex->lock_history[i].unlocked.line = line; mutex->lock_history[i].unlocked.func = func; mutex->reentrancy--; #endif #ifdef WIN32 os_unused_arg(file); os_unused_arg(line); os_unused_arg(func); LeaveCriticalSection(&mutex->mutex); #else if (pthread_mutex_unlock(&mutex->mutex)) { os_log(file, func, line, OS_LOG_LEVEL_ERROR, "Failed to unlock mutex: %s\n", strerror(errno)); #ifdef OS_DEBUG_MUTEX mutex->reentrancy++; #endif return OS_FAIL; } #endif return OS_SUCCESS; }
static void eeprom_test_setup(void) { int i; i2c_master_enable(I2C1, I2C_BUS_RESET); buffer_r = (uint8 *) zalloc(BUFFER_SIZE); os_assert(buffer_r != NULL); buffer_w = (uint8 *) zalloc(BUFFER_SIZE + 1); os_assert(buffer_w != NULL); buffer_w[0] = 0x0; for (i = 1; i < BUFFER_SIZE + 1; i++) buffer_w[i] = i - 1; os_log(LOG_DEBUG, "buffers are ready: r: 0x%x, w: 0x%x\n", buffer_r, buffer_w); }
/** * Decode sandeshs from the buffer and calls the sandesh handler function * for each decoded sandesh * * Returns the number of bytes processed, -1 on error and sets error */ int32_t sandesh_decode (u_int8_t *buf, u_int32_t buf_len, sandesh_find_info_fn sinfo_find_fn, int *error) { u_int32_t xfer = 0; int32_t ret; while (xfer < buf_len) { ret = sandesh_decode_one(buf + xfer, buf_len - xfer, sinfo_find_fn, error); if (ret < 0) { os_log(OS_LOG_ERR, "Sandesh read from %d bytes, at offset %d " "FAILED (%d)", buf_len, xfer, ret); return ret; } xfer += ret; } return xfer; }
int if_set_low_power(ifnet_t ifp, bool on) { int error = 0; if (ifp == NULL) return (EINVAL); os_log(OS_LOG_DEFAULT, "%s: ifp %s low_power mode %d", __func__, if_name(ifp), on); ifnet_lock_exclusive(ifp); ifp->if_xflags = on ? (ifp->if_xflags | IFXF_LOW_POWER) : (ifp->if_xflags & ~IFXF_LOW_POWER); ifnet_lock_done(ifp); return (error); }
int main(int argc, char** argv) { os_log_t logger = os_log_create("org.llvm.lldb.test", "basic-test"); if (!logger) return 1; // Note we cannot use the os_log() line as the breakpoint because, as of // the initial writing of this test, we get multiple breakpoints for that // line, which confuses the pexpect test logic. printf("About to log\n"); // break here os_log(logger, "Hello, world"); // Sleep, as the darwin log reporting doesn't always happen until a bit // later. We need the message to come out before the process terminates. sleep(FINAL_WAIT_SECONDS); return 0; }
int32_t thrift_binary_protocol_read_message_begin (ThriftProtocol *protocol, char **name, ThriftMessageType *message_type, int32_t *seqid, int *error) { int32_t ret; int32_t xfer = 0; int32_t sz; if ((ret = thrift_protocol_read_i32 (protocol, &sz, error)) < 0) { return -1; } xfer += ret; if (sz < 0) { /* check for version */ u_int32_t version = sz & THRIFT_BINARY_PROTOCOL_VERSION_MASK; if (version != THRIFT_BINARY_PROTOCOL_VERSION_1) { *error = THRIFT_PROTOCOL_ERROR_BAD_VERSION; os_log(OS_LOG_ERR, "Expected version %d, got %d", THRIFT_BINARY_PROTOCOL_VERSION_1, version); return -1; } *message_type = (ThriftMessageType) (sz & 0x000000ff); if ((ret = thrift_protocol_read_string (protocol, name, error)) < 0) { return -1; } xfer += ret; if ((ret = thrift_protocol_read_i32 (protocol, seqid, error)) < 0) { return -1; } xfer += ret; } return xfer; }
OS_DECLARE(os_status_t) _os_mutex_lock(const char *file, int line, const char *func, os_mutex_t *mutex) { #ifdef WIN32 os_unused_arg(file); os_unused_arg(line); os_unused_arg(func); EnterCriticalSection(&mutex->mutex); #else int err; if ((err = pthread_mutex_lock(&mutex->mutex))) { os_log(file, func, line, OS_LOG_LEVEL_ERROR, "Failed to lock mutex %d:%s\n", err, strerror(err)); return OS_FAIL; } #endif #ifdef OS_DEBUG_MUTEX ADD_LOCK_HISTORY(mutex, file, line, func); #endif return OS_SUCCESS; }
void mono_log_write_asl (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message) { switch (level & G_LOG_LEVEL_MASK) { case G_LOG_LEVEL_MESSAGE: os_log (OS_LOG_DEFAULT, "%s%s%s\n", log_domain != NULL ? log_domain : "", log_domain != NULL ? ": " : "", message); break; case G_LOG_LEVEL_INFO: os_log_info (OS_LOG_DEFAULT, "%s%s%s\n", log_domain != NULL ? log_domain : "", log_domain != NULL ? ": " : "", message); break; case G_LOG_LEVEL_DEBUG: os_log_debug (OS_LOG_DEFAULT, "%s%s%s\n", log_domain != NULL ? log_domain : "", log_domain != NULL ? ": " : "", message); break; case G_LOG_LEVEL_ERROR: case G_LOG_LEVEL_WARNING: os_log_error (OS_LOG_DEFAULT, "%s%s%s\n", log_domain != NULL ? log_domain : "", log_domain != NULL ? ": " : "", message); case G_LOG_LEVEL_CRITICAL: default: os_log_fault (OS_LOG_DEFAULT, "%s%s%s\n", log_domain != NULL ? log_domain : "", log_domain != NULL ? ": " : "", message); break; } if (level & G_LOG_LEVEL_ERROR) abort(); }
/** * Decode a sandesh from the buffer and call the sandesh handler function * * Returns the number of bytes processed, -1 on error and sets error */ static int32_t sandesh_decode_one (u_int8_t *buf, u_int32_t buf_len, sandesh_find_info_fn sinfo_find_fn, int *error) { int32_t rxfer, ret; char *sname = NULL; ThriftBinaryProtocol protocol; ThriftMemoryBuffer transport; sandesh_info_t *sinfo; void *sandesh; /* Initialize the transport and protocol */ thrift_memory_buffer_init(&transport, buf, buf_len); thrift_protocol_init(&protocol, T_PROTOCOL_BINARY, (ThriftTransport *)&transport); thrift_memory_buffer_wrote_bytes(&transport, buf_len); /* Read the sandesh name */ rxfer = thrift_protocol_read_sandesh_begin(&protocol, &sname, error); if (rxfer < 0) { os_log(OS_LOG_ERR, "Read sandesh begin FAILED (%d)", *error); ret = -1; goto exit; } /* Find the corresponding sandesh information */ sinfo = sinfo_find_fn(sname); if (sinfo == NULL) { os_log(OS_LOG_ERR, "No information for sandesh %s", sname); *error = EINVAL; ret = -1; goto exit; } sandesh = os_zalloc(sinfo->size); if (sandesh == NULL) { os_log(OS_LOG_ERR, "Allocation of sandesh %s : %d bytes FAILED", sname, sinfo->size); *error = ENOMEM; ret = -1; goto exit; } /* * Reinitialize the transport and protocol, this is needed so that * the sandesh name read above is done again in the sandesh type specific * read function */ thrift_memory_buffer_init(&transport, buf, buf_len); thrift_protocol_init(&protocol, T_PROTOCOL_BINARY, (ThriftTransport *)&transport); thrift_memory_buffer_wrote_bytes(&transport, buf_len); /* Now, read the sandesh */ rxfer = sinfo->read(sandesh, &protocol, error); if (rxfer < 0) { os_log(OS_LOG_ERR, "%s read FAILED (%d)", sname, *error); sinfo->free(sandesh); os_free(sandesh); sandesh = NULL; ret = -1; goto exit; } ret = rxfer; /* Process the sandesh */ sinfo->process(sandesh); /* Release the sandesh */ sinfo->free(sandesh); os_free(sandesh); sandesh = NULL; exit: if (sname) { os_free(sname); sname = NULL; } return ret; }