From: Juan Perez-Sanchez <lithoxs@gmail.com>
To: linux-8086 <linux-8086@vger.kernel.org>
Subject: [PATCH] standardization of get_user_* and put_user_* functions
Date: Thu, 15 Nov 2012 17:42:08 -0600 [thread overview]
Message-ID: <CAD6VGuaRqEYtq5MkXEDxNYU2GE-SimBWxrLBENRFcDxYoEVFtw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]
Hi,
The second of five patches.
Juan
PREVIOUS OPERATION
1. Functions get_fs_*() and put_fs_*(), defined in arch/i86/mm/user.c do
exactly the same than get_user_*() and put_user_*() defined as macros
in include/arch/segment.h, wasting memory.
2. Parallel port driver lp.c defined its own macro for "get_user_char()".
Oddly, it named this macro as "put_user()"
NEW OPERATION
1. All calls to get_fs_*() and put_fs_*() were replaced with calls to
get_user_*() and put_user_*(), as in mainstream linux. The macro
definitions for get_user_*() and put_user_*() were removed and replaced
with actual functions in arch/i86/mm/user.c. Header files were changed
accordingly.
2. Removed macro definitions for "put_user()" in arch/i86/drivers/block/doshd.c
and arch/i86/drivers/char/lp.c. Fixed usage of "get_user_char()" in lp.c.
OTHER CHANGES
1. Code size reduced by 32 bytes.
2. Optimized assembly code in assembly functions in arch/i86/mm/user.c
The Image builded without errors. The kernel was tested with QEMU and
dioscuri emulators. Also in a PPro pc booting from floppy.
[-- Attachment #2: elksP.patch --]
[-- Type: application/octet-stream, Size: 11775 bytes --]
diff -Nurb elks.orig/arch/i86/drivers/block/doshd.c elks/arch/i86/drivers/block/doshd.c
--- elks.orig/arch/i86/drivers/block/doshd.c 2012-10-17 12:08:45.000000000 -0500
+++ elks/arch/i86/drivers/block/doshd.c 2012-10-17 13:34:52.000000000 -0500
@@ -44,7 +44,6 @@
#define MAJOR_NR BIOSHD_MAJOR
#define BIOSDISK
#define NR_HD ((drive_info[1].heads)?2:((drive_info[0].heads)?1:0))
-#define put_user(val,ptr) pokew(current->t_regs.ds,ptr,val)
#include "blk.h"
diff -Nurb elks.orig/arch/i86/drivers/block/floppy.c elks/arch/i86/drivers/block/floppy.c
--- elks.orig/arch/i86/drivers/block/floppy.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/arch/i86/drivers/block/floppy.c 2012-10-17 12:12:32.000000000 -0500
@@ -1178,7 +1178,7 @@
if (i)
return i;
for (cnt = 0; cnt < sizeof(struct floppy_struct); cnt++)
- put_fs_byte(((char *) this_floppy)[cnt], (char *) param + cnt);
+ put_user_char(((char *) this_floppy)[cnt], (char *) param + cnt);
return 0;
case FDFMTTRK:
if (!suser())
@@ -1189,7 +1189,7 @@
while (format_status != FORMAT_NONE)
sleep_on(&format_done);
for (cnt = 0; cnt < sizeof(struct format_descr); cnt++)
- ((char *) &format_req)[cnt] = get_fs_byte((char *) param + cnt);
+ ((char *) &format_req)[cnt] = get_user_char((char *) param + cnt);
format_req.device = drive;
format_status = FORMAT_WAIT;
format_errors = 0;
diff -Nurb elks.orig/arch/i86/drivers/char/lp.c elks/arch/i86/drivers/char/lp.c
--- elks.orig/arch/i86/drivers/char/lp.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/arch/i86/drivers/char/lp.c 2012-10-17 12:12:32.000000000 -0500
@@ -16,9 +16,6 @@
#include <arch/io.h>
-/* byte-wide put_user() */
-#define put_user(offset) peekb(current->t_regs.ds, offset)
-
#if 0
static int access_count[LP_PORTS] = {0,};
#endif
@@ -178,7 +175,7 @@
chrsp = 0;
while (((int)chrsp) < count) {
- if (!lp_char_polled((int) put_user((__u16) (buf + (int)chrsp)),
+ if (!lp_char_polled((int)get_user_char((void *)(buf + (int)chrsp)),
MINOR(inode->i_rdev)))
break;
chrsp++;
diff -Nurb elks.orig/arch/i86/kernel/strace.c elks/arch/i86/kernel/strace.c
--- elks.orig/arch/i86/kernel/strace.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/arch/i86/kernel/strace.c 2012-10-17 12:12:32.000000000 -0500
@@ -67,7 +67,7 @@
case P_STR:
con_charout('\"');
tmpa = p->s_param[i];
- while ((tmpb = get_fs_byte(tmpa++)))
+ while ((tmpb = get_user_char(tmpa++)))
con_charout(tmpb);
con_charout('\"');
break;
@@ -76,7 +76,7 @@
con_charout('&');
con_charout('\"');
tmpa = p->s_param[i];
- while ((tmpb = get_fs_byte(tmpa++)))
+ while ((tmpb = get_user_char(tmpa++)))
con_charout(tmpb);
con_charout('\"');
break;
@@ -106,11 +106,11 @@
break;
case P_PSLONG:
- printk("%ld", get_fs_long(p->s_param[i]));
+ printk("%ld", get_user_long(p->s_param[i]));
break;
case P_PULONG:
- printk("%lu", get_fs_long(p->s_param[i]));
+ printk("%lu", get_user_long(p->s_param[i]));
break;
default:
diff -Nurb elks.orig/arch/i86/mm/user.c elks/arch/i86/mm/user.c
--- elks.orig/arch/i86/mm/user.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/arch/i86/mm/user.c 2012-10-17 13:38:32.000000000 -0500
@@ -39,9 +39,8 @@
mov dx,es
mov bx,ds
mov es,bx
- mov ax,[bp+.memcpy_fromfs.ds] ! source segment (local variable)
- mov ds,ax
mov di,[bp+.memcpy_fromfs.daddr] ! destination address
+ mov ds,[bp+.memcpy_fromfs.ds] ! source segment (local variable)
mov si,[bp+.memcpy_fromfs.saddr] ! source address
mov cx,[bp+.memcpy_fromfs.len] ! number of bytes to copy
cld
@@ -77,8 +76,7 @@
push si
push di
mov dx,es
- mov ax,[bp+.memcpy_tofs.es] ! source segment (local variable)
- mov es,ax
+ mov es,[bp+.memcpy_tofs.es] ! destination segment (local variable)
mov di,[bp+.memcpy_tofs.daddr] ! destination address
mov si,[bp+.memcpy_tofs.saddr] ! source address
mov cx,[bp+.memcpy_tofs.len] ! number of bytes to copy
@@ -119,14 +117,11 @@
push ds
push es
pushf
- mov ds, ax
- mov si, $A[bp]
+ mov es, 4[bp]
mov di, 6[bp]
- mov cx, $C[bp]
- mov ax, 4[bp]
- mov es, ax
- mov ax, 8[bp]
- mov ds, ax
+ mov ds, 8[bp]
+ mov si, 10[bp]
+ mov cx, 12[bp]
cld ! Must move upwards...
rep
movsb
@@ -169,8 +164,8 @@
push di
push si
- mov ax,[bp+.strlen_fromfs.ds] ! source segment (local variable)
- mov es,ax
+ mov dx,es
+ mov es,[bp+.strlen_fromfs.ds] ! source segment (local variable)
mov di,[bp+.strlen_fromfs.saddr] ! source address
cld
xor al,al ! search for NULL byte
@@ -180,6 +175,7 @@
sub di,[bp+.strlen_fromfs.saddr] ! calc len +1
dec di
mov [bp+.strlen_fromfs.ds],di ! save in local var ds
+ mov es,dx
pop si
pop di
#endasm
@@ -189,7 +185,7 @@
}
#endif
-unsigned long int get_fs_long(void *dv)
+unsigned long int get_user_long(void *dv)
{
unsigned long retv;
@@ -198,16 +194,12 @@
return retv;
}
-#if 0
-
-void put_fs_long(unsigned long int dv, void *dp)
+void put_user_long(unsigned long int dv, void *dp)
{
memcpy_tofs(dp,&dv,4);
}
-#endif
-
-unsigned char get_fs_byte(void *dv)
+unsigned char get_user_char(void *dv)
{
unsigned char retv;
@@ -215,14 +207,14 @@
return retv;
}
-#if 0
-
-void put_fs_byte(unsigned char dv, void *dp)
+void put_user_char(unsigned char dv, void *dp)
{
memcpy_tofs(dp,&dv,1);
}
-unsigned short int get_fs_word(void *dv)
+#if 0
+
+unsigned short int get_user(void *dv)
{
unsigned short int retv;
@@ -230,13 +222,13 @@
return retv;
}
-void put_fs_word(unsigned short int dv, void *dp)
+#endif
+
+void put_user(unsigned short int dv, void *dp)
{
memcpy_tofs(dp,&dv,2);
}
-#endif
-
int fs_memcmp(void *s, void *d, size_t len)
{
unsigned char *p1 = s, *p2 = d;
diff -Nurb elks.orig/fs/ioctl.c elks/fs/ioctl.c
--- elks.orig/fs/ioctl.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/ioctl.c 2012-10-17 12:12:32.000000000 -0500
@@ -56,7 +56,7 @@
case FIONBIO:
memcpy_fromfs(&on, (unsigned int *) arg, 2);
#if 0
- on = get_fs_word((unsigned int *) arg);
+ on = get_user((void *) arg);
#endif
filp->f_flags = (on)
? filp->f_flags | O_NONBLOCK
diff -Nurb elks.orig/fs/minix/namei.c elks/fs/minix/namei.c
--- elks.orig/fs/minix/namei.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/minix/namei.c 2012-10-17 12:12:32.000000000 -0500
@@ -216,7 +216,7 @@
dir->i_mtime = dir->i_ctime = CURRENT_TIME;
dir->i_dirt = 1;
for (i = 0; i < info->s_namelen; i++)
- de->name[i] = (i < namelen) ? (char) get_fs_byte(name + i)
+ de->name[i] = (i < namelen) ? (char) get_user_char(name + i)
: '\0';
#ifdef BLOAT_FS
diff -Nurb elks.orig/fs/minix/symlink.c elks/fs/minix/symlink.c
--- elks.orig/fs/minix/symlink.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/minix/symlink.c 2012-10-17 12:12:32.000000000 -0500
@@ -90,7 +90,7 @@
while (((int)pi) < buflen && (c = bh->b_data[(int)pi])) {
pi++;
memcpy_tofs(buffer++, &c, 1);
- /* put_fs_byte(c,buffer++); */
+ /* put_user_char(c,buffer++); */
}
unmap_brelse(bh);
return (int)pi;
diff -Nurb elks.orig/fs/namei.c elks/fs/namei.c
--- elks.orig/fs/namei.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/namei.c 2012-10-17 12:12:32.000000000 -0500
@@ -98,8 +98,8 @@
if (dir) {
/* check permissions before traversing mount-points */
perm = permission(dir, MAY_EXEC);
- if (len == 2 && get_fs_byte(name) == '.'
- && get_fs_byte(name + 1) == '.') {
+ if (len == 2 && get_user_char(name) == '.'
+ && get_user_char(name + 1) == '.') {
if (dir == current->fs.root) {
*result = dir;
goto lkp_end;
@@ -178,7 +178,7 @@
base = current->fs.pwd;
base->i_count++;
}
- if ((c = get_fs_byte(pathname)) == '/') {
+ if ((c = get_user_char(pathname)) == '/') {
iput(base);
base = current->fs.root;
pathname++;
@@ -186,7 +186,7 @@
}
while (1) {
thisname = pathname;
- for (len = 0; (c = get_fs_byte(pathname++)) && (c != '/'); len++)
+ for (len = 0; (c = get_user_char(pathname++)) && (c != '/'); len++)
/* Do nothing */ ;
if (!c)
break;
diff -Nurb elks.orig/fs/open.c elks/fs/open.c
--- elks.orig/fs/open.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/open.c 2012-10-17 12:12:32.000000000 -0500
@@ -155,8 +155,8 @@
return error;
pinode = inode;
if (times) {
- pinode->i_atime = get_fs_long((unsigned long *) ×->actime);
- pinode->i_mtime = get_fs_long((unsigned long *) ×->modtime);
+ pinode->i_atime = get_user_long((void *) ×->actime);
+ pinode->i_mtime = get_user_long((void *) ×->modtime);
} else
pinode->i_atime = pinode->i_mtime = CURRENT_TIME;
pinode->i_dirt = 1;
diff -Nurb elks.orig/fs/read_write.c elks/fs/read_write.c
--- elks.orig/fs/read_write.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/read_write.c 2012-10-17 12:12:32.000000000 -0500
@@ -21,7 +21,7 @@
register struct file_operations *fop;
loff_t offset, tmp;
- offset = (loff_t) get_fs_long(p_offset);
+ offset = (loff_t) get_user_long(p_offset);
if (fd >= NR_OPEN || !(file = current->files.fd[fd])
|| !(file->f_inode))
return -EBADF;
diff -Nurb elks.orig/fs/select.c elks/fs/select.c
--- elks.orig/fs/select.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/fs/select.c 2012-10-17 12:12:32.000000000 -0500
@@ -207,8 +207,8 @@
if (error)
goto out;
- timeout = ROUND_UP(get_fs_long(&tvp->tv_usec), (1000000 / HZ));
- timeout += get_fs_long(&tvp->tv_sec) * (jiff_t) HZ;
+ timeout = ROUND_UP(get_user_long(&tvp->tv_usec), (1000000 / HZ));
+ timeout += get_user_long(&tvp->tv_sec) * (jiff_t) HZ;
if (timeout)
timeout += jiffies + 1UL;
}
diff -Nurb elks.orig/include/arch/segment.h elks/include/arch/segment.h
--- elks.orig/include/arch/segment.h 2012-08-18 13:28:59.000000000 -0500
+++ elks/include/arch/segment.h 2012-10-17 12:12:32.000000000 -0500
@@ -30,15 +30,4 @@
extern short *_endtext, *_enddata, *_endbss;
-/*@+namechecks@*/
-
-#define put_user_char(val,ptr) pokeb(current->t_regs.ds,ptr,val)
-#define get_user_char(ptr) peekb(current->t_regs.ds,ptr)
-
-#define put_user(val,ptr) pokew(current->t_regs.ds,ptr,val)
-#define get_user(ptr) peekw(current->t_regs.ds,ptr)
-
-#define put_user_long(val,ptr) poked(current->t_regs.ds,ptr,val)
-#define get_user_long(ptr) peekd(current->t_regs.ds,ptr)
-
#endif
diff -Nurb elks.orig/include/linuxmt/mm.h elks/include/linuxmt/mm.h
--- elks.orig/include/linuxmt/mm.h 2012-08-18 13:28:59.000000000 -0500
+++ elks/include/linuxmt/mm.h 2012-10-17 12:12:32.000000000 -0500
@@ -30,12 +30,12 @@
/*@+namechecks@*/
extern int verfy_area(void *,size_t);
-extern void put_fs_long(unsigned long int,void *);
-extern void put_fs_byte(unsigned char,void *);
-extern void put_fs_word(unsigned short int,void *);
-extern unsigned long int get_fs_long(void *);
-extern unsigned char get_fs_byte(void *);
-extern unsigned short int get_fs_word(void *);
+extern void put_user_long(unsigned long int,void *);
+extern void put_user_char(unsigned char,void *);
+extern void put_user(unsigned short int,void *);
+extern unsigned long int get_user_long(void *);
+extern unsigned char get_user_char(void *);
+extern unsigned short int get_user(void *);
extern int fs_memcmp(void *,void *,size_t);
extern int verified_memcpy_tofs(void *,void *,size_t);
extern int verified_memcpy_fromfs(void *,void *,size_t);
diff -Nurb elks.orig/kernel/printk.c elks/kernel/printk.c
--- elks.orig/kernel/printk.c 2012-08-18 13:28:59.000000000 -0500
+++ elks/kernel/printk.c 2012-10-17 12:12:32.000000000 -0500
@@ -172,7 +172,7 @@
goto FILLSP;
case 't':
cp = va_arg(p, char*);
- while ((c = (char) get_fs_byte(cp))) {
+ while ((c = (char) get_user_char(cp))) {
kputchar(c);
cp++;
width--;
reply other threads:[~2012-11-15 23:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAD6VGuaRqEYtq5MkXEDxNYU2GE-SimBWxrLBENRFcDxYoEVFtw@mail.gmail.com \
--to=lithoxs@gmail.com \
--cc=linux-8086@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).