OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [linux-2.6/] [linux-2.6.24/] [arch/] [x86/] [kernel/] [sys_i386_32.c] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 xianfeng
/*
2
 * This file contains various random system calls that
3
 * have a non-standard calling sequence on the Linux/i386
4
 * platform.
5
 */
6
 
7
#include <linux/errno.h>
8
#include <linux/sched.h>
9
#include <linux/mm.h>
10
#include <linux/fs.h>
11
#include <linux/smp.h>
12
#include <linux/sem.h>
13
#include <linux/msg.h>
14
#include <linux/shm.h>
15
#include <linux/stat.h>
16
#include <linux/syscalls.h>
17
#include <linux/mman.h>
18
#include <linux/file.h>
19
#include <linux/utsname.h>
20
#include <linux/ipc.h>
21
 
22
#include <asm/uaccess.h>
23
#include <asm/unistd.h>
24
 
25
/*
26
 * sys_pipe() is the normal C calling standard for creating
27
 * a pipe. It's not the way Unix traditionally does this, though.
28
 */
29
asmlinkage int sys_pipe(unsigned long __user * fildes)
30
{
31
        int fd[2];
32
        int error;
33
 
34
        error = do_pipe(fd);
35
        if (!error) {
36
                if (copy_to_user(fildes, fd, 2*sizeof(int)))
37
                        error = -EFAULT;
38
        }
39
        return error;
40
}
41
 
42
asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
43
                          unsigned long prot, unsigned long flags,
44
                          unsigned long fd, unsigned long pgoff)
45
{
46
        int error = -EBADF;
47
        struct file *file = NULL;
48
        struct mm_struct *mm = current->mm;
49
 
50
        flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
51
        if (!(flags & MAP_ANONYMOUS)) {
52
                file = fget(fd);
53
                if (!file)
54
                        goto out;
55
        }
56
 
57
        down_write(&mm->mmap_sem);
58
        error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
59
        up_write(&mm->mmap_sem);
60
 
61
        if (file)
62
                fput(file);
63
out:
64
        return error;
65
}
66
 
67
/*
68
 * Perform the select(nd, in, out, ex, tv) and mmap() system
69
 * calls. Linux/i386 didn't use to be able to handle more than
70
 * 4 system call parameters, so these system calls used a memory
71
 * block for parameter passing..
72
 */
73
 
74
struct mmap_arg_struct {
75
        unsigned long addr;
76
        unsigned long len;
77
        unsigned long prot;
78
        unsigned long flags;
79
        unsigned long fd;
80
        unsigned long offset;
81
};
82
 
83
asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
84
{
85
        struct mmap_arg_struct a;
86
        int err = -EFAULT;
87
 
88
        if (copy_from_user(&a, arg, sizeof(a)))
89
                goto out;
90
 
91
        err = -EINVAL;
92
        if (a.offset & ~PAGE_MASK)
93
                goto out;
94
 
95
        err = sys_mmap2(a.addr, a.len, a.prot, a.flags,
96
                        a.fd, a.offset >> PAGE_SHIFT);
97
out:
98
        return err;
99
}
100
 
101
 
102
struct sel_arg_struct {
103
        unsigned long n;
104
        fd_set __user *inp, *outp, *exp;
105
        struct timeval __user *tvp;
106
};
107
 
108
asmlinkage int old_select(struct sel_arg_struct __user *arg)
109
{
110
        struct sel_arg_struct a;
111
 
112
        if (copy_from_user(&a, arg, sizeof(a)))
113
                return -EFAULT;
114
        /* sys_select() does the appropriate kernel locking */
115
        return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
116
}
117
 
118
/*
119
 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
120
 *
121
 * This is really horribly ugly.
122
 */
123
asmlinkage int sys_ipc (uint call, int first, int second,
124
                        int third, void __user *ptr, long fifth)
