int dept_get_next(void far *receive_buffer, unsigned recvLen, void far *path, unsigned pathlen ) { int retv; char code[5]; DEPT_RECORD far *dept; if ( recvLen != sizeof(DEPT_RECORD)) return (INV_SEND_PARAM ); dept = receive_buffer; if ( (retv = dept_open_file (path,pathlen) ) != NORMAL ) return retv; /* check first if btrieve is in valid positioning */ if ( position == -1L) { /* invalid positioning get first record */ BTRV (B_GETFIRST, filePosBlock, (char *)dept, &bufLen, code, 0 ); } else { _bcopy(dept,(char *)&position,sizeof(position)); retv = BTRV(B_DIRECT, filePosBlock, (char *) dept, &bufLen, code, 0 ); } /* issue a btrieve seek (GET NEXT) request... */ retv = BTRV (B_GETNEXT, filePosBlock, (char *) dept, &bufLen, code, 0 ); while ( retv == NORMAL && dept->deleted == '*' ) { retv = BTRV (B_GETNEXT, filePosBlock, (char *) dept, &bufLen, code, 0 ); } if (retv != NORMAL) { retv = BTRIEVE_ENDOFFILE; } else { retv = BTRV (B_GETPOSI, filePosBlock, (char *) &position, &posLen, code, 0 ); } dept_close_file(); return (retv); }
int dept_search_and_get(void far *receive_buffer, unsigned recvLen, void far *data, unsigned sendLen, void far *path, unsigned pathlen ) { int retv; unsigned char code[5]; DEPT_RECORD far *dept; if ( recvLen != sizeof(DEPT_RECORD) ) return (INV_RECV_PARAM ); if ( sendLen != sizeof(dept->dp_code) ) return (INV_SEND_PARAM ); dept = receive_buffer; _bset (code, 0x0, sizeof(code)); /* get the DEPT code to search... */ /* data is in ASCII */ _bcopy(code,data,sizeof(dept->dp_code)); if ((retv = dept_open_file(path,pathlen)) != NORMAL ) return retv; /* issue a btrieve seek (GET EQUAL) request... */ retv = BTRV (B_GETEQ, filePosBlock, (char *)dept, &bufLen, code, 0 ); if ( retv == NORMAL ) { if ( dept->deleted == '*' ) retv = CODE_NOT_FOUND; } if ( retv != NORMAL ) retv = CODE_NOT_FOUND; else { posLen = sizeof(position); BTRV (B_GETPOSI, filePosBlock, (char *) &position, &posLen, code, 0 ); } dept_close_file(); return (retv); }
__private_extern__ int ml_copy_phys(addr64_t src64, addr64_t dst64, vm_size_t bytes) { void *src, *dst; int err = 0; mp_disable_preemption(); #if NCOPY_WINDOWS > 0 mapwindow_t *src_map, *dst_map; /* We rely on MTRRs here */ src_map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | ((pmap_paddr_t)src64 & PG_FRAME) | INTEL_PTE_REF)); dst_map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | INTEL_PTE_RW | ((pmap_paddr_t)dst64 & PG_FRAME) | INTEL_PTE_REF | INTEL_PTE_MOD)); src = (void *) ((uintptr_t)src_map->prv_CADDR | ((uint32_t)src64 & INTEL_OFFMASK)); dst = (void *) ((uintptr_t)dst_map->prv_CADDR | ((uint32_t)dst64 & INTEL_OFFMASK)); #elif defined(__x86_64__) addr64_t debug_pa = 0; /* If either destination or source are outside the * physical map, establish a physical window onto the target frame. */ assert(physmap_enclosed(src64) || physmap_enclosed(dst64)); if (physmap_enclosed(src64) == FALSE) { src = (void *)(debugger_window_kva | (src64 & INTEL_OFFMASK)); dst = PHYSMAP_PTOV(dst64); debug_pa = src64 & PG_FRAME; } else if (physmap_enclosed(dst64) == FALSE) { src = PHYSMAP_PTOV(src64); dst = (void *)(debugger_window_kva | (dst64 & INTEL_OFFMASK)); debug_pa = dst64 & PG_FRAME; } else { src = PHYSMAP_PTOV(src64); dst = PHYSMAP_PTOV(dst64); } /* DRK: debugger only routine, we don't bother checking for an * identical mapping. */ if (debug_pa) { if (debugger_window_kva == 0) panic("%s: invoked in non-debug mode", __FUNCTION__); /* Establish a cache-inhibited physical window; some platforms * may not cover arbitrary ranges with MTRRs */ pmap_store_pte(debugger_ptep, debug_pa | INTEL_PTE_NCACHE | INTEL_PTE_RW | INTEL_PTE_REF| INTEL_PTE_MOD | INTEL_PTE_VALID); flush_tlb_raw(); #if DEBUG kprintf("Remapping debugger physical window at %p to 0x%llx\n", (void *)debugger_window_kva, debug_pa); #endif } #endif /* ensure we stay within a page */ if (((((uint32_t)src64 & (I386_PGBYTES-1)) + bytes) > I386_PGBYTES) || ((((uint32_t)dst64 & (I386_PGBYTES-1)) + bytes) > I386_PGBYTES) ) { panic("ml_copy_phys spans pages, src: 0x%llx, dst: 0x%llx", src64, dst64); } /* * For device register access from the debugger, * 2-byte/16-bit, 4-byte/32-bit and 8-byte/64-bit copies are handled * by assembly routines ensuring the required access widths. * 1-byte and other copies are handled by the regular _bcopy. */ switch (bytes) { case 2: err = _bcopy2(src, dst); break; case 4: err = _bcopy4(src, dst); break; case 8: err = _bcopy8(src, dst); break; case 1: default: err = _bcopy(src, dst, bytes); break; } #if NCOPY_WINDOWS > 0 pmap_put_mapwindow(src_map); pmap_put_mapwindow(dst_map); #endif mp_enable_preemption(); return err; }
// -------------------------------------------------------------------------- // CLIPPER Memo2aStr() // ( cMemo, nMaxWidth ) -> acItems { LPBYTE lpMemo; WORD wLines; WORD wWidth; LONG lMaxWidth; LPBYTE lpTmp; char cLine[ MAX_LINE_WIDTH ]; WORD wLastSpace; // Obtenemos el primer par metro lpMemo = _parc( 1 ); if( lpMemo ) { // Obtenemos el valor m ximo de la cadena lMaxWidth = _parni( 2 ); // por si no se pasa el segundo parametro if( !lMaxWidth ) { lMaxWidth = MAX_LINE_WIDTH; } // Contamos cuantas l¡neas hay, para crear el array wLines = 0; wWidth = 0; lpTmp = lpMemo; wLastSpace = 0; while( * lpTmp ) { if( * lpTmp == ' ' ) { wLastSpace = wWidth; } if( ( * lpTmp++ == CR && * lpTmp == LF ) || // CRLF ( ++wWidth >= lMaxWidth ) ) { if( * lpTmp == LF ) { // Para que no lea el LF o el CR en la siguiente linea lpTmp++; } else if( wLastSpace > 0 ) { lpTmp -= ( wWidth - wLastSpace ); } wWidth = 0; wLastSpace = 0; wLines++; } } // Si ha quedado algo en la £ltima l¡nea if( wWidth ) { wLines++; } // Creamos el array _ARRAYNEW( wLines ); _bcopy( ( LPBYTE ) ++_tos, ( LPBYTE ) _eval, sizeof( CLIPVAR ) ); // A¤adimos cada l¡nea en el array wLines = 0; wWidth = 0; lpTmp = lpMemo; wLastSpace = 0; while( * lpTmp ) { if( ( cLine[ wWidth ] = * lpTmp ) == ' ' ) { wLastSpace = wWidth; } if( ( * lpTmp++ == CR && * lpTmp == LF ) || ( ++wWidth >= lMaxWidth ) ) { if( * lpTmp == LF ) { // Para que no lea el LF en la siguiente linea lpTmp++; } else if( wLastSpace > 0 ) // Por si no tiene espacios { // Partimos la l¡nea pero en el £ltimo espacio lpTmp -= ( wWidth - wLastSpace ); wWidth = wLastSpace; } _cAtPutStr( _tos, wLines + 1, cLine, wWidth ); wWidth = 0; wLastSpace = 0; wLines++; } } // Si ha quedado algo en la £ltima l¡nea if( wWidth ) { _cAtPutStr( _tos, wLines + 1, cLine, wWidth ); } // Ponemos el array en eval _bcopy( ( LPBYTE ) _eval, ( LPBYTE ) _tos--, sizeof( CLIPVAR ) ); } // Si el array est vacio se inserta una linea en blanco if( !_VARRAYLEN( _eval ) ) { _ARRAYNEW( 1 ); _cAtPutStr( _eval, 1, cLine, 0 ); } }
int dpcount_search_and_put(void far *data, unsigned datalen, void far *path, unsigned pathlen, int par) { DP_COUNT_IN far * putBuf; int retv = BTRIEVE_OPEN_ERR; char code[5]; if ( datalen != sizeof(DP_COUNT_IN) ) /* amount + quantity and code */ return (INV_SEND_PARAM); retv = dept_open_file (path,pathlen); if ( retv != NORMAL ) return retv; putBuf = data; _bcopy(code,data,sizeof(putBuf->dept_code)); retv = BTRV (B_GETEQ, filePosBlock, (char *) &deptdata, &bufLen, code, 0); if ( retv == NORMAL ) { if ( par == 1 ) { deptdata.quantity.n = 0; deptdata.amount.n = 0; deptdata.discount.n = 0; }else if ( par == 2 ) { deptdata.ptd_qty.n = 0; deptdata.ptd_amt.n = 0; deptdata.ptd_dsc.n = 0; }else { deptdata.quantity.n += putBuf->quantity.n; deptdata.amount.n += putBuf->amount.n; deptdata.discount.n += putBuf->discount.n; deptdata.ptd_qty.n += putBuf->quantity.n; deptdata.ptd_amt.n += putBuf->amount.n; deptdata.ptd_dsc.n += putBuf->discount.n; } retv = BTRV (B_UPDATE, filePosBlock, (char *) &deptdata, &bufLen, code, 0); if ( retv != NORMAL ) retv = BTRIEVE_UPDATE_ERR; }else if ( retv == 4 ) { _bset(&deptdata,0x0,sizeof(deptdata)); _bcopy(deptdata.dp_code,putBuf->dept_code,sizeof(putBuf->dept_code)); _bcopy(&deptdata.dp_desc,"AUTO ADD DEPARTMENT.",DEP_DESC_LEN); deptdata.quantity.n = putBuf->quantity.n; deptdata.amount.n = putBuf->amount.n; deptdata.discount.n = putBuf->discount.n; deptdata.ptd_qty.n = putBuf->quantity.n; deptdata.ptd_amt.n = putBuf->amount.n; deptdata.ptd_dsc.n = putBuf->discount.n; retv = BTRV (B_INSERT, filePosBlock, (char *) &deptdata, &bufLen, code, 0); if ( retv != NORMAL ) retv = CODE_NOT_FOUND; } dept_close_file(); return(retv); }
int dpcount_search_and_get(void far *data, unsigned datalen, void far *receive_buffer, unsigned recvlen, void far *path, unsigned pathlen, int parameter ) { char code[5]; DP_COUNT_OUT far *getBuf; int retv; if ( recvlen != sizeof(DP_COUNT_OUT) ) return (INV_RECV_PARAM); if ( datalen != sizeof(getBuf->dept_code) ) return (INV_SEND_PARAM); retv = dept_open_file(path,pathlen); if ( retv != NORMAL ) return retv; getBuf = receive_buffer; _bset( code, 0x0, sizeof(code) ); _bcopy(code,data,datalen); if ( memcmp(code,"++++",sizeof(getBuf->dept_code)) == 0 ) { if ( position == -1L) retv = BTRV (B_GETFIRST, filePosBlock, (char *) &deptdata, &bufLen, code, 0 ); else { _bcopy(&deptdata,(char *)&position, sizeof(position) ); retv = BTRV(B_DIRECT, filePosBlock, (char *) &deptdata, &bufLen, code, 0); } } else retv = BTRV (B_GETGE, filePosBlock, (char *) &deptdata, &bufLen, code, 0 ); if ( retv == NORMAL) { /* save the data to the return block */ _bcopy(getBuf->dept_code,&deptdata.dp_code,DEP_CODE_LEN); _bcopy(getBuf->dept_desc,&deptdata.dp_desc,DEP_DESC_LEN); getBuf->quantity.n = deptdata.quantity.n; getBuf->amount.n = deptdata.amount.n; getBuf->discount.n = deptdata.discount.n; getBuf->ptd_qty.n = deptdata.ptd_qty.n; getBuf->ptd_amt.n = deptdata.ptd_amt.n; getBuf->ptd_dsc.n = deptdata.ptd_dsc.n; } /* now get the next record possible */ retv = BTRV (B_GETNEXT, filePosBlock, (char *) &deptdata, &bufLen, code, 0); if (parameter) /* zero skip */ { while (retv == NORMAL) { if (( deptdata.quantity.n + deptdata.amount.n + deptdata.discount.n ) != 0) break; retv = BTRV (B_GETNEXT, filePosBlock, (char *) &deptdata , &bufLen, code, 0); } } if (retv == NORMAL) retv = BTRV (B_GETPOSI, filePosBlock, (char *) &position, &posLen, code, 0 ); dept_close_file(); return(retv); }
static int copyio(int copy_type, user_addr_t user_addr, char *kernel_addr, vm_size_t nbytes, vm_size_t *lencopied, int use_kernel_map) { thread_t thread; pmap_t pmap; vm_size_t bytes_copied; int error = 0; boolean_t istate = FALSE; boolean_t recursive_CopyIOActive; #if KDEBUG int debug_type = 0xeff70010; debug_type += (copy_type << 2); #endif thread = current_thread(); KERNEL_DEBUG(debug_type | DBG_FUNC_START, (unsigned)(user_addr >> 32), (unsigned)user_addr, nbytes, thread->machine.copyio_state, 0); if (nbytes == 0) goto out; pmap = thread->map->pmap; if ((copy_type != COPYINPHYS) && (copy_type != COPYOUTPHYS) && ((vm_offset_t)kernel_addr < VM_MIN_KERNEL_AND_KEXT_ADDRESS)) { panic("Invalid copy parameter, copy type: %d, kernel address: %p", copy_type, kernel_addr); } /* Sanity and security check for addresses to/from a user */ if (((pmap != kernel_pmap) && (use_kernel_map == 0)) && ((nbytes && (user_addr+nbytes <= user_addr)) || ((user_addr + nbytes) > vm_map_max(thread->map)))) { error = EFAULT; goto out; } /* * If the no_shared_cr3 boot-arg is set (true), the kernel runs on * its own pmap and cr3 rather than the user's -- so that wild accesses * from kernel or kexts can be trapped. So, during copyin and copyout, * we need to switch back to the user's map/cr3. The thread is flagged * "CopyIOActive" at this time so that if the thread is pre-empted, * we will later restore the correct cr3. */ recursive_CopyIOActive = thread->machine.specFlags & CopyIOActive; thread->machine.specFlags |= CopyIOActive; user_access_enable(); if (no_shared_cr3) { istate = ml_set_interrupts_enabled(FALSE); if (get_cr3_base() != pmap->pm_cr3) set_cr3_raw(pmap->pm_cr3); } /* * Ensure that we're running on the target thread's cr3. */ if ((pmap != kernel_pmap) && !use_kernel_map && (get_cr3_base() != pmap->pm_cr3)) { panic("copyio(%d,%p,%p,%ld,%p,%d) cr3 is %p expects %p", copy_type, (void *)user_addr, kernel_addr, nbytes, lencopied, use_kernel_map, (void *) get_cr3_raw(), (void *) pmap->pm_cr3); } if (no_shared_cr3) (void) ml_set_interrupts_enabled(istate); KERNEL_DEBUG(0xeff70044 | DBG_FUNC_NONE, (unsigned)user_addr, (unsigned)kernel_addr, nbytes, 0, 0); switch (copy_type) { case COPYIN: error = _bcopy((const void *) user_addr, kernel_addr, nbytes); break; case COPYOUT: error = _bcopy(kernel_addr, (void *) user_addr, nbytes); break; case COPYINPHYS: error = _bcopy((const void *) user_addr, PHYSMAP_PTOV(kernel_addr), nbytes); break; case COPYOUTPHYS: error = _bcopy((const void *) PHYSMAP_PTOV(kernel_addr), (void *) user_addr, nbytes); break; case COPYINSTR: error = _bcopystr((const void *) user_addr, kernel_addr, (int) nbytes, &bytes_copied); /* * lencopied should be updated on success * or ENAMETOOLONG... but not EFAULT */ if (error != EFAULT) *lencopied = bytes_copied; if (error) { #if KDEBUG nbytes = *lencopied; #endif break; } if (*(kernel_addr + bytes_copied - 1) == 0) { /* * we found a NULL terminator... we're done */ #if KDEBUG nbytes = *lencopied; #endif break; } else { /* * no more room in the buffer and we haven't * yet come across a NULL terminator */ #if KDEBUG nbytes = *lencopied; #endif error = ENAMETOOLONG; break; } break; } user_access_disable(); if (!recursive_CopyIOActive) { thread->machine.specFlags &= ~CopyIOActive; } if (no_shared_cr3) { istate = ml_set_interrupts_enabled(FALSE); if (get_cr3_raw() != kernel_pmap->pm_cr3) set_cr3_raw(kernel_pmap->pm_cr3); (void) ml_set_interrupts_enabled(istate); } out: KERNEL_DEBUG(debug_type | DBG_FUNC_END, (unsigned)user_addr, (unsigned)kernel_addr, (unsigned)nbytes, error, 0); return (error); }
CLIPPER a_rjs_prnt(void) { static unsigned char printer_type; /* bit assignments for print station */ static unsigned int text_len; /* data length */ static char *data; /* data pointer */ static int line_feed; /* line feed flag */ static int next_buff_in; /* next buffer input index */ /* validate parameters */ if (PCOUNT == 5 && ISNUM(RCPT) && ISNUM(JRNAL) && ISNUM(SLIP) && ISCHAR(TXT) && ISNUM(LINE_FLAG)) { if (!async_printing) /* not in asynchronous printing mode */ { _retni(INVP); return; } data = _parc(TXT); /* get data to be printed */ /* check data length */ text_len = _parclen(TXT); if (NOT_IN_RANGE(text_len, 1, 80)) { _retni(INVP); return; } /* determine printer station */ printer_type = 0x00; if (_parni(JRNAL)) printer_type |= 0x01; /* print on journal */ if (_parni(RCPT)) printer_type |= 0x02; /* print on receipt */ if (_parni(SLIP)) printer_type |= 0x04; /* print on slip/document */ if (printer_type == 0x04) /* slip validation not supported */ { _retni(INVP); return; } if (printer_type == 0) /* no printer assignment */ printer_type = 0x02; /* default to receipt */ /* only one printer station at a time */ if (((printer_type & 0x02) && (printer_type & 0x04)) || ((printer_type & 0x01) && (printer_type & 0x04))) { _retni(INVP); return; } /* get line feed flag */ line_feed = _parni(LINE_FLAG); /* verify initial status */ if (chk_init_flag(POS_PRINTER) == 0) { _retni(DEV_NOT_EXIST); /* device not yet initialized */ return; } /* buffer the print job */ next_buff_in = buff_in1; /* get current buffer input index */ ++next_buff_in; if (next_buff_in == PRINT_JOBS) /* past the end of buffer ? */ next_buff_in = 0; /* reset to start of buffer */ if (next_buff_in == buff_out1) /* is the buffer full ? */ { _retni(MEM_OUT); return; } prnt_data1[buff_in1].func_type = 0; /* A_RJS_PRNT() */ prnt_data1[buff_in1].printer_type = printer_type; prnt_data1[buff_in1].line_flag = line_feed; prnt_data1[buff_in1].text_len = text_len; _bcopy(prnt_data1[buff_in1].txt_msg, data,text_len); buff_in1 = next_buff_in; /* update buffer input index */ buffer_empty = 0; /* buffer is not empty */ _retni(NORMAL); } else _retni(INVP); }