| Petr Machata | f6ec08a | 2012-01-06 16:58:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of ltrace. |
| 3 | * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of the |
| 8 | * License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 | * 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef FETCH_H |
| 22 | #define FETCH_H |
| 23 | |
| 24 | #include "forward.h" |
| Petr Machata | e36298a | 2012-09-13 17:12:41 +0200 | [diff] [blame] | 25 | #include "param.h" |
| Petr Machata | f6ec08a | 2012-01-06 16:58:54 +0100 | [diff] [blame] | 26 | |
| 27 | /* XXX isn't SYSCALL TOF just a different ABI? Maybe we needed to |
| 28 | * support variant ABIs all along. */ |
| 29 | enum tof { |
| 30 | LT_TOF_FUNCTION, /* A real library function */ |
| 31 | LT_TOF_FUNCTIONR, /* Return from a real library function */ |
| 32 | LT_TOF_SYSCALL, /* A syscall */ |
| 33 | LT_TOF_SYSCALLR, /* Return from a syscall */ |
| 34 | }; |
| 35 | |
| 36 | /* The contents of the structure is defined by the back end. */ |
| 37 | struct fetch_context; |
| 38 | |
| 39 | /* Initialize argument fetching. Returns NULL on failure. RET_INFO |
| 40 | * is the return type of the function. */ |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 41 | struct fetch_context *fetch_arg_init(enum tof type, struct process *proc, |
| Petr Machata | f6ec08a | 2012-01-06 16:58:54 +0100 | [diff] [blame] | 42 | struct arg_type_info *ret_info); |
| 43 | |
| 44 | /* Make a clone of context. */ |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 45 | struct fetch_context *fetch_arg_clone(struct process *proc, |
| Petr Machata | f6ec08a | 2012-01-06 16:58:54 +0100 | [diff] [blame] | 46 | struct fetch_context *context); |
| 47 | |
| 48 | /* Load next argument. The function returns 0 on success or a |
| 49 | * negative value on failure. The extracted value is stored in |
| 50 | * *VALUEP. */ |
| 51 | int fetch_arg_next(struct fetch_context *context, enum tof type, |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 52 | struct process *proc, |
| Petr Machata | f6ec08a | 2012-01-06 16:58:54 +0100 | [diff] [blame] | 53 | struct arg_type_info *info, struct value *valuep); |
| 54 | |
| 55 | /* Load return value. The function returns 0 on success or a negative |
| 56 | * value on failure. The extracted value is stored in *VALUEP. */ |
| 57 | int fetch_retval(struct fetch_context *context, enum tof type, |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 58 | struct process *proc, |
| Petr Machata | f6ec08a | 2012-01-06 16:58:54 +0100 | [diff] [blame] | 59 | struct arg_type_info *info, struct value *valuep); |
| 60 | |
| 61 | /* Destroy fetch context. CONTEXT shall be the same memory location |
| 62 | * that was passed to fetch_arg_next. */ |
| 63 | void fetch_arg_done(struct fetch_context *context); |
| 64 | |
| Petr Machata | e36298a | 2012-09-13 17:12:41 +0200 | [diff] [blame] | 65 | /* Called before fetching arguments that come from parameter packs. |
| 66 | * Returns 0 on success or a negative value on failure. */ |
| 67 | int fetch_param_pack_start(struct fetch_context *context, |
| 68 | enum param_pack_flavor ppflavor); |
| 69 | |
| 70 | /* Called after a parameter pack has been fetched. */ |
| 71 | void fetch_param_pack_end(struct fetch_context *context); |
| 72 | |
| Petr Machata | 311358a | 2012-09-22 15:24:06 +0200 | [diff] [blame] | 73 | |
| 74 | /* The following callbacks have to be implemented in backend if arch.h |
| 75 | * defines ARCH_HAVE_FETCH_ARG. These backend callbacks correspond to |
| 76 | * above functions. */ |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 77 | struct fetch_context *arch_fetch_arg_init(enum tof type, struct process *proc, |
| Petr Machata | 311358a | 2012-09-22 15:24:06 +0200 | [diff] [blame] | 78 | struct arg_type_info *ret_info); |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 79 | struct fetch_context *arch_fetch_arg_clone(struct process *proc, |
| Petr Machata | 311358a | 2012-09-22 15:24:06 +0200 | [diff] [blame] | 80 | struct fetch_context *context); |
| 81 | int arch_fetch_arg_next(struct fetch_context *ctx, enum tof type, |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 82 | struct process *proc, struct arg_type_info *info, |
| Petr Machata | 311358a | 2012-09-22 15:24:06 +0200 | [diff] [blame] | 83 | struct value *valuep); |
| 84 | int arch_fetch_retval(struct fetch_context *ctx, enum tof type, |
| Petr Machata | 929bd57 | 2012-12-17 03:20:34 +0100 | [diff] [blame] | 85 | struct process *proc, struct arg_type_info *info, |
| Petr Machata | 311358a | 2012-09-22 15:24:06 +0200 | [diff] [blame] | 86 | struct value *valuep); |
| 87 | void arch_fetch_arg_done(struct fetch_context *context); |
| 88 | |
| 89 | /* The following callbacks have to be implemented in backend if arch.h |
| 90 | * defines ARCH_HAVE_FETCH_ARG and ARCH_HAVE_FETCH_PACK. */ |
| 91 | int arch_fetch_param_pack_start(struct fetch_context *context, |
| 92 | enum param_pack_flavor ppflavor); |
| 93 | void arch_fetch_param_pack_end(struct fetch_context *context); |
| 94 | |
| Petr Machata | f6ec08a | 2012-01-06 16:58:54 +0100 | [diff] [blame] | 95 | #endif /* FETCH_H */ |