125
{
126
        int version, ret;
127
 
128
        version = call >> 16; /* hack for backward compatibility */
129
        call &= 0xffff;
130
 
131
        switch (call) {
132
        case SEMOP:
133
                return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
134
        case SEMTIMEDOP:
135
                return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
136
                                        (const struct timespec __user *)fifth);
137
 
138
        case SEMGET:
139
                return sys_semget (first, second, third);
140
        case SEMCTL: {
141
                union semun fourth;
142
                if (!ptr)
143
                        return -EINVAL;
144
                if (get_user(fourth.__pad, (void __user * __user *) ptr))
145
                        return -EFAULT;
146
                return sys_semctl (first, second, third, fourth);
147
        }
148
 
149
        case MSGSND:
150
                return sys_msgsnd (first, (struct msgbuf __user *) ptr,
151
                                   second, third);
152
        case MSGRCV:
153
                switch (version) {
154
                case 0: {
155
                        struct ipc_kludge tmp;
156
                        if (!ptr)
157
                                return -EINVAL;
158
 
159
                        if (copy_from_user(&tmp,
160
                                           (struct ipc_kludge __user *) ptr,
161
                                           sizeof (tmp)))
162
                                return -EFAULT;
163
                        return sys_msgrcv (first, tmp.msgp, second,
164
                                           tmp.msgtyp, third);
165
                }
166
                default:
167
                        return sys_msgrcv (first,
168
                                           (struct msgbuf __user *) ptr,
169
                                           second, fifth, third);
170
                }
171
        case MSGGET:
172
                return sys_msgget ((key_t) first, second);
173
        case MSGCTL:
174
                return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
175
 
176
        case SHMAT:
177
                switch (version) {
178
                default: {
179
                        ulong raddr;
180
                        ret = do_shmat (first, (char __user *) ptr, second, &raddr);
181
                        if (ret)
182
                                return ret;
183
                        return put_user (raddr, (ulong __user *) third);
184
                }
185
                case 1: /* iBCS2 emulator entry point */
186
                        if (!segment_eq(get_fs(), get_ds()))
187
                                return -EINVAL;
188
                        /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
189
                        return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
190
                }
191
        case SHMDT:
192
                return sys_shmdt ((char __user *)ptr);
193
        case SHMGET:
194
                return sys_shmget (first, second, third);
195
        case SHMCTL:
196
                return sys_shmctl (first, second,
197
                                   (struct shmid_ds __user *) ptr);
198
        default:
199
                return -ENOSYS;
200
        }
201
}
202
 
203
/*
204
 * Old cruft
205
 */
206
asmlinkage int sys_uname(struct old_utsname __user * name)
207
{
208
        int err;
209
        if (!name)
210
                return -EFAULT;
211
        down_read(&uts_sem);
212
        err = copy_to_user(name, utsname(), sizeof (*name));
213
        up_read(&uts_sem);
214
        return err?-EFAULT:0;
215
}
216
 
217
asmlinkage int sys_olduname(struct oldold_utsname __user * name)
218
{
219
        int error;
220
 
221
        if (!name)
222
                return -EFAULT;
223
        if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
224
                return -EFAULT;
225
 
226
        down_read(&uts_sem);
227
 
228
        error = __copy_to_user(&name->sysname, &utsname()->sysname,
229
                               __OLD_UTS_LEN);
230
        error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
231
        error |= __copy_to_user(&name->nodename, &utsname()->nodename,
232
                                __OLD_UTS_LEN);
233
        error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
234
        error |= __copy_to_user(&name->release, &utsname()->release,
235
                                __OLD_UTS_LEN);
236
        error |= __put_user(0, name->release + __OLD_UTS_LEN);
237
        error |= __copy_to_user(&name->version, &utsname()->version,
238
                                __OLD_UTS_LEN);
239
        error |= __put_user(0, name->version + __OLD_UTS_LEN);
240
        error |= __copy_to_user(&name->machine, &utsname()->machine,
241
                                __OLD_UTS_LEN);
242
        error |= __put_user(0, name->machine + __OLD_UTS_LEN);
243
 
244
        up_read(&uts_sem);
245
 
246
        error = error ? -EFAULT : 0;
247
 
248
        return error;
249
}
250
 
251
 
252
/*
253
 * Do a system call from kernel instead of calling sys_execve so we
254
 * end up with proper pt_regs.
255
 */
256
int kernel_execve(const char *filename, char *const argv[], char *const envp[])
257
{
258
        long __res;
259
        asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
260
        : "=a" (__res)
261
        : "0" (__NR_execve),"ri" (filename),"c" (argv), "d" (envp) : "memory");
262
        return __res;
263
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.