static void trace_dup(int oldfd, int newfd) { debug("trace_dup %d %d", oldfd, newfd); Descriptor *o = get_descriptor(oldfd); if (o == NULL) { return; } /* Not a descriptor we are tracing */ if (o->path == NULL) { return; } /* Just in case newfd is already open */ trace_close(newfd); char *temp = strdup(o->path); if (temp == NULL) { printerr("strdup: %s\n", strerror(errno)); return; } /* Copy the old descriptor into the new */ Descriptor *n = get_descriptor(newfd); n->type = o->type; n->path = temp; n->bread = 0; n->bwrite = 0; }
void udp_socket::set_nonblocking() { #ifdef BLAHNET_WIN32 u_long non_blocking = 1; ioctlsocket(get_descriptor(*this), FIONBIO, &non_blocking); #else fcntl(get_descriptor(*this), F_SETFL, O_NONBLOCK); #endif // BLAHNET_WIN32 }
int udp_socket::sendto(char const* msg, std::size_t len, address const& addr) { return ::sendto(get_descriptor(*this), msg, len, 0, reinterpret_cast<sockaddr const*>(addr.data()), sizeof(sockaddr)); }
static void trace_file(const char *path, int fd) { debug("trace_file %s %d", path, fd); Descriptor *f = get_descriptor(fd); if (f == NULL) { return; } /* Skip all the common system paths, which we don't care about */ if (startswith(path, "/lib") || startswith(path, "/usr") || startswith(path, "/dev") || startswith(path, "/etc") || startswith(path, "/proc")|| startswith(path, "/sys")) { return; } char *temp = strdup(path); if (temp == NULL) { printerr("strdup: %s\n", strerror(errno)); return; } f->type = DTYPE_FILE; f->path = temp; f->bread = 0; f->bwrite = 0; }
status_t get_descriptor_v2(const void *device, uint8 type, uint8 index, uint16 languageID, void *data, size_t dataLength, size_t *actualLength) { return get_descriptor((usb_id)(ssize_t)device, type, index, languageID, data, dataLength, actualLength); }
int udp_socket::bind(unsigned short int port) { address addr(port); return ::bind(get_descriptor(*this), reinterpret_cast<sockaddr*>(addr.data()), sizeof(sockaddr)); }
int main() { printf("msp430_serial starting...\n"); printf("libusb initing...\n"); // initialize USB context, and get a device handle. HANDLE h = init_dev(1, 0, 0xf432); if (h == NULL) { fprintf(stderr, "Handle is NULL, initialization failed.\n"); return(1); } // enable debugging #ifdef DEBUG libusb_set_debug(mspContext, 3); #endif // get endpoints MSP_get_endpoints(h, &ep_int_in, &ep_bulk_in, &ep_bulk_out); // Send magic setup control transfers... MSP_setup(h); get_descriptor(h); // TI driver does this 26 times... not sure why // read status do_control_transfer(h,0xa1,0x21); // write back to device do_send_std(h,0x21,0x20,true); while (1) { do_bulk_transfer(h); libusb_handle_events(mspContext); } printf("Exiting.\n"); MSP_uninitialize(h); return(0); }
static void trace_close(int fd) { Descriptor *f = get_descriptor(fd); if (f == NULL) { return; } if (f->path == NULL) { /* If the path is null, then it is a descriptor we aren't tracking */ return; } debug("trace_close %d", fd); if (f->type == DTYPE_FILE) { /* Try to get the final size of the file */ size_t size = 0; struct stat st; if (stat(f->path, &st) == 0) { size = st.st_size; } tprintf("file: '%s' %lu %lu %lu\n", f->path, size, f->bread, f->bwrite); } else if (f->type == DTYPE_SOCK) { tprintf("socket: %s %lu %lu\n", f->path, f->bread, f->bwrite); } /* Reset the entry */ free(f->path); f->type = DTYPE_NONE; f->path = NULL; f->bread = 0; f->bwrite = 0; }
f2d_detector::result_type f2d_detector::get_descriptor(const cv::Mat &input) { result_type output; get_descriptor(input, output); return output; }
static int plugin_open_plugin (plugin_desc_t * desc, void ** dl_handle_ptr, const LADSPA_Descriptor ** descriptor_ptr) { void * dl_handle; const char * dlerr; LADSPA_Descriptor_Function get_descriptor; /* open the object file */ dl_handle = dlopen (desc->object_file, RTLD_NOW|RTLD_GLOBAL); if (!dl_handle) { mlt_log_warning( NULL, "%s: error opening shared object file '%s': %s\n", __FUNCTION__, desc->object_file, dlerror()); return 1; } /* get the get_descriptor function */ dlerror (); /* clear the error report */ get_descriptor = (LADSPA_Descriptor_Function) dlsym (dl_handle, "ladspa_descriptor"); dlerr = dlerror(); if (dlerr) { mlt_log_warning( NULL, "%s: error finding descriptor symbol in object file '%s': %s\n", __FUNCTION__, desc->object_file, dlerr); dlclose (dl_handle); return 1; } #ifdef __APPLE__ if (!get_descriptor (desc->index)) { void (*constructor)(void) = dlsym (dl_handle, "_init"); if (constructor) constructor(); } #endif *descriptor_ptr = get_descriptor (desc->index); *dl_handle_ptr = dl_handle; return 0; }
static void trace_write(int fd, ssize_t amount) { debug("trace_write %d %lu", fd, amount); Descriptor *f = get_descriptor(fd); if (f == NULL) { return; } f->bwrite += amount; }
static void trace_read(int fd, ssize_t amount) { debug("trace_read %d %lu", fd, amount); Descriptor *f = get_descriptor(fd); if (f == NULL) { return; } f->bread += amount; f->nread += 1; }
static void trace_seek(int fd, off_t offset) { debug("trace_seek %d %ld", fd, offset); Descriptor *f = get_descriptor(fd); if (f == NULL) { return; } f->bseek += offset > 0 ? offset : -offset; f->nseek += 1; }
int udp_socket::recvfrom(char* msg, std::size_t len, address& addr) { #ifdef BLAHNET_WIN32 int from_len = sizeof(sockaddr); #else socklen_t from_len = sizeof(sockaddr); #endif // BLAHNET_WIN32 return ::recvfrom(get_descriptor(*this), msg, len, 0, reinterpret_cast<sockaddr*>(addr.data()), &from_len); }
//----------------------------------------------------------------- // usb_process_request: //----------------------------------------------------------------- static void usb_process_request(struct device_request *request, unsigned char type, unsigned char req, unsigned char *data) { if ( type == USB_STANDARD_REQUEST ) { // Standard requests switch (req) { case REQ_GET_STATUS: get_status(request); break; case REQ_CLEAR_FEATURE: clear_feature(request); break; case REQ_SET_FEATURE: set_feature(request); break; case REQ_SET_ADDRESS: set_address(request); break; case REQ_GET_DESCRIPTOR: get_descriptor(request); break; case REQ_GET_CONFIGURATION: get_configuration(request); break; case REQ_SET_CONFIGURATION: set_configuration(request); break; case REQ_GET_INTERFACE: get_interface(request); break; case REQ_SET_INTERFACE: set_interface(request); break; default: log_printf(USBLOG_ERR, "USB: Unknown standard request %x\n", req); usbhw_control_endpoint_stall(); break; } } else if ( type == USB_VENDOR_REQUEST ) { log_printf(USBLOG_ERR, "Vendor: Unknown command\n"); // None supported usbhw_control_endpoint_stall(); } else if ( type == USB_CLASS_REQUEST && _class_request) { _class_request(req, request->wValue, request->wIndex, data, request->wLength); } else usbhw_control_endpoint_stall(); }
std::pair<mapnik::datasource_ptr,mapnik::feature_ptr> fetch_first_feature(std::string const& filename, bool cache_features) { mapnik::parameters params; params["type"] = "geojson"; params["file"] = filename; params["cache_features"] = cache_features; auto ds = mapnik::datasource_cache::instance().create(params); CHECK(ds->type() == mapnik::datasource::datasource_t::Vector); auto fields = ds->get_descriptor().get_descriptors(); mapnik::query query(ds->envelope()); for (auto const& field : fields) { query.add_property_name(field.get_name()); } auto features = ds->features(query); auto feature = features->next(); return std::make_pair(ds,feature); }
static void trace_sock(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { debug("trace_sock %d"); Descriptor *d = get_descriptor(sockfd); if (d == NULL) { return; } char *addrstr = get_addr(addr, addrlen); if (addrstr == NULL) { /* It is not a type of socket we understand */ return; } debug("sock addr %s", addrstr); if (d->path == NULL || strcmp(addrstr, d->path) != 0) { /* This is here to handle the case where a socket is reused to connect * to another address without being closed first. This happens, for example, * with DNS lookups in curl. */ trace_close(sockfd); /* Reset the descriptor */ d->type = DTYPE_NONE; d->path = NULL; d->bread = 0; d->bwrite = 0; d->nread = 0; d->nwrite = 0; d->bseek = 0; d->nseek = 0; char *temp = strdup(addrstr); if (temp == NULL) { printerr("strdup: %s\n", strerror(errno)); return; } d->type = DTYPE_SOCK; d->path = temp; } }
static void load_lv2_descriptors(Lv2World *world) { unsigned int i; Lv2Plugin *cur, *prev=NULL, *first=NULL; for (i=0;lv2_descriptor_loaders[i];i++) { cur = malloc(sizeof(Lv2Plugin)); cur->next = NULL; if (prev) prev->next = cur; else first=cur; get_descriptor = lv2_descriptor_loaders[i]; cur->descriptor = (LV2_Descriptor*)get_descriptor(0); cur->handle = cur->descriptor->instantiate( cur->descriptor, world->sample_rate, NULL, world->lv2_features); prev = cur; } world->num_plugins = i; world->plugin_list = first; }
static int plugin_open_plugin (plugin_desc_t * desc, void ** dl_handle_ptr, const LADSPA_Descriptor ** descriptor_ptr) { void * dl_handle; const char * dlerr; LADSPA_Descriptor_Function get_descriptor; /* open the object file */ dl_handle = dlopen (desc->object_file, RTLD_NOW|RTLD_GLOBAL); if (!dl_handle) { fprintf (stderr, _("%s: error opening shared object file '%s': %s\n"), __FUNCTION__, desc->object_file, dlerror()); return 1; } /* get the get_descriptor function */ dlerror (); /* clear the error report */ get_descriptor = (LADSPA_Descriptor_Function) dlsym (dl_handle, "ladspa_descriptor"); dlerr = dlerror(); if (dlerr) { fprintf (stderr, _("%s: error finding descriptor symbol in object file '%s': %s\n"), __FUNCTION__, desc->object_file, dlerr); dlclose (dl_handle); return 1; } *descriptor_ptr = get_descriptor (desc->index); *dl_handle_ptr = dl_handle; return 0; }
static void trace_file(const char *path, int fd) { debug("trace_file %s %d", path, fd); Descriptor *f = get_descriptor(fd); if (f == NULL) { return; } if (!should_trace(path)) { return; } struct stat s; if (fstat(fd, &s) != 0) { printerr("fstat: %s\n", strerror(errno)); return; } /* Skip directories */ if (s.st_mode & S_IFDIR) { return; } char *temp = strdup(path); if (temp == NULL) { printerr("strdup: %s\n", strerror(errno)); return; } f->type = DTYPE_FILE; f->path = temp; f->bread = 0; f->bwrite = 0; f->nread = 0; f->nwrite = 0; f->bseek = 0; f->nseek = 0; }
static inline int build_device( JNIEnv *env, jclass JavaxUsb, jobject linuxUsbServices, unsigned char bus, unsigned char dev, jobject parent, int parentport, jobject connectedDevices, jobject disconnectedDevices ) { int fd = 0, port, ncfg; int devices = 0; char node[4] = { 0, }; char *path = (char*)getcwd( NULL, 0 ); char *key = NULL; struct usbdevfs_ioctl *usbioctl = NULL; struct usbdevfs_hub_portinfo *portinfo = NULL; struct usbdevfs_connectinfo *connectinfo = NULL; struct jusb_device_descriptor *dev_desc; jobject device = NULL, existingDevice; jstring speedString = NULL, keyString = NULL; jclass LinuxUsbServices = (*env)->GetObjectClass( env, linuxUsbServices ); jmethodID createUsbHubImp = (*env)->GetStaticMethodID( env, JavaxUsb, "createUsbHubImp", "(Ljava/lang/String;I)Lcom/ibm/jusb/UsbHubImp;" ); jmethodID createUsbDeviceImp = (*env)->GetStaticMethodID( env, JavaxUsb, "createUsbDeviceImp", "(Ljava/lang/String;)Lcom/ibm/jusb/UsbDeviceImp;" ); jmethodID configureUsbDeviceImp = (*env)->GetStaticMethodID( env, JavaxUsb, "configureUsbDeviceImp", "(Lcom/ibm/jusb/UsbDeviceImp;BBBBBBBBBBSSSSLjava/lang/String;)V" ); jmethodID checkUsbDeviceImp = (*env)->GetMethodID( env, LinuxUsbServices, "checkUsbDeviceImp", "(Lcom/ibm/jusb/UsbHubImp;ILcom/ibm/jusb/UsbDeviceImp;Ljava/util/List;Ljava/util/List;)Lcom/ibm/jusb/UsbDeviceImp;" ); if (!path) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_device : Could not get current directory!\n" ); goto BUILD_DEVICE_EXIT; } key = malloc(strlen(path) + 5); sprintf( key, "%s/%3.03d", path, dev ); keyString = (*env)->NewStringUTF( env, key ); dbg( MSG_DEBUG2, "nativeTopologyUpdater.build_device : Building device %s\n", key ); sprintf( node, "%3.03d", dev ); fd = open( node, O_RDWR ); if ( 0 >= fd ) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_device : Could not access %s\n", key ); goto BUILD_DEVICE_EXIT; } if (!(dev_desc = get_descriptor( fd ))) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_device : Short read on device descriptor\n" ); goto BUILD_DEVICE_EXIT; } if (dev_desc->bDeviceClass == USB_CLASS_HUB) { usbioctl = malloc(sizeof(*usbioctl)); portinfo = malloc(sizeof(*portinfo)); usbioctl->ioctl_code = USBDEVFS_HUB_PORTINFO; usbioctl->ifno = 0; usbioctl->data = portinfo; errno = 0; if (0 >= ioctl( fd, USBDEVFS_IOCTL, usbioctl )) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_device : Could not get portinfo from hub, error = %d\n", errno ); goto BUILD_DEVICE_EXIT; } else { dbg( MSG_DEBUG2, "nativeTopologyUpdater.build_device : Device is hub with %d ports\n",portinfo->nports ); } free(usbioctl); usbioctl = NULL; device = (*env)->CallStaticObjectMethod( env, JavaxUsb, createUsbHubImp, keyString, portinfo->nports ); } else { device = (*env)->CallStaticObjectMethod( env, JavaxUsb, createUsbDeviceImp, keyString ); } connectinfo = malloc(sizeof(*connectinfo)); errno = 0; if (ioctl( fd, USBDEVFS_CONNECTINFO, connectinfo )) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_device : Could not get connectinfo from device, error = %d\n", errno ); goto BUILD_DEVICE_EXIT; } else { dbg( MSG_DEBUG2, "nativeTopologyUpdater.build_device : Device speed is %s\n", (connectinfo->slow?"1.5 Mbps":"12 Mbps") ); } speedString = (*env)->NewStringUTF( env, ( connectinfo->slow ? "1.5 Mbps" : "12 Mbps" ) ); free(connectinfo); connectinfo = NULL; (*env)->CallStaticVoidMethod( env, JavaxUsb, configureUsbDeviceImp, device, dev_desc->bLength, dev_desc->bDescriptorType, dev_desc->bDeviceClass, dev_desc->bDeviceSubClass, dev_desc->bDeviceProtocol, dev_desc->bMaxPacketSize0, dev_desc->iManufacturer, dev_desc->iProduct, dev_desc->iSerialNumber, dev_desc->bNumConfigurations, dev_desc->idVendor, dev_desc->idProduct, dev_desc->bcdDevice, dev_desc->bcdUSB, speedString ); (*env)->DeleteLocalRef( env, speedString ); speedString = NULL; /* Build config descriptors */ for (ncfg=0; ncfg<dev_desc->bNumConfigurations; ncfg++) { if (build_config( env, JavaxUsb, fd, device, bus, dev )) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_device : Could not get config %d for device %d\n", ncfg, dev ); goto BUILD_DEVICE_EXIT; } } existingDevice = (*env)->CallObjectMethod( env, linuxUsbServices, checkUsbDeviceImp, parent, parentport+1, device, connectedDevices, disconnectedDevices ); (*env)->DeleteLocalRef( env, device ); device = existingDevice; /* This device is set up and ready! */ devices = 1; close( fd ); fd = 0; if ((dev_desc->bDeviceClass == USB_CLASS_HUB) && portinfo) for (port=0; port<(portinfo->nports); port++) if (portinfo->port[port]) { dbg( MSG_DEBUG2, "nativeTopologyUpdater.build_device : Building device attached to port %d\n", portinfo->port[port]); devices += build_device( env, JavaxUsb, linuxUsbServices, bus, portinfo->port[port], device, port, connectedDevices, disconnectedDevices ); } BUILD_DEVICE_EXIT: if (fd) close(fd); if (device) (*env)->DeleteLocalRef( env, device ); if (connectinfo) free(connectinfo); if (dev_desc) free(dev_desc); if (usbioctl) free(usbioctl); if (portinfo) free(portinfo); if (keyString) (*env)->DeleteLocalRef( env, keyString ); if (speedString) (*env)->DeleteLocalRef( env, speedString ); if (path) free(path); if (key) free(key); return devices; }
static void plugin_mgr_get_object_file_plugins (plugin_mgr_t * plugin_mgr, const char * filename) { const char * dlerr; void * dl_handle; LADSPA_Descriptor_Function get_descriptor; const LADSPA_Descriptor * descriptor; unsigned long plugin_index; plugin_desc_t * desc, * other_desc = NULL; GSList * list; gboolean exists; int err; /* open the object file */ dl_handle = dlopen (filename, RTLD_NOW); if (!dl_handle) { mlt_log_info( NULL, "%s: error opening shared object file '%s': %s\n", __FUNCTION__, filename, dlerror()); return; } /* get the get_descriptor function */ dlerror (); /* clear the error report */ get_descriptor = (LADSPA_Descriptor_Function) dlsym (dl_handle, "ladspa_descriptor"); dlerr = dlerror(); if (dlerr) { mlt_log_info( NULL, "%s: error finding ladspa_descriptor symbol in object file '%s': %s\n", __FUNCTION__, filename, dlerr); dlclose (dl_handle); return; } #ifdef __DARWIN__ if (!get_descriptor (0)) { void (*constructor)(void) = dlsym (dl_handle, "_init"); if (constructor) constructor(); } #endif plugin_index = 0; while ( (descriptor = get_descriptor (plugin_index)) ) { if (!plugin_is_valid (descriptor)) { plugin_index++; continue; } /* check it doesn't already exist */ exists = FALSE; for (list = plugin_mgr->all_plugins; list; list = g_slist_next (list)) { other_desc = (plugin_desc_t *) list->data; if (other_desc->id == descriptor->UniqueID) { exists = TRUE; break; } } if (exists) { mlt_log_info( NULL, "Plugin %ld exists in both '%s' and '%s'; using version in '%s'\n", descriptor->UniqueID, other_desc->object_file, filename, other_desc->object_file); plugin_index++; continue; } desc = plugin_desc_new_with_descriptor (filename, plugin_index, descriptor); plugin_mgr->all_plugins = g_slist_append (plugin_mgr->all_plugins, desc); plugin_index++; plugin_mgr->plugin_count++; /* print in the splash screen */ /* mlt_log_verbose( NULL, "Loaded plugin '%s'\n", desc->name); */ } err = dlclose (dl_handle); if (err) { mlt_log_warning( NULL, "%s: error closing object file '%s': %s\n", __FUNCTION__, filename, dlerror ()); } }
/* * FUNCTION UTL_FILE.FOPEN(location text, * filename text, * open_mode text, * max_linesize integer) * RETURNS UTL_FILE.FILE_TYPE; * * The FOPEN function opens specified file and returns file handle. * open_mode: ['R', 'W', 'A'] * max_linesize: [1 .. 32767] * * Exceptions: * INVALID_MODE, INVALID_OPERATION, INVALID_PATH, INVALID_MAXLINESIZE */ Datum utl_file_fopen(PG_FUNCTION_ARGS) { text *open_mode; int max_linesize; int encoding; const char *mode = NULL; FILE *file; char *fullname; int d; NOT_NULL_ARG(0); NOT_NULL_ARG(1); NOT_NULL_ARG(2); NOT_NULL_ARG(3); open_mode = PG_GETARG_TEXT_P(2); NON_EMPTY_TEXT(open_mode); max_linesize = PG_GETARG_INT32(3); CHECK_LINESIZE(max_linesize); if (PG_NARGS() > 4 && !PG_ARGISNULL(4)) { const char *encname = NameStr(*PG_GETARG_NAME(4)); encoding = pg_char_to_encoding(encname); if (encoding < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid encoding name \"%s\"", encname))); } else encoding = GetDatabaseEncoding(); if (VARSIZE(open_mode) - VARHDRSZ != 1) CUSTOM_EXCEPTION(INVALID_MODE, "open mode is different than [R,W,A]"); switch (*((char*)VARDATA(open_mode))) { case 'a': case 'A': mode = "a"; break; case 'r': case 'R': mode = "r"; break; case 'w': case 'W': mode = "w"; break; default: CUSTOM_EXCEPTION(INVALID_MODE, "open mode is different than [R,W,A]"); } /* open file */ fullname = get_safe_path(PG_GETARG_TEXT_P(0), PG_GETARG_TEXT_P(1)); /* * We cannot use AllocateFile here because those files are automatically * closed at the end of (sub)transactions, but we want to keep them open * for oracle compatibility. */ #if NOT_USED fullname = convert_encoding_server_to_platform(fullname); #endif file = fopen(fullname, mode); if (!file) IO_EXCEPTION(); d = get_descriptor(file, max_linesize, encoding); if (d == INVALID_SLOTID) { fclose(file); ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("program limit exceeded"), errdetail("Too much concurent opened files"), errhint("You can only open a maximum of ten files for each session"))); } PG_RETURN_INT32(d); }
static inline int build_config( JNIEnv *env, jclass JavaxUsb, int fd, jobject device, unsigned char bus, unsigned char dev ) { int result = -1; struct jusb_config_descriptor *cfg_desc = NULL; unsigned char *desc = NULL; unsigned short wTotalLength; unsigned int pos; jobject config = NULL, interface = NULL; jmethodID createUsbConfigImp; jboolean isActive = JNI_FALSE; if (!(cfg_desc = get_descriptor( fd ))) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_config : Short read on config desriptor\n" ); goto BUILD_CONFIG_EXIT; } createUsbConfigImp = (*env)->GetStaticMethodID( env, JavaxUsb, "createUsbConfigImp", "(Lcom/ibm/jusb/UsbDeviceImp;BBSBBBBBZ)Lcom/ibm/jusb/UsbConfigImp;" ); dbg( MSG_DEBUG3, "nativeTopologyUpdater.build_config : Building config %d\n", cfg_desc->bConfigurationValue ); wTotalLength = cfg_desc->wTotalLength; pos = cfg_desc->bLength; isActive = isConfigActive( fd, bus, dev, cfg_desc->bConfigurationValue ); config = (*env)->CallStaticObjectMethod( env, JavaxUsb, createUsbConfigImp, device, cfg_desc->bLength, cfg_desc->bDescriptorType, wTotalLength, cfg_desc->bNumInterfaces, cfg_desc->bConfigurationValue, cfg_desc->iConfiguration, cfg_desc->bmAttributes, cfg_desc->bMaxPower, isActive ); while (pos < wTotalLength) { desc = get_descriptor( fd ); if ((!desc) || (2 > desc[0])) { dbg( MSG_ERROR, "nativeTopologyUpdater.build_config : Short read on descriptor\n" ); goto BUILD_CONFIG_EXIT; } pos += desc[0]; switch( desc[1] ) { case USB_DT_DEVICE: dbg( MSG_ERROR, "nativeTopologyUpdater.build_config : Got device descriptor inside of config descriptor\n" ); goto BUILD_CONFIG_EXIT; case USB_DT_CONFIG: dbg( MSG_ERROR, "nativeTopologyUpdater.build_config : Got config descriptor inside of config descriptor\n" ); goto BUILD_CONFIG_EXIT; case USB_DT_INTERFACE: if (interface) (*env)->DeleteLocalRef( env, interface ); interface = build_interface( env, JavaxUsb, fd, config, (struct jusb_interface_descriptor*)desc ); break; case USB_DT_ENDPOINT: build_endpoint( env, JavaxUsb, interface, (struct jusb_endpoint_descriptor*)desc ); break; default: /* Ignore proprietary descriptor */ break; } free(desc); desc = NULL; } result = 0; BUILD_CONFIG_EXIT: if (config) (*env)->DeleteLocalRef( env, config ); if (interface) (*env)->DeleteLocalRef( env, interface ); if (cfg_desc) free(cfg_desc); if (desc) free(desc); return result; }
void process_control_transfer(void) { if (USTAT == USTAT_OUT) { unsigned char PID = (ep0_o.STAT & 0x3C) >> 2; // Pull PID from middle of BD0STAT if (PID == 0x0D) { // Setup stage // Note: Microchip says to turn off the UOWN bit on the IN direction as // soon as possible after detecting that a SETUP has been received. ep0_i.STAT &= ~UOWN; ep0_o.STAT &= ~UOWN; // Initialize the transfer process control_stage = SETUP_STAGE; request_handled = 0; // Default is that request hasn't been handled dlen = 0; // No unsigned chars transferred // See if this is a standard (as definded in USB chapter 9) request debug=setup_packet.bmrequesttype; if (1 /* (setup_packet.bmrequesttype & 0x60) == 0x00*/) {// ---------- unsigned char request = setup_packet.brequest; debug = request; if (request == SET_ADDRESS) { // Set the address of the device. All future requests // will come to that address. Can't actually set UADDR // to the new address yet because the rest of the SET_ADDRESS // transaction uses address 0. request_handled = 1; usbcdc_device_state = ADDRESS; device_address = setup_packet.wvalue0; } else if (request == GET_DESCRIPTOR) { get_descriptor(); } else if (request == SET_CONFIGURATION) { request_handled = 1; current_configuration = setup_packet.wvalue0; // TBD: ensure the new configuration value is one that // exists in the descriptor. if (current_configuration == 0) { // If configuration value is zero, device is put in // address state (USB 2.0 - 9.4.7) usbcdc_device_state = ADDRESS; } else { // Set the configuration. usbcdc_device_state = CONFIGURED; // Initialize the endpoints for all interfaces { // Turn on both in and out for this endpoint UEP1 = 0x1E; ep1_i.ADDR = (int) &cdcint_buffer; ep1_i.STAT = DTS; UEP2 = 0x1E; ep2_o.CNT = sizeof(cdc_rx_buffer); ep2_o.ADDR = (int) &cdc_rx_buffer; ep2_o.STAT = UOWN | DTSEN; //set up to receive stuff as soon as we get something ep2_i.ADDR = (int) &cdc_tx_buffer; ep2_i.STAT = DTS; } } } else if (request == GET_CONFIGURATION) { // Never seen in Windows request_handled = 1; code_ptr = (codePtr) &const_values_0x00_0x01[current_configuration]; dlen = 1; } else if (request == GET_STATUS) { // Never seen in Windows get_status(); } else if ((request == CLEAR_FEATURE) || (request == SET_FEATURE)) { // Never seen in Windows set_feature(); } else if (request == GET_INTERFACE) { // Never seen in Windows // No support for alternate interfaces. Send // zero back to the host. request_handled = 1; code_ptr = (codePtr) (&const_values_0x00_0x00); dlen = 1; // || (request == SET_CONTROL_LINE_STATE) } else if ((request == SET_INTERFACE) || (request == SET_LINE_CODING) || (request == SET_CONTROL_LINE_STATE)) { // No support for alternate interfaces - just ignore. request_handled = 1; } else if (request == GET_LINE_CODING) { code_ptr = (codePtr) (&cdc_line_coding); dlen = sizeof(cdc_line_coding); request_handled = 1; } } if (!request_handled) { // If this service wasn't handled then stall endpoint 0 ep0_o.CNT = E0SZ; ep0_o.ADDR = (int) &setup_packet; ep0_o.STAT = UOWN | BSTALL; ep0_i.STAT = UOWN | BSTALL; } else if (setup_packet.bmrequesttype & 0x80) { // Device-to-host if (setup_packet.wlength < dlen)//9.4.3, p.253 dlen = setup_packet.wlength; in_data_stage(); control_stage = DATA_IN_STAGE; // Reset the out buffer descriptor for endpoint 0 ep0_o.CNT = E0SZ; ep0_o.ADDR = (int) &setup_packet; ep0_o.STAT = UOWN; // Set the in buffer descriptor on endpoint 0 to send data // NOT NEEDED ep0_i.ADDR = (int) &control_transfer_buffer; // Give to SIE, DATA1 packet, enable data toggle checks ep0_i.STAT = UOWN | DTS | DTSEN; } else { // Host-to-device control_stage = DATA_OUT_STAGE; // Clear the input buffer descriptor ep0_i.CNT = 0; ep0_i.STAT = UOWN | DTS | DTSEN; // Set the out buffer descriptor on endpoint 0 to receive data ep0_o.CNT = E0SZ; ep0_o.ADDR = (int) &control_transfer_buffer; // Give to SIE, DATA1 packet, enable data toggle checks ep0_o.STAT = UOWN | DTS | DTSEN; } // Enable SIE token and packet processing UCONbits.PKTDIS = 0; } else if (control_stage == DATA_OUT_STAGE) { // Complete the data stage so that all information has // passed from host to device before servicing it. { unsigned char bufferSize; //bufferSize = ((0x03 & ep0_o.STAT) << 8) | ep0_o.CNT; bufferSize = ep0_o.CNT; // Accumulate total number of unsigned chars read dlen = dlen + bufferSize; data_ptr = (dataPtr) &control_transfer_buffer; for (idx = bufferSize; idx--;) *in_ptr++ = *data_ptr++; } // Turn control over to the SIE and toggle the data bit if (ep0_o.STAT & DTS) ep0_o.STAT = UOWN | DTSEN; else ep0_o.STAT = UOWN | DTS | DTSEN; } else { // Prepare for the Setup stage of a control transfer prepare_for_setup_stage(); } } else if (USTAT == USTAT_IN) {
PUSB_CONFIGURATION_DESCRIPTOR get_config_descriptor( libusb_device_t *dev, int value, int *size, int* index) { NTSTATUS status; USB_CONFIGURATION_DESCRIPTOR *desc = NULL; USB_DEVICE_DESCRIPTOR device_descriptor; int i; volatile int desc_size; *index = 0; status = get_descriptor(dev, &device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR), USB_DEVICE_DESCRIPTOR_TYPE, USB_RECIP_DEVICE, 0, 0, size, LIBUSB_DEFAULT_TIMEOUT); if (!NT_SUCCESS(status) || *size != sizeof(USB_DEVICE_DESCRIPTOR)) { USBERR0("getting device descriptor failed\n"); return NULL; } if (!(desc = ExAllocatePool(NonPagedPool, sizeof(USB_CONFIGURATION_DESCRIPTOR)))) { USBERR0("memory allocation error\n"); return NULL; } for (i = 0; i < device_descriptor.bNumConfigurations; i++) { if (!NT_SUCCESS(get_descriptor(dev, desc, sizeof(USB_CONFIGURATION_DESCRIPTOR), USB_CONFIGURATION_DESCRIPTOR_TYPE, USB_RECIP_DEVICE, i, 0, size, LIBUSB_DEFAULT_TIMEOUT))) { USBERR0("getting configuration descriptor failed\n"); break; } // if value is negative, get the descriptor by index // if positive, get it by value. if ((value > 0 && desc->bConfigurationValue == value) || (value < 0 && -(i+1) == (value))) { desc_size = desc->wTotalLength; ExFreePool(desc); if (!(desc = ExAllocatePool(NonPagedPool, desc_size))) { USBERR0("memory allocation error\n"); break; } if (!NT_SUCCESS(get_descriptor(dev, desc, desc_size, USB_CONFIGURATION_DESCRIPTOR_TYPE, USB_RECIP_DEVICE, i, 0, size, LIBUSB_DEFAULT_TIMEOUT))) { USBERR0("getting configuration descriptor failed\n"); break; } else { *index = i; } return desc; } } if (desc) { ExFreePool(desc); } return NULL; }
void Method::_set_nop() { bool verbose = false; Global_Env *env = VM_Global_State::loader_env; if (get_name() != env->Init_String || get_descriptor() != env->VoidVoidDescriptor_String) { return; } if(is_native()) { return; } unsigned len = _byte_code_length; if(!len) { return; } U_8* bc = _byte_codes; Nop_Stack_State stack_state = NS_StackEmpty; if(verbose) { printf("=========== nop[%d]: %s.%s%s\n", len, get_class()->get_name()->bytes, get_name()->bytes, get_descriptor()->bytes); } for (unsigned idx = 0; idx < len; idx++) { U_8 b = bc[idx]; if(verbose) { printf("\tbc[%d]=%d, state=%d\n", idx, b, stack_state); } if(b == 0xb1) { // return if(verbose) { printf("+++++++ nop: %s.%s%s\n", get_class()->get_name()->bytes, get_name()->bytes, get_descriptor()->bytes); } _flags.is_nop = TRUE; return; } switch(stack_state) { case NS_StackEmpty: switch(b) { case 0x2a: // aload_0 stack_state = NS_ThisPushed; break; default: return; } break; case NS_ThisPushed: switch(b) { case 0x01: // aconst_null case 0x03: // iconst_0 stack_state = NS_ThisAndZeroPushed; break; case 0xb7: // invokespecial { unsigned index = (bc[idx + 1] << 8) + bc[idx + 2]; if(verbose) { printf("\tinvokespecial, index=%d\n", index); } Method_Handle mh = resolve_special_method_env(VM_Global_State::loader_env, get_class(), index, false); Method *callee = (Method *)mh; if(!callee) { if(verbose) { printf("\tinvokespecial, callee==null\n"); } return; } if(callee == this) { return; } if(verbose) { printf("invokespecial: %s.%s%s\n", callee->get_class()->get_name()->bytes, callee->get_name()->bytes, callee->get_descriptor()->bytes); } if(!callee->is_nop()) { return; } const char *descr = callee->get_descriptor()->bytes; if(descr[1] != ')') { return; } if(verbose) { printf("invokespecial nop: %s.%s%s\n", callee->get_class()->get_name()->bytes, callee->get_name()->bytes, callee->get_descriptor()->bytes); } } stack_state = NS_StackEmpty; idx += 2; break; default: return; } break; case NS_ThisAndZeroPushed: switch(b) { case 0xb5: // putfield stack_state = NS_StackEmpty; if(verbose) { printf("\tputfield\n"); } idx += 2; break; default: return; } break; default: LDIE(57, "Unexpected stack state"); return; } } LDIE(56, "should'nt get here"); } //Method::_set_nop
auto run_simulation(const wayverb::core::geo::box& boundary, const util::aligned::vector<glm::vec3>& receivers, const wayverb::waveguide::coefficients_canonical& coefficients) const { const auto scene_data = wayverb::core::geo::get_scene_data( boundary, wayverb::core::make_surface<wayverb::core::simulation_bands>( 0, 0)); auto mesh = wayverb::waveguide::compute_mesh( cc_, make_voxelised_scene_data( scene_data, 5, wayverb::waveguide::compute_adjusted_boundary( wayverb::core::geo::compute_aabb( scene_data.get_vertices()), source_position_, divisions_)), divisions_, speed_of_sound); mesh.set_coefficients({coefficients}); const auto source_index = compute_index(mesh.get_descriptor(), source_position_); const auto input = [&] { const util::aligned::vector<float> raw_input{1.0f}; auto ret = wayverb::waveguide::make_transparent( raw_input.data(), raw_input.data() + raw_input.size()); ret.resize(steps, 0); return ret; }(); auto prep = wayverb::waveguide::preprocessor::make_soft_source( source_index, input.begin(), input.end()); auto output_holders = util::map_to_vector( begin(receivers), end(receivers), [&](auto i) { const auto receiver_index{ compute_index(mesh.get_descriptor(), i)}; if (!wayverb::waveguide::is_inside(mesh, receiver_index)) { throw std::runtime_error{ "receiver is outside of mesh!"}; } return wayverb::core::callback_accumulator< wayverb::waveguide::postprocessor::node> { receiver_index }; }); util::progress_bar pb{}; wayverb::waveguide::run( cc_, mesh, prep, [&](auto& queue, const auto& buffer, auto step) { for (auto& i : output_holders) { i(queue, buffer, step); } set_progress(pb, step, steps); }, true); return util::map_to_vector( begin(output_holders), end(output_holders), [](const auto& i) { return i.get_output(); }); }