type stringclasses 5
values | content stringlengths 9 163k |
|---|---|
includes | #include <stdio.h> |
includes | #include <string.h> |
includes | #include <inttypes.h> |
includes | #include <sys/mman.h> |
includes | #include <sys/signal.h> |
includes | #include <sys/ucontext.h> |
includes | #include <asm/ldt.h> |
includes | #include <err.h> |
includes | #include <setjmp.h> |
includes | #include <stddef.h> |
includes | #include <stdbool.h> |
includes | #include <sys/ptrace.h> |
includes | #include <sys/user.h> |
defines |
#define _GNU_SOURCE |
defines | #define UC_SIGCONTEXT_SS 0x2 |
defines | #define UC_STRICT_RESTORE_SS 0x4 |
defines | #define LDT_OFFSET 6 |
structs | struct selectors {
unsigned short cs, gs, fs, ss;
}; |
functions | short GDT3(int idx)
{
return (idx << 3) | 3;
} |
functions | short LDT3(int idx)
{
return (idx << 3) | 7;
} |
functions | void clearhandler(int sig)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sigemptyset(&sa.sa_mask);
if (sigaction(sig, &sa, 0))
err(1, "sigaction");
} |
functions | void add_ldt(const struct user_desc *desc, unsigned short *var,
const char *name)
{
if (syscall(SYS_modify_ldt, 1, desc, sizeof(*desc)) == 0) {
*var = LDT3(desc->entry_number);
} |
functions | void setup_ldt(void)
{
if ((unsigned long)stack16 > (1ULL << 32) - sizeof(stack16))
errx(1, "stack16 is too high\n");
if ((unsigned long)int3 > (1ULL << 32) - sizeof(int3))
errx(1, "int3 is too high\n");
ldt_nonexistent_sel = LDT3(LDT_OFFSET + 2);
const struct user_desc code16_desc = {
.entry_number = LD... |
functions | int cs_bitness(unsigned short cs)
{
uint32_t valid = 0, ar;
asm ("lar %[cs], %[ar]\n\t"
"jnz 1f\n\t"
"mov $1, %[valid]\n\t"
"1:"
: [ar] "=r" (ar), [valid] "+rm" (valid)
: [cs] "r" (cs));
if (!valid)
return -1;
bool db = (ar & (1 << 22));
bool l = (ar & (1 << 21));
if (!(ar & (1<... |
functions | bool is_valid_ss(unsigned short cs)
{
uint32_t valid = 0, ar;
asm ("lar %[cs], %[ar]\n\t"
"jnz 1f\n\t"
"mov $1, %[valid]\n\t"
"1:"
: [ar] "=r" (ar), [valid] "+rm" (valid)
: [cs] "r" (cs));
if (!valid)
return false;
if ((ar & AR_TYPE_MASK) != AR_TYPE_RWDATA &&
(ar & AR_TYPE_MAS... |
functions | void validate_signal_ss(int sig, ucontext_t *ctx)
{
#ifdef __x86_64__
bool was_64bit = (cs_bitness(*csptr(ctx)) == 64);
if (!(ctx->uc_flags & UC_SIGCONTEXT_SS)) {
printf("[FAIL]\tUC_SIGCONTEXT_SS was not set\n");
nerrs++;
/*
* This happens on Linux 4.1. The rest will fail, too, so
* return now to reduc... |
functions | void sigusr1(int sig, siginfo_t *info, void *ctx_void)
{
ucontext_t *ctx = (ucontext_t*)ctx_void;
validate_signal_ss(sig, ctx);
memcpy(&initial_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t));
*csptr(ctx) = sig_cs;
*ssptr(ctx) = sig_ss;
ctx->uc_mcontext.gregs[REG_IP] =
sig_cs == code16_sel ? 0 : (unsigned... |
functions | void sigtrap(int sig, siginfo_t *info, void *ctx_void)
{
ucontext_t *ctx = (ucontext_t*)ctx_void;
validate_signal_ss(sig, ctx);
sig_err = ctx->uc_mcontext.gregs[REG_ERR];
sig_trapno = ctx->uc_mcontext.gregs[REG_TRAPNO];
unsigned short ss;
asm ("mov %%ss,%0" : "=r" (ss));
greg_t asm_ss = ctx->uc_mcontext.greg... |
functions | __x86_64__
if (sig_corrupt_final_ss) {
if (ctx->uc_flags & UC_STRICT_RESTORE_SS) {
printf("[FAIL]\tUC_STRICT_RESTORE_SS was set inappropriately\n");
nerrs++;
} |
functions | void sigusr2(int sig, siginfo_t *info, void *ctx_void)
{
ucontext_t *ctx = (ucontext_t*)ctx_void;
if (!(ctx->uc_flags & UC_STRICT_RESTORE_SS)) {
printf("[FAIL]\traise(2) didn't set UC_STRICT_RESTORE_SS\n");
nerrs++;
return; /* We can't do the rest. */
} |
functions | int test_nonstrict_ss(void)
{
clearhandler(SIGUSR1);
clearhandler(SIGTRAP);
clearhandler(SIGSEGV);
clearhandler(SIGILL);
sethandler(SIGUSR2, sigusr2, 0);
nerrs = 0;
printf("[RUN]\tClear UC_STRICT_RESTORE_SS and corrupt SS\n");
raise(SIGUSR2);
if (!nerrs)
printf("[OK]\tIt worked\n");
return nerrs;
} |
functions | int find_cs(int bitness)
{
unsigned short my_cs;
asm ("mov %%cs,%0" : "=r" (my_cs));
if (cs_bitness(my_cs) == bitness)
return my_cs;
if (cs_bitness(my_cs + (2 << 3)) == bitness)
return my_cs + (2 << 3);
if (my_cs > (2<<3) && cs_bitness(my_cs - (2 << 3)) == bitness)
return my_cs - (2 << 3);
if (cs_bitn... |
functions | int test_valid_sigreturn(int cs_bits, bool use_16bit_ss, int force_ss)
{
int cs = find_cs(cs_bits);
if (cs == -1) {
printf("[SKIP]\tCode segment unavailable for %d-bit CS, %d-bit SS\n",
cs_bits, use_16bit_ss ? 16 : 32);
return 0;
} |
functions | else
if (i == REG_CSGSFS) {
struct selectors *req_sels =
(void *)&requested_regs[REG_CSGSFS];
struct selectors *res_sels =
(void *)&resulting_regs[REG_CSGSFS];
if (req_sels->cs != res_sels->cs) {
printf("[FAIL]\tCS mismatch: requested 0x%hx; got 0x%hx\n",
req_sels->cs, res_sels->cs);
... |
functions | int test_bad_iret(int cs_bits, unsigned short ss, int force_cs)
{
int cs = force_cs == -1 ? find_cs(cs_bits) : force_cs;
if (cs == -1)
return 0;
sig_cs = cs;
sig_ss = ss;
printf("[RUN]\t%d-bit CS (%hx), bogus SS (%hx)\n",
cs_bits, sig_cs, sig_ss);
sig_trapped = 0;
raise(SIGUSR1);
if (sig_trapped) {... |
main | int main()
{
int total_nerrs = 0;
unsigned short my_cs, my_ss;
asm volatile ("mov %%cs,%0" : "=r" (my_cs));
asm volatile ("mov %%ss,%0" : "=r" (my_ss));
setup_ldt();
stack_t stack = {
.ss_sp = altstack_data,
.ss_size = SIGSTKSZ,
} |
includes | #include <linux/module.h> |
includes | #include <linux/kernel.h> |
includes | #include <linux/errno.h> |
includes | #include <linux/init.h> |
includes | #include <linux/wait.h> |
includes | #include <linux/spinlock.h> |
includes | #include <linux/mtio.h> |
includes | #include <linux/device.h> |
includes | #include <linux/dma-mapping.h> |
includes | #include <linux/fs.h> |
includes | #include <linux/cdev.h> |
includes | #include <linux/major.h> |
includes | #include <linux/completion.h> |
includes | #include <linux/proc_fs.h> |
includes | #include <linux/seq_file.h> |
includes | #include <linux/smp_lock.h> |
includes | #include <linux/slab.h> |
includes |
#include <asm/uaccess.h> |
includes | #include <asm/ioctls.h> |
includes | #include <asm/firmware.h> |
includes | #include <asm/vio.h> |
includes | #include <asm/iseries/vio.h> |
includes | #include <asm/iseries/hv_lp_event.h> |
includes | #include <asm/iseries/hv_call_event.h> |
includes | #include <asm/iseries/hv_lp_config.h> |
defines |
#define VIOTAPE_VERSION "1.2" |
defines | #define VIOTAPE_MAXREQ 1 |
defines |
#define VIOTAPE_KERN_WARN KERN_WARNING "viotape: " |
defines | #define VIOTAPE_KERN_INFO KERN_INFO "viotape: " |
defines |
#define VIOTAPOP_RESET 0 |
defines | #define VIOTAPOP_FSF 1 |
defines | #define VIOTAPOP_BSF 2 |
defines | #define VIOTAPOP_FSR 3 |
defines | #define VIOTAPOP_BSR 4 |
defines | #define VIOTAPOP_WEOF 5 |
defines | #define VIOTAPOP_REW 6 |
defines | #define VIOTAPOP_NOP 7 |
defines | #define VIOTAPOP_EOM 8 |
defines | #define VIOTAPOP_ERASE 9 |
defines | #define VIOTAPOP_SETBLK 10 |
defines | #define VIOTAPOP_SETDENSITY 11 |
defines | #define VIOTAPOP_SETPOS 12 |
defines | #define VIOTAPOP_GETPOS 13 |
defines | #define VIOTAPOP_SETPART 14 |
defines | #define VIOTAPOP_UNLOAD 15 |
defines | #define VIOTAPE_MAX_TAPE HVMAXARCHITECTEDVIRTUALTAPES |
defines | #define MAX_PARTITIONS 4 |
defines | #define VIOT_IDLE 0 |
defines | #define VIOT_READING 1 |
defines | #define VIOT_WRITING 2 |
structs | struct viot_devinfo_struct {
int devno;
int mode;
int rewind;
}; |
structs | struct op_struct {
void *buffer;
dma_addr_t dmaaddr;
size_t count;
int rc;
int non_blocking;
struct completion com;
struct device *dev;
struct op_struct *next;
}; |
functions | int proc_viotape_show(struct seq_file *m, void *v)
{
int i;
seq_printf(m, "viotape driver version " VIOTAPE_VERSION "\n");
for (i = 0; i < viotape_numdev; i++) {
seq_printf(m, "viotape device %d is iSeries resource %10.10s"
"type %4.4s, model %3.3s\n",
i, viotape_unitinfo[i].rsrcname,
viotape_unitinfo... |
functions | int proc_viotape_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_viotape_show, NULL);
} |
functions | void get_dev_info(struct inode *ino, struct viot_devinfo_struct *devi)
{
devi->devno = iminor(ino) & 0x1F;
devi->mode = (iminor(ino) & 0x60) >> 5;
/* if bit is set in the minor, do _not_ rewind automatically */
devi->rewind = (iminor(ino) & 0x80) == 0;
} |
functions | void clear_op_struct_pool(void)
{
while (op_struct_list) {
struct op_struct *toFree = op_struct_list;
op_struct_list = op_struct_list->next;
kfree(toFree);
} |
functions | int add_op_structs(int structs)
{
int i;
for (i = 0; i < structs; ++i) {
struct op_struct *new_struct =
kmalloc(sizeof(*new_struct), GFP_KERNEL);
if (!new_struct) {
clear_op_struct_pool();
return -ENOMEM;
} |
functions | void free_op_struct(struct op_struct *op_struct)
{
unsigned long flags;
spin_lock_irqsave(&op_struct_list_lock, flags);
op_struct->next = op_struct_list;
op_struct_list = op_struct;
spin_unlock_irqrestore(&op_struct_list_lock, flags);
} |
functions | int tape_rc_to_errno(int tape_rc, char *operation, int tapeno)
{
const struct vio_error_entry *err;
if (tape_rc == 0)
return 0;
err = vio_lookup_rc(viotape_err_table, tape_rc);
printk(VIOTAPE_KERN_WARN "error(%s) 0x%04x on Device %d (%-10s): %s\n",
operation, tape_rc, tapeno,
viotape_unitinfo[tapeno].rsrc... |
functions | ssize_t viotap_write(struct file *file, const char *buf,
size_t count, loff_t * ppos)
{
HvLpEvent_Rc hvrc;
unsigned short flags = file->f_flags;
int noblock = ((flags & O_NONBLOCK) != 0);
ssize_t ret;
struct viot_devinfo_struct devi;
struct op_struct *op = get_op_struct();
if (op == NULL)
return -ENOMEM;
... |
functions | ssize_t viotap_read(struct file *file, char *buf, size_t count,
loff_t *ptr)
{
HvLpEvent_Rc hvrc;
unsigned short flags = file->f_flags;
struct op_struct *op = get_op_struct();
int noblock = ((flags & O_NONBLOCK) != 0);
ssize_t ret;
struct viot_devinfo_struct devi;
if (op == NULL)
return -ENOMEM;
get_dev_i... |
functions | int viotap_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
HvLpEvent_Rc hvrc;
int ret;
struct viot_devinfo_struct devi;
struct mtop mtc;
u32 myOp;
struct op_struct *op = get_op_struct();
if (op == NULL)
return -ENOMEM;
get_dev_info(file->f_path.dentry->d_inode, &devi);... |
functions | long viotap_unlocked_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
long rc;
lock_kernel();
rc = viotap_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
unlock_kernel();
return rc;
} |
functions | int viotap_open(struct inode *inode, struct file *file)
{
HvLpEvent_Rc hvrc;
struct viot_devinfo_struct devi;
int ret;
struct op_struct *op = get_op_struct();
if (op == NULL)
return -ENOMEM;
lock_kernel();
get_dev_info(file->f_path.dentry->d_inode, &devi);
/* Note: We currently only support one mode! */
i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.