Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Linux/tools/testing/selftests/bpf/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 2 kB image not shown  

Quelle  urandom_read.c   Sprache: C

 
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>

#define _SDT_HAS_SEMAPHORES 1
#include "sdt.h"

#define SHARED 1
#include "bpf/libbpf_internal.h"

#define SEC(name) __attribute__((section(name), used))

#define BUF_SIZE 256

/* defined in urandom_read_aux.c */
void urand_read_without_sema(int iter_num, int iter_cnt, int read_sz);
/* these are coming from urandom_read_lib{1,2}.c */
void urandlib_read_with_sema(int iter_num, int iter_cnt, int read_sz);
void urandlib_read_without_sema(int iter_num, int iter_cnt, int read_sz);

int urandlib_api(void);
COMPAT_VERSION(urandlib_api_old, urandlib_api, LIBURANDOM_READ_1.0.0)
int urandlib_api_old(void);
int urandlib_api_sameoffset(void);

unsigned short urand_read_with_sema_semaphore SEC(".probes");

static noinline void urandom_read(int fd, int count)
{
 char buf[BUF_SIZE];
 int i;

 for (i = 0; i < count; ++i) {
  read(fd, buf, BUF_SIZE);

  /* trigger USDTs defined in executable itself */
  urand_read_without_sema(i, count, BUF_SIZE);
  STAP_PROBE3(urand, read_with_sema, i, count, BUF_SIZE);

  /* trigger USDTs defined in shared lib */
  urandlib_read_without_sema(i, count, BUF_SIZE);
  urandlib_read_with_sema(i, count, BUF_SIZE);
 }
}

static volatile bool parent_ready;

static void handle_sigpipe(int sig)
{
 parent_ready = true;
}

int main(int argc, char *argv[])
{
 int fd = open("/dev/urandom", O_RDONLY);
 int count = 4;
 bool report_pid = false;

 if (fd < 0)
  return 1;

 if (argc >= 2)
  count = atoi(argv[1]);
 if (argc >= 3) {
  report_pid = true;
  /* install SIGPIPE handler to catch when parent closes their
 * end of the pipe (on the other side of our stdout)
 */

  signal(SIGPIPE, handle_sigpipe);
 }

 /* report PID and wait for parent process to send us "signal" by
 * closing stdout
 */

 if (report_pid) {
  while (!parent_ready) {
   fprintf(stdout, "%d\n", getpid());
   fflush(stdout);
  }
  /* at this point stdout is closed, parent process knows our
 * PID and is ready to trace us
 */

 }

 urandom_read(fd, count);

 urandlib_api();
 urandlib_api_old();
 urandlib_api_sameoffset();

 close(fd);
 return 0;
}

Messung V0.5
C=94 H=92 G=92

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.