linux/arch/x86/include/asm/syscall.h
<<
>>
Prefs
   1/*
   2 * Access to user system call parameters and results
   3 *
   4 * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
   5 *
   6 * This copyrighted material is made available to anyone wishing to use,
   7 * modify, copy, or redistribute it subject to the terms and conditions
   8 * of the GNU General Public License v.2.
   9 *
  10 * See asm-generic/syscall.h for descriptions of what we must do here.
  11 */
  12
  13#ifndef _ASM_X86_SYSCALL_H
  14#define _ASM_X86_SYSCALL_H
  15
  16#include <linux/sched.h>
  17#include <linux/err.h>
  18#include <asm/asm-offsets.h>    /* For NR_syscalls */
  19
  20extern const unsigned long sys_call_table[];
  21
  22/*
  23 * Only the low 32 bits of orig_ax are meaningful, so we return int.
  24 * This importantly ignores the high bits on 64-bit, so comparisons
  25 * sign-extend the low 32 bits.
  26 */
  27static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  28{
  29        return regs->orig_ax;
  30}
  31
  32static inline void syscall_rollback(struct task_struct *task,
  33                                    struct pt_regs *regs)
  34{
  35        regs->ax = regs->orig_ax;
  36}
  37
  38static inline long syscall_get_error(struct task_struct *task,
  39                                     struct pt_regs *regs)
  40{
  41        unsigned long error = regs->ax;
  42#ifdef CONFIG_IA32_EMULATION
  43        /*
  44         * TS_COMPAT is set for 32-bit syscall entries and then
  45         * remains set until we return to user mode.
  46         */
  47        if (task_thread_info(task)->status & TS_COMPAT)
  48                /*
  49                 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
  50                 * and will match correctly in comparisons.
  51                 */
  52                error = (long) (int) error;
  53#endif
  54        return IS_ERR_VALUE(error) ? error : 0;
  55}
  56
  57static inline long syscall_get_return_value(struct task_struct *task,
  58                                            struct pt_regs *regs)
  59{
  60        return regs->ax;
  61}
  62
  63static inline void syscall_set_return_value(struct task_struct *task,
  64                                            struct pt_regs *regs,
  65                                            int error, long val)
  66{
  67        regs->ax = (long) error ?: val;
  68}
  69
  70#ifdef CONFIG_X86_32
  71
  72static inline void syscall_get_arguments(struct task_struct *task,
  73                                         struct pt_regs *regs,
  74                                         unsigned int i, unsigned int n,
  75                                         unsigned long *args)
  76{
  77        BUG_ON(i + n > 6);
  78        memcpy(args, &regs->bx + i, n * sizeof(args[0]));
  79}
  80
  81static inline void syscall_set_arguments(struct task_struct *task,
  82                                         struct pt_regs *regs,
  83                                         unsigned int i, unsigned int n,
  84                                         const unsigned long *args)
  85{
  86        BUG_ON(i + n > 6);
  87        memcpy(&regs->bx + i, args, n * sizeof(args[0]));
  88}
  89
  90#else    /* CONFIG_X86_64 */
  91
  92static inline void syscall_get_arguments(struct task_struct *task,
  93                                         struct pt_regs *regs,
  94                                         unsigned int i, unsigned int n,
  95                                         unsigned long *args)
  96{
  97# ifdef CONFIG_IA32_EMULATION
  98        if (task_thread_info(task)->status & TS_COMPAT)
  99                switch (i) {
 100                case 0:
 101                        if (!n--) break;
 102                        *args++ = regs->bx;
 103                case 1:
 104                        if (!n--) break;
 105                        *args++ = regs->cx;
 106                case 2:
 107                        if (!n--) break;
 108                        *args++ = regs->dx;
 109                case 3:
 110                        if (!n--) break;
 111                        *args++ = regs->si;
 112                case 4:
 113                        if (!n--) break;
 114                        *args++ = regs->di;
 115                case 5:
 116                        if (!n--) break;
 117                        *args++ = regs->bp;
 118                case 6:
 119                        if (!n--) break;
 120                default:
 121                        BUG();
 122                        break;
 123                }
 124        else
 125# endif
 126                switch (i) {
 127                case 0:
 128                        if (!n--) break;
 129                        *args++ = regs->di;
 130                case 1:
 131                        if (!n--) break;
 132                        *args++ = regs->si;
 133                case 2:
 134                        if (!n--) break;
 135                        *args++ = regs->dx;
 136                case 3:
 137                        if (!n--) break;
 138                        *args++ = regs->r10;
 139                case 4:
 140                        if (!n--) break;
 141                        *args++ = regs->r8;
 142                case 5:
 143                        if (!n--) break;
 144                        *args++ = regs->r9;
 145                case 6:
 146                        if (!n--) break;
 147                default:
 148                        BUG();
 149                        break;
 150                }
 151}
 152
 153static inline void syscall_set_arguments(struct task_struct *task,
 154                                         struct pt_regs *regs,
 155                                         unsigned int i, unsigned int n,
 156                                         const unsigned long *args)
 157{
 158# ifdef CONFIG_IA32_EMULATION
 159        if (task_thread_info(task)->status & TS_COMPAT)
 160                switch (i) {
 161                case 0:
 162                        if (!n--) break;
 163                        regs->bx = *args++;
 164                case 1:
 165                        if (!n--) break;
 166                        regs->cx = *args++;
 167                case 2:
 168                        if (!n--) break;
 169                        regs->dx = *args++;
 170                case 3:
 171                        if (!n--) break;
 172                        regs->si = *args++;
 173                case 4:
 174                        if (!n--) break;
 175                        regs->di = *args++;
 176                case 5:
 177                        if (!n--) break;
 178                        regs->bp = *args++;
 179                case 6:
 180                        if (!n--) break;
 181                default:
 182                        BUG();
 183                        break;
 184                }
 185        else
 186# endif
 187                switch (i) {
 188                case 0:
 189                        if (!n--) break;
 190                        regs->di = *args++;
 191                case 1:
 192                        if (!n--) break;
 193                        regs->si = *args++;
 194                case 2:
 195                        if (!n--) break;
 196                        regs->dx = *args++;
 197                case 3:
 198                        if (!n--) break;
 199                        regs->r10 = *args++;
 200                case 4:
 201                        if (!n--) break;
 202                        regs->r8 = *args++;
 203                case 5:
 204                        if (!n--) break;
 205                        regs->r9 = *args++;
 206                case 6:
 207                        if (!n--) break;
 208                default:
 209                        BUG();
 210                        break;
 211                }
 212}
 213
 214#endif  /* CONFIG_X86_32 */
 215
 216#endif  /* _ASM_X86_SYSCALL_H */
 217
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.