Skip to content

Commit fde753c

Browse files
committed
tetragon: Move argument reading code to __read_arg
Move argument reading code to separate __read_arg function to ease up following changes. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 06ee28b commit fde753c

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

bpf/process/generic_calls.h

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -190,47 +190,17 @@ copy_iov_iter(void *ctx, long off, unsigned long arg, int argm, struct msg_gener
190190
#define copy_iov_iter(ctx, orig_off, arg, argm, e) 0
191191
#endif /* __LARGE_BPF_PROG */
192192

193-
/**
194-
* Read a generic argument
195-
*
196-
* @args: destination buffer for the generic argument
197-
* @type: type of the argument
198-
* @off: offset of the argument within @args
199-
* @arg: argument location (generally, address of the argument)
200-
* @argm: argument metadata. The meaning of this depends on the @type. Some
201-
* types use a -1 to designate saving @arg into the retprobe map
202-
* @filter_map:
203-
*
204-
* Returns the size of data appended to @args.
205-
*/
206193
FUNC_INLINE long
207-
read_arg(void *ctx, int index, int type, long orig_off, unsigned long arg, int argm)
194+
__read_arg(void *ctx, int type, long orig_off, unsigned long arg, int argm, char *args)
208195
{
209-
size_t min_size = type_to_min_size(type, argm);
210196
struct msg_generic_kprobe *e;
211-
char *args;
212197
long size = -1;
213-
const struct path *path_arg = 0;
214-
struct path path_buf;
215198
int zero = 0;
216199

217200
e = map_lookup_elem(&process_call_heap, &zero);
218201
if (!e)
219202
return 0;
220203

221-
if (orig_off >= 16383 - min_size)
222-
return 0;
223-
224-
orig_off &= 16383;
225-
args = args_off(e, orig_off);
226-
227-
/* Cache args offset for filter use later */
228-
e->argsoff[index & MAX_SELECTORS_MASK] = orig_off;
229-
230-
path_arg = get_path(type, arg, &path_buf);
231-
if (path_arg)
232-
return copy_path(args, path_arg);
233-
234204
switch (type) {
235205
case iov_iter_type:
236206
size = copy_iov_iter(ctx, orig_off, arg, argm, e);
@@ -392,6 +362,49 @@ read_arg(void *ctx, int index, int type, long orig_off, unsigned long arg, int a
392362
return size;
393363
}
394364

365+
/**
366+
* Read a generic argument
367+
*
368+
* @args: destination buffer for the generic argument
369+
* @type: type of the argument
370+
* @off: offset of the argument within @args
371+
* @arg: argument location (generally, address of the argument)
372+
* @argm: argument metadata. The meaning of this depends on the @type. Some
373+
* types use a -1 to designate saving @arg into the retprobe map
374+
* @filter_map:
375+
*
376+
* Returns the size of data appended to @args.
377+
*/
378+
FUNC_INLINE long
379+
read_arg(void *ctx, int index, int type, long orig_off, unsigned long arg, int argm)
380+
{
381+
size_t min_size = type_to_min_size(type, argm);
382+
struct msg_generic_kprobe *e;
383+
char *args;
384+
const struct path *path_arg = 0;
385+
struct path path_buf;
386+
int zero = 0;
387+
388+
e = map_lookup_elem(&process_call_heap, &zero);
389+
if (!e)
390+
return 0;
391+
392+
if (orig_off >= 16383 - min_size)
393+
return 0;
394+
395+
orig_off &= 16383;
396+
args = args_off(e, orig_off);
397+
398+
/* Cache args offset for filter use later */
399+
e->argsoff[index & MAX_SELECTORS_MASK] = orig_off;
400+
401+
path_arg = get_path(type, arg, &path_buf);
402+
if (path_arg)
403+
return copy_path(args, path_arg);
404+
405+
return __read_arg(ctx, type, orig_off, arg, argm, args);
406+
}
407+
395408
FUNC_INLINE int
396409
extract_arg_depth(u32 i, struct extract_arg_data *data)
397410
{

0 commit comments

Comments
 (0)