Pass tcp argument to get_optmem_max/read_int_from_file

In preparation to passing tcp to all tracee-related syscalls.

* defs.h (read_int_from_file): Add "struct tcb *" as the first argument.
* util.c (read_int_from_file): Likewise.
* msghdr.c (get_optmem_max): Add "struct tcb *tcp" as the first
argument, pass it to read_int_from_file call.
(decode_msg_control): Pass tcp to get_optmem_max.
This commit is contained in:
Eugene Syromiatnikov 2017-12-25 23:55:22 +01:00 committed by Dmitry V. Levin
parent cc057e03ae
commit bf2e6250bb
3 changed files with 6 additions and 6 deletions

2
defs.h
View File

@ -383,7 +383,7 @@ extern unsigned os_release;
#undef KERNEL_VERSION
#define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
extern int read_int_from_file(const char *, int *);
extern int read_int_from_file(struct tcb *, const char *, int *);
extern void set_sortby(const char *);
extern void set_overhead(int);

View File

@ -262,12 +262,12 @@ print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
}
static unsigned int
get_optmem_max(void)
get_optmem_max(struct tcb *tcp)
{
static int optmem_max;
if (!optmem_max) {
if (read_int_from_file("/proc/sys/net/core/optmem_max",
if (read_int_from_file(tcp, "/proc/sys/net/core/optmem_max",
&optmem_max) || optmem_max <= 0) {
optmem_max = sizeof(long long) * (2 * IOV_MAX + 512);
} else {
@ -293,8 +293,8 @@ decode_msg_control(struct tcb *const tcp, const kernel_ulong_t addr,
#endif
sizeof(struct cmsghdr);
unsigned int control_len = in_control_len > get_optmem_max()
? get_optmem_max() : in_control_len;
unsigned int control_len = in_control_len > get_optmem_max(tcp)
? get_optmem_max(tcp) : in_control_len;
unsigned int buf_len = control_len;
char *buf = buf_len < cmsg_size ? NULL : malloc(buf_len);
if (!buf || umoven(tcp, addr, buf_len, buf) < 0) {

2
util.c
View File

@ -1076,7 +1076,7 @@ print_abnormal_hi(const kernel_ulong_t val)
#endif
int
read_int_from_file(const char *const fname, int *const pvalue)
read_int_from_file(struct tcb *tcp, const char *const fname, int *const pvalue)
{
const int fd = open_file(fname, O_RDONLY);
if (fd < 0)