cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

mode_t.c (1538B)


      1// SPDX-License-Identifier: LGPL-2.1
      2#include <sys/types.h>
      3#include <sys/stat.h>
      4#include <unistd.h>
      5
      6/* From include/linux/stat.h */
      7#ifndef S_IRWXUGO
      8#define S_IRWXUGO	(S_IRWXU|S_IRWXG|S_IRWXO)
      9#endif
     10#ifndef S_IALLUGO
     11#define S_IALLUGO	(S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
     12#endif
     13#ifndef S_IRUGO
     14#define S_IRUGO         (S_IRUSR|S_IRGRP|S_IROTH)
     15#endif
     16#ifndef S_IWUGO
     17#define S_IWUGO         (S_IWUSR|S_IWGRP|S_IWOTH)
     18#endif
     19#ifndef S_IXUGO
     20#define S_IXUGO         (S_IXUSR|S_IXGRP|S_IXOTH)
     21#endif
     22
     23static size_t syscall_arg__scnprintf_mode_t(char *bf, size_t size, struct syscall_arg *arg)
     24{
     25	bool show_prefix = arg->show_string_prefix;
     26	const char *prefix = "S_";
     27	int printed = 0, mode = arg->val;
     28
     29#define	P_MODE(n) \
     30	if ((mode & S_##n) == S_##n) { \
     31		printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
     32		mode &= ~S_##n; \
     33	}
     34
     35	P_MODE(IALLUGO);
     36	P_MODE(IRWXUGO);
     37	P_MODE(IRUGO);
     38	P_MODE(IWUGO);
     39	P_MODE(IXUGO);
     40	P_MODE(IFMT);
     41	P_MODE(IFSOCK);
     42	P_MODE(IFLNK);
     43	P_MODE(IFREG);
     44	P_MODE(IFBLK);
     45	P_MODE(IFDIR);
     46	P_MODE(IFCHR);
     47	P_MODE(IFIFO);
     48	P_MODE(ISUID);
     49	P_MODE(ISGID);
     50	P_MODE(ISVTX);
     51	P_MODE(IRWXU);
     52	P_MODE(IRUSR);
     53	P_MODE(IWUSR);
     54	P_MODE(IXUSR);
     55	P_MODE(IRWXG);
     56	P_MODE(IRGRP);
     57	P_MODE(IWGRP);
     58	P_MODE(IXGRP);
     59	P_MODE(IRWXO);
     60	P_MODE(IROTH);
     61	P_MODE(IWOTH);
     62	P_MODE(IXOTH);
     63#undef P_MODE
     64
     65	if (mode)
     66		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", mode);
     67
     68	return printed;
     69}
     70
     71#define SCA_MODE_T syscall_arg__scnprintf_mode_t