Blame view

arch/score/kernel/sys_score.c 3.62 KB
6bc9a3966   Chen Liqin   score: Add suppor...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  /*
   * arch/score/kernel/syscall.c
   *
   * Score Processor version.
   *
   * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
   *  Chen Liqin <liqin.chen@sunplusct.com>
   *  Lennox Wu <lennox.wu@sunplusct.com>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, see the file COPYING, or write
   * to the Free Software Foundation, Inc.,
   * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   */
  
  #include <linux/file.h>
  #include <linux/fs.h>
cf52c4683   Chen Liqin   score: add old sy...
28
  #include <linux/mm.h>
6bc9a3966   Chen Liqin   score: Add suppor...
29
30
  #include <linux/mman.h>
  #include <linux/module.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
31
  #include <linux/slab.h>
6bc9a3966   Chen Liqin   score: Add suppor...
32
  #include <linux/unistd.h>
9fb24cc50   Arnd Bergmann   score: add missin...
33
34
  #include <linux/syscalls.h>
  #include <asm/syscalls.h>
6bc9a3966   Chen Liqin   score: Add suppor...
35

c60674722   Arnd Bergmann   score: cleanups: ...
36
  asmlinkage long 
6bc9a3966   Chen Liqin   score: Add suppor...
37
38
39
  sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
  	  unsigned long flags, unsigned long fd, unsigned long pgoff)
  {
f8b725609   Al Viro   Unify sys_mmap*
40
  	return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
6bc9a3966   Chen Liqin   score: Add suppor...
41
  }
cf52c4683   Chen Liqin   score: add old sy...
42
43
  asmlinkage long
  sys_mmap(unsigned long addr, unsigned long len, unsigned long prot,
aa6560737   Al Viro   Add missing align...
44
  	unsigned long flags, unsigned long fd, off_t offset)
cf52c4683   Chen Liqin   score: add old sy...
45
  {
aa6560737   Al Viro   Add missing align...
46
47
48
  	if (unlikely(offset & ~PAGE_MASK))
  		return -EINVAL;
  	return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
cf52c4683   Chen Liqin   score: add old sy...
49
50
51
52
53
54
55
  }
  
  asmlinkage long
  score_fork(struct pt_regs *regs)
  {
  	return do_fork(SIGCHLD, regs->regs[0], regs, 0, NULL, NULL);
  }
6bc9a3966   Chen Liqin   score: Add suppor...
56
57
58
59
  /*
   * Clone a task - this clones the calling program thread.
   * This is called indirectly via a small wrapper
   */
bddc60595   Arnd Bergmann   score: fix functi...
60
61
  asmlinkage long
  score_clone(struct pt_regs *regs)
6bc9a3966   Chen Liqin   score: Add suppor...
62
63
64
65
66
67
68
69
70
71
  {
  	unsigned long clone_flags;
  	unsigned long newsp;
  	int __user *parent_tidptr, *child_tidptr;
  
  	clone_flags = regs->regs[4];
  	newsp = regs->regs[5];
  	if (!newsp)
  		newsp = regs->regs[0];
  	parent_tidptr = (int __user *)regs->regs[6];
f673c032e   Arnd Bergmann   score: add generi...
72
  	child_tidptr = (int __user *)regs->regs[8];
6bc9a3966   Chen Liqin   score: Add suppor...
73
74
75
76
  
  	return do_fork(clone_flags, newsp, regs, 0,
  			parent_tidptr, child_tidptr);
  }
cf52c4683   Chen Liqin   score: add old sy...
77
78
79
80
81
82
  asmlinkage long
  score_vfork(struct pt_regs *regs)
  {
  	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
  			regs->regs[0], regs, 0, NULL, NULL);
  }
6bc9a3966   Chen Liqin   score: Add suppor...
83
84
85
86
  /*
   * sys_execve() executes a new program.
   * This is called indirectly via a small wrapper
   */
a1f8213b9   Arnd Bergmann   score: add addres...
87
88
  asmlinkage long
  score_execve(struct pt_regs *regs)
6bc9a3966   Chen Liqin   score: Add suppor...
89
90
91
  {
  	int error;
  	char *filename;
a1f8213b9   Arnd Bergmann   score: add addres...
92
  	filename = getname((char __user*)regs->regs[4]);
6bc9a3966   Chen Liqin   score: Add suppor...
93
94
95
  	error = PTR_ERR(filename);
  	if (IS_ERR(filename))
  		return error;
d7627467b   David Howells   Make do_execve() ...
96
97
98
99
  	error = do_execve(filename,
  			  (const char __user *const __user *)regs->regs[5],
  			  (const char __user *const __user *)regs->regs[6],
  			  regs);
6bc9a3966   Chen Liqin   score: Add suppor...
100
101
102
103
104
105
  
  	putname(filename);
  	return error;
  }
  
  /*
6bc9a3966   Chen Liqin   score: Add suppor...
106
107
108
   * Do a system call from kernel instead of calling sys_execve so we
   * end up with proper pt_regs.
   */
d7627467b   David Howells   Make do_execve() ...
109
110
111
  int kernel_execve(const char *filename,
  		  const char *const argv[],
  		  const char *const envp[])
6bc9a3966   Chen Liqin   score: Add suppor...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  {
  	register unsigned long __r4 asm("r4") = (unsigned long) filename;
  	register unsigned long __r5 asm("r5") = (unsigned long) argv;
  	register unsigned long __r6 asm("r6") = (unsigned long) envp;
  	register unsigned long __r7 asm("r7");
  
  	__asm__ __volatile__ ("	
  "
  		"ldi	r27, %5		
  "
  		"syscall		
  "
  		"mv	%0, r4		
  "
  		"mv	%1, r7		
  "
  		: "=&r" (__r4), "=r" (__r7)
  		: "r" (__r4), "r" (__r5), "r" (__r6), "i" (__NR_execve)
  		: "r8", "r9", "r10", "r11", "r22", "r23", "r24", "r25",
  		  "r26", "r27", "memory");
  
  	if (__r7 == 0)
  		return __r4;
  
  	return -__r4;
  }