ok i get it i wil try to answer even though my knowledge is very limited and some of what say will no doubt be wrong and forgive as i go over what's already obvious.
first i'm not so sure you can use the read from <asm/unistd.h> directly..
some of the kernels internal implementations of things involve passed arguments from other interfaces.. sometimes you can use them on one archetecture and not the other.
the best thing to do from within the kernel would be to use sys_read from fs/read_write.c
because that's actually the kernel side read but for ix86 you can't and i might be wrong but sys_read is what calls /asm/unistd.h
sys_read calls vfs_read() which uses
Code:
if (file->f_op->read)
ret = file->f_op->read(file, buf, count, pos);
and i think that's what you ought to be doing if you don't want to use libc
is implement read the same way
once you make a kernel side file object
from include/linux/fs.h: you get
Code:
struct file {
struct list_head f_list;
struct dentry *f_dentry;
struct vfsmount *f_vfsmnt;
struct file_operations *f_op;
atomic_t f_count;
unsigned int f_flags;
mode_t f_mode;
int f_error;
loff_t f_pos;
struct fown_struct f_owner;
unsigned int f_uid, f_gid;
struct file_ra_state f_ra;
unsigned long f_version;
void *f_security;
/* needed for tty driver, and maybe others */
void *private_data;
#ifdef CONFIG_EPOLL
/* Used by fs/eventpoll.c to link all the hooks to this file */
struct list_head f_ep_links;
spinlock_t f_ep_lock;
#endif /* #ifdef CONFIG_EPOLL */
struct address_space *f_mapping;
};
normally a system call from user space is implemented by softirq 0x80
the call is held in an EAX register and the args are held in other registers
see __NR_read in <asm/unistd.h>
after the transition to kernel mode the processor saves all registers to proper function after checking if
EAX is out of range.
the sys_read function needs a file object looked up by the file descriptor passed from user space.
ok when you do it from kernel space
like you have accept you have to return at the end to user space
set_fs(fs); (you know that already i bet)
see you still have a user space call because like i said earlier thats what sys calls from glibc are designed to be even though you are doing it is kernel space so if you don't return to user space addressing to user space all pointers go false
_libc_read() a user space syscall then goes to kernel system_call() then to the kernel fs/read_write.c then to the read() in asm you were talking about (i think) so using glibc you are just being alowed to do system_call() a user space thing from within the kernel
so to try someting actually kernel level instead of _libc_read() so timing is not such an issue and you are not
push pop args across user to kernel space trying to make the transition between softirq and kernel space over and over making all those changes in cpu registers
try: (warning untested of course) and with no failure checking
perhaps further investigation will reveal how i have written this wrong as all my code is always wrong at first ! you should be able to get to this stuff from fs.h or that might be included in more external headers
Code:
fs = get_fs();
set_fs(get_ds());
file1 = fget(fd_ttyS4);
file2 = fget(fd_ttyS5);
file1->f_op->write(file1,&tempChar,0, &file1->f_pos )
file2->f_op->read(file2,buf,0, &file2->f_pos)
set_fs(fs);