Changeset 407 for trunk/kernel/syscalls/sys_write.c
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_write.c
r315 r407 32 32 #include <process.h> 33 33 34 /* TODO: user page(s) need to be locked[AG] */34 /* TODO: concurrent user page(s) unmap need to be handled [AG] */ 35 35 36 36 ////////////////////////////////// 37 37 int sys_write( uint32_t file_id, 38 void * buf,38 void * vaddr, 39 39 uint32_t count ) 40 40 { 41 41 error_t error; 42 paddr_t paddr; // required for user space checking42 paddr_t paddr; // unused, but required for user space checking 43 43 xptr_t file_xp; // remote file extended pointer 44 uint32_t nbytes; // number of bytes actually written 45 46 uint32_t tm_start; 47 uint32_t tm_end; 48 49 tm_start = hal_get_cycles(); 44 50 45 51 thread_t * this = CURRENT_THREAD; … … 55 61 56 62 // check user buffer in user space 57 error = vmm_v2p_translate( false , buf, &paddr );63 error = vmm_v2p_translate( false , vaddr , &paddr ); 58 64 59 65 if ( error ) 60 66 { 61 67 printk("\n[ERROR] in %s : user buffer unmapped = %x\n", 62 __FUNCTION__ , (intptr_t)buf);68 __FUNCTION__ , (intptr_t)vaddr ); 63 69 this->errno = EINVAL; 64 70 return -1; … … 70 76 if( file_xp == XPTR_NULL ) 71 77 { 72 printk("\n[ERROR] in %s : undefined file descriptor index = %d \n",73 __FUNCTION__ , file_id );78 printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n", 79 __FUNCTION__ , file_id , process->pid ); 74 80 this->errno = EBADFD; 75 81 return -1; … … 84 90 if( (attr & FD_ATTR_WRITE_ENABLE) == 0 ) 85 91 { 86 printk("\n[ERROR] in %s : file %d not writable \n",87 __FUNCTION__ , file_id );92 printk("\n[ERROR] in %s : file %d not writable in process %x\n", 93 __FUNCTION__ , file_id , process->pid ); 88 94 this->errno = EBADFD; 89 95 return -1; 90 96 } 91 97 92 // transfer count bytes directly from user buffer to mapper 93 error = vfs_user_move( false, // from buffer 94 file_xp, 95 buf , 96 count ); 98 // get file type 99 vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) ); 97 100 98 if( error ) 101 // action depend on file type 102 if( type == INODE_TYPE_FILE ) // transfer count bytes to file mapper 99 103 { 100 printk("\n[ERROR] in %s cannot read data from file %d\n", 101 __FUNCTION__ , file_id ); 104 nbytes = vfs_user_move( false, // from buffer to mapper 105 file_xp, 106 vaddr, 107 count ); 108 } 109 else if( type == INODE_TYPE_DEV ) // transfer count bytes to device 110 { 111 nbytes = devfs_user_move( false, // from buffer to device 112 file_xp, 113 vaddr, 114 count ); 115 } 116 else 117 { 118 nbytes = 0; 119 panic("file type %d non supported", type ); 120 } 121 122 if( nbytes != count ) 123 { 124 printk("\n[ERROR] in %s cannot write data to file %d in process %x\n", 125 __FUNCTION__ , file_id , process->pid ); 102 126 this->errno = error; 103 127 return -1; … … 106 130 hal_fence(); 107 131 108 return 0; 132 tm_end = hal_get_cycles(); 133 134 syscall_dmsg("\n[DBG] %s : core[%x,%d] / thread %x / nbytes = %d / cycle %d\n" 135 " first byte = %c / file_id = %d / cost = %d\n", 136 __FUNCTION__ , local_cxy , this->core->lid , this->trdid , nbytes , tm_start , 137 *((char *)(intptr_t)paddr) , file_id , tm_end - tm_start ); 138 139 return nbytes; 109 140 110 141 } // end sys_write()
Note: See TracChangeset
for help on using the changeset viewer.