Example #1
1
int main(void) {
  struct __user_cap_header_struct* hdr;
  struct __user_cap_data_struct* data;

  ALLOCATE_GUARD(hdr, 'a');
  hdr->version = 0;
  hdr->pid = 0;
  test_assert(0 == capget(hdr, NULL));
  test_assert(hdr->version > 0);
  VERIFY_GUARD(hdr);

  ALLOCATE_GUARD(hdr, 'a');
  hdr->version = _LINUX_CAPABILITY_VERSION_1;
  hdr->pid = 0;
  ALLOCATE_GUARD(data, 'b');
  test_assert(0 == capget(hdr, data));
  VERIFY_GUARD(hdr);
  VERIFY_GUARD(data);

  ALLOCATE_GUARD(hdr, 'c');
  hdr->version = _LINUX_CAPABILITY_VERSION_3;
  hdr->pid = 0;
  data = allocate_guard(sizeof(*data) * 2, 'd');
  test_assert(0 == capget(hdr, data));
  VERIFY_GUARD(hdr);
  verify_guard(sizeof(*data) * 2, data);

  atomic_puts("EXIT-SUCCESS");
  return 0;
}
Example #2
0
File: sem.c Project: khuey/rr
static int run_child(void) {
  int child2;
  int status;
  struct sembuf ops[2];
  struct timespec ts = { 0, 20000000 };
  struct timespec ts_short = { 0, 10000000 };
  struct timespec ts_long = { 10000, 0 };
  union semun un_arg;
  struct semid_ds* ds;
  struct seminfo* si;
  unsigned short* array;

  ops[0].sem_num = 0;
  ops[0].sem_op = 1;
  ops[0].sem_flg = SEM_UNDO;
  ops[1].sem_num = 1;
  ops[1].sem_op = 1;
  ops[1].sem_flg = SEM_UNDO;
  test_assert(0 == semop(semid, ops, 2));
  *shmem = 0;

  ALLOCATE_GUARD(ds, 'd');
  un_arg.buf = ds;
  test_assert(0 == semctl(semid, 0, IPC_STAT, un_arg));
  VERIFY_GUARD(ds);
  test_assert(ds->sem_perm.mode == 0666);
  test_assert(ds->sem_nsems == COUNT);

  ds->sem_perm.mode = 0660;
  test_assert(0 == semctl(semid, 0, IPC_SET, un_arg));

  ALLOCATE_GUARD(si, 'i');
  un_arg.__buf = si;
  /* The following syscall should always return >= 1, but
     sometimes it returns 0. I don't know why. */
  test_assert(0 <= semctl(semid, 0, IPC_INFO, un_arg));
  VERIFY_GUARD(si);
  test_assert(si->semvmx > 0);
  test_assert(si->semusz < 100000);

  /* The following syscall should always return >= 1, but
     sometimes it returns 0. I don't know why. */
  test_assert(0 <= semctl(semid, 0, SEM_INFO, un_arg));
  VERIFY_GUARD(si);
  test_assert(si->semusz > 0);
  test_assert(si->semusz < 100000);

  array = allocate_guard(COUNT * sizeof(*array), 'a');
  un_arg.array = array;
  test_assert(0 == semctl(semid, 0, GETALL, un_arg));
  verify_guard(COUNT * sizeof(*array), array);
  test_assert(array[0] == 1);
  test_assert(array[1] == 1);
  test_assert(array[2] == 0);
  test_assert(array[3] == 0);

  array[2] = 2;
  test_assert(0 == semctl(semid, 0, SETALL, un_arg));

  test_assert(0 == semctl(semid, 1, GETNCNT, NULL));

  test_assert(getpid() == semctl(semid, 1, GETPID, NULL));

  test_assert(2 == semctl(semid, 2, GETVAL, NULL));

  test_assert(0 == semctl(semid, 0, GETZCNT, NULL));

  un_arg.val = 0;
  test_assert(0 == semctl(semid, 2, SETVAL, un_arg));

  if ((child2 = fork()) == 0) {
    ops[0].sem_op = -1;
    ops[1].sem_op = -1;
    /* The semtimedop timeout is irrelevant. We're just checking that the
       syscall works. */
    test_assert(0 == semtimedop(semid, ops, 2, &ts_long));

    *shmem = 1;

    test_assert(0 == nanosleep(&ts, NULL));

    *shmem = 0;

    ops[0].sem_op = 1;
    ops[1].sem_op = 1;
    test_assert(0 == semtimedop(semid, ops, 2, &ts));

    return 0;
  }

  test_assert(0 == nanosleep(&ts_short, NULL));

  ops[0].sem_op = -1;
  ops[1].sem_op = -1;
  test_assert(0 == semop(semid, ops, 2));

  test_assert(*shmem == 0);

  ops[0].sem_op = 1;
  ops[1].sem_op = 1;
  test_assert(0 == semop(semid, ops, 2));

  test_assert(child2 == waitpid(child2, &status, __WALL));
  test_assert(0 == status);

  return 0;
}