···5151 * system call/exception. As usual the registers k0/k1 aren't being saved.5252 */5353struct pt_regs {5454- unsigned long pad0[6];5454+ unsigned long pad0[6]; /* stack arguments */5555 unsigned long orig_r4;5656 unsigned long orig_r7;5757+ long is_syscall;5858+5759 unsigned long regs[32];58605961 unsigned long cel;···7068 unsigned long cp0_psr;7169 unsigned long cp0_ecr;7270 unsigned long cp0_condition;7373-7474- long is_syscall;7571};76727773#ifdef __KERNEL__7474+7575+struct task_struct;78767977/*8078 * Does the process account for user or for system time?
+418-21
arch/score/include/asm/uaccess.h
···11-#ifndef _ASM_SCORE_UACCESS_H22-#define _ASM_SCORE_UACCESS_H11+#ifndef __SCORE_UACCESS_H22+#define __SCORE_UACCESS_H33+44+#include <linux/kernel.h>55+#include <linux/errno.h>66+#include <linux/thread_info.h>77+88+#define VERIFY_READ 099+#define VERIFY_WRITE 11010+1111+#define get_ds() (KERNEL_DS)1212+#define get_fs() (current_thread_info()->addr_limit)1313+#define segment_eq(a, b) ((a).seg == (b).seg)1414+315/*44- * Copyright (C) 2006 Atmark Techno, Inc.1616+ * Is a address valid? This does a straighforward calculation rather1717+ * than tests.518 *66- * This file is subject to the terms and conditions of the GNU General Public77- * License. See the file "COPYING" in the main directory of this archive88- * for more details.1919+ * Address valid if:2020+ * - "addr" doesn't have any high-bits set2121+ * - AND "size" doesn't have any high-bits set2222+ * - AND "addr+size" doesn't have any high-bits set2323+ * - OR we are in kernel mode.2424+ *2525+ * __ua_size() is a trick to avoid runtime checking of positive constant2626+ * sizes; for those we already know at compile time that the size is ok.927 */1010-struct pt_regs;2828+#define __ua_size(size) \2929+ ((__builtin_constant_p(size) && (signed long) (size) > 0) ? 0 : (size))3030+3131+/*3232+ * access_ok: - Checks if a user space pointer is valid3333+ * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that3434+ * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe3535+ * to write to a block, it is always safe to read from it.3636+ * @addr: User space pointer to start of block to check3737+ * @size: Size of block to check3838+ *3939+ * Context: User context only. This function may sleep.4040+ *4141+ * Checks if a pointer to a block of memory in user space is valid.4242+ *4343+ * Returns true (nonzero) if the memory block may be valid, false (zero)4444+ * if it is definitely invalid.4545+ *4646+ * Note that, depending on architecture, this function probably just4747+ * checks that the pointer is in the user space range - after calling4848+ * this function, memory access functions may still return -EFAULT.4949+ */5050+5151+#define __access_ok(addr, size) \5252+ (((long)((get_fs().seg) & \5353+ ((addr) | ((addr) + (size)) | \5454+ __ua_size(size)))) == 0)5555+5656+#define access_ok(type, addr, size) \5757+ likely(__access_ok((unsigned long)(addr), (size)))5858+5959+/*6060+ * put_user: - Write a simple value into user space.6161+ * @x: Value to copy to user space.6262+ * @ptr: Destination address, in user space.6363+ *6464+ * Context: User context only. This function may sleep.6565+ *6666+ * This macro copies a single simple value from kernel space to user6767+ * space. It supports simple types like char and int, but not larger6868+ * data types like structures or arrays.6969+ *7070+ * @ptr must have pointer-to-simple-variable type, and @x must be assignable7171+ * to the result of dereferencing @ptr.7272+ *7373+ * Returns zero on success, or -EFAULT on error.7474+ */7575+#define put_user(x, ptr) __put_user_check((x), (ptr), sizeof(*(ptr)))7676+7777+/*7878+ * get_user: - Get a simple variable from user space.7979+ * @x: Variable to store result.8080+ * @ptr: Source address, in user space.8181+ *8282+ * Context: User context only. This function may sleep.8383+ *8484+ * This macro copies a single simple variable from user space to kernel8585+ * space. It supports simple types like char and int, but not larger8686+ * data types like structures or arrays.8787+ *8888+ * @ptr must have pointer-to-simple-variable type, and the result of8989+ * dereferencing @ptr must be assignable to @x without a cast.9090+ *9191+ * Returns zero on success, or -EFAULT on error.9292+ * On error, the variable @x is set to zero.9393+ */9494+#define get_user(x, ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))9595+9696+/*9797+ * __put_user: - Write a simple value into user space, with less checking.9898+ * @x: Value to copy to user space.9999+ * @ptr: Destination address, in user space.100100+ *101101+ * Context: User context only. This function may sleep.102102+ *103103+ * This macro copies a single simple value from kernel space to user104104+ * space. It supports simple types like char and int, but not larger105105+ * data types like structures or arrays.106106+ *107107+ * @ptr must have pointer-to-simple-variable type, and @x must be assignable108108+ * to the result of dereferencing @ptr.109109+ *110110+ * Caller must check the pointer with access_ok() before calling this111111+ * function.112112+ *113113+ * Returns zero on success, or -EFAULT on error.114114+ */115115+#define __put_user(x, ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr)))116116+117117+/*118118+ * __get_user: - Get a simple variable from user space, with less checking.119119+ * @x: Variable to store result.120120+ * @ptr: Source address, in user space.121121+ *122122+ * Context: User context only. This function may sleep.123123+ *124124+ * This macro copies a single simple variable from user space to kernel125125+ * space. It supports simple types like char and int, but not larger126126+ * data types like structures or arrays.127127+ *128128+ * @ptr must have pointer-to-simple-variable type, and the result of129129+ * dereferencing @ptr must be assignable to @x without a cast.130130+ *131131+ * Caller must check the pointer with access_ok() before calling this132132+ * function.133133+ *134134+ * Returns zero on success, or -EFAULT on error.135135+ * On error, the variable @x is set to zero.136136+ */137137+#define __get_user(x, ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))138138+139139+struct __large_struct { unsigned long buf[100]; };140140+#define __m(x) (*(struct __large_struct __user *)(x))141141+142142+/*143143+ * Yuck. We need two variants, one for 64bit operation and one144144+ * for 32 bit mode and old iron.145145+ */146146+extern void __get_user_unknown(void);147147+148148+#define __get_user_common(val, size, ptr) \149149+do { \150150+ switch (size) { \151151+ case 1: \152152+ __get_user_asm(val, "lb", ptr); \153153+ break; \154154+ case 2: \155155+ __get_user_asm(val, "lh", ptr); \156156+ break; \157157+ case 4: \158158+ __get_user_asm(val, "lw", ptr); \159159+ break; \160160+ case 8: \161161+ if ((copy_from_user((void *)&val, ptr, 8)) == 0) \162162+ __gu_err = 0; \163163+ else \164164+ __gu_err = -EFAULT; \165165+ break; \166166+ default: \167167+ __get_user_unknown(); \168168+ break; \169169+ } \170170+} while (0)171171+172172+#define __get_user_nocheck(x, ptr, size) \173173+({ \174174+ long __gu_err = 0; \175175+ __get_user_common((x), size, ptr); \176176+ __gu_err; \177177+})178178+179179+#define __get_user_check(x, ptr, size) \180180+({ \181181+ long __gu_err = -EFAULT; \182182+ const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \183183+ \184184+ if (likely(access_ok(VERIFY_READ, __gu_ptr, size))) \185185+ __get_user_common((x), size, __gu_ptr); \186186+ \187187+ __gu_err; \188188+})189189+190190+#define __get_user_asm(val, insn, addr) \191191+{ \192192+ long __gu_tmp; \193193+ \194194+ __asm__ __volatile__( \195195+ "1:" insn " %1, %3\n" \196196+ "2:\n" \197197+ ".section .fixup,\"ax\"\n" \198198+ "3:li %0, %4\n" \199199+ "j 2b\n" \200200+ ".previous\n" \201201+ ".section __ex_table,\"a\"\n" \202202+ ".word 1b, 3b\n" \203203+ ".previous\n" \204204+ : "=r" (__gu_err), "=r" (__gu_tmp) \205205+ : "0" (0), "o" (__m(addr)), "i" (-EFAULT)); \206206+ \207207+ (val) = (__typeof__(*(addr))) __gu_tmp; \208208+}209209+210210+/*211211+ * Yuck. We need two variants, one for 64bit operation and one212212+ * for 32 bit mode and old iron.213213+ */214214+#define __put_user_nocheck(val, ptr, size) \215215+({ \216216+ __typeof__(*(ptr)) __pu_val; \217217+ long __pu_err = 0; \218218+ \219219+ __pu_val = (val); \220220+ switch (size) { \221221+ case 1: \222222+ __put_user_asm("sb", ptr); \223223+ break; \224224+ case 2: \225225+ __put_user_asm("sh", ptr); \226226+ break; \227227+ case 4: \228228+ __put_user_asm("sw", ptr); \229229+ break; \230230+ case 8: \231231+ if ((__copy_to_user((void *)ptr, &__pu_val, 8)) == 0) \232232+ __pu_err = 0; \233233+ else \234234+ __pu_err = -EFAULT; \235235+ break; \236236+ default: \237237+ __put_user_unknown(); \238238+ break; \239239+ } \240240+ __pu_err; \241241+})242242+243243+244244+#define __put_user_check(val, ptr, size) \245245+({ \246246+ __typeof__(*(ptr)) __user *__pu_addr = (ptr); \247247+ __typeof__(*(ptr)) __pu_val = (val); \248248+ long __pu_err = -EFAULT; \249249+ \250250+ if (likely(access_ok(VERIFY_WRITE, __pu_addr, size))) { \251251+ switch (size) { \252252+ case 1: \253253+ __put_user_asm("sb", __pu_addr); \254254+ break; \255255+ case 2: \256256+ __put_user_asm("sh", __pu_addr); \257257+ break; \258258+ case 4: \259259+ __put_user_asm("sw", __pu_addr); \260260+ break; \261261+ case 8: \262262+ if ((__copy_to_user((void *)__pu_addr, &__pu_val, 8)) == 0)\263263+ __pu_err = 0; \264264+ else \265265+ __pu_err = -EFAULT; \266266+ break; \267267+ default: \268268+ __put_user_unknown(); \269269+ break; \270270+ } \271271+ } \272272+ __pu_err; \273273+})274274+275275+#define __put_user_asm(insn, ptr) \276276+ __asm__ __volatile__( \277277+ "1:" insn " %2, %3\n" \278278+ "2:\n" \279279+ ".section .fixup,\"ax\"\n" \280280+ "3:li %0, %4\n" \281281+ "j 2b\n" \282282+ ".previous\n" \283283+ ".section __ex_table,\"a\"\n" \284284+ ".word 1b, 3b\n" \285285+ ".previous\n" \286286+ : "=r" (__pu_err) \287287+ : "0" (0), "r" (__pu_val), "o" (__m(ptr)), \288288+ "i" (-EFAULT));289289+290290+extern void __put_user_unknown(void);291291+extern int __copy_tofrom_user(void *to, const void *from, unsigned long len);292292+293293+static inline unsigned long294294+copy_from_user(void *to, const void *from, unsigned long len)295295+{296296+ unsigned long over;297297+298298+ if (access_ok(VERIFY_READ, from, len))299299+ return __copy_tofrom_user(to, from, len);300300+301301+ if ((unsigned long)from < TASK_SIZE) {302302+ over = (unsigned long)from + len - TASK_SIZE;303303+ return __copy_tofrom_user(to, from, len - over) + over;304304+ }305305+ return len;306306+}307307+308308+static inline unsigned long309309+copy_to_user(void *to, const void *from, unsigned long len)310310+{311311+ unsigned long over;312312+313313+ if (access_ok(VERIFY_WRITE, to, len))314314+ return __copy_tofrom_user(to, from, len);315315+316316+ if ((unsigned long)to < TASK_SIZE) {317317+ over = (unsigned long)to + len - TASK_SIZE;318318+ return __copy_tofrom_user(to, from, len - over) + over;319319+ }320320+ return len;321321+}322322+323323+#define __copy_from_user(to, from, len) \324324+ __copy_tofrom_user((to), (from), (len))325325+326326+#define __copy_to_user(to, from, len) \327327+ __copy_tofrom_user((to), (from), (len))328328+329329+static inline unsigned long330330+__copy_to_user_inatomic(void *to, const void *from, unsigned long len)331331+{332332+ return __copy_to_user(to, from, len);333333+}334334+335335+static inline unsigned long336336+__copy_from_user_inatomic(void *to, const void *from, unsigned long len)337337+{338338+ return __copy_from_user(to, from, len);339339+}340340+341341+#define __copy_in_user(to, from, len) __copy_from_user(to, from, len)342342+343343+static inline unsigned long344344+copy_in_user(void *to, const void *from, unsigned long len)345345+{346346+ if (access_ok(VERIFY_READ, from, len) &&347347+ access_ok(VERFITY_WRITE, to, len))348348+ return copy_from_user(to, from, len);349349+}350350+351351+/*352352+ * __clear_user: - Zero a block of memory in user space, with less checking.353353+ * @to: Destination address, in user space.354354+ * @n: Number of bytes to zero.355355+ *356356+ * Zero a block of memory in user space. Caller must check357357+ * the specified block with access_ok() before calling this function.358358+ *359359+ * Returns number of bytes that could not be cleared.360360+ * On success, this will be zero.361361+ */362362+extern unsigned long __clear_user(void __user *src, unsigned long size);363363+364364+static inline unsigned long clear_user(char *src, unsigned long size)365365+{366366+ if (access_ok(VERIFY_WRITE, src, size))367367+ return __clear_user(src, size);368368+369369+ return -EFAULT;370370+}371371+/*372372+ * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.373373+ * @dst: Destination address, in kernel space. This buffer must be at374374+ * least @count bytes long.375375+ * @src: Source address, in user space.376376+ * @count: Maximum number of bytes to copy, including the trailing NUL.377377+ *378378+ * Copies a NUL-terminated string from userspace to kernel space.379379+ * Caller must check the specified block with access_ok() before calling380380+ * this function.381381+ *382382+ * On success, returns the length of the string (not including the trailing383383+ * NUL).384384+ *385385+ * If access to userspace fails, returns -EFAULT (some data may have been386386+ * copied).387387+ *388388+ * If @count is smaller than the length of the string, copies @count bytes389389+ * and returns @count.390390+ */391391+extern int __strncpy_from_user(char *dst, const char *src, long len);392392+393393+static inline int strncpy_from_user(char *dst, const char *src, long len)394394+{395395+ if (access_ok(VERIFY_READ, src, 1))396396+ return __strncpy_from_user(dst, src, len);397397+398398+ return -EFAULT;399399+}400400+401401+extern int __strlen_user(const char *src);402402+static inline long strlen_user(const char __user *src)403403+{404404+ return __strlen_user(src);405405+}406406+407407+extern int __strnlen_user(const char *str, long len);408408+static inline long strnlen_user(const char __user *str, long len)409409+{410410+ if (!access_ok(VERIFY_READ, str, 0))411411+ return 0;412412+ else 413413+ return __strnlen_user(str, len);414414+}415415+416416+struct exception_table_entry {417417+ unsigned long insn;418418+ unsigned long fixup;419419+};420420+11421extern int fixup_exception(struct pt_regs *regs);124221313-#ifndef __ASSEMBLY__423423+#endif /* __SCORE_UACCESS_H */144241515-#define __range_ok(addr, size) \1616- ((((unsigned long __force)(addr) >= 0x80000000) \1717- || ((unsigned long)(size) > 0x80000000) \1818- || (((unsigned long __force)(addr) + (unsigned long)(size)) > 0x80000000)))1919-2020-#define __access_ok(addr, size) \2121- (__range_ok((addr), (size)) == 0)2222-2323-#include <asm-generic/uaccess.h>2424-2525-#endif /* __ASSEMBLY__ */2626-2727-#endif /* _ASM_SCORE_UACCESS_H */
+17
arch/score/include/asm/user.h
···11#ifndef _ASM_SCORE_USER_H22#define _ASM_SCORE_USER_H3344+struct user_regs_struct {55+ unsigned long regs[32];66+77+ unsigned long cel;88+ unsigned long ceh;99+1010+ unsigned long sr0; /* cnt */1111+ unsigned long sr1; /* lcr */1212+ unsigned long sr2; /* scr */1313+1414+ unsigned long cp0_epc;1515+ unsigned long cp0_ema;1616+ unsigned long cp0_psr;1717+ unsigned long cp0_ecr;1818+ unsigned long cp0_condition;1919+};2020+421#endif /* _ASM_SCORE_USER_H */