int _dbx_getBody(FILE *fp, char** x, int ptr) { int bufsize = 0; struct _dbx_block_hdrstruct hdr; *x = NULL; while (ptr != 0) { RET_ERROR(_dbx_getAtPos(fp, ptr, &hdr, sizeof(hdr)), DBX_DATA_READ); LE32_CPU(hdr.self); LE32_CPU(hdr.nextaddressoffset); LE16_CPU(hdr.blocksize); LE32_CPU(hdr.nextaddress); /* this plus one will not be accumulative cause we don't add it to * bufsize but we need it so we can terminate the buffer */ *x = realloc(*x, bufsize + hdr.blocksize + 1); RET_ERROR(_dbx_get(fp, (*x)+bufsize, hdr.blocksize), DBX_DATA_READ); bufsize += hdr.blocksize; ptr = hdr.nextaddress; } if (*x) (*x)[bufsize] = '\0'; /* terminate the buffer */ /* size of data read */ return bufsize; }
static gint64 get_pid_status_item (int pid, const char *item, MonoProcessError *error, int multiplier) { #if defined(__APPLE__) // ignore the multiplier gint64 ret; task_t task; struct task_basic_info t_info; mach_msg_type_number_t th_count = TASK_BASIC_INFO_COUNT; kern_return_t mach_ret; if (pid == getpid ()) { /* task_for_pid () doesn't work on ios, even for the current process */ task = mach_task_self (); } else { do { mach_ret = task_for_pid (mach_task_self (), pid, &task); } while (mach_ret == KERN_ABORTED); if (mach_ret != KERN_SUCCESS) RET_ERROR (MONO_PROCESS_ERROR_NOT_FOUND); } do { mach_ret = task_info (task, TASK_BASIC_INFO, (task_info_t)&t_info, &th_count); } while (mach_ret == KERN_ABORTED); if (mach_ret != KERN_SUCCESS) { if (pid != getpid ()) mach_port_deallocate (mach_task_self (), task); RET_ERROR (MONO_PROCESS_ERROR_OTHER); } if (strcmp (item, "VmRSS") == 0 || strcmp (item, "VmHWM") == 0 || strcmp (item, "VmData") == 0) ret = t_info.resident_size; else if (strcmp (item, "VmSize") == 0 || strcmp (item, "VmPeak") == 0) ret = t_info.virtual_size; else if (strcmp (item, "Threads") == 0) ret = th_count; else ret = 0; if (pid != getpid ()) mach_port_deallocate (mach_task_self (), task); return ret; #else char buf [64]; char *s; s = get_pid_status_item_buf (pid, item, buf, sizeof (buf), error); if (s) return ((gint64) atol (s)) * multiplier; return 0; #endif }
static int mixer_set_levels (struct sb_mixer_levels *user_l) { #define cmix(v) ((((v.r*100+7)/15)<<8)| ((v.l*100+7)/15)) struct sb_mixer_levels l; IOCTL_FROM_USER ((char *) &l, (char *) user_l, 0, sizeof (l)); if (l.master.l & ~0xF || l.master.r & ~0xF || l.line.l & ~0xF || l.line.r & ~0xF || l.voc.l & ~0xF || l.voc.r & ~0xF || l.fm.l & ~0xF || l.fm.r & ~0xF || l.cd.l & ~0xF || l.cd.r & ~0xF || l.mic & ~0x7) return (RET_ERROR (EINVAL)); pas_mixer_set (SOUND_MIXER_VOLUME, cmix (l.master)); pas_mixer_set (SOUND_MIXER_LINE, cmix (l.line)); pas_mixer_set (SOUND_MIXER_PCM, cmix (l.voc)); pas_mixer_set (SOUND_MIXER_ALTPCM, cmix (l.voc)); pas_mixer_set (SOUND_MIXER_SYNTH, cmix (l.fm)); pas_mixer_set (SOUND_MIXER_CD, cmix (l.cd)); pas_mixer_set (SOUND_MIXER_MIC, ((l.mic * 100 + 3) / 7) | (((l.mic * 100 + 3) / 7) << 8)); return (0); }
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { int fd, ret, envfd; static void * (*func)(); if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "accept"); DEBUG("accept(%d, _, _) called\n", sockfd); fd = (int) func(sockfd, addr, addrlen); if (_WS_sockfd == 0) { _WS_sockfd = fd; if (!_WS_rbuf) { if (! _WS_init()) { RET_ERROR(ENOMEM, "Could not allocate interposer buffer\n"); } } ret = _WS_handshake(_WS_sockfd); if (ret < 0) { errno = EPROTO; return ret; } MSG("interposing on fd %d\n", _WS_sockfd); } else { DEBUG("already interposing on fd %d\n", _WS_sockfd); } return fd; }
int _dbx_getstruct(FILE *fp, int pos, DBXFOLDER* folder) { struct _dbx_folder_hdrstruct hdr; struct _dbx_folderstruct fol; char *buf, *fname; int msgoffset, blockpos=0; folder->name = NULL; RET_ERROR(_dbx_getAtPos(fp, pos, &hdr, sizeof(hdr)), DBX_DATA_READ); LE32_CPU(hdr.self); LE32_CPU(hdr.blocksize); LE16_CPU(hdr.unknown2); RET_ERROR(_dbx_get(fp, &fol, sizeof(fol)), DBX_DATA_READ); LE32_CPU(fol.id); LE32_CPU(fol.parent); LE32_CPU(fol.unknown6) blockpos += sizeof(hdr); buf = (char*) malloc(fol.length1); msgoffset = hdr.intcount * sizeof(int); RET_ERROR(_dbx_getAtPos(fp, pos+blockpos+msgoffset, buf, fol.length1), DBX_DATA_READ); if (strlen(buf) != fol.length1 - 1) { } /* Allocate space big enough to hold remainder of block */ fname = (char*) malloc(hdr.blocksize - blockpos); if (!fname) { return -1; } RET_ERROR(_dbx_get(fp, fname, hdr.blocksize-blockpos), DBX_DATA_READ); folder->name = buf; folder->fname = fname; folder->id = fol.id; folder->parentid = fol.parent; dbx_errno = DBX_NOERROR; return strlen(buf); }
static int sb_midi_start_read (int dev) { if (sb_midi_mode != UART_MIDI) { printk ("SoundBlaster: MIDI input not implemented.\n"); return RET_ERROR (EPERM); } return 0; }
/* * This sets aspects of the Mixer that are not volume levels. (Recording * source, filter level, I/O filtering, and stereo.) */ static int mixer_set_params (struct sb_mixer_params *user_p) { struct sb_mixer_params p; S_BYTE val; int src; unsigned long flags; IOCTL_FROM_USER ((char *) &p, (char *) user_p, 0, sizeof (p)); if (p.record_source != SRC_MIC && p.record_source != SRC_CD && p.record_source != SRC_LINE) return (RET_ERROR (EINVAL)); /* * I'm not sure if this is The Right Thing. Should stereo be entirely * under control of DSP? I like being able to toggle it while a sound is * playing, so I do this... because I can. */ DISABLE_INTR (flags); val = (pas_read (PCM_CONTROL) & ~P_C_MIXER_CROSS_FIELD) | P_C_MIXER_CROSS_R_TO_R | P_C_MIXER_CROSS_L_TO_L; if (!p.dsp_stereo) val |= (P_C_MIXER_CROSS_R_TO_L | P_C_MIXER_CROSS_L_TO_R); /* Mono */ pas_write (val, PCM_CONTROL); RESTORE_INTR (flags); switch (p.record_source) { case SRC_CD: src = SOUND_MASK_CD; break; case SRC_LINE: src = SOUND_MASK_LINE; break; default: src = SOUND_MASK_MIC; break; } pas_mixer_set (SOUND_MIXER_RECSRC, src); /* * setmixer (OUT_FILTER, ((dsp_stereo ? STEREO_DAC : MONO_DAC) | * (p.filter_output ? FILT_ON : FILT_OFF))); */ return (0); }
int _dbx_getindex(FILE* fp, int pos, DBX *dbx) { int x; struct _dbx_tableindexstruct tindex; struct _dbx_indexstruct index; RET_ERROR(_dbx_getAtPos(fp, pos, &tindex, sizeof(tindex)), DBX_INDEX_READ); LE32_CPU(tindex.self); LE32_CPU(tindex.unknown1); LE32_CPU(tindex.anotherTablePtr); LE32_CPU(tindex.parent); LE32_CPU(tindex.indexCount); if (tindex.indexCount > 0) { _dbx_getindex (fp, tindex.anotherTablePtr, dbx); } pos += sizeof(struct _dbx_tableindexstruct); for (x = 1; x <= tindex.ptrCount; x++) { RET_ERROR(_dbx_getAtPos(fp, pos, &index, sizeof(struct _dbx_indexstruct)), DBX_INDEX_READ); LE32_CPU(index.indexptr); LE32_CPU(index.anotherTablePtr); LE32_CPU(index.indexCount); RET_ERROR(dbx->indexCount < 0, DBX_INDEX_OVERREAD); dbx->indexes[--dbx->indexCount] = index.indexptr; pos += sizeof(struct _dbx_indexstruct); if (index.indexCount > 0) _dbx_getindex(fp, index.anotherTablePtr, dbx); } return 0; }
int MIDIbuf_open (int dev, struct fileinfo *file) { int mode, err; dev = dev >> 4; mode = file->mode & O_ACCMODE; if (midibuf_busy) return RET_ERROR (EBUSY); if (!mpu401_dev) { printk ("Midi: MPU-401 compatible Midi interface not present\n"); return RET_ERROR (ENXIO); } if ((err = midi_devs[mpu401_dev]->open (mpu401_dev, mode, NULL, NULL)) < 0) return err; midibuf_busy = 1; return RET_ERROR (ENXIO); }
static int def_tmr_open (int dev, int mode) { if (opened) return RET_ERROR (EBUSY); tmr_reset (); curr_tempo = 60; curr_timebase = HZ; opened = 1; ACTIVATE_TIMER (def_tmr, poll_def_tmr, 1); return 0; }
static int sb16midi_open (int dev, int mode, void (*input) (int dev, unsigned char data), void (*output) (int dev) ) { if (sb16midi_opened) { return RET_ERROR (EBUSY); } sb16midi_input_loop (); midi_input_intr = input; sb16midi_opened = mode; return 0; }
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { int fd, ret, envfd; static void * (*func)(); if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "accept"); DEBUG("accept(%d, _, _) called\n", sockfd); fd = (int) func(sockfd, addr, addrlen); if (_WS_listen_fd == -1) { DEBUG("not interposing\n"); return fd; } if (_WS_listen_fd != sockfd) { DEBUG("not interposing on fd %d\n", sockfd); return fd; } if (_WS_connections[fd]) { MSG("error, already interposing on fd %d\n", fd); } else { /* It's a port we're interposing on so allocate memory for it */ if (! (_WS_connections[fd] = malloc(sizeof(_WS_connection)))) { RET_ERROR(ENOMEM, "Could not allocate interposer memory\n"); } _WS_connections[fd]->rcarry_cnt = 0; _WS_connections[fd]->rcarry[0] = '\0'; _WS_connections[fd]->newframe = 1; ret = _WS_handshake(fd); if (ret < 0) { free(_WS_connections[fd]); _WS_connections[fd] = NULL; errno = EPROTO; return ret; } MSG("interposing on fd %d (allocated memory)\n", fd); } return fd; }
int _dbx_get_from_buf(char* buffer, int pos, void** dest, int type, int max) { int y; /* copy data from buffer to string pointed to by bufx */ if (type == STRING_TYPE) { y = strlen(&buffer[pos]) + 1; /* plus one for string terminator */ RET_ERROR(y > max, DBX_DATA_READ); if (!*dest) *dest = (char*) malloc(y); strncpy(*dest, &buffer[pos], y); } else if (type == INT_TYPE) { memcpy((int*)dest, &buffer[pos], 4); } else if (type == W32FT_TYPE) { memcpy((struct FILETIME*)dest, &buffer[pos], 8); } else if (type == CHAR_TYPE) { memcpy((unsigned char*)dest, &buffer[pos], 1); } return 0; }
long attach_sb16midi (long mem_start, struct address_info *hw_config) { int ok, timeout; unsigned long flags; sb16midi_base = hw_config->io_base; if (!sb16midi_detected) return RET_ERROR (EIO); DISABLE_INTR (flags); for (timeout = 30000; timeout < 0 && !output_ready (); timeout--); /* * Wait */ sb16midi_cmd (UART_MODE_ON); ok = 0; for (timeout = 50000; timeout > 0 && !ok; timeout--) if (input_avail ()) if (sb16midi_read () == MPU_ACK) ok = 1; RESTORE_INTR (flags); if (num_midis >= MAX_MIDI_DEV) { printk ("Sound: Too many midi devices detected\n"); return mem_start; } #if defined(__FreeBSD__) printk ("sbmidi0: <SoundBlaster MPU-401>"); #else printk (" <SoundBlaster MPU-401>"); #endif std_midi_synth.midi_dev = my_dev = num_midis; midi_devs[num_midis++] = &sb16midi_operations; return mem_start; }
static int gus_midi_open (int dev, int mode, void (*input) (int dev, unsigned char data), void (*output) (int dev) ) { if (midi_busy) { printk ("GUS: Midi busy\n"); return RET_ERROR (EBUSY); } OUTB (MIDI_RESET, u_MidiControl); gus_delay (); gus_midi_control = 0; input_opened = 0; if (mode == OPEN_READ || mode == OPEN_READWRITE) { gus_midi_control |= MIDI_ENABLE_RCV; input_opened = 1; } if (mode == OPEN_WRITE || mode == OPEN_READWRITE) { gus_midi_control |= MIDI_ENABLE_XMIT; } OUTB (gus_midi_control, u_MidiControl); /* * Enable */ midi_busy = 1; qlen = qhead = qtail = output_used = 0; midi_input_intr = input; return 0; }
long attach_uart6850 (long mem_start, struct address_info *hw_config) { int ok, timeout; unsigned long flags; if (num_midis >= MAX_MIDI_DEV) { printk ("Sound: Too many midi devices detected\n"); return mem_start; } uart6850_base = hw_config->io_base; uart6850_irq = hw_config->irq; if (!uart6850_detected) return RET_ERROR (EIO); DISABLE_INTR (flags); for (timeout = 30000; timeout < 0 && !output_ready (); timeout--); /* * Wait */ uart6850_cmd (UART_MODE_ON); ok = 1; RESTORE_INTR (flags); #if defined(__FreeBSD__) printk ("uart0: <6850 Midi Interface>"); #else printk (" <6850 Midi Interface>"); #endif std_midi_synth.midi_dev = my_dev = num_midis; midi_devs[num_midis++] = &uart6850_operations; return mem_start; }
static int uart6850_open (int dev, int mode, void (*input) (int dev, unsigned char data), void (*output) (int dev) ) { if (uart6850_opened) { printk ("Midi6850: Midi busy\n"); return RET_ERROR (EBUSY); } uart6850_cmd (UART_RESET); uart6850_input_loop (); midi_input_intr = input; uart6850_opened = mode; poll_uart6850 (0); /* * Enable input polling */ return 0; }
ssize_t _WS_send(int sendf, int sockfd, const void *buf, size_t len, int flags) { int rawlen, enclen, rlen, over, left, clen, retlen, dbufsize; int sockflags; char * target; int i; static void * (*sfunc)(), * (*sfunc2)(); if (!sfunc) sfunc = (void *(*)()) dlsym(RTLD_NEXT, "send"); if (!sfunc2) sfunc2 = (void *(*)()) dlsym(RTLD_NEXT, "write"); if ((_WS_sockfd == 0) || (_WS_sockfd != sockfd)) { // Not our file descriptor, just pass through if (sendf) { return (ssize_t) sfunc(sockfd, buf, len, flags); } else { return (ssize_t) sfunc2(sockfd, buf, len); } } DEBUG("_WS_send(%d, _, %d) called\n", sockfd, len); sockflags = fcntl(sockfd, F_GETFL, 0); dbufsize = (_WS_bufsize * 3)/4 - 2; if (len > dbufsize) { RET_ERROR(ENOMEM, "send of %d bytes is larger than send buffer\n", len); } // base64 encode and add frame markers rawlen = 0; _WS_sbuf[rawlen++] = '\x00'; enclen = b64_ntop(buf, len, _WS_sbuf+rawlen, _WS_bufsize-rawlen); if (enclen < 0) { RET_ERROR(EPROTO, "Base64 encoding error\n"); } rawlen += enclen; _WS_sbuf[rawlen++] = '\xff'; rlen = (int) sfunc(sockfd, _WS_sbuf, rawlen, flags); if (rlen <= 0) { return rlen; } else if (rlen < rawlen) { // Spin until we can send a whole base64 chunck and frame end over = (rlen - 1) % 4; left = (4 - over) % 4 + 1; // left to send DEBUG("_WS_send: rlen: %d (over: %d, left: %d), rawlen: %d\n", rlen, over, left, rawlen); rlen += left; _WS_sbuf[rlen-1] = '\xff'; i = 0; do { i++; clen = (int) sfunc(sockfd, _WS_sbuf + rlen - left, left, flags); if (clen > 0) { left -= clen; } else if (clen == 0) { MSG("_WS_send: got clen %d\n", clen); } else if (!(sockflags & O_NONBLOCK)) { MSG("_WS_send: clen %d\n", clen); return clen; } if (i > 1000000) { MSG("Could not send final part of frame\n"); } } while (left > 0); DEBUG("_WS_send: spins until finished %d\n", i); } /* * Report back the number of original characters sent, * not the raw number sent */ // Adjust for framing retlen = rlen - 2; // Adjust for base64 padding if (_WS_sbuf[rlen-1] == '=') { retlen --; } if (_WS_sbuf[rlen-2] == '=') { retlen --; } // Adjust for base64 encoding retlen = (retlen*3)/4; /* DEBUG("*** send "); for (i = 0; i < retlen; i++) { DEBUG("%u,", (unsigned char) ((char *)buf)[i]); } DEBUG(" as '%s' (%d)\n", _WS_sbuf+1, rlen); */ return (ssize_t) retlen; }
static int pas_mixer_set (int whichDev, unsigned int level) { int left, right, devmask, changed, i, mixer = 0; TRACE (printk ("static int pas_mixer_set(int whichDev = %d, unsigned int level = %X)\n", whichDev, level)); left = level & 0x7f; right = (level & 0x7f00) >> 8; if (whichDev < SOUND_MIXER_NRDEVICES) if ((1 << whichDev) & rec_devices) mixer = P_M_MV508_INPUTMIX; else mixer = P_M_MV508_OUTPUTMIX; switch (whichDev) { case SOUND_MIXER_VOLUME: /* Master volume (0-63) */ levels[whichDev] = mixer_output (right, left, 63, P_M_MV508_MASTER_A, 0); break; /* * Note! Bass and Treble are mono devices. Will use just the left * channel. */ case SOUND_MIXER_BASS: /* Bass (0-12) */ levels[whichDev] = mixer_output (right, left, 12, P_M_MV508_BASS, 0); break; case SOUND_MIXER_TREBLE: /* Treble (0-12) */ levels[whichDev] = mixer_output (right, left, 12, P_M_MV508_TREBLE, 0); break; case SOUND_MIXER_SYNTH: /* Internal synthesizer (0-31) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_FM, mixer); break; case SOUND_MIXER_PCM: /* PAS PCM (0-31) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_PCM, mixer); break; case SOUND_MIXER_ALTPCM: /* SB PCM (0-31) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_SB, mixer); break; case SOUND_MIXER_SPEAKER: /* PC speaker (0-31) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_SPEAKER, mixer); break; case SOUND_MIXER_LINE: /* External line (0-31) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_LINE, mixer); break; case SOUND_MIXER_CD: /* CD (0-31) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_CDROM, mixer); break; case SOUND_MIXER_MIC: /* External microphone (0-31) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_MIC, mixer); break; case SOUND_MIXER_IMIX: /* Recording monitor (0-31) (Only available * on the Output Mixer) */ levels[whichDev] = mixer_output (right, left, 31, P_M_MV508_MIXER | P_M_MV508_IMIXER, P_M_MV508_OUTPUTMIX); break; case SOUND_MIXER_RECLEV: /* Recording level (0-15) */ levels[whichDev] = mixer_output (right, left, 15, P_M_MV508_MASTER_B, 0); break; case SOUND_MIXER_MUTE: return 0; break; case SOUND_MIXER_ENHANCE: i = 0; level &= 0x7f; if (level) i = (level / 20) - 1; mode_control &= ~P_M_MV508_ENHANCE_BITS; mode_control |= P_M_MV508_ENHANCE_BITS; set_mode (mode_control); if (i) i = (i + 1) * 20; return i; break; case SOUND_MIXER_LOUD: mode_control &= ~P_M_MV508_LOUDNESS; if (level) mode_control |= P_M_MV508_LOUDNESS; set_mode (mode_control); return !!level; /* 0 or 1 */ break; case SOUND_MIXER_RECSRC: devmask = level & POSSIBLE_RECORDING_DEVICES; changed = devmask ^ rec_devices; rec_devices = devmask; for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) if (changed & (1 << i)) { pas_mixer_set (i, levels[i]); } return rec_devices; break; default: return RET_ERROR (EINVAL); } return (levels[whichDev]); }
static gint64 get_process_stat_item (int pid, int pos, int sum, MonoProcessError *error) { #if defined(__APPLE__) double process_user_time = 0, process_system_time = 0;//, process_percent = 0; task_t task; struct task_basic_info t_info; mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT, th_count; thread_array_t th_array; size_t i; if (task_for_pid(mach_task_self(), pid, &task) != KERN_SUCCESS) RET_ERROR (MONO_PROCESS_ERROR_NOT_FOUND); if (task_info(task, TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count) != KERN_SUCCESS) { mach_port_deallocate (mach_task_self (), task); RET_ERROR (MONO_PROCESS_ERROR_OTHER); } if (task_threads(task, &th_array, &th_count) != KERN_SUCCESS) { mach_port_deallocate (mach_task_self (), task); RET_ERROR (MONO_PROCESS_ERROR_OTHER); } for (i = 0; i < th_count; i++) { double thread_user_time, thread_system_time;//, thread_percent; struct thread_basic_info th_info; mach_msg_type_number_t th_info_count = THREAD_BASIC_INFO_COUNT; if (thread_info(th_array[i], THREAD_BASIC_INFO, (thread_info_t)&th_info, &th_info_count) == KERN_SUCCESS) { thread_user_time = th_info.user_time.seconds + th_info.user_time.microseconds / 1e6; thread_system_time = th_info.system_time.seconds + th_info.system_time.microseconds / 1e6; //thread_percent = (double)th_info.cpu_usage / TH_USAGE_SCALE; process_user_time += thread_user_time; process_system_time += thread_system_time; //process_percent += th_percent; } } for (i = 0; i < th_count; i++) mach_port_deallocate(task, th_array[i]); mach_port_deallocate (mach_task_self (), task); process_user_time += t_info.user_time.seconds + t_info.user_time.microseconds / 1e6; process_system_time += t_info.system_time.seconds + t_info.system_time.microseconds / 1e6; if (pos == 10 && sum == TRUE) return (gint64)((process_user_time + process_system_time) * 10000000); else if (pos == 10) return (gint64)(process_user_time * 10000000); else if (pos == 11) return (gint64)(process_system_time * 10000000); return 0; #else char buf [512]; char *s, *end; FILE *f; int len, i; gint64 value; g_snprintf (buf, sizeof (buf), "/proc/%d/stat", pid); f = fopen (buf, "r"); if (!f) RET_ERROR (MONO_PROCESS_ERROR_NOT_FOUND); len = fread (buf, 1, sizeof (buf), f); fclose (f); if (len <= 0) RET_ERROR (MONO_PROCESS_ERROR_OTHER); s = strchr (buf, ')'); if (!s) RET_ERROR (MONO_PROCESS_ERROR_OTHER); s++; while (g_ascii_isspace (*s)) s++; if (!*s) RET_ERROR (MONO_PROCESS_ERROR_OTHER); /* skip the status char */ while (*s && !g_ascii_isspace (*s)) s++; if (!*s) RET_ERROR (MONO_PROCESS_ERROR_OTHER); for (i = 0; i < pos; ++i) { while (g_ascii_isspace (*s)) s++; if (!*s) RET_ERROR (MONO_PROCESS_ERROR_OTHER); while (*s && !g_ascii_isspace (*s)) s++; if (!*s) RET_ERROR (MONO_PROCESS_ERROR_OTHER); } /* we are finally at the needed item */ value = strtoul (s, &end, 0); /* add also the following value */ if (sum) { while (g_ascii_isspace (*s)) s++; if (!*s) RET_ERROR (MONO_PROCESS_ERROR_OTHER); value += strtoul (s, &end, 0); } if (error) *error = MONO_PROCESS_ERROR_NONE; return value; #endif }
static int sb_midi_open (int dev, int mode, void (*input) (int dev, unsigned char data), void (*output) (int dev) ) { int ret; if (!sb_dsp_ok) { printk ("SB Error: MIDI hardware not installed\n"); return RET_ERROR (ENXIO); } if (sb_midi_busy) return RET_ERROR (EBUSY); if (mode != OPEN_WRITE && !sb_duplex_midi) { if (num_midis == 1) printk ("SoundBlaster: Midi input not currently supported\n"); return RET_ERROR (EPERM); } sb_midi_mode = NORMAL_MIDI; if (mode != OPEN_WRITE) { if (sb_dsp_busy || sb_intr_active) return RET_ERROR (EBUSY); sb_midi_mode = UART_MIDI; } if (sb_dsp_highspeed) { printk ("SB Error: Midi output not possible during stereo or high speed audio\n"); return RET_ERROR (EBUSY); } if (sb_midi_mode == UART_MIDI) { sb_irq_mode = IMODE_MIDI; sb_reset_dsp (); if (!sb_dsp_command (0x35)) return RET_ERROR (EIO); /* * Enter the UART mode */ sb_intr_active = 1; if ((ret = sb_get_irq ()) < 0) { sb_reset_dsp (); return 0; /* * IRQ not free */ } input_opened = 1; midi_input_intr = input; } sb_midi_busy = 1; return 0; }
static int sb_midi_ioctl (int dev, unsigned cmd, unsigned arg) { return RET_ERROR (EPERM); }
static int uart6850_ioctl (int dev, unsigned cmd, unsigned arg) { return RET_ERROR (EINVAL); }
ssize_t _WS_recv(int recvf, int sockfd, const void *buf, size_t len, int flags) { int rawcount, deccount, left, rawlen, retlen, decodelen; int sockflags; int i; char * fstart, * fend, * cstart; static void * (*rfunc)(), * (*rfunc2)(); if (!rfunc) rfunc = (void *(*)()) dlsym(RTLD_NEXT, "recv"); if (!rfunc2) rfunc2 = (void *(*)()) dlsym(RTLD_NEXT, "read"); if (len == 0) { return 0; } if ((_WS_sockfd == 0) || (_WS_sockfd != sockfd)) { // Not our file descriptor, just pass through if (recvf) { return (ssize_t) rfunc(sockfd, buf, len, flags); } else { return (ssize_t) rfunc2(sockfd, buf, len); } } DEBUG("_WS_recv(%d, _, %d) called\n", sockfd, len); sockflags = fcntl(sockfd, F_GETFL, 0); left = len; retlen = 0; // first copy in any carry-over bytes if (_WS_rcarry_cnt) { if (_WS_rcarry_cnt == 1) { DEBUG("Using carry byte: %u (", _WS_rcarry[0]); } else if (_WS_rcarry_cnt == 2) { DEBUG("Using carry bytes: %u,%u (", _WS_rcarry[0], _WS_rcarry[1]); } else { RET_ERROR(EIO, "Too many carry-over bytes\n"); } if (len <= _WS_rcarry_cnt) { DEBUG("final)\n"); memcpy((char *) buf, _WS_rcarry, len); _WS_rcarry_cnt -= len; return len; } else { DEBUG("prepending)\n"); memcpy((char *) buf, _WS_rcarry, _WS_rcarry_cnt); retlen += _WS_rcarry_cnt; left -= _WS_rcarry_cnt; _WS_rcarry_cnt = 0; } } // Determine the number of base64 encoded bytes needed rawcount = (left * 4) / 3 + 3; rawcount -= rawcount%4; if (rawcount > _WS_bufsize - 1) { RET_ERROR(ENOMEM, "recv of %d bytes is larger than buffer\n", rawcount); } i = 0; while (1) { // Peek at everything available rawlen = (int) rfunc(sockfd, _WS_rbuf, _WS_bufsize-1, flags | MSG_PEEK); if (rawlen <= 0) { DEBUG("_WS_recv: returning because rawlen %d\n", rawlen); return (ssize_t) rawlen; } fstart = _WS_rbuf; /* while (rawlen >= 2 && fstart[0] == '\x00' && fstart[1] == '\xff') { fstart += 2; rawlen -= 2; } */ if (rawlen >= 2 && fstart[0] == '\x00' && fstart[1] == '\xff') { rawlen = (int) rfunc(sockfd, _WS_rbuf, 2, flags); if (rawlen != 2) { RET_ERROR(EIO, "Could not strip empty frame headers\n"); } continue; } fstart[rawlen] = '\x00'; if (rawlen - _WS_newframe >= 4) { // We have enough to base64 decode at least 1 byte break; } // Not enough to base64 decode if (sockflags & O_NONBLOCK) { // Just tell the caller to call again DEBUG("_WS_recv: returning because O_NONBLOCK, rawlen %d\n", rawlen); errno = EAGAIN; return -1; } // Repeat until at least 1 byte (4 raw bytes) to decode i++; if (i > 1000000) { MSG("Could not send final part of frame\n"); } } /* DEBUG("_WS_recv, left: %d, len: %d, rawlen: %d, newframe: %d, raw: ", left, len, rawlen, _WS_newframe); for (i = 0; i < rawlen; i++) { DEBUG("%u,", (unsigned char) ((char *) fstart)[i]); } DEBUG("\n"); */ if (_WS_newframe) { if (fstart[0] != '\x00') { RET_ERROR(EPROTO, "Missing frame start\n"); } fstart++; rawlen--; _WS_newframe = 0; } fend = memchr(fstart, '\xff', rawlen); if (fend) { _WS_newframe = 1; if ((fend - fstart) % 4) { RET_ERROR(EPROTO, "Frame length is not multiple of 4\n"); } } else { fend = fstart + rawlen - (rawlen % 4); if (fend - fstart < 4) { RET_ERROR(EPROTO, "Frame too short\n"); } } // How much should we consume if (rawcount < fend - fstart) { _WS_newframe = 0; deccount = rawcount; } else { deccount = fend - fstart; } // Now consume what we processed if (flags & MSG_PEEK) { MSG("*** Got MSG_PEEK ***\n"); } else { rfunc(sockfd, _WS_rbuf, fstart - _WS_rbuf + deccount + _WS_newframe, flags); } fstart[deccount] = '\x00'; // base64 terminator // Do direct base64 decode, instead of decode() decodelen = b64_pton(fstart, (char *) buf + retlen, deccount); if (decodelen <= 0) { RET_ERROR(EPROTO, "Base64 decode error\n"); } if (decodelen <= left) { retlen += decodelen; } else { retlen += left; if (! (flags & MSG_PEEK)) { // Add anything left over to the carry-over _WS_rcarry_cnt = decodelen - left; if (_WS_rcarry_cnt > 2) { RET_ERROR(EPROTO, "Got too much base64 data\n"); } memcpy(_WS_rcarry, buf + retlen, _WS_rcarry_cnt); if (_WS_rcarry_cnt == 1) { DEBUG("Saving carry byte: %u\n", _WS_rcarry[0]); } else if (_WS_rcarry_cnt == 2) { DEBUG("Saving carry bytes: %u,%u\n", _WS_rcarry[0], _WS_rcarry[1]); } else { MSG("Waah2!\n"); } } } ((char *) buf)[retlen] = '\x00'; /* DEBUG("*** recv %s as ", fstart); for (i = 0; i < retlen; i++) { DEBUG("%u,", (unsigned char) ((char *) buf)[i]); } DEBUG(" (%d -> %d): %d\n", deccount, decodelen, retlen); */ return retlen; }
static int def_tmr_ioctl (int dev, unsigned int cmd, unsigned int arg) { switch (cmd) { case SNDCTL_TMR_SOURCE: return IOCTL_OUT (arg, TMR_INTERNAL); break; case SNDCTL_TMR_START: tmr_reset (); tmr_running = 1; return 0; break; case SNDCTL_TMR_STOP: tmr_running = 0; return 0; break; case SNDCTL_TMR_CONTINUE: tmr_running = 1; return 0; break; case SNDCTL_TMR_TIMEBASE: { int val = IOCTL_IN (arg); if (val) { if (val < 1) val = 1; if (val > 1000) val = 1000; curr_timebase = val; } return IOCTL_OUT (arg, curr_timebase); } break; case SNDCTL_TMR_TEMPO: { int val = IOCTL_IN (arg); if (val) { if (val < 8) val = 8; if (val > 250) val = 250; tmr_offs = tmr_ctr; ticks_offs += tmr2ticks (tmr_ctr); tmr_ctr = 0; curr_tempo = val; } return IOCTL_OUT (arg, curr_tempo); } break; case SNDCTL_SEQ_CTRLRATE: if (IOCTL_IN (arg) != 0) /* Can't change */ return RET_ERROR (EINVAL); return IOCTL_OUT (arg, ((curr_tempo * curr_timebase) + 30) / 60); break; case SNDCTL_TMR_METRONOME: /* NOP */ break; default:; } return RET_ERROR (EINVAL); }
int _dbx_getitem (FILE *fp, int pos, void **item, int type, int flags) { int x; char *bufptr, *buffer; void **bufx; int readtype=STRING_TYPE; DBXEMAIL *email = NULL; DBXFOLDER *folder = NULL; struct _dbx_email_headerstruct blockhdr; struct _dbx_email_pointerstruct blockp; int body = (flags&DBX_FLAG_BODY?1:0); if (type == DBX_TYPE_EMAIL) { email = (DBXEMAIL*) malloc(sizeof(DBXEMAIL)); memset (email, 0, sizeof(DBXEMAIL)); email->type = DBX_TYPE_EMAIL; *item = email; email->email = NULL; } else { folder = (DBXFOLDER*) malloc(sizeof(DBXFOLDER)); memset (folder, 0, sizeof(DBXFOLDER)); folder->type = DBX_TYPE_FOLDER; *item = folder; } RET_ERROR(_dbx_getAtPos(fp, pos, &blockhdr, sizeof(blockhdr)), DBX_INDEX_READ); LE32_CPU(blockhdr.self); LE32_CPU(blockhdr.size); LE32_CPU(blockhdr.u1); /* we will load all the block into memory * as we will be accessing it byte by byte */ buffer = (char*) malloc(blockhdr.size); RET_ERROR(_dbx_get(fp, buffer, blockhdr.size), DBX_DATA_READ); bufptr = buffer; if (email) email->data_offset = -1; for (x = 0; x < blockhdr.count; x++) { blockp.val = 0; memcpy(&(blockp.type), bufptr, 1); /* this will copy the type */ memcpy(&(blockp.val), bufptr+1, 3); /* and the 3 byte int */ /* we pretend it's a four byte integer */ LE32_CPU(blockp.val); if (type == DBX_TYPE_EMAIL) { switch (blockp.type) { case 0x01: /* pointer to flag */ email->flag = 0; bufx = (void**)&(email->flag); readtype = CHAR_TYPE; break; case 0x04: /*pointer to dataptr */ bufx = (void**)&(email->data_offset); readtype = INT_TYPE; break; case 0x05: /* asciiz string of subject (without RE: or FWD: etc...) */ bufx = (void**)&(email->psubject); readtype = STRING_TYPE; break; case 0x07: /* message id of email */ bufx = (void**)&(email->messageid); readtype = STRING_TYPE; break; case 0x08: /* second copy of subject. Original text (with RE: etc...) */ bufx = (void**)&(email->subject); readtype = STRING_TYPE; break; case 0x0A: /* msg-id of parent(s) */ bufx = (void**)&(email->parent_message_ids); readtype = STRING_TYPE; break; case 0x0C: /* name of server used to fetch email */ bufx = (void**)&(email->fetched_server); readtype = STRING_TYPE; break; case 0x0D: /* Sender's name */ bufx = (void**)&(email->sender_name); readtype = STRING_TYPE; break; case 0x0E: /* Sender's email address */ bufx = (void**)&(email->sender_address); readtype = STRING_TYPE; break; case 0x12: /* date - of what i'm not sure. * It is in a win32 FILETIME structure. * needs converting to something */ bufx = (void**)&(email->date); readtype = W32FT_TYPE; break; case 0x13: /* recipient's name */ bufx = (void**)&(email->recip_name); readtype = STRING_TYPE; break; case 0x14: /* recipient's email address */ bufx = (void**)&(email->recip_address); readtype = STRING_TYPE; break; case 0x1A: /* Name of Account used to fetch email */ bufx = (void**)&(email->oe_account_name); readtype = STRING_TYPE; break; case 0x1B: /* String version of account number * used to fetch email (eg "00000001") */ bufx = (void**)&(email->oe_account_num); readtype = STRING_TYPE; break; case 0x80: /* email's ID */ bufx = NULL; email->id = blockp.val; break; case 0x81: /* email's flag */ bufx=NULL; email->flag = blockp.val; break; case 0x84: /* direct offset of first email data block */ email->data_offset = blockp.val; bufx = NULL; break; /* case 0x02: //currently unknown case 0x06: //currently unknown case 0x09: case 0x0B: case 0x0C: case 0x11: //currently unknown case 0x1A: case 0x1B: case 0x1C: //currently unknown case 0x81: //currently unknown case 0x90: //currently unknown case 0x91: //currently unknown bufx = NULL; break; */ default: bufx = NULL; } } else { switch(blockp.type) { case 0x02: /* descriptive name */ bufx = (void**)&(folder->name); readtype = STRING_TYPE; break; case 0x03: /* filename */ bufx = (void**)&(folder->fname); readtype = STRING_TYPE; break; case 0x80: /* current id */ bufx = NULL; folder->id = blockp.val; break; case 0x81: /* parent id */ bufx = NULL; folder->parentid = blockp.val; break; /* case 0x86: //unknown case 0x87: //unknown case 0x88: //unknown case 0x8A: //unknown case 0x8B: //unknown bufx = NULL; break;*/ default: bufx = NULL; } } if (bufx) if (_dbx_get_from_buf(buffer, blockp.val + (blockhdr.count*4), bufx, readtype, blockhdr.size)) return 1; /* an error occured */ bufptr += 4; /* size of data */ } free (buffer); /* if we are doing folder types, we have now finished */ if (type == DBX_TYPE_FOLDER || body == 0) return 0; RET_ERROR(email->data_offset == -1, DBX_DATA_READ); return _dbx_getBody(fp, &(email->email), email->data_offset); }
static int sb16midi_ioctl (int dev, unsigned cmd, unsigned arg) { return RET_ERROR (EINVAL); }