file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/81734.c | #include <stdint.h>
static __attribute__((always_inline)) inline void arch_mmio_write(uint32_t address, uint32_t data)
{
uint32_t *ptr = (uint32_t *)address;
asm volatile("str %[data], [%[address]]"
:
: [address] "r"(ptr), [data] "r"(data));
}
static __attribute__((always_inline)) inline uint32_t arch_mmio_read(uint32_t address)
{
uint32_t *ptr = (uint32_t *)address;
uint32_t data;
asm volatile("ldr %[data], [%[address]]"
: [data] "=r"(data)
: [address] "r"(ptr));
return data;
} |
the_stack_data/427112.c | /* Based on the following from Beej's socket tutorial:
** client.c -- a stream socket client demo
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
int main(int argc, char *argv[])
{
int sockfd, numbytes;
char *inbuf, *outbuf, *hostname, *port;
struct addrinfo hints, *servinfo, *p;
int rv, numThreads, numRequests, i, j, dataLength, status, combined = 0;
char s[INET6_ADDRSTRLEN];
if (argc != 6) {
fprintf(stderr,"usage: %s <hostname> <port> <numThreads> <numRequests> <dataLength>\n", argv[0]);
return 1;
}
hostname = argv[1];
port = argv[2];
numThreads = atoi(argv[3]);
numRequests = atoi(argv[4]);
dataLength = atoi(argv[5]);
inbuf = malloc(dataLength);
outbuf = malloc(dataLength);
for (i = 0; i < numThreads; ++i) {
if (!fork()) {
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if ((rv = getaddrinfo(hostname, port, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
// loop through all the results and connect to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype,
p->ai_protocol)) == -1) {
perror("client: socket");
continue;
}
if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
perror("client: connect");
continue;
}
break;
}
if (p == NULL) {
fprintf(stderr, "client: failed to connect\n");
return 2;
}
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
s, sizeof s);
freeaddrinfo(servinfo); // all done with this structure
srand(getpid() * time(NULL));
for (j = 0; j < numRequests; ++j) {
for (i = 0; i < dataLength; ++i)
outbuf[i] = rand();
// Initialize random data
for (i = 0; i < dataLength; ) {
numbytes = write(sockfd, outbuf + i, dataLength - i);
if (numbytes <= 0) {
perror("write");
return 1;
}
i += numbytes;
}
for (i = 0; i < dataLength; ) {
numbytes = read(sockfd, inbuf + i, dataLength - i);
if (numbytes <= 0) {
perror("read");
return 1;
}
i += numbytes;
}
if (memcmp(inbuf, outbuf, dataLength)) {
fprintf(stderr, "Wrong data echoed back!\n");
for (i = 0; i < dataLength; ++i) {
if (inbuf[i] != outbuf[i]) {
fprintf(stderr, "First mismatch: %d -> %d, %d\n", i, inbuf[i], outbuf[i]);
break;
}
}
return 1;
}
}
close(sockfd);
return 0;
}
}
for (i = 0; i < numThreads; ++i) {
wait(&status);
combined = combined || status;
}
if (combined)
fprintf(stderr, "At least one child failed!\n");
return combined;
}
|
the_stack_data/9514008.c | #include <stdio.h>
int fib(int n)
{
int k = 100, p=9, q=4;
if (n == 0 || n == 1)
{
return n;
}
return fib(n - 1) + fib(n - 2);
}
int main(void)
{
int a;
scanf("%d", &a);
int fib_number = fib(a);
printf("fib number is %d", fib_number);
return 0;
}
|
the_stack_data/126702259.c | /*
Practica 8: Ultimo caracter del ultimo argumento
Autor: Espinosa Curiel Oscar
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char ** argv){
printf("%c\n", *(*(argv + argc - 1) + strlen(*(argv + argc - 1)) - 1));
return 0;
} |
the_stack_data/168894372.c | /*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* %sccs.include.redist.c%
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)setgid.c 5.4 (Berkeley) 06/01/90";
#endif /* LIBC_SCCS and not lint */
/*
* Backwards compatible setgid.
*/
setgid(gid)
int gid;
{
return (setregid(gid, gid));
}
|
the_stack_data/706977.c | #include <stdio.h>
int factorial(int f)
{
if( f == 1 )
return(f);
return( f * factorial( f-1 ) );
}
int main()
{
int a,b;
printf("Enter a positive value: ");
scanf("%d",&a);
if( a < 1 )
{
printf("%d is not a positive value\n",a);
return(1);
}
b = factorial(a);
printf("The factoral of %d! is %d\n",a,b);
return(0);
}
|
the_stack_data/61272.c | // SPDX-License-Identifier: MIT
/* Extending functionality of the string.h standard library. */
#include <stdlib.h>
#include <string.h>
/* Append SRC onto DEST, using reallocation. */
char *strapp(char **__dest, const char *__src)
{
char *__new = (char *)malloc(
(strlen(*__dest) + strlen(__src)) * sizeof(char) + 1);
if (!__new)
return NULL; /* Memory allocation failed. */
strcpy(__new, *__dest);
strcat(__new, __src);
free(*__dest);
*__dest = __new;
return *__dest;
}
/* Create a new dynamic string. */
char *strnew()
{
char *__new = (char *)malloc(sizeof(char));
if (!__new)
return NULL; /* Memory allocation failed. */
memset(__new, 0, 1);
return __new;
}
/* Check whether the PRE is a prefix of STR. */
int strprefix(const char *__pre, const char *__str)
{
return strncmp(__pre, __str, strlen(__pre)) == 0;
}
|
the_stack_data/187643013.c | #include<stdio.h>
int main(int argc, char **argv) {
printf("I should not be run ever.\n");
return 1;
}
|
the_stack_data/46534.c | #include <stdio.h>
#define true 1
#define false 0
long int primos[500];
int primov(long int n)
{
primos[0] = 2;
int k = 0, primo;
for (long int i = 3; (primos[k] * primos[k]) <= n; i += 2)
{
primo = true;
for (int j = 0; (j <= k) && (primo == true); j++)
{
if ((i % primos[j]) == 0)
{
primo = false;
}
}
if (primo == true)
{
primos[k + 1] = i;
k++;
}
//printf("%i %li\n", k, primos[k]);
}
return k;
}
int busca(long int n, int k)
{
for (int j = 0; (j <= k) && ((primos[j] * primos[j]) <= n); j++)
{
if ((n % primos[j]) == 0)
{
printf("composto\n");
return 0;
}
}
printf("primo\n");
return 0;
}
int main()
{
long int num[100000], maior;
int n, k;
scanf("%i", &n);
for (int i = 0; i < n; i++)
{
scanf("%li", &num[i]);
if (i == 0)
{
maior = num[i];
}
else if (num[i] > maior)
{
maior = num[i];
}
}
k = primov(maior);
for (int i = 0; i < n; i++)
{
if (num[i] == 1)
{
printf("composto\n");
}
else if (num[i] == 2)
{
printf("primo\n");
}
else
{
busca(num[i], k);
}
}
/*for (int i = 0; i <= k; i++)
{
printf("%li ", primos[i]);
}
printf("\n%i\n", k);*/
return 0;
} |
the_stack_data/22012662.c | #include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
struct numbers
{
int a, b;
} numbers;
void *sum(void *args)
{
struct numbers *numbers = (struct numbers *)args;
int a = numbers->a;
int b = numbers->b;
void *res = malloc(sizeof(int));
*(int *)res = a + b;
return res;
}
void *subtract(void *args)
{
struct numbers *numbers = (struct numbers *)args;
int a = numbers->a;
int b = numbers->b;
void *res = malloc(sizeof(int));
*(int *)res = a - b;
return res;
}
void *multiply(void *args)
{
struct numbers *numbers = (struct numbers *)args;
int a = numbers->a;
int b = numbers->b;
void *res = malloc(sizeof(int));
*(int *)res = a * b;
return res;
}
void *divide(void *args)
{
struct numbers *numbers = (struct numbers *)args;
int a = numbers->a;
int b = numbers->b;
void *res = malloc(sizeof(int));
*(int *)res = a / b;
return res;
}
int main()
{
pthread_t threads[4];
struct numbers numbers;
void *res[4];
printf("The numbers pretty please (a b) ");
scanf("%d %d", &(numbers.a), &(numbers.b));
pthread_create(&threads[0], NULL, sum, &numbers);
pthread_create(&threads[1], NULL, subtract, &numbers);
pthread_create(&threads[2], NULL, multiply, &numbers);
pthread_create(&threads[3], NULL, divide, &numbers);
pthread_join(threads[0], &res[0]);
printf("%d + %d = %d\n", numbers.a, numbers.b, *(int *)(res[0]));
free(res[0]);
pthread_join(threads[1], &res[1]);
printf("%d - %d = %d\n", numbers.a, numbers.b, *(int *)(res[1]));
free(res[1]);
pthread_join(threads[2], &res[2]);
printf("%d * %d = %d\n", numbers.a, numbers.b, *(int *)(res[2]));
free(res[2]);
pthread_join(threads[3], &res[3]);
printf("%d / %d = %d\n", numbers.a, numbers.b, *(int *)(res[3]));
free(res[3]);
exit(0);
} |
the_stack_data/128959.c | /*
* This file is part of mipOS
* Copyright (c) Antonino Calderone ([email protected])
* All rights reserved.
* Licensed under the MIT License.
* See COPYING file in the project root for full license information.
*/
/* -------------------------------------------------------------------------- */
#ifdef ENABLE_MIPOS_FS
/* -------------------------------------------------------------------------- */
#include "mipos_fs.h"
/* -------------------------------------------------------------------------- */
static unsigned int mipos_fs_last_error_code_t = 0;
/* -------------------------------------------------------------------------- */
#define mipos_fs_FREE_CLUSTER 0xFFFF
#define mipos_fs_LAST_ALLOCATED_CLUSTER 0xFFFD
#define mipos_fs_RESERVED_CLUSTER 0xFFFC
#define mipos_fs_EMPTY_CLUSTER 0xFFFB
#define mipos_fs_INVALID_FILE_HANDLE 0xFFFF
/* -------------------------------------------------------------------------- */
void mipos_fs_lock_access(mipos_fs_t* fs_ptr)
{
mipos_mu_lock(&fs_ptr->lock);
}
/* -------------------------------------------------------------------------- */
void mipos_fs_unlock_access(mipos_fs_t* fs_ptr)
{
mipos_mu_unlock(&fs_ptr->lock);
}
/* -------------------------------------------------------------------------- */
void mipos_fs_call_os_scheduler(void)
{
mipos_tm_wkafter(0);
}
/* -------------------------------------------------------------------------- */
/* PRIVATE FUNCTIONS */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static
int mipos_update_fs_on_disk(mipos_fs_t* fs_ptr)
{
return fs_ptr->io_dev.io_write(
(const char*)&fs_ptr->ftbl,
sizeof(mipos_fs_ftbl_t),
mipos_fs_OFFSET);
}
/* -------------------------------------------------------------------------- */
static
mipos_fs_cluster_t mipos_fs_get_cluster_val(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t current
)
{
mipos_fs_cluster_t cluster_value;
// Get a cluster value from the cluster table
mipos_fs_lock_access(fs_ptr);
cluster_value = MIPOS_LE_U16(fs_ptr->ftbl.cluster_tbl[current]);
mipos_fs_unlock_access(fs_ptr);
return cluster_value;
}
/* -------------------------------------------------------------------------- */
static
void set_cluster_val(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t current,
mipos_fs_cluster_t cluster_value
)
{
// Set a cluster value in the cluster table
mipos_fs_lock_access(fs_ptr);
fs_ptr->ftbl.cluster_tbl[current] = MIPOS_LE_U16(cluster_value);
mipos_fs_unlock_access(fs_ptr);
}
/* -------------------------------------------------------------------------- */
static
bool_t reserve_cluster(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t* free_cluster
)
{
mipos_fs_cluster_t i = 0;
bool_t ret_val = FALSE;
// Search a free cluster and reserve it
mipos_fs_lock_access(fs_ptr);
for (i = 0; i < mipos_fs_CLUSTERS_COUNT; ++i) {
mipos_fs_call_os_scheduler();
if (MIPOS_LE_U16(fs_ptr->ftbl.cluster_tbl[i]) == mipos_fs_FREE_CLUSTER) {
MIPOS_LE_U16(fs_ptr->ftbl.cluster_tbl[i]) = mipos_fs_RESERVED_CLUSTER;
*free_cluster = MIPOS_LE_U16(i);
ret_val = TRUE;
break;
}
}
mipos_fs_unlock_access(fs_ptr);
return ret_val;
}
/* -------------------------------------------------------------------------- */
static
bool_t get_next_cluster(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t current,
mipos_fs_cluster_t* next_cluster
)
{
mipos_fs_cluster_t ret_val;
if (current >= mipos_fs_CLUSTERS_COUNT) {
return FALSE;
}
// Get the linked cluster to the "current" one
ret_val = mipos_fs_get_cluster_val(fs_ptr, current);
if (ret_val >= mipos_fs_CLUSTERS_COUNT) {
return FALSE;
}
*next_cluster = ret_val;
return TRUE;
}
/* -------------------------------------------------------------------------- */
static
bool_t link_cluster(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t current,
mipos_fs_cluster_t link_to
)
{
if ((current >= mipos_fs_CLUSTERS_COUNT) ||
(link_to >= mipos_fs_CLUSTERS_COUNT))
{
return FALSE;
}
set_cluster_val(fs_ptr,
current,
link_to);
return TRUE;
}
/* -------------------------------------------------------------------------- */
static
void mark_cluster_last(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t cluster
)
{
set_cluster_val(fs_ptr,
cluster,
mipos_fs_LAST_ALLOCATED_CLUSTER);
}
/* -------------------------------------------------------------------------- */
inline
void mark_cluster_free(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t cluster
)
{
set_cluster_val(fs_ptr,
cluster,
mipos_fs_FREE_CLUSTER);
}
/* -------------------------------------------------------------------------- */
inline
void mark_cluster_reserved(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t cluster
)
{
set_cluster_val(fs_ptr,
cluster,
mipos_fs_RESERVED_CLUSTER);
}
/* -------------------------------------------------------------------------- */
static
bool_t get_cluster_seek_pt(
mipos_fs_t* fs_ptr,
mipos_fs_fd_t* file_fs_desc,
mipos_fs_ctl_t* file_ctl,
mipos_fs_cluster_t* cluster
)
{
mipos_fs_cluster_t next_cluster,
current_cluster,
clusters_num,
cluster_counter = 0;
bool_t break_loop = FALSE;
uint32_t seek_pointer;
seek_pointer = file_ctl->seek_pointer;
clusters_num =
(mipos_fs_cluster_t)(seek_pointer / mipos_fs_CLUSTER_SIZE);
next_cluster = file_fs_desc->first_cluster;
do
{
current_cluster = next_cluster;
if (cluster_counter == clusters_num)
break;
break_loop =
bool_t_cast(!get_next_cluster(fs_ptr,
current_cluster,
&next_cluster));
cluster_counter++;
} while (!break_loop);
*cluster = current_cluster;
return bool_t_cast(cluster_counter == clusters_num);
}
/* -------------------------------------------------------------------------- */
static
int write_cluster(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t cluster,
uint32_t cluster_offset,
const char* source_buffer,
// IN num of byte to write, OUT bytes written
uint32_t* wbytes
)
{
uint32_t offset = 0;
uint32_t destination_pointer = 0;
uint32_t bytes_written = 0, left_cluster_size = 0;
int ret = 0;
mipos_fs_lock_access(fs_ptr);
offset = cluster_offset % mipos_fs_CLUSTER_SIZE;
destination_pointer =
cluster * mipos_fs_CLUSTER_SIZE + offset +
mipos_fs_SIZE +
mipos_fs_OFFSET;
left_cluster_size = mipos_fs_CLUSTER_SIZE - offset;
// Is the left part of cluster buffer enough to copy all
// *wbytes data ? If No copy only left_cluster_size
// data bytes
bytes_written =
(*wbytes) < left_cluster_size ?
(*wbytes) : left_cluster_size;
if (bytes_written) {
ret = fs_ptr->io_dev.io_write(
source_buffer,
bytes_written,
destination_pointer);
}
*wbytes = bytes_written;
mipos_fs_unlock_access(fs_ptr);
return ret;
}
/* -------------------------------------------------------------------------- */
static
int read_cluster(
mipos_fs_t* fs_ptr,
mipos_fs_cluster_t cluster,
uint32_t cluster_offset,
char* destination_buffer,
// IN num of byte to read, OUT bytes read
uint32_t* rbytes
)
{
uint32_t offset = 0;
uint32_t source_pointer = 0;
uint32_t bytes_read = 0, left_cluster_size = 0;
int ret = 0;
mipos_fs_lock_access(fs_ptr);
offset = cluster_offset % mipos_fs_CLUSTER_SIZE;
source_pointer =
cluster * mipos_fs_CLUSTER_SIZE + offset +
mipos_fs_SIZE +
mipos_fs_OFFSET;
left_cluster_size = mipos_fs_CLUSTER_SIZE - offset;
// Is the left part of cluster buffer enough to copy all
// *rbytes data ?
// If No copy only left_cluster_size data bytes
bytes_read =
(*rbytes) < left_cluster_size ?
(*rbytes) : left_cluster_size;
if (bytes_read) {
ret = fs_ptr->io_dev.io_read(
destination_buffer,
bytes_read,
source_pointer);
}
*rbytes = bytes_read;
mipos_fs_unlock_access(fs_ptr);
return ret;
}
/* -------------------------------------------------------------------------- */
static
bool_t mipos_fs_check_file_name(const char* filename)
{
int len, i;
len = (int)strlen(filename);
if (len >= mipos_fs_MAX_FILENAME_LENGTH) {
return FALSE;
}
for (i = 0; i < len; ++i) {
char c = filename[i];
if (((c >= '0') && (c <= '9')) ||
((c >= 'A') && (c <= 'Z')) ||
((c >= 'a') && (c <= 'z')) ||
(c == '_') || (c == '-')
|| (c == '.'))
{
continue;
}
else {
return FALSE;
}
}
return TRUE;
}
/* -------------------------------------------------------------------------- */
/* PUBLIC FUNCTIONS DEFINITIONs */
/* -------------------------------------------------------------------------- */
uint32_t mipos_fs_get_last_error(void)
{
return mipos_fs_last_error_code_t;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_setup(mipos_fs_t* fs_ptr)
{
int i = 0;
mipos_fs_fd_t* fd_ptr = 0;
mipos_fs_ctl_t* fctl_ptr = 0;
if (!fs_ptr->io_dev.io_read ||
!fs_ptr->io_dev.io_write)
{
return FALSE;
}
if (0 > fs_ptr->io_dev.io_read(
(char*)&fs_ptr->ftbl,
sizeof(fs_ptr->ftbl),
mipos_fs_OFFSET))
{
return FALSE;
}
// Reset initial state for each file
for (i = 0; i < mipos_fs_MAX_N_OF_FILES; ++i) {
fctl_ptr = &(fs_ptr->file_ctl[i]);
memset(fctl_ptr, 0, sizeof(mipos_fs_ctl_t));
}
mipos_update_fs_on_disk(fs_ptr);
mipos_mu_init(&fs_ptr->lock);
return TRUE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_get_label(
mipos_fs_t* fs_ptr,
char* volume_description
)
{
mipos_fs_lock_access(fs_ptr);
strcpy(volume_description, fs_ptr->ftbl.volume_description);
mipos_fs_unlock_access(fs_ptr);
return TRUE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_seek_file(
mipos_fs_t* fs_ptr,
mipos_fs_seek_t seek_code,
int* seekpos,
mipos_fs_file_handle_t file_handle
)
{
mipos_fs_fd_t* fd_ptr = 0;
mipos_fs_ctl_t* fctl_ptr = 0;
uint32_t size;
// Lock the file
if (!mipos_fs_lock_file(fs_ptr, file_handle)) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__SEEK_FAILED;
return FALSE;
}
// Get the size of the file
mipos_fs_lock_access(fs_ptr);
fd_ptr = &(fs_ptr->ftbl.file_fs_desc[file_handle]);
fctl_ptr = &(fs_ptr->file_ctl[file_handle]);
size = fd_ptr->size;
mipos_fs_unlock_access(fs_ptr);
// Test for the seek_code
switch (seek_code) {
case mipos_fs_SEEK_BEGIN:
mipos_fs_lock_access(fs_ptr);
if ((*seekpos) > 0 && (((uint32_t)(*seekpos)) < size)) {
fctl_ptr->seek_pointer = *seekpos;
}
else {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__SEEK_FAILED;
mipos_fs_unlock_file(fs_ptr, file_handle);
mipos_fs_unlock_access(fs_ptr);
return FALSE;
}
mipos_fs_unlock_access(fs_ptr);
break;
case mipos_fs_SEEK_CURRENT:
mipos_fs_lock_access(fs_ptr);
fctl_ptr->seek_pointer += *seekpos;
mipos_fs_unlock_access(fs_ptr);
break;
case mipos_fs_SEEK_END:
mipos_fs_lock_access(fs_ptr);
fctl_ptr->seek_pointer = fd_ptr->size + *seekpos;
mipos_fs_unlock_access(fs_ptr);
break;
default:
// The seek code is not valid (all the previous
// cases are skipped) the function fails
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__SEEK_FAILED;
mipos_fs_unlock_file(fs_ptr, file_handle);
return FALSE;
}
mipos_fs_unlock_file(fs_ptr, file_handle);
return TRUE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_read_file(
mipos_fs_t* fs_ptr,
char* dest_buffer,
uint32_t* rbytes,
mipos_fs_file_handle_t file_handle
)
{
uint32_t cluster_offset = 0;
uint32_t bytes_to_read = 0;
uint32_t bytes_read = 0;
uint32_t tmp_rbytes;
mipos_fs_fd_t file_fs_desc, *fd_ptr = 0;
mipos_fs_ctl_t file_ctl, *fclt_ptr = 0;
mipos_fs_cluster_t cluster,
next_cluster;
char* dest_pointer = dest_buffer;
bool_t ret_val = TRUE;
// Lock the file
if (!mipos_fs_lock_file(fs_ptr, file_handle)) {
goto RD_EXCEPTION_HANDLER;
}
// Get the file descriptor
mipos_fs_get_fd(fs_ptr, file_handle, &file_fs_desc);
mipos_fs_get_ctl(fs_ptr, file_handle, &file_ctl);
if ((!file_ctl.open) ||
(file_ctl.seek_pointer >= MIPOS_LE_U32(file_fs_desc.size)))
{
goto RD_EXCEPTION_HANDLER;
}
// Get the cluster pointed by the current "seek pointer"
if (!get_cluster_seek_pt(fs_ptr,
&file_fs_desc,
&file_ctl,
&cluster))
{
goto RD_EXCEPTION_HANDLER;
}
// Calculate the cluster offset using
// the file "seek pointer"
cluster_offset =
file_ctl.seek_pointer % mipos_fs_CLUSTER_SIZE;
bytes_to_read = *rbytes;
if (
(bytes_to_read + file_ctl.seek_pointer) >
MIPOS_LE_U32(file_fs_desc.size))
{
mipos_fs_lock_access(fs_ptr);
fclt_ptr = &(fs_ptr->file_ctl[file_handle]);
fclt_ptr->eof_while_read = TRUE;
mipos_fs_unlock_access(fs_ptr);
bytes_to_read =
MIPOS_LE_U32(file_fs_desc.size) - file_ctl.seek_pointer;
}
tmp_rbytes = bytes_to_read;
for (;;) {
read_cluster(fs_ptr,
cluster,
cluster_offset,
dest_pointer,
&tmp_rbytes);
if (tmp_rbytes == 0) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__READ_NOT_COMPLETED;
ret_val = FALSE;
break;
}
// Reset cluster_offset (set it to begin of cluster)
cluster_offset = 0;
bytes_read += tmp_rbytes;
dest_pointer += tmp_rbytes;
// Move the seek pointer of the read bytes count
mipos_fs_lock_access(fs_ptr);
fs_ptr->file_ctl[file_handle].seek_pointer += tmp_rbytes;
mipos_fs_unlock_access(fs_ptr);
// Break the loop when all bytes are read
if (bytes_read >= bytes_to_read) {
break;
}
// Get the next linked cluster of the file
else if (!get_next_cluster(fs_ptr,
cluster,
&next_cluster))
{
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__READ_NOT_COMPLETED;
ret_val = FALSE;
break;
}
cluster = next_cluster;
// Set tmp_rbytes to the left bytes count
tmp_rbytes = bytes_to_read - bytes_read;
}
// Set *rbytes to the read bytes count
*rbytes = bytes_read;
// Unlock the file and return the ret_val
mipos_fs_unlock_file(fs_ptr, file_handle);
return ret_val;
RD_EXCEPTION_HANDLER:
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__READ_FAILED;
mipos_fs_unlock_file(fs_ptr, file_handle);
return FALSE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_write_file(
mipos_fs_t* fs_ptr,
const char* source_buffer,
uint32_t* wbytes,
mipos_fs_file_handle_t file_handle
)
{
mipos_fs_fd_t file_fs_desc, *fd_ptr = 0;
mipos_fs_ctl_t file_ctl, *fctl_ptr = 0;
mipos_fs_cluster_t cluster, prev_cluster;
const char* source_ptr;
uint32_t tot_wbytes, tmp_wbytes;
bool_t end_loop = FALSE;
mipos_fs_cluster_t first_cluster = 0;
uint32_t cluster_offset = 0;
uint32_t bytes_to_write = 0;
uint32_t bytes_written = 0;
uint32_t fsize = 0;
int ret = 0;
// Lock the file
if (!mipos_fs_lock_file(fs_ptr, file_handle))
goto WR_EXCEPTION_HANDLER;
// Get the file descriptor
mipos_fs_get_fd(fs_ptr, file_handle, &file_fs_desc);
mipos_fs_get_ctl(fs_ptr, file_handle, &file_ctl);
fsize = MIPOS_LE_U32(file_fs_desc.size);
if ((file_fs_desc.readonly) ||
(file_ctl.file_open_mode != mipos_fs_FILE_OPEN_WRITE)
||
(file_ctl.open == 0))
{
goto WR_EXCEPTION_HANDLER;
}
bytes_to_write = *wbytes;
// The seek pointer cannot be after the size of the file
if (file_ctl.seek_pointer > fsize)
goto WR_EXCEPTION_HANDLER;
cluster_offset =
file_ctl.seek_pointer % mipos_fs_CLUSTER_SIZE;
tot_wbytes = *wbytes;
source_ptr = source_buffer;
// If it is required, allocate a new cluster ?
if ((file_ctl.seek_pointer == fsize)
&& (cluster_offset == 0))
{
// Are we overwriting an existing file ?
if (file_ctl.seek_pointer > 0) {
// We must link last allocated
// cluster to the new one
if (!get_cluster_seek_pt(fs_ptr,
&file_fs_desc,
&file_ctl,
&cluster))
{
goto WR_EXCEPTION_HANDLER;
}
if (!reserve_cluster(fs_ptr, &first_cluster))
goto WR_EXCEPTION_HANDLER;
if (!link_cluster(fs_ptr,
cluster,
first_cluster))
{
goto WR_EXCEPTION_HANDLER;
}
}
else if (!reserve_cluster(fs_ptr,
&first_cluster))
{
goto WR_EXCEPTION_HANDLER;
}
}
else {
// Get cluster at the seek_pointer
if (!get_cluster_seek_pt(fs_ptr,
&file_fs_desc,
&file_ctl,
&first_cluster))
{
goto WR_EXCEPTION_HANDLER;
}
}
cluster = first_cluster;
do {
tmp_wbytes = tot_wbytes;
// Write the cluster
ret = write_cluster(fs_ptr,
cluster,
cluster_offset,
source_ptr,
&tmp_wbytes);
if (ret != 0) {
end_loop = TRUE;
}
cluster_offset = 0;
tot_wbytes -= tmp_wbytes;
// Move the "seek pointer"
mipos_fs_lock_access(fs_ptr);
fd_ptr = &(fs_ptr->ftbl.file_fs_desc[file_handle]);
fctl_ptr = &(fs_ptr->file_ctl[file_handle]);
fctl_ptr->seek_pointer += tmp_wbytes;
mipos_fs_unlock_access(fs_ptr);
// No more bytes written ?
if (tot_wbytes == 0) {
// Is the "seek pointer" out of range ?
if (fctl_ptr->seek_pointer > fd_ptr->size) {
// Set it to last position,
// mark this cluster as the last of the file
fd_ptr->size = fctl_ptr->seek_pointer;
mark_cluster_last(fs_ptr, cluster);
}
// terminate the loop
end_loop = TRUE;
}
else {
// Remember the current cluster
prev_cluster = cluster;
// Have we to allocate a new cluster ?
if (fctl_ptr->seek_pointer > fd_ptr->size) {
fd_ptr->size += bytes_written;
if (!reserve_cluster(fs_ptr, &cluster)) {
// Mark this cluster as
// the last of the file and terminate the loop
mark_cluster_last(fs_ptr, prev_cluster);
end_loop = TRUE;
}
}
// NO, get the next cluster
else if (!get_next_cluster(fs_ptr,
prev_cluster,
&cluster))
{
// If it is non-possible mark this cluster as
// the last of the file and terminate the loop
mark_cluster_last(fs_ptr,
prev_cluster);
end_loop = TRUE;
}
// If loop continues link current
// cluster with previous one
if (!end_loop) {
link_cluster(fs_ptr, prev_cluster, cluster);
}
}
// Move the source buffer pointer to the new position
// adding the number of written bytes
source_ptr += tmp_wbytes;
} while (end_loop == FALSE);
if (ret == 0) {
bytes_written = bytes_to_write - tot_wbytes;
// If the first cluster of
// file descriptor was not set, do it
mipos_fs_lock_access(fs_ptr);
fd_ptr = &(fs_ptr->ftbl.file_fs_desc[file_handle]);
if (MIPOS_LE_U16(fd_ptr->first_cluster) >= mipos_fs_CLUSTERS_COUNT) {
fd_ptr->first_cluster = MIPOS_LE_U16(first_cluster);
}
mipos_fs_unlock_access(fs_ptr);
*wbytes = bytes_written;
}
// Unlock file
mipos_fs_unlock_file(fs_ptr, file_handle);
if (ret != 0) {
return FALSE;
}
// If no all bytes was written return FALSE, TRUE else
return bool_t_cast(tot_wbytes == 0);
WR_EXCEPTION_HANDLER:
*wbytes = 0;
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__WRITE_FAILED;
mipos_fs_unlock_file(fs_ptr, file_handle);
return FALSE;
}
/* -------------------------------------------------------------------------- */
static char _zero_buf[mipos_fs_CLUSTER_SIZE] = { 0 };
bool_t mipos_fs_mkfs(mipos_fs_t* fs_ptr, const char* volume_description)
{
mipos_fs_file_handle_t i;
mipos_fs_cluster_t j;
mipos_fs_fd_t* fd_ptr = 0;
mipos_fs_ctl_t* fctl_ptr = 0;
int ret = 0;
mipos_fs_lock_access(fs_ptr);
// Set the volume label for the file system
// (if the volume description is NULL,
//this label is filled with the null character)
if (volume_description) {
strncpy(fs_ptr->ftbl.volume_description,
volume_description,
mipos_fs_MAX_VOLUME_LENGTH);
}
else {
memset(fs_ptr->ftbl.volume_description,
0,
sizeof volume_description);
}
// Set the version 0.1
fs_ptr->ftbl.maj_version = mipos_fs_MAX_VERSION;
fs_ptr->ftbl.min_version = mipos_fs_MIN_VERSION;
// Clean the file descriptor table
for (i = 0; i < mipos_fs_MAX_N_OF_FILES; ++i) {
fd_ptr = &(fs_ptr->ftbl.file_fs_desc[i]);
fctl_ptr = &fs_ptr->file_ctl[i];
memset(fctl_ptr, 0, sizeof(mipos_fs_ctl_t));
memset((void*)fd_ptr, 0, sizeof(mipos_fs_fd_t));
fd_ptr->erased = TRUE;
mipos_fs_call_os_scheduler();
}
// Format the cluster arena
for (j = 0; j < mipos_fs_CLUSTERS_COUNT; ++j) {
fs_ptr->ftbl.cluster_tbl[j] = MIPOS_LE_U16(mipos_fs_FREE_CLUSTER);
ret = fs_ptr->io_dev.io_write(
_zero_buf,
mipos_fs_CLUSTER_SIZE,
j*mipos_fs_CLUSTER_SIZE + mipos_fs_OFFSET);
mipos_fs_call_os_scheduler();
if (ret != 0)
break;
}
mipos_fs_unlock_access(fs_ptr);
if (ret == 0) {
ret = mipos_update_fs_on_disk(fs_ptr);
}
return ret == 0 ? TRUE : FALSE;
};
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_rename_file(
mipos_fs_t* fs_ptr,
const char* filename,
const char* new_filename
)
{
// If the file exists and the new_filename is valid,
// the old file name is replaced with the new one
mipos_fs_file_handle_t file_handle;
if ((mipos_fs_ffirst(fs_ptr,
filename,
&file_handle))
&&
(mipos_fs_check_file_name(new_filename)))
{
mipos_fs_lock_access(fs_ptr);
strncpy(
&fs_ptr->ftbl.file_fs_desc->filename[file_handle],
new_filename,
mipos_fs_MAX_FILENAME_LENGTH);
mipos_fs_unlock_access(fs_ptr);
}
else {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__BAD_FILENAME;
return FALSE;
}
return mipos_update_fs_on_disk(fs_ptr) == 0 ? TRUE : FALSE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_ffirst(
mipos_fs_t* fs_ptr,
const char* filename,
mipos_fs_file_handle_t* file_handle
)
{
int erased, jolly_pos, slen;
mipos_fs_file_handle_t i;
char tmpFileName[mipos_fs_MAX_FILENAME_LENGTH] = { 0 };
char tmpDescFileName[mipos_fs_MAX_FILENAME_LENGTH] = { 0 };
if (!filename) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__BAD_FILENAME;
return FALSE;
}
slen = (int)strlen(filename);
jolly_pos = slen;
for (i = 0; i < slen; ++i) {
if (filename[i] == '*') {
jolly_pos = i;
break;
}
}
strncpy(tmpFileName,
filename,
jolly_pos);
if (TRUE != mipos_fs_check_file_name(tmpFileName)) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__BAD_FILENAME;
return FALSE;
}
//For each element of the file descriptor table ...
for (i = 0; i < mipos_fs_MAX_N_OF_FILES; ++i) {
mipos_fs_lock_access(fs_ptr);
erased = fs_ptr->ftbl.file_fs_desc[i].erased;
mipos_fs_unlock_access(fs_ptr);
// If the file descriptor is not-erased...
if (!erased) {
// Get the file name and compare with one passed as
// function's argument
mipos_fs_lock_access(fs_ptr);
strncpy(tmpDescFileName,
fs_ptr->ftbl.file_fs_desc[i].filename,
jolly_pos);
mipos_fs_unlock_access(fs_ptr);
// If it matchs update *file_handle with the fd index
// and return TRUE
if (0 == strcmp(tmpDescFileName, tmpFileName)) {
*file_handle = i;
return TRUE;
}
}
}
return FALSE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_fnext(
mipos_fs_t* fs_ptr,
mipos_fs_file_handle_t* file_handle)
{
int erased;
mipos_fs_file_handle_t i;
// Search a valid file descriptor starting from the
// *file_handle position
// *file_handle is set to the index of the first file
// descriptor that's found
for (i = ++(*file_handle);
i < mipos_fs_MAX_N_OF_FILES;
++i)
{
mipos_fs_lock_access(fs_ptr);
erased = fs_ptr->ftbl.file_fs_desc[i].erased;
mipos_fs_unlock_access(fs_ptr);
if (!erased) {
*file_handle = i;
return TRUE;
}
}
return FALSE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_fexist(
mipos_fs_t* fs_ptr,
const char* filename
)
{
mipos_fs_file_handle_t file_handle;
return mipos_fs_ffirst(fs_ptr,
filename,
&file_handle);
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_lock_file(
mipos_fs_t* fs_ptr,
mipos_fs_file_handle_t file_handle)
{
bool_t ret_val = TRUE;
mipos_fs_ctl_t * fctl_ptr;
if (file_handle >= mipos_fs_MAX_N_OF_FILES) {
return FALSE;
}
fctl_ptr = &(fs_ptr->file_ctl)[file_handle];
if (!fctl_ptr->locked) {
fctl_ptr->locked = 1;
}
else {
ret_val = FALSE;
}
return ret_val;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_unlock_file(
mipos_fs_t* fs_ptr,
mipos_fs_file_handle_t file_handle)
{
mipos_fs_ctl_t * fctl_ptr;
bool_t ret_val = TRUE;
if (file_handle >= mipos_fs_MAX_N_OF_FILES) {
return FALSE;
}
fctl_ptr = &(fs_ptr->file_ctl)[file_handle];
if (fctl_ptr->locked) {
fctl_ptr->locked = 0;
}
else {
ret_val = FALSE;
}
return ret_val;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_get_ctl(
mipos_fs_t* fs_ptr,
mipos_fs_file_handle_t file_handle,
mipos_fs_ctl_t* file_ctl
)
{
if (file_handle >= mipos_fs_MAX_N_OF_FILES) {
return FALSE;
}
// Copy the file descriptor in the buffer pointed
// by file_ctl pointer
mipos_fs_lock_access(fs_ptr);
memcpy(file_ctl,
&fs_ptr->file_ctl[file_handle],
sizeof(mipos_fs_ctl_t));
mipos_fs_unlock_access(fs_ptr);
return TRUE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_get_fd(
mipos_fs_t* fs_ptr,
mipos_fs_file_handle_t file_handle,
mipos_fs_fd_t* file_fs_desc
)
{
if (file_handle >= mipos_fs_MAX_N_OF_FILES) {
return FALSE;
}
// Copy the file descriptor in the buffer pointed
// by file_fs_desc pointer
mipos_fs_lock_access(fs_ptr);
memcpy(file_fs_desc,
&fs_ptr->ftbl.file_fs_desc[file_handle],
sizeof(mipos_fs_fd_t));
mipos_fs_unlock_access(fs_ptr);
// Return false if the file does not exist
return bool_t_cast(file_fs_desc->erased == FALSE);
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_get_fsize(
mipos_fs_t* fs_ptr,
const char* filename,
uint32_t* file_size
)
{
mipos_fs_file_handle_t file_handle;
mipos_fs_fd_t file_fs_desc;
if (!mipos_fs_ffirst(fs_ptr,
filename,
&file_handle))
{
return FALSE;
}
if (!mipos_fs_get_fd(fs_ptr,
file_handle,
&file_fs_desc))
{
return FALSE;
}
*file_size = file_fs_desc.size;
return TRUE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_open_file(
mipos_fs_t* fs_ptr, //fs ptr
const char* filename, //file to open
mipos_fs_file_handle_t* file_handle,//returend file handle
mipos_fs_fopenmode_t mode //open mode
)
{
int erased, readonly, locked, open = 0;
mipos_fs_file_handle_t i;
char tmpFileName[mipos_fs_MAX_FILENAME_LENGTH] = { 0 };
mipos_fs_fd_t* fd_ptr = 0;
mipos_fs_ctl_t* fctl_ptr = 0;
*file_handle = mipos_fs_INVALID_FILE_HANDLE;
// Test if the file name is a valid one
if (TRUE != mipos_fs_check_file_name(filename)) {
return FALSE;
}
i = 0;
// Search the file in the file descritor table
for (; i < mipos_fs_MAX_N_OF_FILES; ++i) {
// Get the attributes of the file
mipos_fs_lock_access(fs_ptr);
fd_ptr = &(fs_ptr->ftbl.file_fs_desc[i]);
fctl_ptr = &(fs_ptr->file_ctl[i]);
erased = fd_ptr->erased;
readonly = fd_ptr->readonly;
mipos_fs_unlock_access(fs_ptr);
if (!erased) { // Skip erased files
mipos_fs_lock_access(fs_ptr);
strcpy(tmpFileName, fd_ptr->filename);
open = fctl_ptr->open;
locked = fctl_ptr->locked;
mipos_fs_unlock_access(fs_ptr);
if ((0 == strcmp(filename, tmpFileName)) &&
(0 == locked && 0 == open))
// File exists and it is not already opened and
// not locked...
{
// Do you have the privilege to write it ?
if ((mode == mipos_fs_FILE_OPEN_WRITE) &&
(readonly))
{
return FALSE;
}
// Ok, open it
*file_handle = i;
mipos_fs_lock_access(fs_ptr);
fctl_ptr->open = 1;
fctl_ptr->file_open_mode = mode;
fctl_ptr->seek_pointer = 0;
fctl_ptr->eof_while_read = FALSE;
mipos_fs_unlock_access(fs_ptr);
return TRUE;
}
}
}
return FALSE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_create_file(
mipos_fs_t* fs_ptr,
const char* filename,
mipos_fs_file_handle_t* file_handle
)
{
bool_t found;
int erased = 0;
mipos_fs_file_handle_t i;
mipos_fs_fd_t* fd_ptr = 0;
mipos_fs_ctl_t* fctl_ptr = 0;
*file_handle = mipos_fs_INVALID_FILE_HANDLE;
// Is filename valid ? NO, error
if (!mipos_fs_check_file_name(filename)) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__BAD_FILENAME;
return FALSE;
}
// Is the file already existent ? NO, error
if (mipos_fs_fexist(fs_ptr, filename)) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__FILENAME_ALREADY_PRESENT;
return FALSE;
}
found = FALSE;
// Search a free file descriptor
for (i = 0; i < mipos_fs_MAX_N_OF_FILES; ++i) {
mipos_fs_lock_access(fs_ptr);
fd_ptr = &(fs_ptr->ftbl.file_fs_desc[i]);
fctl_ptr = &(fs_ptr->file_ctl[i]);
erased = fd_ptr->erased;
mipos_fs_unlock_access(fs_ptr);
if (erased != 0) {
found = TRUE;
break;
}
}
// If it is not found return
// mipos_fs_ERRCODE__NO_ENOUGH_FREE_BLOCKS error
if (!found) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__NO_ENOUGH_FREE_BLOCKS;
return FALSE;
}
// Create update the file descriptor
mipos_fs_lock_access(fs_ptr);
fd_ptr->first_cluster = mipos_fs_EMPTY_CLUSTER;
fd_ptr->erased = FALSE;
fctl_ptr->open = 1;
fctl_ptr->locked = 0;
fd_ptr->readonly = 0;
fd_ptr->size = 0;
fctl_ptr->seek_pointer = 0;
fctl_ptr->file_open_mode = mipos_fs_FILE_OPEN_WRITE;
strncpy(fd_ptr->filename,
filename,
mipos_fs_MAX_FILENAME_LENGTH - 1);
mipos_fs_unlock_access(fs_ptr);
// The file handle is set to current file descriptor index
*file_handle = i;
return mipos_update_fs_on_disk(fs_ptr) == 0 ? TRUE : FALSE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_close_file(
mipos_fs_t* fs_ptr,
mipos_fs_file_handle_t file_handle
)
{
mipos_fs_ctl_t* fctl_ptr = 0;
if (file_handle >= mipos_fs_MAX_N_OF_FILES) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__CLOSE_FAILED;
return FALSE;
}
// Close the file and reset the "seek pointer"
mipos_fs_lock_access(fs_ptr);
fctl_ptr = &(fs_ptr->file_ctl[file_handle]);
fctl_ptr->open = 0;
fctl_ptr->seek_pointer = 0;
mipos_fs_unlock_access(fs_ptr);
return TRUE;
}
/* -------------------------------------------------------------------------- */
bool_t mipos_fs_delete_file(
mipos_fs_t* fs_ptr,
const char* filename
)
{
int readonly, erased;
mipos_fs_cluster_t current_cluster, next_cluster;
bool_t break_loop = FALSE;
mipos_fs_fd_t* fd_ptr = 0;
mipos_fs_file_handle_t file_handle;
int ret = 0;
// Get the handle of the file
if (!mipos_fs_ffirst(fs_ptr, filename, &file_handle)) {
mipos_fs_last_error_code_t = mipos_fs_ERRCODE__CLOSE_FAILED;
return FALSE;
}
// Lock the file
if (!mipos_fs_lock_file(fs_ptr, file_handle)) {
mipos_fs_last_error_code_t =
mipos_fs_ERRCODE__DELETE_FAILED;
return FALSE;
}
// Get the attributes of the file
mipos_fs_lock_access(fs_ptr);
fd_ptr = &(fs_ptr->ftbl.file_fs_desc[file_handle]);
readonly = fd_ptr->readonly;
erased = fd_ptr->erased;
mipos_fs_unlock_access(fs_ptr);
// Is it an erased or a readonly file ?
if ((erased) || (readonly)) {
// Unlock it and return an error
mipos_fs_unlock_file(fs_ptr, file_handle);
mipos_fs_last_error_code_t = mipos_fs_ERRCODE__DELETE_FAILED;
return FALSE;
}
// Clean the file descriptor
// and set the flag erased to TRUE
mipos_fs_lock_access(fs_ptr);
next_cluster = fd_ptr->first_cluster;
memset((void*)fd_ptr, 0, sizeof(mipos_fs_fd_t));
fd_ptr->erased = TRUE;
mipos_fs_unlock_access(fs_ptr);
do {
// For each cluster of the file set it to FREE
current_cluster = next_cluster;
break_loop =
bool_t_cast(!get_next_cluster(fs_ptr,
current_cluster,
&next_cluster));
if (current_cluster < mipos_fs_CLUSTERS_COUNT) {
mark_cluster_free(fs_ptr, current_cluster);
}
mipos_fs_call_os_scheduler();
}
while (!break_loop);
return mipos_update_fs_on_disk(fs_ptr) == 0 ? TRUE : FALSE;
}
/* -------------------------------------------------------------------------- */
#endif //!ENABLE_MIPOS_FS
/* -------------------------------------------------------------------------- */
|
the_stack_data/49522.c | /* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern void signal(int sig , void *func ) ;
extern float strtof(char const *str , char const *endptr ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned long input[1] , unsigned long output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
int main(int argc , char *argv[] )
{
unsigned long input[1] ;
unsigned long output[1] ;
int randomFuns_i5 ;
unsigned long randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 4242424242UL) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%lu\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
void megaInit(void)
{
{
}
}
void RandomFunc(unsigned long input[1] , unsigned long output[1] )
{
unsigned long state[1] ;
unsigned long local1 ;
char copy11 ;
unsigned short copy12 ;
{
state[0UL] = (input[0UL] + 914778474UL) * 67330564296145686UL;
local1 = 0UL;
while (local1 < 1UL) {
if (state[0UL] < local1) {
if (state[0UL] != local1) {
state[0UL] += state[0UL];
} else {
copy11 = *((char *)(& state[0UL]) + 1);
*((char *)(& state[0UL]) + 1) = *((char *)(& state[0UL]) + 7);
*((char *)(& state[0UL]) + 7) = copy11;
}
} else
if (state[0UL] == local1) {
state[0UL] -= state[local1];
} else {
copy12 = *((unsigned short *)(& state[local1]) + 3);
*((unsigned short *)(& state[local1]) + 3) = *((unsigned short *)(& state[local1]) + 0);
*((unsigned short *)(& state[local1]) + 0) = copy12;
}
local1 ++;
}
output[0UL] = (state[0UL] - 1059477100UL) + 204337520UL;
}
}
|
the_stack_data/141093.c | /* { dg-do run } */
/* { dg-options "-fstrict-overflow" } */
extern void abort (void);
int foo (int i, int j, int o, int m) { return i*o + 1 + j*m > 1; }
int main()
{
if (foo (- __INT_MAX__ - 1, -1, 1, 1))
abort ();
return 0;
}
|
the_stack_data/1157900.c | /****************************************************************************
* Ralink Tech Inc.
* 4F, No. 2 Technology 5th Rd.
* Science-based Industrial Park
* Hsin-chu, Taiwan, R.O.C.
* (c) Copyright 2002, Ralink Technology, Inc.
*
* All rights reserved. Ralink's source code is an unpublished work and the
* use of a copyright notice does not imply otherwise. This source code
* contains confidential trade secret material of Ralink Tech. Any attemp
* or participation in deciphering, decoding, reverse engineering or in any
* way altering the source code is stricitly prohibited, unless the prior
* written consent of Ralink Technology, Inc. is obtained.
****************************************************************************
Module Name:
ap_ids.c
Abstract:
monitor intrusion detection condition
Revision History:
Who When What
-------- ---------- ----------------------------------------------
*/
#ifdef IDS_SUPPORT
#include "rt_config.h"
#define IDS_EXEC_INTV 1000 /* 1 sec */
VOID RTMPIdsStart(
IN PRTMP_ADAPTER pAd)
{
if (pAd->ApCfg.IDSTimerRunning == FALSE)
{
RTMPSetTimer(&pAd->ApCfg.IDSTimer, IDS_EXEC_INTV);
pAd->ApCfg.IDSTimerRunning = TRUE;
}
}
VOID RTMPIdsStop(
IN PRTMP_ADAPTER pAd)
{
BOOLEAN Cancelled;
if (pAd->ApCfg.IDSTimerRunning == TRUE)
{
RTMPCancelTimer(&pAd->ApCfg.IDSTimer, &Cancelled);
pAd->ApCfg.IDSTimerRunning = FALSE;
}
}
#ifdef SYSTEM_LOG_SUPPORT
VOID RTMPHandleIdsEvent(
IN PRTMP_ADAPTER pAd)
{
INT i, j;
UINT32 FloodFrameCount[IW_FLOOD_EVENT_TYPE_NUM];
UINT32 FloodFrameThreshold[IW_FLOOD_EVENT_TYPE_NUM];
FloodFrameCount[0] = pAd->ApCfg.RcvdAuthCount;
FloodFrameCount[1] = pAd->ApCfg.RcvdAssocReqCount;
FloodFrameCount[2] = pAd->ApCfg.RcvdReassocReqCount;
FloodFrameCount[3] = pAd->ApCfg.RcvdProbeReqCount;
FloodFrameCount[4] = pAd->ApCfg.RcvdDisassocCount;
FloodFrameCount[5] = pAd->ApCfg.RcvdDeauthCount;
FloodFrameCount[6] = pAd->ApCfg.RcvdEapReqCount;
FloodFrameThreshold[0] = pAd->ApCfg.AuthFloodThreshold;
FloodFrameThreshold[1] = pAd->ApCfg.AssocReqFloodThreshold;
FloodFrameThreshold[2] = pAd->ApCfg.ReassocReqFloodThreshold;
FloodFrameThreshold[3] = pAd->ApCfg.ProbeReqFloodThreshold;
FloodFrameThreshold[4] = pAd->ApCfg.DisassocFloodThreshold;
FloodFrameThreshold[5] = pAd->ApCfg.DeauthFloodThreshold;
FloodFrameThreshold[6] = pAd->ApCfg.EapReqFloodThreshold;
/* trigger flooding traffic event */
for (j = 0; j < IW_FLOOD_EVENT_TYPE_NUM; j++)
{
if ((FloodFrameThreshold[j] > 0) && (FloodFrameCount[j] > FloodFrameThreshold[j]))
{
RTMPSendWirelessEvent(pAd, IW_FLOOD_AUTH_EVENT_FLAG + j, NULL, MAX_MBSSID_NUM(pAd), 0);
/*DBGPRINT(RT_DEBUG_TRACE, ("flooding traffic event(%d) - %d\n", IW_FLOOD_AUTH_EVENT_FLAG + j, FloodFrameCount[j])); */
}
}
for (i = 0; i < pAd->ApCfg.BssidNum; i++)
{
UINT32 SpoofedFrameCount[IW_SPOOF_EVENT_TYPE_NUM];
CHAR RssiOfSpoofedFrame[IW_SPOOF_EVENT_TYPE_NUM];
INT k;
SpoofedFrameCount[0] = pAd->ApCfg.MBSSID[i].RcvdConflictSsidCount;
SpoofedFrameCount[1] = pAd->ApCfg.MBSSID[i].RcvdSpoofedAssocRespCount;
SpoofedFrameCount[2] = pAd->ApCfg.MBSSID[i].RcvdSpoofedReassocRespCount;
SpoofedFrameCount[3] = pAd->ApCfg.MBSSID[i].RcvdSpoofedProbeRespCount;
SpoofedFrameCount[4] = pAd->ApCfg.MBSSID[i].RcvdSpoofedBeaconCount;
SpoofedFrameCount[5] = pAd->ApCfg.MBSSID[i].RcvdSpoofedDisassocCount;
SpoofedFrameCount[6] = pAd->ApCfg.MBSSID[i].RcvdSpoofedAuthCount;
SpoofedFrameCount[7] = pAd->ApCfg.MBSSID[i].RcvdSpoofedDeauthCount;
SpoofedFrameCount[8] = pAd->ApCfg.MBSSID[i].RcvdSpoofedUnknownMgmtCount;
SpoofedFrameCount[9] = pAd->ApCfg.MBSSID[i].RcvdReplayAttackCount;
RssiOfSpoofedFrame[0] = pAd->ApCfg.MBSSID[i].RssiOfRcvdConflictSsid;
RssiOfSpoofedFrame[1] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedAssocResp;
RssiOfSpoofedFrame[2] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedReassocResp;
RssiOfSpoofedFrame[3] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedProbeResp;
RssiOfSpoofedFrame[4] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedBeacon;
RssiOfSpoofedFrame[5] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedDisassoc;
RssiOfSpoofedFrame[6] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedAuth;
RssiOfSpoofedFrame[7] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedDeauth;
RssiOfSpoofedFrame[8] = pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedUnknownMgmt;
RssiOfSpoofedFrame[9] = pAd->ApCfg.MBSSID[i].RssiOfRcvdReplayAttack;
/* trigger spoofed attack event */
for (k = 0; k < IW_SPOOF_EVENT_TYPE_NUM; k++)
{
if (SpoofedFrameCount[k] > 0)
{
RTMPSendWirelessEvent(pAd, IW_CONFLICT_SSID_EVENT_FLAG + k, NULL, i, RssiOfSpoofedFrame[k]);
/*DBGPRINT(RT_DEBUG_TRACE, ("spoofed attack event(%d) - %d\n", IW_CONFLICT_SSID_EVENT_FLAG + k, SpoofedFrameCount[k])); */
}
}
}
}
#endif /* SYSTEM_LOG_SUPPORT */
VOID RTMPClearAllIdsCounter(
IN PRTMP_ADAPTER pAd)
{
INT i;
pAd->ApCfg.RcvdAuthCount = 0;
pAd->ApCfg.RcvdAssocReqCount = 0;
pAd->ApCfg.RcvdReassocReqCount = 0;
pAd->ApCfg.RcvdProbeReqCount = 0;
pAd->ApCfg.RcvdDisassocCount = 0;
pAd->ApCfg.RcvdDeauthCount = 0;
pAd->ApCfg.RcvdEapReqCount = 0;
for (i = 0; i < pAd->ApCfg.BssidNum; i++)
{
pAd->ApCfg.MBSSID[i].RcvdConflictSsidCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedAssocRespCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedReassocRespCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedProbeRespCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedBeaconCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedDisassocCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedAuthCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedDeauthCount = 0;
pAd->ApCfg.MBSSID[i].RcvdSpoofedUnknownMgmtCount = 0;
pAd->ApCfg.MBSSID[i].RcvdReplayAttackCount = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdConflictSsid = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedAssocResp = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedReassocResp = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedProbeResp = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedBeacon = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedDisassoc = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedAuth = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedDeauth = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedUnknownMgmt = 0;
pAd->ApCfg.MBSSID[i].RssiOfRcvdReplayAttack = 0;
}
}
VOID RTMPIdsPeriodicExec(
IN PVOID SystemSpecific1,
IN PVOID FunctionContext,
IN PVOID SystemSpecific2,
IN PVOID SystemSpecific3)
{
PRTMP_ADAPTER pAd = (RTMP_ADAPTER *)FunctionContext;
pAd->ApCfg.IDSTimerRunning = FALSE;
#ifdef SYSTEM_LOG_SUPPORT
/* when IDS occured, send out wireless event */
if (pAd->CommonCfg.bWirelessEvent)
RTMPHandleIdsEvent(pAd);
#endif /* SYSTEM_LOG_SUPPORT */
/* clear all IDS counter */
RTMPClearAllIdsCounter(pAd);
/* set timer */
if (pAd->ApCfg.IdsEnable)
{
RTMPSetTimer(&pAd->ApCfg.IDSTimer, IDS_EXEC_INTV);
pAd->ApCfg.IDSTimerRunning = TRUE;
}
}
/*
========================================================================
Routine Description:
This routine is used to check if a rogue AP sent an 802.11 management
frame to a client using our BSSID.
Arguments:
pAd - Pointer to our adapter
pHeader - Pointer to 802.11 header
Return Value:
TRUE - This is a spoofed frame
FALSE - This isn't a spoofed frame
========================================================================
*/
BOOLEAN RTMPSpoofedMgmtDetection(
IN PRTMP_ADAPTER pAd,
IN PHEADER_802_11 pHeader,
IN CHAR Rssi0,
IN CHAR Rssi1,
IN CHAR Rssi2,
IN UCHAR AntSel)
{
INT i;
for (i = 0; i < pAd->ApCfg.BssidNum; i++)
{
/* Spoofed BSSID detection */
if (NdisEqualMemory(pHeader->Addr2, pAd->ApCfg.MBSSID[i].Bssid, MAC_ADDR_LEN))
{
CHAR RcvdRssi;
RcvdRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Rssi0, RSSI_0, AntSel, BW_20), ConvertToRssi(pAd, Rssi1, RSSI_1, AntSel, BW_20), ConvertToRssi(pAd, Rssi2, RSSI_2, AntSel, BW_20));
switch (pHeader->FC.SubType)
{
case SUBTYPE_ASSOC_RSP:
pAd->ApCfg.MBSSID[i].RcvdSpoofedAssocRespCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedAssocResp = RcvdRssi;
break;
case SUBTYPE_REASSOC_RSP:
pAd->ApCfg.MBSSID[i].RcvdSpoofedReassocRespCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedReassocResp = RcvdRssi;
break;
case SUBTYPE_PROBE_RSP:
pAd->ApCfg.MBSSID[i].RcvdSpoofedProbeRespCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedProbeResp = RcvdRssi;
break;
case SUBTYPE_BEACON:
pAd->ApCfg.MBSSID[i].RcvdSpoofedBeaconCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedBeacon = RcvdRssi;
break;
case SUBTYPE_DISASSOC:
pAd->ApCfg.MBSSID[i].RcvdSpoofedDisassocCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedDisassoc = RcvdRssi;
break;
case SUBTYPE_AUTH:
pAd->ApCfg.MBSSID[i].RcvdSpoofedAuthCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedAuth = RcvdRssi;
break;
case SUBTYPE_DEAUTH:
pAd->ApCfg.MBSSID[i].RcvdSpoofedDeauthCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedDeauth = RcvdRssi;
break;
default:
pAd->ApCfg.MBSSID[i].RcvdSpoofedUnknownMgmtCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdSpoofedUnknownMgmt = RcvdRssi;
break;
}
return TRUE;
}
}
return FALSE;
}
VOID RTMPConflictSsidDetection(
IN PRTMP_ADAPTER pAd,
IN PUCHAR pSsid,
IN UCHAR SsidLen,
IN CHAR Rssi0,
IN CHAR Rssi1,
IN CHAR Rssi2,
IN UCHAR AntSel)
{
INT i;
for (i = 0; i < pAd->ApCfg.BssidNum; i++)
{
/* Conflict SSID detection */
if (SSID_EQUAL(pSsid, SsidLen, pAd->ApCfg.MBSSID[i].Ssid, pAd->ApCfg.MBSSID[i].SsidLen))
{
CHAR RcvdRssi;
RcvdRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Rssi0, RSSI_0, AntSel, BW_20), ConvertToRssi(pAd, Rssi1, RSSI_1, AntSel, BW_20), ConvertToRssi(pAd, Rssi2, RSSI_2, AntSel, BW_20));
pAd->ApCfg.MBSSID[i].RcvdConflictSsidCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdConflictSsid = RcvdRssi;
return;
}
}
}
BOOLEAN RTMPReplayAttackDetection(
IN PRTMP_ADAPTER pAd,
IN PUCHAR pAddr2,
IN CHAR Rssi0,
IN CHAR Rssi1,
IN CHAR Rssi2,
IN UCHAR AntSel,
IN UCHAR BW)
{
INT i;
for (i = 0; i < pAd->ApCfg.BssidNum; i++)
{
/* Conflict SSID detection */
if (NdisEqualMemory(pAddr2, pAd->ApCfg.MBSSID[i].Bssid, MAC_ADDR_LEN))
{
CHAR RcvdRssi;
RcvdRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Rssi0, RSSI_0, AntSel, BW), ConvertToRssi(pAd, Rssi1, RSSI_1, AntSel, BW), ConvertToRssi(pAd, Rssi2, RSSI_2, AntSel, BW));
pAd->ApCfg.MBSSID[i].RcvdReplayAttackCount ++;
pAd->ApCfg.MBSSID[i].RssiOfRcvdReplayAttack = RcvdRssi;
return TRUE;
}
}
return FALSE;
}
VOID RTMPUpdateStaMgmtCounter(
IN PRTMP_ADAPTER pAd,
IN USHORT type)
{
switch (type)
{
case SUBTYPE_ASSOC_REQ:
pAd->ApCfg.RcvdAssocReqCount ++;
/*DBGPRINT(RT_DEBUG_TRACE, ("RcvdAssocReqCount=%d\n", pAd->ApCfg.RcvdAssocReqCount)); */
break;
case SUBTYPE_REASSOC_REQ:
pAd->ApCfg.RcvdReassocReqCount ++;
/*DBGPRINT(RT_DEBUG_TRACE, ("RcvdReassocReqCount=%d\n", pAd->ApCfg.RcvdReassocReqCount)); */
break;
case SUBTYPE_PROBE_REQ:
pAd->ApCfg.RcvdProbeReqCount ++;
/*DBGPRINT(RT_DEBUG_TRACE, ("RcvdProbeReqCount=%d\n", pAd->ApCfg.RcvdProbeReqCount)); */
break;
case SUBTYPE_DISASSOC:
pAd->ApCfg.RcvdDisassocCount ++;
/*DBGPRINT(RT_DEBUG_TRACE, ("RcvdDisassocCount=%d\n", pAd->ApCfg.RcvdDisassocCount)); */
break;
case SUBTYPE_DEAUTH:
pAd->ApCfg.RcvdDeauthCount ++;
/*DBGPRINT(RT_DEBUG_TRACE, ("RcvdDeauthCount=%d\n", pAd->ApCfg.RcvdDeauthCount)); */
break;
case SUBTYPE_AUTH:
pAd->ApCfg.RcvdAuthCount ++;
/*DBGPRINT(RT_DEBUG_TRACE, ("RcvdAuthCount=%d\n", pAd->ApCfg.RcvdAuthCount)); */
break;
}
}
VOID rtmp_read_ids_from_file(
IN PRTMP_ADAPTER pAd,
PSTRING tmpbuf,
PSTRING buffer)
{
/*IdsEnable */
if(RTMPGetKeyParameter("IdsEnable", tmpbuf, 10, buffer, TRUE))
{
if (simple_strtol(tmpbuf, 0, 10) == 1)
pAd->ApCfg.IdsEnable = TRUE;
else
pAd->ApCfg.IdsEnable = FALSE;
DBGPRINT(RT_DEBUG_TRACE, ("IDS is %s\n", pAd->ApCfg.IdsEnable ? "enabled" : "disabled"));
}
/*AuthFloodThreshold */
if(RTMPGetKeyParameter("AuthFloodThreshold", tmpbuf, 10, buffer, TRUE))
{
pAd->ApCfg.AuthFloodThreshold = simple_strtol(tmpbuf, 0, 10);
DBGPRINT(RT_DEBUG_TRACE, ("AuthFloodThreshold = %d\n", pAd->ApCfg.AuthFloodThreshold));
}
/*AssocReqFloodThreshold */
if(RTMPGetKeyParameter("AssocReqFloodThreshold", tmpbuf, 10, buffer, TRUE))
{
pAd->ApCfg.AssocReqFloodThreshold = simple_strtol(tmpbuf, 0, 10);
DBGPRINT(RT_DEBUG_TRACE, ("AssocReqFloodThreshold = %d\n", pAd->ApCfg.AssocReqFloodThreshold));
}
/*ReassocReqFloodThreshold */
if(RTMPGetKeyParameter("ReassocReqFloodThreshold", tmpbuf, 10, buffer, TRUE))
{
pAd->ApCfg.ReassocReqFloodThreshold = simple_strtol(tmpbuf, 0, 10);
DBGPRINT(RT_DEBUG_TRACE, ("ReassocReqFloodThreshold = %d\n", pAd->ApCfg.ReassocReqFloodThreshold));
}
/*ProbeReqFloodThreshold */
if(RTMPGetKeyParameter("ProbeReqFloodThreshold", tmpbuf, 10, buffer, TRUE))
{
pAd->ApCfg.ProbeReqFloodThreshold = simple_strtol(tmpbuf, 0, 10);
DBGPRINT(RT_DEBUG_TRACE, ("ProbeReqFloodThreshold = %d\n", pAd->ApCfg.ProbeReqFloodThreshold));
}
/*DisassocFloodThreshold */
if(RTMPGetKeyParameter("DisassocFloodThreshold", tmpbuf, 10, buffer, TRUE))
{
pAd->ApCfg.DisassocFloodThreshold = simple_strtol(tmpbuf, 0, 10);
DBGPRINT(RT_DEBUG_TRACE, ("DisassocFloodThreshold = %d\n", pAd->ApCfg.DisassocFloodThreshold));
}
/*DeauthFloodThreshold */
if(RTMPGetKeyParameter("DeauthFloodThreshold", tmpbuf, 10, buffer, TRUE))
{
pAd->ApCfg.DeauthFloodThreshold = simple_strtol(tmpbuf, 0, 10);
DBGPRINT(RT_DEBUG_TRACE, ("DeauthFloodThreshold = %d\n", pAd->ApCfg.DeauthFloodThreshold));
}
/*EapReqFloodThreshold */
if(RTMPGetKeyParameter("EapReqFloodThreshold", tmpbuf, 10, buffer, TRUE))
{
pAd->ApCfg.EapReqFloodThreshold = simple_strtol(tmpbuf, 0, 10);
DBGPRINT(RT_DEBUG_TRACE, ("EapReqFloodThreshold = %d\n", pAd->ApCfg.EapReqFloodThreshold));
}
}
#endif /* IDS_SUPPORT */
|
the_stack_data/237644466.c | #include<stdio.h>
int main(void) {
int tests;
scanf("%i", &tests);
getchar();
char word[10001];
int min = 32, max = 0;
for(int i = 0; i < tests; i++) {
min = 32;
max = 0;
fgets(word, 10001, stdin);
for(int j = 0; word[j] != '\n'; j++) {
if(word[j] - 'A' < min) {
min = word[j] - 'A';
}
if(word[j] - 'A' > max) {
max = word[j] - 'A';
}
}
printf("%i\n", max - min);
}
return 0;
} |
the_stack_data/1011471.c | #include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <setjmp.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static jmp_buf b;
static void
__attribute__ ((noinline))
f (void)
{
char buf[1000];
asm volatile ("" : "=m" (buf));
if (setjmp (b) != 0)
{
puts ("second longjmp succeeded");
exit (1);
}
}
static bool expected_to_fail;
static void
handler (int sig)
{
if (expected_to_fail)
_exit (0);
else
{
static const char msg[] = "unexpected longjmp failure\n";
TEMP_FAILURE_RETRY (write (STDOUT_FILENO, msg, sizeof (msg) - 1));
_exit (1);
}
}
int
main (void)
{
struct sigaction sa;
sa.sa_handler = handler;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
sigaction (SIGABRT, &sa, NULL);
/* Avoid all the buffer overflow messages on stderr. */
int fd = open (_PATH_DEVNULL, O_WRONLY);
if (fd == -1)
close (STDERR_FILENO);
else
{
dup2 (fd, STDERR_FILENO);
close (fd);
}
setenv ("LIBC_FATAL_STDERR_", "1", 1);
expected_to_fail = false;
if (setjmp (b) == 0)
{
longjmp (b, 1);
/* NOTREACHED */
printf ("first longjmp returned\n");
return 1;
}
expected_to_fail = true;
f ();
longjmp (b, 1);
puts ("second longjmp returned");
return 1;
}
|
the_stack_data/167329635.c | /*
https://github.com/lintingbin2009/C-language/tree/master/%E5%89%91%E6%8C%87offer/%E9%9D%A2%E8%AF%95%E9%A2%9804%E2%80%94%E2%80%94%E6%9B%BF%E6%8D%A2%E7%A9%BA%E6%A0%BC
面试题04——替换空格
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i,j=0;
char buff[100];
char new_buff[100];
while(gets(buff) != NULL)
{
memset(new_buff, 0 ,sizeof(new_buff));
j = 0;
for (i = 0; i< strlen(buff); i++)
{
if (buff[i] == ' ' && buff[i+1] != ' ')
{
new_buff[j++] = '%';
new_buff[j++] = '2';
new_buff[j++] = '0';
}
if (buff[i] != ' ')
{
new_buff[j++] = buff[i];
}
}
printf("%s\n", new_buff);
memset(buff, 0, sizeof(buff));
}
} |
the_stack_data/175144461.c | /*
This program prints all of the possible substrings of a word
and calculates the number of the substrings
By: randerson112358
7/28/17
*/
# include<stdio.h>
# include<string.h>
void printStr(int begin, int end, char* str);
int main(void)
{
char* string = "Rod" ;
int length = strlen(string);
int i,j,k;
//Calculating the number of possible substrings
int numSubstring = ( length * (length +1) )/ 2;
//Print the possible number of substrings
printf("The number of substrings in the word %s is %d\n\n", string,numSubstring);
for(i=0; i<length; i++){
for(j=0; j<length-i; j++){
printStr(i, length-j, string);
}
}
system("pause");
}
//Prints the string from the start location to the finish location
void printStr(int begin, int end, char* str){
int i;
for(i=begin; i<end; i++)
printf("%c", str[i]);
printf("\n");
}
|
the_stack_data/761323.c | #include <math.h>
double snrm(unsigned long n, double sx[], int itol)
{
unsigned long i,isamax;
double ans;
if (itol <= 3) {
ans = 0.0;
for (i=1;i<=n;i++) ans += sx[i]*sx[i];
return sqrt(ans);
} else {
isamax=1;
for (i=1;i<=n;i++) {
if (fabs(sx[i]) > fabs(sx[isamax])) isamax=i;
}
return fabs(sx[isamax]);
}
}
/* (C) Copr. 1986-92 Numerical Recipes Software 9.1-5i. */
|
the_stack_data/36074818.c | // general protection fault in tls_write_space
// https://syzkaller.appspot.com/bug?id=8e788a915d5eb99a280db507a932d577ec967bed
// status:fixed
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/capability.h>
#include <linux/futex.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
unsigned long long procid;
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) &&
(addr < prog_start || addr > prog_end)) {
_longjmp(segv_env, 1);
}
exit(sig);
}
static void install_segv_handler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
exit(1);
if (chmod(tmpdir, 0777))
exit(1);
if (chdir(tmpdir))
exit(1);
}
static void thread_start(void* (*fn)(void*), void* arg)
{
pthread_t th;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
int i;
for (i = 0; i < 100; i++) {
if (pthread_create(&th, &attr, fn, arg) == 0) {
pthread_attr_destroy(&attr);
return;
}
if (errno == EAGAIN) {
usleep(50);
continue;
}
break;
}
exit(1);
}
typedef struct {
int state;
} event_t;
static void event_init(event_t* ev)
{
ev->state = 0;
}
static void event_reset(event_t* ev)
{
ev->state = 0;
}
static void event_set(event_t* ev)
{
if (ev->state)
exit(1);
__atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG);
}
static void event_wait(event_t* ev)
{
while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
}
static int event_isset(event_t* ev)
{
return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}
static int event_timedwait(event_t* ev, uint64_t timeout)
{
uint64_t start = current_time_ms();
uint64_t now = start;
for (;;) {
uint64_t remain = timeout - (now - start);
struct timespec ts;
ts.tv_sec = remain / 1000;
ts.tv_nsec = (remain % 1000) * 1000 * 1000;
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static struct {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
} nlmsg;
static void netlink_init(int typ, int flags, const void* data, int size)
{
memset(&nlmsg, 0, sizeof(nlmsg));
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf;
hdr->nlmsg_type = typ;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
memcpy(hdr + 1, data, size);
nlmsg.pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
}
static void netlink_attr(int typ, const void* data, int size)
{
struct nlattr* attr = (struct nlattr*)nlmsg.pos;
attr->nla_len = sizeof(*attr) + size;
attr->nla_type = typ;
memcpy(attr + 1, data, size);
nlmsg.pos += NLMSG_ALIGN(attr->nla_len);
}
static void netlink_nest(int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg.pos;
attr->nla_type = typ;
nlmsg.pos += sizeof(*attr);
nlmsg.nested[nlmsg.nesting++] = attr;
}
static void netlink_done(void)
{
struct nlattr* attr = nlmsg.nested[--nlmsg.nesting];
attr->nla_len = nlmsg.pos - (char*)attr;
}
static int netlink_send(int sock)
{
if (nlmsg.pos > nlmsg.buf + sizeof(nlmsg.buf) || nlmsg.nesting)
exit(1);
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf;
hdr->nlmsg_len = nlmsg.pos - nlmsg.buf;
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
unsigned n = sendto(sock, nlmsg.buf, hdr->nlmsg_len, 0,
(struct sockaddr*)&addr, sizeof(addr));
if (n != hdr->nlmsg_len)
exit(1);
n = recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0);
if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return -((struct nlmsgerr*)(hdr + 1))->error;
}
static void netlink_add_device_impl(const char* type, const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr));
if (name)
netlink_attr(IFLA_IFNAME, name, strlen(name));
netlink_nest(IFLA_LINKINFO);
netlink_attr(IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(int sock, const char* type, const char* name)
{
netlink_add_device_impl(type, name);
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_veth(int sock, const char* name, const char* peer)
{
netlink_add_device_impl("veth", name);
netlink_nest(IFLA_INFO_DATA);
netlink_nest(VETH_INFO_PEER);
nlmsg.pos += sizeof(struct ifinfomsg);
netlink_attr(IFLA_IFNAME, peer, strlen(peer));
netlink_done();
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_hsr(int sock, const char* name, const char* slave1,
const char* slave2)
{
netlink_add_device_impl("hsr", name);
netlink_nest(IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_device_change(int sock, const char* name, bool up,
const char* master, const void* mac,
int macsize)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr));
netlink_attr(IFLA_IFNAME, name, strlen(name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(IFLA_ADDRESS, mac, macsize);
int err = netlink_send(sock);
(void)err;
}
static int netlink_add_addr(int sock, const char* dev, const void* addr,
int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr));
netlink_attr(IFA_LOCAL, addr, addrsize);
netlink_attr(IFA_ADDRESS, addr, addrsize);
return netlink_send(sock);
}
static void netlink_add_addr4(int sock, const char* dev, const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(int sock, const char* dev, const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
static void netlink_add_neigh(int sock, const char* name, const void* addr,
int addrsize, const void* mac, int macsize)
{
struct ndmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ndm_ifindex = if_nametoindex(name);
hdr.ndm_state = NUD_PERMANENT;
netlink_init(RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr));
netlink_attr(NDA_DST, addr, addrsize);
netlink_attr(NDA_LLADDR, mac, macsize);
int err = netlink_send(sock);
(void)err;
}
static int tunfd = -1;
static int tun_frags_enabled;
#define SYZ_TUN_MAX_PACKET_SIZE 1000
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC 0xaaaaaaaaaaaa
#define REMOTE_MAC 0xaaaaaaaaaabb
#define LOCAL_IPV4 "172.20.20.170"
#define REMOTE_IPV4 "172.20.20.187"
#define LOCAL_IPV6 "fe80::aa"
#define REMOTE_IPV6 "fe80::bb"
#define IFF_NAPI 0x0010
#define IFF_NAPI_FRAGS 0x0020
static void initialize_tun(void)
{
tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (tunfd == -1) {
printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n");
printf("otherwise fuzzing or reproducing might not work as intended\n");
return;
}
const int kTunFd = 240;
if (dup2(tunfd, kTunFd) < 0)
exit(1);
close(tunfd);
tunfd = kTunFd;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ);
ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_NAPI | IFF_NAPI_FRAGS;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) {
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0)
exit(1);
}
if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0)
exit(1);
tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0;
char sysctl[64];
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE);
write_file(sysctl, "0");
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE);
write_file(sysctl, "0");
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
netlink_add_addr4(sock, TUN_IFACE, LOCAL_IPV4);
netlink_add_addr6(sock, TUN_IFACE, LOCAL_IPV6);
uint64_t macaddr = REMOTE_MAC;
struct in_addr in_addr;
inet_pton(AF_INET, REMOTE_IPV4, &in_addr);
netlink_add_neigh(sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr,
ETH_ALEN);
struct in6_addr in6_addr;
inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr);
netlink_add_neigh(sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr,
ETH_ALEN);
macaddr = LOCAL_MAC;
netlink_device_change(sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN);
close(sock);
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
};
const char* devmasters[] = {"bridge", "bond", "team"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(sock, slave0, false, master, 0, 0);
netlink_device_change(sock, slave1, false, master, 0, 0);
}
netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0);
netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0);
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true},
{"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
netlink_add_addr6(sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize);
}
close(sock);
}
static int read_tun(char* data, int size)
{
if (tunfd < 0)
return -1;
int rv = read(tunfd, data, size);
if (rv < 0) {
if (errno == EAGAIN)
return -1;
if (errno == EBADFD)
return -1;
exit(1);
}
return rv;
}
static void flush_tun()
{
char data[SYZ_TUN_MAX_PACKET_SIZE];
while (read_tun(&data[0], sizeof(data)) != -1) {
}
}
static long syz_genetlink_get_family_id(volatile long name)
{
char buf[512] = {0};
struct nlmsghdr* hdr = (struct nlmsghdr*)buf;
struct genlmsghdr* genlhdr = (struct genlmsghdr*)NLMSG_DATA(hdr);
struct nlattr* attr = (struct nlattr*)(genlhdr + 1);
hdr->nlmsg_len =
sizeof(*hdr) + sizeof(*genlhdr) + sizeof(*attr) + GENL_NAMSIZ;
hdr->nlmsg_type = GENL_ID_CTRL;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
genlhdr->cmd = CTRL_CMD_GETFAMILY;
attr->nla_type = CTRL_ATTR_FAMILY_NAME;
attr->nla_len = sizeof(*attr) + GENL_NAMSIZ;
NONFAILING(strncpy((char*)(attr + 1), (char*)name, GENL_NAMSIZ));
struct iovec iov = {hdr, hdr->nlmsg_len};
struct sockaddr_nl addr = {0};
addr.nl_family = AF_NETLINK;
int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (fd == -1) {
return -1;
}
struct msghdr msg = {&addr, sizeof(addr), &iov, 1, NULL, 0, 0};
if (sendmsg(fd, &msg, 0) == -1) {
close(fd);
return -1;
}
ssize_t n = recv(fd, buf, sizeof(buf), 0);
close(fd);
if (n <= 0) {
return -1;
}
if (hdr->nlmsg_type != GENL_ID_CTRL) {
return -1;
}
for (; (char*)attr < buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID)
return *(uint16_t*)(attr + 1);
}
return -1;
}
#define XT_TABLE_SIZE 1536
#define XT_MAX_ENTRIES 10
struct xt_counters {
uint64_t pcnt, bcnt;
};
struct ipt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_entries;
unsigned int size;
};
struct ipt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct ipt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct ipt_table_desc {
const char* name;
struct ipt_getinfo info;
struct ipt_replace replace;
};
static struct ipt_table_desc ipv4_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
static struct ipt_table_desc ipv6_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
#define IPT_BASE_CTL 64
#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
#define IPT_SO_GET_INFO (IPT_BASE_CTL)
#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
struct arpt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_entries;
unsigned int size;
};
struct arpt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct arpt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct arpt_table_desc {
const char* name;
struct arpt_getinfo info;
struct arpt_replace replace;
};
static struct arpt_table_desc arpt_tables[] = {
{.name = "filter"},
};
#define ARPT_BASE_CTL 96
#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct ipt_get_entries entries;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct ipt_get_entries entries;
struct ipt_getinfo info;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_arptables(void)
{
struct arpt_get_entries entries;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_arptables()
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct arpt_get_entries entries;
struct arpt_getinfo info;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
} else {
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
#define NF_BR_NUMHOOKS 6
#define EBT_TABLE_MAXNAMELEN 32
#define EBT_CHAIN_MAXNAMELEN 32
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1)
struct ebt_replace {
char name[EBT_TABLE_MAXNAMELEN];
unsigned int valid_hooks;
unsigned int nentries;
unsigned int entries_size;
struct ebt_entries* hook_entry[NF_BR_NUMHOOKS];
unsigned int num_counters;
struct ebt_counter* counters;
char* entries;
};
struct ebt_entries {
unsigned int distinguisher;
char name[EBT_CHAIN_MAXNAMELEN];
unsigned int counter_offset;
int policy;
unsigned int nentries;
char data[0] __attribute__((aligned(__alignof__(struct ebt_replace))));
};
struct ebt_table_desc {
const char* name;
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
};
static struct ebt_table_desc ebt_tables[] = {
{.name = "filter"},
{.name = "nat"},
{.name = "broute"},
};
static void checkpoint_ebtables(void)
{
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
strcpy(table->replace.name, table->name);
optlen = sizeof(table->replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace,
&optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->replace.entries_size > sizeof(table->entrytable))
exit(1);
table->replace.num_counters = 0;
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace,
&optlen))
exit(1);
}
close(fd);
}
static void reset_ebtables()
{
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
socklen_t optlen;
unsigned i, j, h;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
if (table->replace.valid_hooks == 0)
continue;
memset(&replace, 0, sizeof(replace));
strcpy(replace.name, table->name);
optlen = sizeof(replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen))
exit(1);
replace.num_counters = 0;
table->replace.entries = 0;
for (h = 0; h < NF_BR_NUMHOOKS; h++)
table->replace.hook_entry[h] = 0;
if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) {
memset(&entrytable, 0, sizeof(entrytable));
replace.entries = entrytable;
optlen = sizeof(replace) + replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen))
exit(1);
if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0)
continue;
}
for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) {
if (table->replace.valid_hooks & (1 << h)) {
table->replace.hook_entry[h] =
(struct ebt_entries*)table->entrytable + j;
j++;
}
}
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_net_namespace(void)
{
checkpoint_ebtables();
checkpoint_arptables();
checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void reset_net_namespace(void)
{
reset_ebtables();
reset_arptables();
reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void setup_cgroups()
{
if (mkdir("/syzcgroup", 0777)) {
}
if (mkdir("/syzcgroup/unified", 0777)) {
}
if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) {
}
if (chmod("/syzcgroup/unified", 0777)) {
}
write_file("/syzcgroup/unified/cgroup.subtree_control",
"+cpu +memory +io +pids +rdma");
if (mkdir("/syzcgroup/cpu", 0777)) {
}
if (mount("none", "/syzcgroup/cpu", "cgroup", 0,
"cpuset,cpuacct,perf_event,hugetlb")) {
}
write_file("/syzcgroup/cpu/cgroup.clone_children", "1");
if (chmod("/syzcgroup/cpu", 0777)) {
}
if (mkdir("/syzcgroup/net", 0777)) {
}
if (mount("none", "/syzcgroup/net", "cgroup", 0,
"net_cls,net_prio,devices,freezer")) {
}
if (chmod("/syzcgroup/net", 0777)) {
}
}
static void setup_cgroups_loop()
{
int pid = getpid();
char file[128];
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/pids.max", cgroupdir);
write_file(file, "32");
snprintf(file, sizeof(file), "%s/memory.low", cgroupdir);
write_file(file, "%d", 298 << 20);
snprintf(file, sizeof(file), "%s/memory.high", cgroupdir);
write_file(file, "%d", 299 << 20);
snprintf(file, sizeof(file), "%s/memory.max", cgroupdir);
write_file(file, "%d", 300 << 20);
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
}
static void setup_cgroups_test()
{
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.cpu")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.net")) {
}
}
void initialize_cgroups()
{
if (mkdir("./syz-tmp/newroot/syzcgroup", 0700))
exit(1);
if (mkdir("./syz-tmp/newroot/syzcgroup/unified", 0700))
exit(1);
if (mkdir("./syz-tmp/newroot/syzcgroup/cpu", 0700))
exit(1);
if (mkdir("./syz-tmp/newroot/syzcgroup/net", 0700))
exit(1);
unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE;
if (mount("/syzcgroup/unified", "./syz-tmp/newroot/syzcgroup/unified", NULL,
bind_mount_flags, NULL)) {
}
if (mount("/syzcgroup/cpu", "./syz-tmp/newroot/syzcgroup/cpu", NULL,
bind_mount_flags, NULL)) {
}
if (mount("/syzcgroup/net", "./syz-tmp/newroot/syzcgroup/net", NULL,
bind_mount_flags, NULL)) {
}
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
setup_cgroups();
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static void drop_caps(void)
{
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
exit(1);
const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
cap_data[0].effective &= ~drop;
cap_data[0].permitted &= ~drop;
cap_data[0].inheritable &= ~drop;
if (syscall(SYS_capset, &cap_hdr, &cap_data))
exit(1);
}
static int real_uid;
static int real_gid;
__attribute__((aligned(64 << 10))) static char sandbox_stack[1 << 20];
static int namespace_sandbox_proc(void* arg)
{
sandbox_common();
write_file("/proc/self/setgroups", "deny");
if (!write_file("/proc/self/uid_map", "0 %d 1\n", real_uid))
exit(1);
if (!write_file("/proc/self/gid_map", "0 %d 1\n", real_gid))
exit(1);
initialize_netdevices_init();
if (unshare(CLONE_NEWNET))
exit(1);
initialize_tun();
initialize_netdevices();
if (mkdir("./syz-tmp", 0777))
exit(1);
if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
exit(1);
if (mkdir("./syz-tmp/newroot", 0777))
exit(1);
if (mkdir("./syz-tmp/newroot/dev", 0700))
exit(1);
unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE;
if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL))
exit(1);
if (mkdir("./syz-tmp/newroot/proc", 0700))
exit(1);
if (mount(NULL, "./syz-tmp/newroot/proc", "proc", 0, NULL))
exit(1);
if (mkdir("./syz-tmp/newroot/selinux", 0700))
exit(1);
const char* selinux_path = "./syz-tmp/newroot/selinux";
if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) {
if (errno != ENOENT)
exit(1);
if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) &&
errno != ENOENT)
exit(1);
}
if (mkdir("./syz-tmp/newroot/sys", 0700))
exit(1);
if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL))
exit(1);
initialize_cgroups();
if (mkdir("./syz-tmp/pivot", 0777))
exit(1);
if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
if (chdir("./syz-tmp"))
exit(1);
} else {
if (chdir("/"))
exit(1);
if (umount2("./pivot", MNT_DETACH))
exit(1);
}
if (chroot("./newroot"))
exit(1);
if (chdir("/"))
exit(1);
drop_caps();
loop();
exit(1);
}
static int do_sandbox_namespace(void)
{
int pid;
setup_common();
real_uid = getuid();
real_gid = getgid();
mprotect(sandbox_stack, 4096, PROT_NONE);
pid =
clone(namespace_sandbox_proc, &sandbox_stack[sizeof(sandbox_stack) - 64],
CLONE_NEWUSER | CLONE_NEWPID, 0);
return wait_for_loop(pid);
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
while (umount2(dir, MNT_DETACH) == 0) {
}
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
while (umount2(filename, MNT_DETACH) == 0) {
}
struct stat st;
if (lstat(filename, &st))
exit(1);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EPERM) {
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exit(1);
if (umount2(filename, MNT_DETACH))
exit(1);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EPERM) {
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
if (umount2(dir, MNT_DETACH))
exit(1);
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exit(1);
}
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_loop()
{
setup_cgroups_loop();
checkpoint_net_namespace();
}
static void reset_loop()
{
reset_net_namespace();
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setup_cgroups_test();
write_file("/proc/self/oom_score_adj", "1000");
flush_tun();
}
static void close_fds()
{
int fd;
for (fd = 3; fd < 30; fd++)
close(fd);
}
static void setup_binfmt_misc()
{
if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) {
}
write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:");
write_file("/proc/sys/fs/binfmt_misc/register",
":syz1:M:1:\x02::./file0:POC");
}
struct thread_t {
int created, call;
event_t ready, done;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
event_wait(&th->ready);
event_reset(&th->ready);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
event_set(&th->done);
}
return 0;
}
static void execute_one(void)
{
int i, call, thread;
int collide = 0;
again:
for (call = 0; call < 23; call++) {
for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
if (collide && (call % 2) == 0)
break;
event_timedwait(&th->done, 45);
break;
}
}
for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
sleep_ms(1);
close_fds();
if (!collide) {
collide = 1;
goto again;
}
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
setup_loop();
int iter;
for (iter = 0;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
reset_loop();
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
if (chdir(cwdbuf))
exit(1);
setup_test();
execute_one();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
remove_dir(cwdbuf);
}
}
uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
0xffffffffffffffff};
void execute_call(int call)
{
intptr_t res;
switch (call) {
case 0:
res = syscall(__NR_socket, 0xa, 1, 0);
if (res != -1)
r[0] = res;
break;
case 1:
res = syscall(__NR_socket, 0xa, 1, 0);
if (res != -1)
r[1] = res;
break;
case 2:
res = syscall(__NR_pipe, 0x20000000);
if (res != -1) {
NONFAILING(r[2] = *(uint32_t*)0x20000000);
NONFAILING(r[3] = *(uint32_t*)0x20000004);
}
break;
case 3:
syscall(__NR_getsockopt, r[3], 0x84, 6, 0, 0);
break;
case 4:
NONFAILING(*(uint32_t*)0x20000380 = 0);
syscall(__NR_getsockopt, r[2], 0x84, 0x18, 0, 0x20000380);
break;
case 5:
NONFAILING(*(uint16_t*)0x200000c0 = 0xa);
NONFAILING(*(uint16_t*)0x200000c2 = htobe16(0x4e22));
NONFAILING(*(uint32_t*)0x200000c4 = htobe32(0));
NONFAILING(memcpy(
(void*)0x200000c8,
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
16));
NONFAILING(*(uint32_t*)0x200000d8 = 0);
syscall(__NR_bind, r[1], 0x200000c0, 0x1c);
break;
case 6:
syscall(__NR_listen, r[1], 1);
break;
case 7:
NONFAILING(*(uint16_t*)0x20000040 = 0xa);
NONFAILING(*(uint16_t*)0x20000042 = htobe16(0x4e22));
NONFAILING(*(uint32_t*)0x20000044 = htobe32(0));
NONFAILING(*(uint64_t*)0x20000048 = htobe64(0));
NONFAILING(*(uint64_t*)0x20000050 = htobe64(1));
NONFAILING(*(uint32_t*)0x20000058 = 0);
syscall(__NR_sendto, r[0], 0, 0, 0x20004004, 0x20000040, 0x1c);
break;
case 8:
syscall(__NR_ioctl, r[2], 0x8980, 0);
break;
case 9:
syscall(__NR_socket, 0xa, 1, 0);
break;
case 10:
NONFAILING(memcpy((void*)0x20000200, "tls\000", 4));
syscall(__NR_setsockopt, r[0], 6, 0x1f, 0x20000200, 4);
break;
case 11:
syscall(__NR_ioctl, r[0], 0, 0x20000280);
break;
case 12:
syscall(__NR_socket, 2, 2, 0x88);
break;
case 13:
syscall(__NR_socket, 0x10, 3, 0xc);
break;
case 14:
NONFAILING(memcpy((void*)0x20000800, "TIPC\000", 5));
syz_genetlink_get_family_id(0x20000800);
break;
case 15:
syscall(__NR_sendmsg, -1, 0, 0);
break;
case 16:
NONFAILING(*(uint16_t*)0x20000100 = 0x303);
NONFAILING(*(uint16_t*)0x20000102 = 0x33);
NONFAILING(
memcpy((void*)0x20000104, "\xd4\x4e\xb8\xc7\x30\x8e\xc7\xc4", 8));
NONFAILING(memcpy(
(void*)0x2000010c,
"\x44\x20\x65\x23\x89\x29\x35\x0a\xde\x91\x90\x0b\x51\xfc\x95\x34",
16));
NONFAILING(memcpy((void*)0x2000011c, "\x6b\xdd\xa7\x20", 4));
NONFAILING(
memcpy((void*)0x20000120, "\x7e\xe5\x14\x30\xda\x3f\x51\xb3", 8));
syscall(__NR_setsockopt, r[0], 0x11a, 1, 0x20000100, 0x28);
break;
case 17:
syscall(__NR_openat, -1, 0, 2, 0);
break;
case 18:
NONFAILING(*(uint32_t*)0x200003c0 = 1);
NONFAILING(*(uint32_t*)0x200003c4 = 9);
syscall(__NR_setsockopt, r[0], 1, 0xd, 0x200003c0, 8);
break;
case 19:
syscall(__NR_setsockopt, r[1], 0x29, 0x17, 0, 0);
break;
case 20:
syscall(__NR_sendto, r[0], 0x200005c0, 0xffffffffffffffc1, 0, 0,
0x1201000000003618);
break;
case 21:
syscall(__NR_sendmsg, -1, 0, 0);
break;
case 22:
syscall(__NR_ioctl, r[1], 4, 0);
break;
}
}
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
setup_binfmt_misc();
install_segv_handler();
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
use_temporary_dir();
do_sandbox_namespace();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/176706010.c | // gcc -O2 -o flex_flip flex_flip.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define DATA_SIZE 256
#define N_STATE 2
char basedir[DATA_SIZE];
char *basedir_end = NULL;
char content[DATA_SIZE];
char command[DATA_SIZE*4];
char *ROT[] = {"normal", "inverted", "left", "right",};
char *COOR[] = {"1 0 0 0 1 0 0 0 1", "-1 0 1 0 -1 1 0 0 1", "0 -1 1 1 0 0 0 0 1", "0 1 0 -1 0 1 0 0 1"};
// char *TOUCH[] = {"enable", "disable", "disable", "disable"};
double accel_y = 0.0,
accel_x = 0.0,
accel_z = 0.0,
accel_g = 6.0;
int current_state = 0;
int rotation_changed(){
int state = 0;
if(accel_y < -accel_g) state = 0;
else if(accel_y > accel_g) state = 1;
else if(accel_x > accel_g) state = 2;
else if(accel_x < -accel_g) state = 3;
else if(accel_z > accel_g) state = 4;
else if(accel_z < -accel_g) state = 4;
if(current_state!=state){
current_state = state;
return 1;
}
else return 0;
}
FILE* bdopen(char const *fname, char leave_open){
*basedir_end = '/';
strcpy(basedir_end+1, fname);
FILE *fin = fopen(basedir, "r");
setvbuf(fin, NULL, _IONBF, 0);
fgets(content, DATA_SIZE, fin);
*basedir_end = '\0';
if(leave_open==0){
fclose(fin);
return NULL;
}
else return fin;
}
void rotate_screen(){
sprintf(command, "xrandr -o %s", ROT[current_state]);
system(command);
sprintf(command, "xinput set-prop \"%s\" \"Coordinate Transformation Matrix\" %s", "Wacom HID 51C4 Finger touch", COOR[current_state]);
system(command);
sprintf(command, "xinput set-prop \"%s\" \"Coordinate Transformation Matrix\" %s", "Wacom HID 51C4 Pen stylus", COOR[current_state]);
system(command);
}
int main(int argc, char const *argv[]) {
FILE *pf = popen("ls /sys/bus/iio/devices/iio:device*/in_accel*", "r");
if(!pf){
fprintf(stderr, "IO Error.\n");
return 2;
}
if(fgets(basedir, DATA_SIZE , pf)!=NULL){
basedir_end = strrchr(basedir, '/');
if(basedir_end) *basedir_end = '\0';
fprintf(stderr, "Accelerometer: %s\n", basedir);
}
else{
fprintf(stderr, "Unable to find any accelerometer.\n");
return 1;
}
pclose(pf);
bdopen("in_accel_scale", 0);
double scale = atof(content);
FILE *dev_accel_y = bdopen("in_accel_y_raw", 1);
FILE *dev_accel_x = bdopen("in_accel_x_raw", 1);
FILE *dev_accel_z = bdopen("in_accel_z_raw", 1);
while(1){
fseek(dev_accel_y, 0, SEEK_SET);
fgets(content, DATA_SIZE, dev_accel_y);
accel_y = atof(content) * scale;
fseek(dev_accel_x, 0, SEEK_SET);
fgets(content, DATA_SIZE, dev_accel_x);
accel_x = atof(content) * scale;
fseek(dev_accel_z, 0, SEEK_SET);
fgets(content, DATA_SIZE, dev_accel_z);
accel_z = atof(content) * scale;
if(rotation_changed())
rotate_screen();
sleep(1);
}
return 0;
}
|
the_stack_data/100139257.c | #define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
char *ecvt(double x, int n, int *dp, int *sign)
{
static char buf[16];
char tmp[32];
int i, j;
if (n-1U > 15) n = 15;
sprintf(tmp, "%.*e", n-1, x);
i = *sign = (tmp[0]=='-');
for (j=0; tmp[i]!='e'; j+=(tmp[i++]!='.'))
buf[j] = tmp[i];
buf[j] = 0;
*dp = atoi(tmp+i+1)+1;
return buf;
}
|
the_stack_data/215767111.c | #include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
int oldfd = open("left.txt", O_RDWR | O_CREAT, 0664);
if (oldfd == -1) {
perror("open");
return -1;
}
int newfd = open("right.txt", O_RDWR | O_CREAT, 0664);
if (newfd == -1) {
perror("open");
return -1;
}
printf("oldfd: %d\nnewfd: %d\n", oldfd, newfd);
// redirect oldfd to newfd
int latestfd = dup2(oldfd, newfd);
if (latestfd == -1) {
perror("dup2");
return -1;
}
char *str = "hello, dup2";
if (write(newfd, str, strlen(str)) == -1) {
perror("write");
return -1;
}
printf("oldfd: %d\nnewfd: %d\nlatestfd: %d\n", oldfd, newfd, latestfd);
close(oldfd);
close(newfd);
return 0;
}
|
the_stack_data/137815.c | #define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sched.h>
#include <wait.h>
#define PROG1 "./get_mem"
#define PROG1_ARGV "0"
#define PROG2 PROG1
#define PROG2_ARGV PROG1_ARGV
int main(int argc, char** argv)
{
pid_t pid, pid1, pid2;
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
CPU_SET(0, &cpu_set);
pid = fork();
if (pid < 0) {
return -1;
}
if (pid == 0) {
// if (sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpu_set) != 0) {
// return -1;
// }
if (execl(PROG1, PROG1, PROG1_ARGV, (char *)NULL) < 0) {
perror(strerror(errno));
return -2;
}
}
pid1 = pid;
pid = fork();
if (pid < 0) {
return -1;
}
if (pid == 0) {
// if (sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpu_set) != 0) {
// return -1;
// }
if (execl(PROG2, PROG2, PROG2_ARGV, (char *)NULL) < 0) {
perror(strerror(errno));
return -2;
}
}
pid2 = pid;
// setpriority(PRIO_PROCESS, pid1, 10);
printf("Parent(%d), child1(%d), child2(%d)\n", getpid(), pid1, pid2);
waitpid(pid1, NULL, 0);
waitpid(pid2, NULL, 0);
return 0;
}
|
the_stack_data/179699.c | /**
* Programa 'redir' que permita executar um comando, opcionalmente redirecionando a
* entrada e/ou a saida:
* redir [-i <inputfile>] [-o <outputfile>] <command> [arg1] [arg2] [...
*
* @author (Pirata)
* @version (2018.02)
*/
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char** argv)
{
int fd_in = STDIN_FILENO, fd_out = STDOUT_FILENO, opt_flag = 1, i = 1, err;
pid_t pid;
/* Getting all the arguments and checking if there is an input or output file
* Assuming that the -o and the -i come as the first pairs of arguments. In case that
* doesn't happens it will consider it as arguments of the command we want to run. */
while (opt_flag && (i < argc)) {
if (!strcmp("-o",argv[i]) || !strcmp("-i",argv[i])) {
// opt_flag keeps being True
if (i + 1 < argc) {
if (!strcmp("-o",argv[i])) {
fd_out = open(argv[i + 1], O_CREAT | O_APPEND | O_WRONLY, 0640);
}
if (!strcmp("-i",argv[i])) {
fd_in = open(argv[i + 1], O_RDONLY);
}
i += 2;
} else {
perror("Ahoy there... where the rest of arguments might be?");
_exit(EXIT_FAILURE);
}
} else {
opt_flag = 0;
}
}
// At this point we already have the files input and output if any were given
pid = fork();
if (pid < 0) {
perror("no child was made, universe didn't wanted it to happen");
_exit(EXIT_FAILURE);
}
if (pid == 0) {
// child process
err = dup2(fd_in, STDIN_FILENO);
if (err < 0) {
perror("Can't read, not even with my good eye!");
_exit(err);
}
close(fd_in);
err = dup2(fd_out, STDOUT_FILENO);
if (err < 0) {
perror("Blamey pirates stole my log book, where to write now!");
_exit(err);
}
close(fd_in);
// Now with the correct redirections, we execute the command
argv[argc] = NULL;
execvp(argv[i], argv+i);
// only comes here if execvp fails
perror(argv[i]);
_exit(EXIT_FAILURE);
} else {
// parent process
wait(NULL);
close(fd_in);
close(fd_out);
}
exit(EXIT_SUCCESS);
} |
the_stack_data/71328.c | /* Return nonzero value if number is negative.
Copyright (C) 1997-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <[email protected]>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <math.h>
int
__signbitl (long double x)
{
return __builtin_signbitl (x);
}
|
the_stack_data/965630.c | #include <nl_types.h>
typedef int nl_item;
/*
XOPEN(4)
*/
|
the_stack_data/206393428.c | #include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define SYSTEM_SIZE 128
typedef struct
{
char data;
unsigned char nextElementAdress;
} block;
int main(int argc, char **argv) {
int fd = open(argv[1], O_RDONLY);
for (int i = 0; i < SYSTEM_SIZE; i++) {
block current_block;
read(fd, ¤t_block.data, sizeof(char));
read(fd, ¤t_block.nextElementAdress, sizeof(unsigned char));
write(1, ¤t_block.data, sizeof(char));
if (!current_block.nextElementAdress) {
break;
}
lseek(fd, current_block.nextElementAdress, SEEK_SET);
}
close(fd);
return 0;
} |
the_stack_data/170454003.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2015 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation nor the names of its contributors may be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
END_LEGAL */
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <dlfcn.h>
#include <stdio.h>
#ifdef TARGET_MAC
#define ONE "libone.dylib"
#define TWO "libtwo.dylib"
#else
#define ONE "libone.so"
#define TWO "libtwo.so"
#endif
void Load(char *name, int expect)
{
int val;
double dval;
void *handle;
int (*sym)();
double (*fsin)(double);
handle = dlopen(name, RTLD_LAZY);
if (handle == 0)
{
fprintf(stderr,"Load of %s failed\n",name);
exit(1);
}
sym = (int(*)())dlsym(handle, "one");
if (sym == 0)
{
fprintf(stderr,"Dlsym of %s failed\n",name);
exit(1);
}
val = sym();
if (val != expect)
exit(1);
dlclose(handle);
}
int main()
{
int i;
for(i = 0; i < 100; i++)
{
switch(1 + rand() % 2) {
case 1:
Load(ONE, 1);
break;
case 2:
Load(TWO, 2);
break;
}
}
return 0;
}
|
the_stack_data/1107548.c | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include <assert.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, const char* argv[])
{
const char filename[] = "/mnt/datafs/myfile";
const size_t filesize = 7;
if (mount("/datafs", "/mnt/datafs", "ramfs", 0, NULL) != 0)
assert(false);
if (access(filename, R_OK) != 0)
assert(false);
/* read a file on the mounted file system */
{
int fd;
struct stat st;
char buf[128];
assert((fd = open(filename, O_RDONLY)) >= 0);
assert(stat(filename, &st) == 0);
assert(st.st_size == filesize);
assert(read(fd, buf, sizeof(buf)) == filesize);
assert(memcmp(buf, "myfile", 6) == 0);
assert(close(fd) == 0);
}
if (umount("/mnt/datafs") != 0)
assert(false);
printf("=== passed test (%s)\n", argv[0]);
return 0;
}
|
the_stack_data/103266264.c | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
int* utworz(int wym)
{
return (int(*)[wym])malloc(wym*wym*sizeof(int));
}
void wypelnij(int* tab, int wym)
{
int i,j;
for (i=0; i<wym; i++)
for (j=0; j<wym; j++)
tab[wym*i+j]=i*j;
}
void wyswietl (int* tab, int wym)
{
int i,j;
for (i=0; i<wym; i++)
{
for (j=0; j<wym; j++)
printf("%d ",tab[wym*i+j]);
printf("\n");
}
}
void zmiana_znaku(int* tab, int wym)
{
int i,j;
for (i=0; i<wym; i++)
for (j=0; j<wym; j++)
tab[wym*i+j]*=-1;
}
int main(int argc, char *args[])
{
int i,j;
char wybor='a';
int wymiar=0;
int *a=NULL, *b=NULL;
if (argc!=2)
{
printf("Niewlasciwa liczba parametrow. Uzycie: './a.out wymiar_tablicy'.\n");
return 1;
}
else wymiar=atoi(args[1]);
if (wymiar<=0)
{
printf("Niepoprawna wartosc parametru. Argument musi byc dodatni.\n");
return 2;
}
while (wybor!='0')
{
printf("----------MENU----------\n");
printf("1 - Tworzenie tablicy.\n");
printf("2 - Wypełnianie tablicy.\n");
printf("3 - Wyświetlanie tablicy.\n");
printf("4 - Zmiana znaków w tablicy.\n");
printf("5 - Tworzenie drugiej tablicy.\n");
printf("6 - Przemnożenie dwóch tablic.\n");
printf("0 - KONIEC\n");
scanf("%c",&wybor);
switch (wybor)
{
case '1':
a=utworz(wymiar);
printf("Tablica została utworzona.\n");
break;
case '2':
wypelnij(a,wymiar);
printf("Tablica została wypełniona.\n");
break;
case '3':
wyswietl(a,wymiar);
break;
case '4':
zmiana_znaku(a,wymiar);
printf("Znak został zmieniony.\n");
break;
case '5':
b=utworz(wymiar);
for (i=0; i<wymiar; i++)
for (j=0; j<wymiar; j++)
b[wymiar*i+j]=i*j;
break;
case '6':
for (i=0; i<wymiar; i++)
for (j=0; j<wymiar; j++)
a[wymiar*i+j]*=b[wymiar*i+j];
break;
case '0':
if (a!=NULL) free(a);
if (b!=NULL) free(b);
printf("PAPA!\n");
}
}
return 0;
}
|
the_stack_data/112200.c | // KASAN: slab-out-of-bounds Read in dlfb_usb_probe
// https://syzkaller.appspot.com/bug?id=ed94135f896a14d75284
// status:0
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/capability.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/usb/ch9.h>
#include <linux/veth.h>
static unsigned long long procid;
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) &&
(addr < prog_start || addr > prog_end)) {
_longjmp(segv_env, 1);
}
exit(sig);
}
static void install_segv_handler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
exit(1);
if (chmod(tmpdir, 0777))
exit(1);
if (chdir(tmpdir))
exit(1);
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
struct nlmsg {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
};
static struct nlmsg nlmsg;
static void netlink_init(struct nlmsg* nlmsg, int typ, int flags,
const void* data, int size)
{
memset(nlmsg, 0, sizeof(*nlmsg));
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_type = typ;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
memcpy(hdr + 1, data, size);
nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
}
static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data,
int size)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_len = sizeof(*attr) + size;
attr->nla_type = typ;
memcpy(attr + 1, data, size);
nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
}
static void netlink_nest(struct nlmsg* nlmsg, int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_type = typ;
nlmsg->pos += sizeof(*attr);
nlmsg->nested[nlmsg->nesting++] = attr;
}
static void netlink_done(struct nlmsg* nlmsg)
{
struct nlattr* attr = nlmsg->nested[--nlmsg->nesting];
attr->nla_len = nlmsg->pos - (char*)attr;
}
static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type,
int* reply_len)
{
if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting)
exit(1);
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_len = nlmsg->pos - nlmsg->buf;
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
unsigned n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0,
(struct sockaddr*)&addr, sizeof(addr));
if (n != hdr->nlmsg_len)
exit(1);
n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
if (hdr->nlmsg_type == NLMSG_DONE) {
*reply_len = 0;
return 0;
}
if (n < sizeof(struct nlmsghdr))
exit(1);
if (reply_len && hdr->nlmsg_type == reply_type) {
*reply_len = n;
return 0;
}
if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return -((struct nlmsgerr*)(hdr + 1))->error;
}
static int netlink_send(struct nlmsg* nlmsg, int sock)
{
return netlink_send_ext(nlmsg, sock, 0, NULL);
}
static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset,
unsigned int total_len)
{
struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset);
if (offset == total_len || offset + hdr->nlmsg_len > total_len)
return -1;
return hdr->nlmsg_len;
}
static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type,
const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr,
sizeof(hdr));
if (name)
netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name));
netlink_nest(nlmsg, IFLA_LINKINFO);
netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type,
const char* name)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name,
const char* peer)
{
netlink_add_device_impl(nlmsg, "veth", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_nest(nlmsg, VETH_INFO_PEER);
nlmsg->pos += sizeof(struct ifinfomsg);
netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer));
netlink_done(nlmsg);
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name,
const char* slave1, const char* slave2)
{
netlink_add_device_impl(nlmsg, "hsr", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type,
const char* name, const char* link)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t id, uint16_t proto)
{
netlink_add_device_impl(nlmsg, "vlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id));
netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link)
{
netlink_add_device_impl(nlmsg, "macvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
uint32_t mode = MACVLAN_MODE_BRIDGE;
netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name,
uint32_t vni, struct in_addr* addr4,
struct in6_addr* addr6)
{
netlink_add_device_impl(nlmsg, "geneve", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni));
if (addr4)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4));
if (addr6)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
#define IFLA_IPVLAN_FLAGS 2
#define IPVLAN_MODE_L3S 2
#undef IPVLAN_F_VEPA
#define IPVLAN_F_VEPA 2
static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t mode, uint16_t flags)
{
netlink_add_device_impl(nlmsg, "ipvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode));
netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_device_change(struct nlmsg* nlmsg, int sock,
const char* name, bool up, const char* master,
const void* mac, int macsize,
const char* new_name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
hdr.ifi_index = if_nametoindex(name);
netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr));
if (new_name)
netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev,
const void* addr, int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr,
sizeof(hdr));
netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize);
netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize);
return netlink_send(nlmsg, sock);
}
static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
const int kInitNetNsFd = 239;
#define DEVLINK_FAMILY_NAME "devlink"
#define DEVLINK_CMD_PORT_GET 5
#define DEVLINK_CMD_RELOAD 37
#define DEVLINK_ATTR_BUS_NAME 1
#define DEVLINK_ATTR_DEV_NAME 2
#define DEVLINK_ATTR_NETDEV_NAME 7
#define DEVLINK_ATTR_NETNS_FD 138
static int netlink_devlink_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = CTRL_CMD_GETFAMILY;
netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, DEVLINK_FAMILY_NAME,
strlen(DEVLINK_FAMILY_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg->buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
id = *(uint16_t*)(attr + 1);
break;
}
}
if (!id) {
return -1;
}
recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */
return id;
}
static void netlink_devlink_netns_move(const char* bus_name,
const char* dev_name, int netns_fd)
{
struct genlmsghdr genlhdr;
int sock;
int id, err;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
id = netlink_devlink_id_get(&nlmsg, sock);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_RELOAD;
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_NETNS_FD, &netns_fd, sizeof(netns_fd));
err = netlink_send(&nlmsg, sock);
if (err) {
}
error:
close(sock);
}
static struct nlmsg nlmsg2;
static void initialize_devlink_ports(const char* bus_name, const char* dev_name,
const char* netdev_prefix)
{
struct genlmsghdr genlhdr;
int len, total_len, id, err, offset;
uint16_t netdev_index;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (rtsock == -1)
exit(1);
id = netlink_devlink_id_get(&nlmsg, sock);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_PORT_GET;
netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
err = netlink_send_ext(&nlmsg, sock, id, &total_len);
if (err) {
goto error;
}
offset = 0;
netdev_index = 0;
while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) {
struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg.buf + offset + len;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) {
char* port_name;
char netdev_name[IFNAMSIZ];
port_name = (char*)(attr + 1);
snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix,
netdev_index);
netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0,
netdev_name);
break;
}
}
offset += len;
netdev_index++;
}
error:
close(rtsock);
close(sock);
}
static void initialize_devlink_pci(void)
{
int netns = open("/proc/self/ns/net", O_RDONLY);
if (netns == -1)
exit(1);
int ret = setns(kInitNetNsFd, 0);
if (ret == -1)
exit(1);
netlink_devlink_netns_move("pci", "0000:00:10.0", netns);
ret = setns(netns, 0);
if (ret == -1)
exit(1);
close(netns);
initialize_devlink_ports("pci", "0000:00:10.0", "netpci");
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa
static void netdevsim_add(unsigned int addr, unsigned int port_count)
{
char buf[16];
sprintf(buf, "%u %u", addr, port_count);
if (write_file("/sys/bus/netdevsim/new_device", buf)) {
snprintf(buf, sizeof(buf), "netdevsim%d", addr);
initialize_devlink_ports("netdevsim", buf, "netdevsim");
}
}
#define WG_GENL_NAME "wireguard"
enum wg_cmd {
WG_CMD_GET_DEVICE,
WG_CMD_SET_DEVICE,
};
enum wgdevice_attribute {
WGDEVICE_A_UNSPEC,
WGDEVICE_A_IFINDEX,
WGDEVICE_A_IFNAME,
WGDEVICE_A_PRIVATE_KEY,
WGDEVICE_A_PUBLIC_KEY,
WGDEVICE_A_FLAGS,
WGDEVICE_A_LISTEN_PORT,
WGDEVICE_A_FWMARK,
WGDEVICE_A_PEERS,
};
enum wgpeer_attribute {
WGPEER_A_UNSPEC,
WGPEER_A_PUBLIC_KEY,
WGPEER_A_PRESHARED_KEY,
WGPEER_A_FLAGS,
WGPEER_A_ENDPOINT,
WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
WGPEER_A_LAST_HANDSHAKE_TIME,
WGPEER_A_RX_BYTES,
WGPEER_A_TX_BYTES,
WGPEER_A_ALLOWEDIPS,
WGPEER_A_PROTOCOL_VERSION,
};
enum wgallowedip_attribute {
WGALLOWEDIP_A_UNSPEC,
WGALLOWEDIP_A_FAMILY,
WGALLOWEDIP_A_IPADDR,
WGALLOWEDIP_A_CIDR_MASK,
};
static int netlink_wireguard_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = CTRL_CMD_GETFAMILY;
netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, WG_GENL_NAME,
strlen(WG_GENL_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg->buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
id = *(uint16_t*)(attr + 1);
break;
}
}
if (!id) {
return -1;
}
recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */
return id;
}
static void netlink_wireguard_setup(void)
{
const char ifname_a[] = "wg0";
const char ifname_b[] = "wg1";
const char ifname_c[] = "wg2";
const char private_a[] = "\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a"
"\x70\xae\x0f\xb2\x0f\xa1\x52\x60\x0c\xb0\x08\x45"
"\x17\x4f\x08\x07\x6f\x8d\x78\x43";
const char private_b[] = "\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22"
"\x43\x82\x44\xbb\x88\x5c\x69\xe2\x69\xc8\xe9\xd8"
"\x35\xb1\x14\x29\x3a\x4d\xdc\x6e";
const char private_c[] = "\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f"
"\xa6\xd0\x31\xc7\x4a\x15\x53\xb6\xe9\x01\xb9\xff"
"\x2f\x51\x8c\x78\x04\x2f\xb5\x42";
const char public_a[] = "\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b"
"\x89\x9f\x8e\xd9\x25\xae\x9f\x09\x23\xc2\x3c\x62\xf5"
"\x3c\x57\xcd\xbf\x69\x1c";
const char public_b[] = "\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41"
"\x3d\xc9\x57\x63\x0e\x54\x93\xc2\x85\xac\xa4\x00\x65"
"\xcb\x63\x11\xbe\x69\x6b";
const char public_c[] = "\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45"
"\x67\x27\x08\x2f\x5c\xeb\xee\x8b\x1b\xf5\xeb\x73\x37"
"\x34\x1b\x45\x9b\x39\x22";
const uint16_t listen_a = 20001;
const uint16_t listen_b = 20002;
const uint16_t listen_c = 20003;
const uint16_t af_inet = AF_INET;
const uint16_t af_inet6 = AF_INET6;
/* Unused, but useful in case we change this:
const struct sockaddr_in endpoint_a_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_a),
.sin_addr = {htonl(INADDR_LOOPBACK)}};*/
const struct sockaddr_in endpoint_b_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_b),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
const struct sockaddr_in endpoint_c_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_c),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_a)};
endpoint_a_v6.sin6_addr = in6addr_loopback;
/* Unused, but useful in case we change this:
const struct sockaddr_in6 endpoint_b_v6 = {
.sin6_family = AF_INET6,
.sin6_port = htons(listen_b)};
endpoint_b_v6.sin6_addr = in6addr_loopback; */
struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_c)};
endpoint_c_v6.sin6_addr = in6addr_loopback;
const struct in_addr first_half_v4 = {0};
const struct in_addr second_half_v4 = {htonl(128 << 24)};
const struct in6_addr first_half_v6 = {{{0}}};
const struct in6_addr second_half_v6 = {{{0x80}}};
const uint8_t half_cidr = 1;
const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19};
struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1};
int sock;
int id, err;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1) {
return;
}
id = netlink_wireguard_id_get(&nlmsg, sock);
if (id == -1)
goto error;
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[0], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6,
sizeof(endpoint_c_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[1], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[2], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4,
sizeof(endpoint_c_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[3], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[4], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[5], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err) {
}
error:
close(sock);
}
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
{"xfrm", "xfrm0"}, {"wireguard", "wg0"},
{"wireguard", "wg1"}, {"wireguard", "wg2"},
};
const char* devmasters[] = {"bridge", "bond", "team", "batadv"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan0", 0, true},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
{"xfrm0", ETH_ALEN},
{"veth0_virt_wifi", ETH_ALEN},
{"veth1_virt_wifi", ETH_ALEN},
{"virt_wifi0", ETH_ALEN},
{"veth0_vlan", ETH_ALEN},
{"veth1_vlan", ETH_ALEN},
{"vlan0", ETH_ALEN},
{"vlan1", ETH_ALEN},
{"macvlan0", ETH_ALEN},
{"macvlan1", ETH_ALEN},
{"ipvlan0", ETH_ALEN},
{"ipvlan1", ETH_ALEN},
{"veth0_macvtap", ETH_ALEN},
{"veth1_macvtap", ETH_ALEN},
{"macvtap0", ETH_ALEN},
{"macsec0", ETH_ALEN},
{"veth0_to_batadv", ETH_ALEN},
{"veth1_to_batadv", ETH_ALEN},
{"batadv_slave_0", ETH_ALEN},
{"batadv_slave_1", ETH_ALEN},
{"geneve0", ETH_ALEN},
{"geneve1", ETH_ALEN},
{"wg0", 0},
{"wg1", 0},
{"wg2", 0},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL);
}
netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi");
netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0",
"veth1_virt_wifi");
netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan");
netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q));
netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD));
netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan");
netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan");
netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0);
netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S,
IPVLAN_F_VEPA);
netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap");
netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap");
netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap");
char addr[32];
sprintf(addr, DEV_IPV4, 14 + 10);
struct in_addr geneve_addr4;
if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0)
exit(1);
struct in6_addr geneve_addr6;
if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0)
exit(1);
netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0);
netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6);
netdevsim_add((int)procid, 4);
netlink_wireguard_setup();
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(&nlmsg, sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(&nlmsg, sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize, NULL);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true}, {"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(&nlmsg, sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
netlink_add_addr6(&nlmsg, sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr,
macsize, NULL);
}
close(sock);
}
#define MAX_FDS 30
#define USB_MAX_IFACE_NUM 4
#define USB_MAX_EP_NUM 32
#define USB_MAX_FDS 6
struct usb_endpoint_index {
struct usb_endpoint_descriptor desc;
int handle;
};
struct usb_iface_index {
struct usb_interface_descriptor* iface;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bInterfaceClass;
struct usb_endpoint_index eps[USB_MAX_EP_NUM];
int eps_num;
};
struct usb_device_index {
struct usb_device_descriptor* dev;
struct usb_config_descriptor* config;
uint8_t bDeviceClass;
uint8_t bMaxPower;
int config_length;
struct usb_iface_index ifaces[USB_MAX_IFACE_NUM];
int ifaces_num;
int iface_cur;
};
struct usb_info {
int fd;
struct usb_device_index index;
};
static struct usb_info usb_devices[USB_MAX_FDS];
static int usb_devices_num;
static bool parse_usb_descriptor(const char* buffer, size_t length,
struct usb_device_index* index)
{
if (length < sizeof(*index->dev) + sizeof(*index->config))
return false;
memset(index, 0, sizeof(*index));
index->dev = (struct usb_device_descriptor*)buffer;
index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev));
index->bDeviceClass = index->dev->bDeviceClass;
index->bMaxPower = index->config->bMaxPower;
index->config_length = length - sizeof(*index->dev);
index->iface_cur = -1;
size_t offset = 0;
while (true) {
if (offset + 1 >= length)
break;
uint8_t desc_length = buffer[offset];
uint8_t desc_type = buffer[offset + 1];
if (desc_length <= 2)
break;
if (offset + desc_length > length)
break;
if (desc_type == USB_DT_INTERFACE &&
index->ifaces_num < USB_MAX_IFACE_NUM) {
struct usb_interface_descriptor* iface =
(struct usb_interface_descriptor*)(buffer + offset);
index->ifaces[index->ifaces_num].iface = iface;
index->ifaces[index->ifaces_num].bInterfaceNumber =
iface->bInterfaceNumber;
index->ifaces[index->ifaces_num].bAlternateSetting =
iface->bAlternateSetting;
index->ifaces[index->ifaces_num].bInterfaceClass = iface->bInterfaceClass;
index->ifaces_num++;
}
if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) {
struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1];
if (iface->eps_num < USB_MAX_EP_NUM) {
memcpy(&iface->eps[iface->eps_num].desc, buffer + offset,
sizeof(iface->eps[iface->eps_num].desc));
iface->eps_num++;
}
}
offset += desc_length;
}
return true;
}
static struct usb_device_index* add_usb_index(int fd, const char* dev,
size_t dev_len)
{
int i = __atomic_fetch_add(&usb_devices_num, 1, __ATOMIC_RELAXED);
if (i >= USB_MAX_FDS)
return NULL;
int rv = 0;
NONFAILING(rv = parse_usb_descriptor(dev, dev_len, &usb_devices[i].index));
if (!rv)
return NULL;
__atomic_store_n(&usb_devices[i].fd, fd, __ATOMIC_RELEASE);
return &usb_devices[i].index;
}
static struct usb_device_index* lookup_usb_index(int fd)
{
int i;
for (i = 0; i < USB_MAX_FDS; i++) {
if (__atomic_load_n(&usb_devices[i].fd, __ATOMIC_ACQUIRE) == fd) {
return &usb_devices[i].index;
}
}
return NULL;
}
struct vusb_connect_string_descriptor {
uint32_t len;
char* str;
} __attribute__((packed));
struct vusb_connect_descriptors {
uint32_t qual_len;
char* qual;
uint32_t bos_len;
char* bos;
uint32_t strs_len;
struct vusb_connect_string_descriptor strs[0];
} __attribute__((packed));
static const char default_string[] = {8, USB_DT_STRING, 's', 0, 'y', 0, 'z', 0};
static const char default_lang_id[] = {4, USB_DT_STRING, 0x09, 0x04};
static bool
lookup_connect_response_in(int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl,
char** response_data, uint32_t* response_length)
{
struct usb_device_index* index = lookup_usb_index(fd);
uint8_t str_idx;
if (!index)
return false;
switch (ctrl->bRequestType & USB_TYPE_MASK) {
case USB_TYPE_STANDARD:
switch (ctrl->bRequest) {
case USB_REQ_GET_DESCRIPTOR:
switch (ctrl->wValue >> 8) {
case USB_DT_DEVICE:
*response_data = (char*)index->dev;
*response_length = sizeof(*index->dev);
return true;
case USB_DT_CONFIG:
*response_data = (char*)index->config;
*response_length = index->config_length;
return true;
case USB_DT_STRING:
str_idx = (uint8_t)ctrl->wValue;
if (descs && str_idx < descs->strs_len) {
*response_data = descs->strs[str_idx].str;
*response_length = descs->strs[str_idx].len;
return true;
}
if (str_idx == 0) {
*response_data = (char*)&default_lang_id[0];
*response_length = default_lang_id[0];
return true;
}
*response_data = (char*)&default_string[0];
*response_length = default_string[0];
return true;
case USB_DT_BOS:
*response_data = descs->bos;
*response_length = descs->bos_len;
return true;
case USB_DT_DEVICE_QUALIFIER:
if (!descs->qual) {
struct usb_qualifier_descriptor* qual =
(struct usb_qualifier_descriptor*)response_data;
qual->bLength = sizeof(*qual);
qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
qual->bcdUSB = index->dev->bcdUSB;
qual->bDeviceClass = index->dev->bDeviceClass;
qual->bDeviceSubClass = index->dev->bDeviceSubClass;
qual->bDeviceProtocol = index->dev->bDeviceProtocol;
qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0;
qual->bNumConfigurations = index->dev->bNumConfigurations;
qual->bRESERVED = 0;
*response_length = sizeof(*qual);
return true;
}
*response_data = descs->qual;
*response_length = descs->qual_len;
return true;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
return false;
}
typedef bool (*lookup_connect_out_response_t)(
int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl, bool* done);
static bool lookup_connect_response_out_generic(
int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl, bool* done)
{
switch (ctrl->bRequestType & USB_TYPE_MASK) {
case USB_TYPE_STANDARD:
switch (ctrl->bRequest) {
case USB_REQ_SET_CONFIGURATION:
*done = true;
return true;
default:
break;
}
break;
}
return false;
}
#define UDC_NAME_LENGTH_MAX 128
struct usb_raw_init {
__u8 driver_name[UDC_NAME_LENGTH_MAX];
__u8 device_name[UDC_NAME_LENGTH_MAX];
__u8 speed;
};
enum usb_raw_event_type {
USB_RAW_EVENT_INVALID = 0,
USB_RAW_EVENT_CONNECT = 1,
USB_RAW_EVENT_CONTROL = 2,
};
struct usb_raw_event {
__u32 type;
__u32 length;
__u8 data[0];
};
struct usb_raw_ep_io {
__u16 ep;
__u16 flags;
__u32 length;
__u8 data[0];
};
#define USB_RAW_EPS_NUM_MAX 30
#define USB_RAW_EP_NAME_MAX 16
#define USB_RAW_EP_ADDR_ANY 0xff
struct usb_raw_ep_caps {
__u32 type_control : 1;
__u32 type_iso : 1;
__u32 type_bulk : 1;
__u32 type_int : 1;
__u32 dir_in : 1;
__u32 dir_out : 1;
};
struct usb_raw_ep_limits {
__u16 maxpacket_limit;
__u16 max_streams;
__u32 reserved;
};
struct usb_raw_ep_info {
__u8 name[USB_RAW_EP_NAME_MAX];
__u32 addr;
struct usb_raw_ep_caps caps;
struct usb_raw_ep_limits limits;
};
struct usb_raw_eps_info {
struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX];
};
#define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init)
#define USB_RAW_IOCTL_RUN _IO('U', 1)
#define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event)
#define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor)
#define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32)
#define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_CONFIGURE _IO('U', 9)
#define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32)
#define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info)
#define USB_RAW_IOCTL_EP0_STALL _IO('U', 12)
#define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32)
#define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32)
#define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32)
static int usb_raw_open()
{
return open("/dev/raw-gadget", O_RDWR);
}
static int usb_raw_init(int fd, uint32_t speed, const char* driver,
const char* device)
{
struct usb_raw_init arg;
strncpy((char*)&arg.driver_name[0], driver, sizeof(arg.driver_name));
strncpy((char*)&arg.device_name[0], device, sizeof(arg.device_name));
arg.speed = speed;
return ioctl(fd, USB_RAW_IOCTL_INIT, &arg);
}
static int usb_raw_run(int fd)
{
return ioctl(fd, USB_RAW_IOCTL_RUN, 0);
}
static int usb_raw_event_fetch(int fd, struct usb_raw_event* event)
{
return ioctl(fd, USB_RAW_IOCTL_EVENT_FETCH, event);
}
static int usb_raw_ep0_write(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP0_WRITE, io);
}
static int usb_raw_ep0_read(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP0_READ, io);
}
static int usb_raw_ep_enable(int fd, struct usb_endpoint_descriptor* desc)
{
return ioctl(fd, USB_RAW_IOCTL_EP_ENABLE, desc);
}
static int usb_raw_ep_disable(int fd, int ep)
{
return ioctl(fd, USB_RAW_IOCTL_EP_DISABLE, ep);
}
static int usb_raw_configure(int fd)
{
return ioctl(fd, USB_RAW_IOCTL_CONFIGURE, 0);
}
static int usb_raw_vbus_draw(int fd, uint32_t power)
{
return ioctl(fd, USB_RAW_IOCTL_VBUS_DRAW, power);
}
static int usb_raw_ep0_stall(int fd)
{
return ioctl(fd, USB_RAW_IOCTL_EP0_STALL, 0);
}
static void set_interface(int fd, int n)
{
struct usb_device_index* index = lookup_usb_index(fd);
int ep;
if (!index)
return;
if (index->iface_cur >= 0 && index->iface_cur < index->ifaces_num) {
for (ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++) {
int rv = usb_raw_ep_disable(
fd, index->ifaces[index->iface_cur].eps[ep].handle);
if (rv < 0) {
} else {
}
}
}
if (n >= 0 && n < index->ifaces_num) {
for (ep = 0; ep < index->ifaces[n].eps_num; ep++) {
int rv = usb_raw_ep_enable(fd, &index->ifaces[n].eps[ep].desc);
if (rv < 0) {
} else {
index->ifaces[n].eps[ep].handle = rv;
}
}
index->iface_cur = n;
}
}
static int configure_device(int fd)
{
struct usb_device_index* index = lookup_usb_index(fd);
if (!index)
return -1;
int rv = usb_raw_vbus_draw(fd, index->bMaxPower);
if (rv < 0) {
return rv;
}
rv = usb_raw_configure(fd);
if (rv < 0) {
return rv;
}
set_interface(fd, 0);
return 0;
}
#define USB_MAX_PACKET_SIZE 4096
struct usb_raw_control_event {
struct usb_raw_event inner;
struct usb_ctrlrequest ctrl;
char data[USB_MAX_PACKET_SIZE];
};
struct usb_raw_ep_io_data {
struct usb_raw_ep_io inner;
char data[USB_MAX_PACKET_SIZE];
};
static volatile long
syz_usb_connect_impl(uint64_t speed, uint64_t dev_len, const char* dev,
const struct vusb_connect_descriptors* descs,
lookup_connect_out_response_t lookup_connect_response_out)
{
if (!dev) {
return -1;
}
int fd = usb_raw_open();
if (fd < 0) {
return fd;
}
if (fd >= MAX_FDS) {
close(fd);
return -1;
}
struct usb_device_index* index = add_usb_index(fd, dev, dev_len);
if (!index) {
return -1;
}
char device[32];
sprintf(&device[0], "dummy_udc.%llu", procid);
int rv = usb_raw_init(fd, speed, "dummy_udc", &device[0]);
if (rv < 0) {
return rv;
}
rv = usb_raw_run(fd);
if (rv < 0) {
return rv;
}
bool done = false;
while (!done) {
struct usb_raw_control_event event;
event.inner.type = 0;
event.inner.length = sizeof(event.ctrl);
rv = usb_raw_event_fetch(fd, (struct usb_raw_event*)&event);
if (rv < 0) {
return rv;
}
if (event.inner.type != USB_RAW_EVENT_CONTROL)
continue;
char* response_data = NULL;
uint32_t response_length = 0;
if (event.ctrl.bRequestType & USB_DIR_IN) {
bool response_found = false;
NONFAILING(response_found = lookup_connect_response_in(
fd, descs, &event.ctrl, &response_data, &response_length));
if (!response_found) {
usb_raw_ep0_stall(fd);
continue;
}
} else {
if (!lookup_connect_response_out(fd, descs, &event.ctrl, &done)) {
usb_raw_ep0_stall(fd);
continue;
}
response_data = NULL;
response_length = event.ctrl.wLength;
}
if ((event.ctrl.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD &&
event.ctrl.bRequest == USB_REQ_SET_CONFIGURATION) {
rv = configure_device(fd);
if (rv < 0) {
return rv;
}
}
struct usb_raw_ep_io_data response;
response.inner.ep = 0;
response.inner.flags = 0;
if (response_length > sizeof(response.data))
response_length = 0;
if (event.ctrl.wLength < response_length)
response_length = event.ctrl.wLength;
response.inner.length = response_length;
if (response_data)
memcpy(&response.data[0], response_data, response_length);
else
memset(&response.data[0], 0, response_length);
if (event.ctrl.bRequestType & USB_DIR_IN) {
rv = usb_raw_ep0_write(fd, (struct usb_raw_ep_io*)&response);
} else {
rv = usb_raw_ep0_read(fd, (struct usb_raw_ep_io*)&response);
}
if (rv < 0) {
return rv;
}
}
sleep_ms(200);
return fd;
}
static volatile long syz_usb_connect(volatile long a0, volatile long a1,
volatile long a2, volatile long a3)
{
uint64_t speed = a0;
uint64_t dev_len = a1;
const char* dev = (const char*)a2;
const struct vusb_connect_descriptors* descs =
(const struct vusb_connect_descriptors*)a3;
return syz_usb_connect_impl(speed, dev_len, dev, descs,
&lookup_connect_response_out_generic);
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
int netns = open("/proc/self/ns/net", O_RDONLY);
if (netns == -1)
exit(1);
if (dup2(netns, kInitNetNsFd) < 0)
exit(1);
close(netns);
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
static int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static void drop_caps(void)
{
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
exit(1);
const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
cap_data[0].effective &= ~drop;
cap_data[0].permitted &= ~drop;
cap_data[0].inheritable &= ~drop;
if (syscall(SYS_capset, &cap_hdr, &cap_data))
exit(1);
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid != 0)
return wait_for_loop(pid);
setup_common();
sandbox_common();
drop_caps();
initialize_netdevices_init();
if (unshare(CLONE_NEWNET)) {
}
initialize_devlink_pci();
initialize_netdevices();
loop();
exit(1);
}
static void close_fds()
{
int fd;
for (fd = 3; fd < MAX_FDS; fd++)
close(fd);
}
static void setup_binfmt_misc()
{
if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) {
}
write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:");
write_file("/proc/sys/fs/binfmt_misc/register",
":syz1:M:1:\x02::./file0:POC");
}
void loop(void)
{
NONFAILING(memcpy(
(void*)0x20000000,
"\x12\x01\x00\x00\xe6\xdd\x08\x20\xe9\x17\x57\x3f\x02\x06\x01\x02\x03\x01"
"\x09\x02\x1b\x00\x01\x00\x00\x00\x00\x09\x04\x00\x00\x01\xff\x00\x00\x00"
"\x09\x5f\xc8\x2a\xbe\xa6\x66\x26\x05\x81\x00\x00\x00\x00\x10\x00\xd5\x99"
"\x0e\x26\xdd\xbc\x92\x47\x83\x34\x3d\xe0\xc9\xd6\x57\xf4\xfb\x0b\xde\xb5"
"\x11\xc6\xfc\x4b\x9a\x84\xed\xf1\x1d\x6e\x36\x3d\x8a\xa2\x51\x3b\xd2\x4b"
"\x3e\x2e\x12\x97\x9b\xd8\xce\xd5\x40\xdf\x3f\xef\xe5\xc6\xc3\x43\x2b\x9c"
"\xab\x71\xd9\xfd\x75\x39\x98\x07\x2f\x9f\xc5\x0b\xf5\xce\xae\x6e\x3a\x4f"
"\x93\x4c\x0e\xa8\xb0\xfb\x3e\x23\x6b\x86\x29\x0f\x49\xf4\x87\xda\xbe\x16"
"\x7b\x66\x5a\x7e\x27\xe3\x5a\x1e\xc3\x13\xb3\x88\xf6\x63\x08\xbd\x3d\xa2"
"\xdc\xf7\xb3\x89\x8a\xc4\x30\x05\xd4\x49\x19\x73\x19\xd9\x9c\x8c\x97\x4d"
"\x3d\x53\x7c\xbc\xe4\x63\x3f\x2b\xdd\x2d\xda\xef\x4c\xa4\xd4\x86\xd5\x0d"
"\xf4\x1d\x75\xaf\xe1\x82\xc0\xc8\x26\x4f\x33\x81\x0c\xf1\xa6\xc8\x0c\xfb"
"\x1c\x73\x76\xf7\x0d\xe7\xb6\xb4\xc9\x25\x46\xde\xdb\xca\xd8\x44\x6e\x3e"
"\xdf\xb8\x1a\x60\x76\x02\x8d\x20\xf8\x78\xfc\xbd\x17\x81\x1c\xbb\x84",
251));
syz_usb_connect(0, 0x2d, 0x20000000, 0);
close_fds();
}
int main(void)
{
syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
setup_binfmt_misc();
install_segv_handler();
use_temporary_dir();
do_sandbox_none();
return 0;
}
|
the_stack_data/135546.c | #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
int marks_summation(int* marks, int number_of_students, char gender) {
int i = 0, Sum=0;
if (gender == 'g'){
i = 1;
}
for (; i < number_of_students; i+=2){
Sum += *(marks + i);
}
//Write your code here.
return Sum;
}
int main() {
int number_of_students;
char gender;
int sum;
scanf("%d", &number_of_students);
int *marks = (int *) malloc(number_of_students * sizeof (int));
for (int student = 0; student < number_of_students; student++) {
scanf("%d", (marks + student));
}
scanf(" %c", &gender);
sum = marks_summation(marks, number_of_students, gender);
printf("%d", sum);
free(marks);
return 0;
} |
the_stack_data/200142619.c | #include <stdio.h>
#include <stdlib.h>
#include <emmintrin.h>
#include <math.h>
#include <float.h>
#include <string.h>
#include <omp.h>
#define NUM_THREADS 16
void mm_28( int m, int n, int ind1, int ind2, float *An, float *Cn);
void p_tail_4( int m, int r, int a, int x, int ind1, int ind2, float *An, float *Cn);
void tail(int r, int x, int a, int ind1, int ind2, float *An, float *Cn);
void sgemm( int m, int n, float *A, float *C )
{
int BLOCKSIZE = 28;
int r = ( m / BLOCKSIZE ) * BLOCKSIZE;
int x = ( n / BLOCKSIZE ) * BLOCKSIZE;
int a = r + (m-r)/4*4;
int b = x + (n-x)/4*4;
int num_chunks = 16;
if(m > 5000)
num_chunks = 32;
if(m > 7000)
num_chunks = 16;
omp_set_num_threads(NUM_THREADS);
#pragma omp parallel
{
int id = omp_get_thread_num();
int chunk = m/num_chunks;
for(int j = 0; j < num_chunks-1; j++)
{
if(id == j % NUM_THREADS)
mm_28(m,n,(j*chunk),(j+1)*chunk,A+0,C+0);
}
if(id == NUM_THREADS-1)
{
mm_28(m,n,((num_chunks-1)*chunk),m,A+0,C+0);
}
if(r != m)
{
for( int j = 0; j < num_chunks-1; j++)
{
if(id == j % NUM_THREADS)
p_tail_4(r,m,a,n,j*chunk,(j+1)*chunk,A+0,C+0);
}
if(id == NUM_THREADS-1)
{
p_tail_4(r,m,a,n,(num_chunks-1)*chunk,m,A+0,C+0);
}
}
if(m % 4 != 0)
{
for(int j = 0; j < num_chunks-1; j++)
{
if(id == j % NUM_THREADS)
tail(m,n,a,j*chunk,(j+1)*chunk,A+0,C+0);
}
if(id == NUM_THREADS-1)
{
tail(m,n,a,(num_chunks-1)*chunk,m,A+0,C+0);
}
}
}
}
void mm_28( int r, int x, int ind1, int ind2, float *An, float *Cn)
{
int BLOCKSIZE = 28;
int m = ( r / BLOCKSIZE ) * BLOCKSIZE;
int i,j,k, blockInd1;
__m128 c0,c1,c2,c3,c4,c5,c6,a0,a1,a2,a3,a4,a5,a6,a0T;
/*------------------------------------------------------------------------*/
#pragma omp nowait
{
/* Start parallel multiply big block */
#pragma omp private(ind1,ind2,j,k,c0,c1,c2,c3,c4,c5,c6,a0,a1,a2,a3,a4,a5,a6,a0T,blockInd1)
for( j = ind1; j < ind2; j++)
{
for(blockInd1 = 0; blockInd1 < m; blockInd1 += BLOCKSIZE)
{
/* Load C data into registers */
c0 = _mm_loadu_ps(Cn+blockInd1+j*r);
c1 = _mm_loadu_ps(Cn+blockInd1+4+j*r);
c2 = _mm_loadu_ps(Cn+blockInd1+8+j*r);
c3 = _mm_loadu_ps(Cn+blockInd1+12+j*r);
c4 = _mm_loadu_ps(Cn+blockInd1+16+j*r);
/* Experiment */
c5 = _mm_loadu_ps(Cn+blockInd1+20+j*r);
c6 = _mm_loadu_ps(Cn+blockInd1+24+j*r);
//c7 = _mm_loadu_ps(Cn+blockInd1+28+j*r);
for(k = 0; k < x; k++)
{
/* Load the value that will be multiplied across multiple a's */
a0T = _mm_load1_ps(An+j+k*r);
/* Load the values to be multiplied */
a0 = _mm_loadu_ps(An+blockInd1+k*r);
a1 = _mm_loadu_ps(An+blockInd1+4+k*r);
a2 = _mm_loadu_ps(An+blockInd1+8+k*r);
a3 = _mm_loadu_ps(An+blockInd1+12+k*r);
a4 = _mm_loadu_ps(An+blockInd1+16+k*r);
/* Experiment */
a5 = _mm_loadu_ps(An+blockInd1+20+k*r);
a6 = _mm_loadu_ps(An+blockInd1+24+k*r);
//a7 = _mm_loadu_ps(An+blockInd1+28+k*r);
/* Multiply */
a0 = _mm_mul_ps(a0, a0T);
a1 = _mm_mul_ps(a1, a0T);
a2 = _mm_mul_ps(a2, a0T);
a3 = _mm_mul_ps(a3, a0T);
a4 = _mm_mul_ps(a4, a0T);
/* Experiment */
a5 = _mm_mul_ps(a5,a0T);
a6 = _mm_mul_ps(a6,a0T);
//a7 = _mm_mul_ps(a7,a0T);
/* Add */
c0 = _mm_add_ps(c0, a0);
c1 = _mm_add_ps(c1, a1);
c2 = _mm_add_ps(c2,a2);
c3 = _mm_add_ps(c3,a3);
c4 = _mm_add_ps(c4, a4);
/* Experiment */
c5 = _mm_add_ps(c5,a5);
c6 = _mm_add_ps(c6,a6);
//c7 = _mm_add_ps(c7,a7);
}
/* Store the registers back into Cn */
_mm_storeu_ps(Cn+blockInd1+j*r, c0);
_mm_storeu_ps(Cn+blockInd1+4+j*r, c1);
_mm_storeu_ps(Cn+blockInd1+8+j*r, c2);
_mm_storeu_ps(Cn+blockInd1+12+j*r, c3);
_mm_storeu_ps(Cn+blockInd1+16+j*r, c4);
/* Experiment */
_mm_storeu_ps(Cn+blockInd1+20+j*r,c5);
_mm_storeu_ps(Cn+blockInd1+24+j*r,c6);
//_mm_storeu_ps(Cn+blockInd1+28+j*r,c7);
}
}
/* End Parallel Multiply Big Block */
}
/*---------------------------------------------------------------------*/
}
/* End Program */
void tail( int r, int x, int a, int ind1, int ind2, float *An, float *Cn)
{
int i,j,k;
#pragma omp nowait
{
#pragma omp private(i,k,j,ind1,ind2)
for( j = ind1; j < ind2; j++)
{
float temp1 = 0;
float temp2 = 0;
float temp3 = 0;
for( k = 0; k < x; k++)
{
for( i = a; i < r/2*2; i+=2)
{
temp1 += An[i+k*r] * An[j+k*r];
temp2 += An[i+1+k*r] * An[j+k*r];
}
for( i = r/2*2; i < r; i++)
{
temp3 += An[i+k*r] * An[j+k*r];
}
}
if(r-a > 1)
{
Cn[a+j*r] += temp1;
Cn[a+1+j*r] += temp2;
}
if(r-a != 2)
Cn[r/2*2+j*r] += temp3;
}
}
}
void p_tail_4(int m, int r, int a, int x, int ind1, int ind2, float *An, float *Cn)
{
int i,j,k;
__m128 c0,c1,c2,c3,c4,c5,a0,a1,a2,a3,a4,a5,a0T;
#pragma omp nowait
{
#pragma omp private(i,j,k,c0,c1,c2,c3,c4,c5,a0,a1,a2,a3,a4,a5,a0T,ind1,ind2)
//parallel bottom
if((m-a) % 24 == 0)
{
for( j = ind1 ; j < ind2; j++)
{
for( i = m; i < a; i+=24 )
{
c0 = _mm_loadu_ps(Cn+i+j*r);
c1 = _mm_loadu_ps(Cn+i+4+j*r);
c2 = _mm_loadu_ps(Cn+i+8+j*r);
c3 = _mm_loadu_ps(Cn+i+12+j*r);
c4 = _mm_loadu_ps(Cn+i+16+j*r);
c5 = _mm_loadu_ps(Cn+i+20+j*r);
for( k = 0; k < x; k++ )
{
a0T = _mm_load1_ps(An+j+k*r);
a0 = _mm_loadu_ps(An+i+k*r);
a1 = _mm_loadu_ps(An+i+4+k*r);
a2 = _mm_loadu_ps(An+i+8+k*r);
a3 = _mm_loadu_ps(An+i+12+k*r);
a4 = _mm_loadu_ps(An+i+16+k*r);
a5 = _mm_loadu_ps(An+i+20+k*r);
a0 = _mm_mul_ps(a0, a0T);
a1 = _mm_mul_ps(a1, a0T);
a2 = _mm_mul_ps(a2, a0T);
a3 = _mm_mul_ps(a3, a0T);
a4 = _mm_mul_ps(a4, a0T);
a5 = _mm_mul_ps(a5, a0T);
c0 = _mm_add_ps(c0, a0);
c1 = _mm_add_ps(c1, a1);
c2 = _mm_add_ps(c2, a2);
c3 = _mm_add_ps(c3, a3);
c4 = _mm_add_ps(c4, a4);
c5 = _mm_add_ps(c5, a5);
}
_mm_storeu_ps(Cn+i+j*r, c0);
_mm_storeu_ps(Cn+i+4+j*r, c1);
_mm_storeu_ps(Cn+i+8+j*r, c2);
_mm_storeu_ps(Cn+i+12+j*r, c3);
_mm_storeu_ps(Cn+i+16+j*r, c4);
_mm_storeu_ps(Cn+i+20+j*r, c5);
}
}
}else if((m-a) % 20 == 0){
for( j = ind1 ; j < ind2; j++)
{
for( i = m; i < a; i+=20 )
{
c0 = _mm_loadu_ps(Cn+i+j*r);
c1 = _mm_loadu_ps(Cn+i+4+j*r);
c2 = _mm_loadu_ps(Cn+i+8+j*r);
c3 = _mm_loadu_ps(Cn+i+12+j*r);
c4 = _mm_loadu_ps(Cn+i+16+j*r);
for( k = 0; k < x; k++ )
{
a0T = _mm_load1_ps(An+j+k*r);
a0 = _mm_loadu_ps(An+i+k*r);
a1 = _mm_loadu_ps(An+i+4+k*r);
a2 = _mm_loadu_ps(An+i+8+k*r);
a3 = _mm_loadu_ps(An+i+12+k*r);
a4 = _mm_loadu_ps(An+i+16+k*r);
a0 = _mm_mul_ps(a0, a0T);
a1 = _mm_mul_ps(a1, a0T);
a2 = _mm_mul_ps(a2, a0T);
a3 = _mm_mul_ps(a3, a0T);
a4 = _mm_mul_ps(a4, a0T);
c0 = _mm_add_ps(c0, a0);
c1 = _mm_add_ps(c1, a1);
c2 = _mm_add_ps(c2, a2);
c3 = _mm_add_ps(c3, a3);
c4 = _mm_add_ps(c4, a4);
}
_mm_storeu_ps(Cn+i+j*r, c0);
_mm_storeu_ps(Cn+i+4+j*r, c1);
_mm_storeu_ps(Cn+i+8+j*r, c2);
_mm_storeu_ps(Cn+i+12+j*r, c3);
_mm_storeu_ps(Cn+i+16+j*r, c4);
}
}
}else if((m-a) % 16 == 0){
for( j = ind1 ; j < ind2; j++)
{
for( i = m; i < a; i+=16 )
{
c0 = _mm_loadu_ps(Cn+i+j*r);
c1 = _mm_loadu_ps(Cn+i+4+j*r);
c2 = _mm_loadu_ps(Cn+i+8+j*r);
c3 = _mm_loadu_ps(Cn+i+12+j*r);
for( k = 0; k < x; k++ )
{
a0T = _mm_load1_ps(An+j+k*r);
a0 = _mm_loadu_ps(An+i+k*r);
a1 = _mm_loadu_ps(An+i+4+k*r);
a2 = _mm_loadu_ps(An+i+8+k*r);
a3 = _mm_loadu_ps(An+i+12+k*r);
a0 = _mm_mul_ps(a0, a0T);
a1 = _mm_mul_ps(a1, a0T);
a2 = _mm_mul_ps(a2, a0T);
a3 = _mm_mul_ps(a3, a0T);
c0 = _mm_add_ps(c0, a0);
c1 = _mm_add_ps(c1, a1);
c2 = _mm_add_ps(c2, a2);
c3 = _mm_add_ps(c3, a3);
}
_mm_storeu_ps(Cn+i+j*r, c0);
_mm_storeu_ps(Cn+i+4+j*r, c1);
_mm_storeu_ps(Cn+i+8+j*r, c2);
_mm_storeu_ps(Cn+i+12+j*r, c3);
}
}
}else if((m-a) % 12 == 0){
for( j = ind1 ; j < ind2; j++)
{
for( i = m; i < a; i+=12 )
{
c0 = _mm_loadu_ps(Cn+i+j*r);
c1 = _mm_loadu_ps(Cn+i+4+j*r);
c2 = _mm_loadu_ps(Cn+i+8+j*r);
for( k = 0; k < x; k++ )
{
a0T = _mm_load1_ps(An+j+k*r);
a0 = _mm_loadu_ps(An+i+k*r);
a1 = _mm_loadu_ps(An+i+4+k*r);
a2 = _mm_loadu_ps(An+i+8+k*r);
a0 = _mm_mul_ps(a0, a0T);
a1 = _mm_mul_ps(a1, a0T);
a2 = _mm_mul_ps(a2, a0T);
c0 = _mm_add_ps(c0, a0);
c1 = _mm_add_ps(c1, a1);
c2 = _mm_add_ps(c2, a2);
}
_mm_storeu_ps(Cn+i+j*r, c0);
_mm_storeu_ps(Cn+i+4+j*r, c1);
_mm_storeu_ps(Cn+i+8+j*r, c2);
}
}
}else if((m-a) % 8 == 0){
for( j = ind1 ; j < ind2; j++)
{
for( i = m; i < a; i+=20 )
{
c0 = _mm_loadu_ps(Cn+i+j*r);
c1 = _mm_loadu_ps(Cn+i+4+j*r);
for( k = 0; k < x; k++ )
{
a0T = _mm_load1_ps(An+j+k*r);
a0 = _mm_loadu_ps(An+i+k*r);
a1 = _mm_loadu_ps(An+i+4+k*r);
a0 = _mm_mul_ps(a0, a0T);
a1 = _mm_mul_ps(a1, a0T);
c0 = _mm_add_ps(c0, a0);
c1 = _mm_add_ps(c1, a1);
}
_mm_storeu_ps(Cn+i+j*r, c0);
_mm_storeu_ps(Cn+i+4+j*r, c1);
}
}
}else{
for( j = ind1 ; j < ind2; j++)
{
for( i = m; i < a; i+=4 )
{
c0 = _mm_loadu_ps(Cn+i+j*r);
for( k = 0; k < x; k++ )
{
a0T = _mm_load1_ps(An+j+k*r);
a0 = _mm_loadu_ps(An+i+k*r);
a0 = _mm_mul_ps(a0, a0T);
c0 = _mm_add_ps(c0, a0);
}
_mm_storeu_ps(Cn+i+j*r, c0);
}
}
}
}
}
|
the_stack_data/45449529.c | /* $XFree86: xc/lib/Xdmcp/WAofA8.c,v 1.3 2006/01/09 14:59:09 dawes Exp $ */
/*
*
Copyright 1989, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
* *
* Author: Keith Packard, MIT X Consortium
*/
#include <X11/Xos.h>
#include <X11/X.h>
#include <X11/Xmd.h>
#include <X11/Xdmcp.h>
int
XdmcpWriteARRAYofARRAY8 (buffer, array)
XdmcpBufferPtr buffer;
ARRAYofARRAY8Ptr array;
{
int i;
if (!XdmcpWriteCARD8 (buffer, array->length))
return FALSE;
for (i = 0; i < (int)array->length; i++)
if (!XdmcpWriteARRAY8 (buffer, &array->data[i]))
return FALSE;
return TRUE;
}
|
the_stack_data/26699063.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CL/cl.h>
unsigned char *read_buffer(char *file_name, size_t *size_ptr)
{
FILE *f;
unsigned char *buf;
size_t size;
/* Open file */
f = fopen(file_name, "rb");
if (!f)
return NULL;
/* Obtain file size */
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
/* Allocate and read buffer */
buf = malloc(size + 1);
fread(buf, 1, size, f);
buf[size] = '\0';
/* Return size of buffer */
if (size_ptr)
*size_ptr = size;
/* Return buffer */
return buf;
}
void write_buffer(char *file_name, const char *buffer, size_t buffer_size)
{
FILE *f;
/* Open file */
f = fopen(file_name, "w+");
/* Write buffer */
if(buffer)
fwrite(buffer, 1, buffer_size, f);
/* Close file */
fclose(f);
}
int main(int argc, char const *argv[])
{
/* Get platform */
cl_platform_id platform;
cl_uint num_platforms;
cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformIDs' failed\n");
exit(1);
}
printf("Number of platforms: %d\n", num_platforms);
printf("platform=%p\n", platform);
/* Get platform name */
char platform_name[100];
ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformInfo' failed\n");
exit(1);
}
printf("platform.name='%s'\n\n", platform_name);
/* Get device */
cl_device_id device;
cl_uint num_devices;
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceIDs' failed\n");
exit(1);
}
printf("Number of devices: %d\n", num_devices);
printf("device=%p\n", device);
/* Get device name */
char device_name[100];
ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name),
device_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceInfo' failed\n");
exit(1);
}
printf("device.name='%s'\n", device_name);
printf("\n");
/* Create a Context Object */
cl_context context;
context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateContext' failed\n");
exit(1);
}
printf("context=%p\n", context);
/* Create a Command Queue Object*/
cl_command_queue command_queue;
command_queue = clCreateCommandQueue(context, device, 0, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateCommandQueue' failed\n");
exit(1);
}
printf("command_queue=%p\n", command_queue);
printf("\n");
/* Program source */
unsigned char *source_code;
size_t source_length;
/* Read program from 'remainder_ushort8ushort8.cl' */
source_code = read_buffer("remainder_ushort8ushort8.cl", &source_length);
/* Create a program */
cl_program program;
program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateProgramWithSource' failed\n");
exit(1);
}
printf("program=%p\n", program);
/* Build program */
ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
if (ret != CL_SUCCESS )
{
size_t size;
char *log;
/* Get log size */
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size);
/* Allocate log and print */
log = malloc(size);
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL);
printf("error: call to 'clBuildProgram' failed:\n%s\n", log);
/* Free log and exit */
free(log);
exit(1);
}
printf("program built\n");
printf("\n");
/* Create a Kernel Object */
cl_kernel kernel;
kernel = clCreateKernel(program, "remainder_ushort8ushort8", &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateKernel' failed\n");
exit(1);
}
/* Create and allocate host buffers */
size_t num_elem = 10;
/* Create and init host side src buffer 0 */
cl_ushort8 *src_0_host_buffer;
src_0_host_buffer = malloc(num_elem * sizeof(cl_ushort8));
for (int i = 0; i < num_elem; i++)
src_0_host_buffer[i] = (cl_ushort8){{2, 2, 2, 2, 2, 2, 2, 2}};
/* Create and init device side src buffer 0 */
cl_mem src_0_device_buffer;
src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_ushort8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_ushort8), src_0_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create and init host side src buffer 1 */
cl_ushort8 *src_1_host_buffer;
src_1_host_buffer = malloc(num_elem * sizeof(cl_ushort8));
for (int i = 0; i < num_elem; i++)
src_1_host_buffer[i] = (cl_ushort8){{2, 2, 2, 2, 2, 2, 2, 2}};
/* Create and init device side src buffer 1 */
cl_mem src_1_device_buffer;
src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_ushort8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_ushort8), src_1_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create host dst buffer */
cl_ushort8 *dst_host_buffer;
dst_host_buffer = malloc(num_elem * sizeof(cl_ushort8));
memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_ushort8));
/* Create device dst buffer */
cl_mem dst_device_buffer;
dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_ushort8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create dst buffer\n");
exit(1);
}
/* Set kernel arguments */
ret = CL_SUCCESS;
ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer);
ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer);
ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clSetKernelArg' failed\n");
exit(1);
}
/* Launch the kernel */
size_t global_work_size = num_elem;
size_t local_work_size = num_elem;
ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueNDRangeKernel' failed\n");
exit(1);
}
/* Wait for it to finish */
clFinish(command_queue);
/* Read results from GPU */
ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_ushort8), dst_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueReadBuffer' failed\n");
exit(1);
}
/* Dump dst buffer to file */
char dump_file[100];
sprintf((char *)&dump_file, "%s.result", argv[0]);
write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_ushort8));
printf("Result dumped to %s\n", dump_file);
/* Free host dst buffer */
free(dst_host_buffer);
/* Free device dst buffer */
ret = clReleaseMemObject(dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 0 */
free(src_0_host_buffer);
/* Free device side src buffer 0 */
ret = clReleaseMemObject(src_0_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 1 */
free(src_1_host_buffer);
/* Free device side src buffer 1 */
ret = clReleaseMemObject(src_1_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Release kernel */
ret = clReleaseKernel(kernel);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseKernel' failed\n");
exit(1);
}
/* Release program */
ret = clReleaseProgram(program);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseProgram' failed\n");
exit(1);
}
/* Release command queue */
ret = clReleaseCommandQueue(command_queue);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseCommandQueue' failed\n");
exit(1);
}
/* Release context */
ret = clReleaseContext(context);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseContext' failed\n");
exit(1);
}
return 0;
} |
the_stack_data/113188.c | #include <stdio.h>
int main(){
int input;
printf("Enter a number: ");
scanf("%d", &input);
if(input >= 0 && input <= 5){
printf("Morsecode: ");
switch(input){
case 0:
printf("-----\n");
break;
case 1:
printf(".----\n");
break;
case 2:
printf("..---\n");
break;
case 3:
printf("...--\n");
break;
case 4:
printf("....-\n");
break;
case 5:
printf(".....\n");
break;
}
}
else{
printf("Input error\n");
}
return 0;
}
|
the_stack_data/200143591.c | /*
* man2tcl.c --
*
* This file contains a program that turns a man page of the
* form used for Tcl and Tk into a Tcl script that invokes
* a Tcl command for each construct in the man page. The
* script can then be eval'ed to translate the manual entry
* into some other format such as MIF or HTML.
*
* Usage:
*
* man2tcl ?fileName?
*
* Copyright (c) 1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
static char sccsid[] = "@(#) man2tcl.c 1.3 95/08/12 17:34:08";
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifndef NO_ERRNO_H
#include <errno.h>
#endif
/*
* Imported things that aren't defined in header files:
*/
/*
* Some <errno.h> define errno to be something complex and
* thread-aware; in that case we definitely do not want to declare
* errno ourselves!
*/
#ifndef errno
extern int errno;
#endif
/*
* Current line number, used for error messages.
*/
static int lineNumber;
/*
* The variable below is set to 1 if an error occurs anywhere
* while reading in the file.
*/
static int status;
/*
* The variable below is set to 1 if output should be generated.
* If it's 0, it means we're doing a pre-pass to make sure that
* the file can be properly parsed.
*/
static int writeOutput;
/*
* Prototypes for procedures defined in this file:
*/
static void DoMacro(char *line);
static void DoText(char *line);
static void QuoteText(char *string, int count);
/*
*----------------------------------------------------------------------
*
* main --
*
* This procedure is the main program, which does all of the work
* of the program.
*
* Results:
* None: exits with a 0 return status to indicate success, or
* 1 to indicate that there were problems in the translation.
*
* Side effects:
* A Tcl script is output to standard output. Error messages may
* be output on standard error.
*
*----------------------------------------------------------------------
*/
int
main(argc, argv)
int argc; /* Number of command-line arguments. */
char **argv; /* Values of command-line arguments. */
{
FILE *f;
#define MAX_LINE_SIZE 1000
char line[MAX_LINE_SIZE];
char *p;
/*
* Find the file to read, and open it if it isn't stdin.
*/
if (argc == 1) {
f = stdin;
} else if (argc == 2) {
f = fopen(argv[1], "r");
if (f == NULL) {
fprintf(stderr, "Couldn't read \"%s\": %s\n", argv[1],
strerror(errno));
exit(1);
}
} else {
fprintf(stderr, "Usage: %s ?fileName?\n", argv[0]);
}
/*
* Make two passes over the file. In the first pass, just check
* to make sure we can handle everything. If there are problems,
* generate output and stop. If everything is OK, make a second
* pass to actually generate output.
*/
for (writeOutput = 0; writeOutput < 2; writeOutput++) {
lineNumber = 0;
status = 0;
while (fgets(line, MAX_LINE_SIZE, f) != NULL) {
for (p = line; *p != 0; p++) {
if (*p == '\n') {
*p = 0;
break;
}
}
lineNumber++;
if ((line[0] == '\'') && (line[1] == '\\') && (line[2] == '\"')) {
/*
* This line is a comment. Ignore it.
*/
continue;
}
if (strlen(line) >= MAX_LINE_SIZE -1) {
fprintf(stderr, "Too long line. Max is %d chars.\n",
MAX_LINE_SIZE - 1);
exit(1);
}
if ((line[0] == '.') || (line[0] == '\'')) {
/*
* This line is a macro invocation.
*/
DoMacro(line);
} else {
/*
* This line is text, possibly with formatting characters
* embedded in it.
*/
DoText(line);
}
}
if (status != 0) {
break;
}
fseek(f, 0, SEEK_SET);
}
exit(status);
}
/*
*----------------------------------------------------------------------
*
* DoMacro --
*
* This procedure is called to handle a macro invocation.
* It parses the arguments to the macro and generates a
* Tcl command to handle the invocation.
*
* Results:
* None.
*
* Side effects:
* A Tcl command is written to stdout.
*
*----------------------------------------------------------------------
*/
static void
DoMacro(line)
char *line; /* The line of text that contains the
* macro invocation. */
{
char *p, *end;
/*
* If there is no macro name, then just skip the whole line.
*/
if ((line[1] == 0) || (isspace(line[1]))) {
return;
}
if (writeOutput) {
printf("macro");
}
if (*line != '.') {
if (writeOutput) {
printf("2");
}
}
/*
* Parse the arguments to the macro (including the name), in order.
*/
p = line+1;
while (1) {
if (writeOutput) {
putc(' ', stdout);
}
if (*p == '"') {
/*
* The argument is delimited by quotes.
*/
for (end = p+1; *end != '"'; end++) {
if (*end == 0) {
fprintf(stderr,
"Unclosed quote in macro call on line %d.\n",
lineNumber);
status = 1;
break;
}
}
QuoteText(p+1, (end-(p+1)));
} else {
for (end = p+1; (*end != 0) && !isspace(*end); end++) {
/* Empty loop body. */
}
QuoteText(p, end-p);
}
if (*end == 0) {
break;
}
p = end+1;
while (isspace(*p)) {
/*
* Skip empty space before next argument.
*/
p++;
}
if (*p == 0) {
break;
}
}
if (writeOutput) {
putc('\n', stdout);
}
}
/*
*----------------------------------------------------------------------
*
* DoText --
*
* This procedure is called to handle a line of troff text.
* It parses the text, generating Tcl commands for text and
* for formatting stuff such as font changes.
*
* Results:
* None.
*
* Side effects:
* Tcl commands are written to stdout.
*
*----------------------------------------------------------------------
*/
static void
DoText(line)
char *line; /* The line of text. */
{
char *p, *end;
/*
* Divide the line up into pieces consisting of backslash sequences,
* tabs, and other text.
*/
p = line;
while (*p != 0) {
if (*p == '\t') {
if (writeOutput) {
printf("tab\n");
}
p++;
} else if (*p != '\\') {
/*
* Ordinary text.
*/
for (end = p+1; (*end != '\\') && (*end != 0); end++) {
/* Empty loop body. */
}
if (writeOutput) {
printf("text ");
}
QuoteText(p, end-p);
if (writeOutput) {
putc('\n', stdout);
}
p = end;
} else {
/*
* A backslash sequence. There are particular ones
* that we understand; output an error message for
* anything else and just ignore the backslash.
*/
p++;
if (*p == 'f') {
/*
* Font change.
*/
if (writeOutput) {
printf("font %c\n", p[1]);
}
p += 2;
} else if (*p == '-') {
if (writeOutput) {
printf("dash\n");
}
p++;
} else if (*p == 'e') {
if (writeOutput) {
printf("text \\\\\n");
}
p++;
} else if (*p == '.') {
if (writeOutput) {
printf("text .\n");
}
p++;
} else if (*p == '&') {
p++;
} else if (*p == '(') {
if ((p[1] == 0) || (p[2] == 0)) {
fprintf(stderr, "Bad \\( sequence on line %d.\n",
lineNumber);
status = 1;
} else {
if (writeOutput) {
printf("char {\\(%c%c}\n", p[1], p[2]);
}
p += 3;
}
} else if (*p != 0) {
if (writeOutput) {
printf("char {\\%c}\n", *p);
}
p++;
}
}
}
if (writeOutput) {
printf("newline\n");
}
}
/*
*----------------------------------------------------------------------
*
* QuoteText --
*
* Copy the "string" argument to stdout, adding quote characters
* around any special Tcl characters so that they'll just be treated
* as ordinary text.
*
* Results:
* None.
*
* Side effects:
* Text is written to stdout.
*
*----------------------------------------------------------------------
*/
static void
QuoteText(string, count)
char *string; /* The line of text. */
int count; /* Number of characters to write from string. */
{
if (count == 0) {
if (writeOutput) {
printf("{}");
}
return;
}
for ( ; count > 0; string++, count--) {
if ((*string == '$') || (*string == '[') || (*string == '{')
|| (*string == ' ') || (*string == ';') || (*string == '\\')
|| (*string == '"') || (*string == '\t')) {
if (writeOutput) {
putc('\\', stdout);
}
}
if (writeOutput) {
putc(*string, stdout);
}
}
}
|
the_stack_data/151706274.c | #include <stdio.h>
typedef enum {
false,
true
} BOOLEAN;
void main (void)
{
BOOLEAN b_var;
b_var = false;
if (b_var == true)
{
printf ("TRUE\n");
}
else
{
printf ("FALSE\n");
}
}
|
the_stack_data/198580674.c | //
// main.c
// 7DrawDots
//
// Created by Carlos Santiago Cruz on 02/06/20.
// Copyright © 2020 Carlos Santiago Cruz. All rights reserved.
//
#include <stdio.h>
void DrawDots( int numberOfDots );
int main(int argc, const char * argv[]) {
int index;
for(index = 1; index<=10; index++) {
DrawDots(30);
printf("\n");
}
return 0;
}
void DrawDots(int numberOfDots)
{
int index;
for (index = 1; index <= numberOfDots; index++)
printf(".");
}
|
the_stack_data/92328468.c | #include <stdio.h>
int main()
{
int n,y,sum=0,i;
float avg;
printf("enter the no of numbers u want to find average for\n");
scanf("%d",&n);
printf("Enter the numbers\n");
for(i=0;i<n;i++)
{
scanf("%d",&y);
sum = sum + y;
}
avg = sum/n;
printf("the avg of given numbers is %f\n",avg);
return(0);
}
|
the_stack_data/23233.c | /*
** 2008 Jan 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains code for a VFS layer that acts as a wrapper around
** an existing VFS. The code in this file attempts to verify that SQLite
** correctly populates and syncs a journal file before writing to a
** corresponding database file.
**
** $Id: test_journal.c,v 1.15 2009/04/07 11:21:29 danielk1977 Exp $
*/
#if SQLITE_TEST /* This file is used for testing only */
#include "sqlite3.h"
#include "sqliteInt.h"
/*
** INTERFACE
**
** The public interface to this wrapper VFS is two functions:
**
** jt_register()
** jt_unregister()
**
** See header comments associated with those two functions below for
** details.
**
** LIMITATIONS
**
** This wrapper will not work if "PRAGMA synchronous = off" is used.
**
** OPERATION
**
** Starting a Transaction:
**
** When a write-transaction is started, the contents of the database is
** inspected and the following data stored as part of the database file
** handle (type struct jt_file):
**
** a) The page-size of the database file.
** b) The number of pages that are in the database file.
** c) The set of page numbers corresponding to free-list leaf pages.
** d) A check-sum for every page in the database file.
**
** The start of a write-transaction is deemed to have occurred when a
** 28-byte journal header is written to byte offset 0 of the journal
** file.
**
** Syncing the Journal File:
**
** Whenever the xSync method is invoked to sync a journal-file, the
** contents of the journal file are read. For each page written to
** the journal file, a check-sum is calculated and compared to the
** check-sum calculated for the corresponding database page when the
** write-transaction was initialized. The success of the comparison
** is assert()ed. So if SQLite has written something other than the
** original content to the database file, an assert() will fail.
**
** Additionally, the set of page numbers for which records exist in
** the journal file is added to (unioned with) the set of page numbers
** corresponding to free-list leaf pages collected when the
** write-transaction was initialized. This set comprises the page-numbers
** corresponding to those pages that SQLite may now safely modify.
**
** Writing to the Database File:
**
** When a block of data is written to a database file, the following
** invariants are asserted:
**
** a) That the block of data is an aligned block of page-size bytes.
**
** b) That if the page being written did not exist when the
** transaction was started (i.e. the database file is growing), then
** the journal-file must have been synced at least once since
** the start of the transaction.
**
** c) That if the page being written did exist when the transaction
** was started, then the page must have either been a free-list
** leaf page at the start of the transaction, or else must have
** been stored in the journal file prior to the most recent sync.
**
** Closing a Transaction:
**
** When a transaction is closed, all data collected at the start of
** the transaction, or following an xSync of a journal-file, is
** discarded. The end of a transaction is recognized when any one
** of the following occur:
**
** a) A block of zeroes (or anything else that is not a valid
** journal-header) is written to the start of the journal file.
**
** b) A journal file is truncated to zero bytes in size using xTruncate.
**
** c) The journal file is deleted using xDelete.
*/
/*
** Maximum pathname length supported by the jt backend.
*/
#define JT_MAX_PATHNAME 512
/*
** Name used to identify this VFS.
*/
#define JT_VFS_NAME "jt"
typedef struct jt_file jt_file;
struct jt_file {
sqlite3_file base;
const char *zName; /* Name of open file */
int flags; /* Flags the file was opened with */
/* The following are only used by database file file handles */
int eLock; /* Current lock held on the file */
u32 nPage; /* Size of file in pages when transaction started */
u32 nPagesize; /* Page size when transaction started */
Bitvec *pWritable; /* Bitvec of pages that may be written to the file */
u32 *aCksum; /* Checksum for first nPage pages */
int nSync; /* Number of times journal file has been synced */
/* Only used by journal file-handles */
sqlite3_int64 iMaxOff; /* Maximum offset written to this transaction */
jt_file *pNext; /* All files are stored in a linked list */
sqlite3_file *pReal; /* The file handle for the underlying vfs */
};
/*
** Method declarations for jt_file.
*/
static int jtClose(sqlite3_file*);
static int jtRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
static int jtWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
static int jtTruncate(sqlite3_file*, sqlite3_int64 size);
static int jtSync(sqlite3_file*, int flags);
static int jtFileSize(sqlite3_file*, sqlite3_int64 *pSize);
static int jtLock(sqlite3_file*, int);
static int jtUnlock(sqlite3_file*, int);
static int jtCheckReservedLock(sqlite3_file*, int *);
static int jtFileControl(sqlite3_file*, int op, void *pArg);
static int jtSectorSize(sqlite3_file*);
static int jtDeviceCharacteristics(sqlite3_file*);
/*
** Method declarations for jt_vfs.
*/
static int jtOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int jtDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int jtAccess(sqlite3_vfs*, const char *zName, int flags, int *);
static int jtFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
static void *jtDlOpen(sqlite3_vfs*, const char *zFilename);
static void jtDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
static void (*jtDlSym(sqlite3_vfs*,void*, const char *zSymbol))(void);
static void jtDlClose(sqlite3_vfs*, void*);
static int jtRandomness(sqlite3_vfs*, int nByte, char *zOut);
static int jtSleep(sqlite3_vfs*, int microseconds);
static int jtCurrentTime(sqlite3_vfs*, double*);
static sqlite3_vfs jt_vfs = {
1, /* iVersion */
sizeof(jt_file), /* szOsFile */
JT_MAX_PATHNAME, /* mxPathname */
0, /* pNext */
JT_VFS_NAME, /* zName */
0, /* pAppData */
jtOpen, /* xOpen */
jtDelete, /* xDelete */
jtAccess, /* xAccess */
jtFullPathname, /* xFullPathname */
jtDlOpen, /* xDlOpen */
jtDlError, /* xDlError */
jtDlSym, /* xDlSym */
jtDlClose, /* xDlClose */
jtRandomness, /* xRandomness */
jtSleep, /* xSleep */
jtCurrentTime /* xCurrentTime */
};
static sqlite3_io_methods jt_io_methods = {
1, /* iVersion */
jtClose, /* xClose */
jtRead, /* xRead */
jtWrite, /* xWrite */
jtTruncate, /* xTruncate */
jtSync, /* xSync */
jtFileSize, /* xFileSize */
jtLock, /* xLock */
jtUnlock, /* xUnlock */
jtCheckReservedLock, /* xCheckReservedLock */
jtFileControl, /* xFileControl */
jtSectorSize, /* xSectorSize */
jtDeviceCharacteristics /* xDeviceCharacteristics */
};
struct JtGlobal {
sqlite3_vfs *pVfs; /* Parent VFS */
jt_file *pList; /* List of all open files */
};
static struct JtGlobal g = {0, 0};
/*
** Functions to obtain and relinquish a mutex to protect g.pList. The
** STATIC_PRNG mutex is reused, purely for the sake of convenience.
*/
static void enterJtMutex(void){
sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PRNG));
}
static void leaveJtMutex(void){
sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PRNG));
}
extern int sqlite3_io_error_pending;
static void stop_ioerr_simulation(int *piSave){
*piSave = sqlite3_io_error_pending;
sqlite3_io_error_pending = -1;
}
static void start_ioerr_simulation(int iSave){
sqlite3_io_error_pending = iSave;
}
/*
** The jt_file pointed to by the argument may or may not be a file-handle
** open on a main database file. If it is, and a transaction is currently
** opened on the file, then discard all transaction related data.
*/
static void closeTransaction(jt_file *p){
sqlite3BitvecDestroy(p->pWritable);
sqlite3_free(p->aCksum);
p->pWritable = 0;
p->aCksum = 0;
p->nSync = 0;
}
/*
** Close an jt-file.
*/
static int jtClose(sqlite3_file *pFile){
jt_file **pp;
jt_file *p = (jt_file *)pFile;
closeTransaction(p);
enterJtMutex();
if( p->zName ){
for(pp=&g.pList; *pp!=p; pp=&(*pp)->pNext);
*pp = p->pNext;
}
leaveJtMutex();
return sqlite3OsClose(p->pReal);
}
/*
** Read data from an jt-file.
*/
static int jtRead(
sqlite3_file *pFile,
void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
jt_file *p = (jt_file *)pFile;
return sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst);
}
/*
** Parameter zJournal is the name of a journal file that is currently
** open. This function locates and returns the handle opened on the
** corresponding database file by the pager that currently has the
** journal file opened. This file-handle is identified by the
** following properties:
**
** a) SQLITE_OPEN_MAIN_DB was specified when the file was opened.
**
** b) The file-name specified when the file was opened matches
** all but the final 8 characters of the journal file name.
**
** c) There is currently a reserved lock on the file.
**/
static jt_file *locateDatabaseHandle(const char *zJournal){
jt_file *pMain = 0;
enterJtMutex();
for(pMain=g.pList; pMain; pMain=pMain->pNext){
int nName = strlen(zJournal) - strlen("-journal");
if( (pMain->flags&SQLITE_OPEN_MAIN_DB)
&& (strlen(pMain->zName)==nName)
&& 0==memcmp(pMain->zName, zJournal, nName)
&& (pMain->eLock>=SQLITE_LOCK_RESERVED)
){
break;
}
}
leaveJtMutex();
return pMain;
}
/*
** Parameter z points to a buffer of 4 bytes in size containing a
** unsigned 32-bit integer stored in big-endian format. Decode the
** integer and return its value.
*/
static u32 decodeUint32(const unsigned char *z){
return (z[0]<<24) + (z[1]<<16) + (z[2]<<8) + z[3];
}
/*
** Calculate a checksum from the buffer of length n bytes pointed to
** by parameter z.
*/
static u32 genCksum(const unsigned char *z, int n){
int i;
u32 cksum = 0;
for(i=0; i<n; i++){
cksum = cksum + z[i] + (cksum<<3);
}
return cksum;
}
/*
** The first argument, zBuf, points to a buffer containing a 28 byte
** serialized journal header. This function deserializes four of the
** integer fields contained in the journal header and writes their
** values to the output variables.
**
** SQLITE_OK is returned if the journal-header is successfully
** decoded. Otherwise, SQLITE_ERROR.
*/
static int decodeJournalHdr(
const unsigned char *zBuf, /* Input: 28 byte journal header */
u32 *pnRec, /* Out: Number of journalled records */
u32 *pnPage, /* Out: Original database page count */
u32 *pnSector, /* Out: Sector size in bytes */
u32 *pnPagesize /* Out: Page size in bytes */
){
unsigned char aMagic[] = { 0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7 };
if( memcmp(aMagic, zBuf, 8) ) return SQLITE_ERROR;
if( pnRec ) *pnRec = decodeUint32(&zBuf[8]);
if( pnPage ) *pnPage = decodeUint32(&zBuf[16]);
if( pnSector ) *pnSector = decodeUint32(&zBuf[20]);
if( pnPagesize ) *pnPagesize = decodeUint32(&zBuf[24]);
return SQLITE_OK;
}
/*
** This function is called when a new transaction is opened, just after
** the first journal-header is written to the journal file.
*/
static int openTransaction(jt_file *pMain, jt_file *pJournal){
unsigned char *aData;
sqlite3_file *p = pMain->pReal;
int rc = SQLITE_OK;
aData = sqlite3_malloc(pMain->nPagesize);
pMain->pWritable = sqlite3BitvecCreate(pMain->nPage);
pMain->aCksum = sqlite3_malloc(sizeof(u32) * (pMain->nPage + 1));
pJournal->iMaxOff = 0;
if( !pMain->pWritable || !pMain->aCksum || !aData ){
rc = SQLITE_IOERR_NOMEM;
}else if( pMain->nPage>0 ){
u32 iTrunk;
int iSave;
stop_ioerr_simulation(&iSave);
/* Read the database free-list. Add the page-number for each free-list
** leaf to the jt_file.pWritable bitvec.
*/
rc = sqlite3OsRead(p, aData, pMain->nPagesize, 0);
iTrunk = decodeUint32(&aData[32]);
while( rc==SQLITE_OK && iTrunk>0 ){
u32 nLeaf;
u32 iLeaf;
sqlite3_int64 iOff = (iTrunk-1)*pMain->nPagesize;
rc = sqlite3OsRead(p, aData, pMain->nPagesize, iOff);
nLeaf = decodeUint32(&aData[4]);
for(iLeaf=0; rc==SQLITE_OK && iLeaf<nLeaf; iLeaf++){
u32 pgno = decodeUint32(&aData[8+4*iLeaf]);
sqlite3BitvecSet(pMain->pWritable, pgno);
}
iTrunk = decodeUint32(aData);
}
/* Calculate and store a checksum for each page in the database file. */
if( rc==SQLITE_OK ){
int ii;
for(ii=0; rc==SQLITE_OK && ii<pMain->nPage; ii++){
i64 iOff = (i64)(pMain->nPagesize) * (i64)ii;
if( iOff==PENDING_BYTE ) continue;
rc = sqlite3OsRead(pMain->pReal, aData, pMain->nPagesize, iOff);
pMain->aCksum[ii] = genCksum(aData, pMain->nPagesize);
}
}
start_ioerr_simulation(iSave);
}
sqlite3_free(aData);
return rc;
}
/*
** Write data to an jt-file.
*/
static int jtWrite(
sqlite3_file *pFile,
const void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
jt_file *p = (jt_file *)pFile;
if( p->flags&SQLITE_OPEN_MAIN_JOURNAL ){
if( iOfst==0 ){
jt_file *pMain = locateDatabaseHandle(p->zName);
assert( pMain );
if( decodeJournalHdr(zBuf, 0, &pMain->nPage, 0, &pMain->nPagesize) ){
/* Zeroing the first journal-file header. This is the end of a
** transaction. */
closeTransaction(pMain);
}else{
/* Writing the first journal header to a journal file. This happens
** when a transaction is first started. */
int rc;
if( SQLITE_OK!=(rc=openTransaction(pMain, p)) ){
return rc;
}
}
}
if( p->iMaxOff<(iOfst + iAmt) ){
p->iMaxOff = iOfst + iAmt;
}
}
if( p->flags&SQLITE_OPEN_MAIN_DB && p->pWritable ){
if( iAmt<p->nPagesize
&& p->nPagesize%iAmt==0
&& iOfst>=(PENDING_BYTE+512)
&& iOfst+iAmt<=PENDING_BYTE+p->nPagesize
){
/* No-op. This special case is hit when the backup code is copying a
** to a database with a larger page-size than the source database and
** it needs to fill in the non-locking-region part of the original
** pending-byte page.
*/
}else{
u32 pgno = iOfst/p->nPagesize + 1;
assert( (iAmt==1||iAmt==p->nPagesize) && ((iOfst+iAmt)%p->nPagesize)==0 );
assert( pgno<=p->nPage || p->nSync>0 );
assert( pgno>p->nPage || sqlite3BitvecTest(p->pWritable, pgno) );
}
}
return sqlite3OsWrite(p->pReal, zBuf, iAmt, iOfst);
}
/*
** Truncate an jt-file.
*/
static int jtTruncate(sqlite3_file *pFile, sqlite_int64 size){
jt_file *p = (jt_file *)pFile;
if( p->flags&SQLITE_OPEN_MAIN_JOURNAL && size==0 ){
/* Truncating a journal file. This is the end of a transaction. */
jt_file *pMain = locateDatabaseHandle(p->zName);
closeTransaction(pMain);
}
if( p->flags&SQLITE_OPEN_MAIN_DB && p->pWritable ){
u32 pgno;
u32 locking_page = (u32)(PENDING_BYTE/p->nPagesize+1);
for(pgno=size/p->nPagesize+1; pgno<=p->nPage; pgno++){
assert( pgno==locking_page || sqlite3BitvecTest(p->pWritable, pgno) );
}
}
return sqlite3OsTruncate(p->pReal, size);
}
/*
** The first argument to this function is a handle open on a journal file.
** This function reads the journal file and adds the page number for each
** page in the journal to the Bitvec object passed as the second argument.
*/
static int readJournalFile(jt_file *p, jt_file *pMain){
int rc = SQLITE_OK;
unsigned char zBuf[28];
sqlite3_file *pReal = p->pReal;
sqlite3_int64 iOff = 0;
sqlite3_int64 iSize = p->iMaxOff;
unsigned char *aPage;
int iSave;
aPage = sqlite3_malloc(pMain->nPagesize);
if( !aPage ){
return SQLITE_IOERR_NOMEM;
}
stop_ioerr_simulation(&iSave);
while( rc==SQLITE_OK && iOff<iSize ){
u32 nRec, nPage, nSector, nPagesize;
u32 ii;
/* Read and decode the next journal-header from the journal file. */
rc = sqlite3OsRead(pReal, zBuf, 28, iOff);
if( rc!=SQLITE_OK
|| decodeJournalHdr(zBuf, &nRec, &nPage, &nSector, &nPagesize)
){
goto finish_rjf;
}
iOff += nSector;
if( nRec==0 ){
/* A trick. There might be another journal-header immediately
** following this one. In this case, 0 records means 0 records,
** not "read until the end of the file". See also ticket #2565.
*/
if( iSize>=(iOff+nSector) ){
rc = sqlite3OsRead(pReal, zBuf, 28, iOff);
if( rc!=SQLITE_OK || 0==decodeJournalHdr(zBuf, 0, 0, 0, 0) ){
continue;
}
}
nRec = (iSize-iOff) / (pMain->nPagesize+8);
}
/* Read all the records that follow the journal-header just read. */
for(ii=0; rc==SQLITE_OK && ii<nRec && iOff<iSize; ii++){
u32 pgno;
rc = sqlite3OsRead(pReal, zBuf, 4, iOff);
if( rc==SQLITE_OK ){
pgno = decodeUint32(zBuf);
if( pgno>0 && pgno<=pMain->nPage ){
if( 0==sqlite3BitvecTest(pMain->pWritable, pgno) ){
rc = sqlite3OsRead(pReal, aPage, pMain->nPagesize, iOff+4);
if( rc==SQLITE_OK ){
u32 cksum = genCksum(aPage, pMain->nPagesize);
assert( cksum==pMain->aCksum[pgno-1] );
}
}
sqlite3BitvecSet(pMain->pWritable, pgno);
}
iOff += (8 + pMain->nPagesize);
}
}
iOff = ((iOff + (nSector-1)) / nSector) * nSector;
}
finish_rjf:
start_ioerr_simulation(iSave);
sqlite3_free(aPage);
if( rc==SQLITE_IOERR_SHORT_READ ){
rc = SQLITE_OK;
}
return rc;
}
/*
** Sync an jt-file.
*/
static int jtSync(sqlite3_file *pFile, int flags){
jt_file *p = (jt_file *)pFile;
if( p->flags&SQLITE_OPEN_MAIN_JOURNAL ){
int rc;
jt_file *pMain; /* The associated database file */
/* The journal file is being synced. At this point, we inspect the
** contents of the file up to this point and set each bit in the
** jt_file.pWritable bitvec of the main database file associated with
** this journal file.
*/
pMain = locateDatabaseHandle(p->zName);
assert(pMain);
/* Set the bitvec values */
if( pMain->pWritable ){
pMain->nSync++;
rc = readJournalFile(p, pMain);
if( rc!=SQLITE_OK ){
return rc;
}
}
}
return sqlite3OsSync(p->pReal, flags);
}
/*
** Return the current file-size of an jt-file.
*/
static int jtFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
jt_file *p = (jt_file *)pFile;
return sqlite3OsFileSize(p->pReal, pSize);
}
/*
** Lock an jt-file.
*/
static int jtLock(sqlite3_file *pFile, int eLock){
int rc;
jt_file *p = (jt_file *)pFile;
rc = sqlite3OsLock(p->pReal, eLock);
if( rc==SQLITE_OK && eLock>p->eLock ){
p->eLock = eLock;
}
return rc;
}
/*
** Unlock an jt-file.
*/
static int jtUnlock(sqlite3_file *pFile, int eLock){
int rc;
jt_file *p = (jt_file *)pFile;
rc = sqlite3OsUnlock(p->pReal, eLock);
if( rc==SQLITE_OK && eLock<p->eLock ){
p->eLock = eLock;
}
return rc;
}
/*
** Check if another file-handle holds a RESERVED lock on an jt-file.
*/
static int jtCheckReservedLock(sqlite3_file *pFile, int *pResOut){
jt_file *p = (jt_file *)pFile;
return sqlite3OsCheckReservedLock(p->pReal, pResOut);
}
/*
** File control method. For custom operations on an jt-file.
*/
static int jtFileControl(sqlite3_file *pFile, int op, void *pArg){
jt_file *p = (jt_file *)pFile;
return sqlite3OsFileControl(p->pReal, op, pArg);
}
/*
** Return the sector-size in bytes for an jt-file.
*/
static int jtSectorSize(sqlite3_file *pFile){
jt_file *p = (jt_file *)pFile;
return sqlite3OsSectorSize(p->pReal);
}
/*
** Return the device characteristic flags supported by an jt-file.
*/
static int jtDeviceCharacteristics(sqlite3_file *pFile){
jt_file *p = (jt_file *)pFile;
return sqlite3OsDeviceCharacteristics(p->pReal);
}
/*
** Open an jt file handle.
*/
static int jtOpen(
sqlite3_vfs *pVfs,
const char *zName,
sqlite3_file *pFile,
int flags,
int *pOutFlags
){
int rc;
jt_file *p = (jt_file *)pFile;
pFile->pMethods = 0;
p->pReal = (sqlite3_file *)&p[1];
p->pReal->pMethods = 0;
rc = sqlite3OsOpen(g.pVfs, zName, p->pReal, flags, pOutFlags);
assert( rc==SQLITE_OK || p->pReal->pMethods==0 );
if( rc==SQLITE_OK ){
pFile->pMethods = &jt_io_methods;
p->eLock = 0;
p->zName = zName;
p->flags = flags;
p->pNext = 0;
p->pWritable = 0;
p->aCksum = 0;
enterJtMutex();
if( zName ){
p->pNext = g.pList;
g.pList = p;
}
leaveJtMutex();
}
return rc;
}
/*
** Delete the file located at zPath. If the dirSync argument is true,
** ensure the file-system modifications are synced to disk before
** returning.
*/
static int jtDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
int nPath = strlen(zPath);
if( nPath>8 && 0==strcmp("-journal", &zPath[nPath-8]) ){
/* Deleting a journal file. The end of a transaction. */
jt_file *pMain = locateDatabaseHandle(zPath);
if( pMain ){
closeTransaction(pMain);
}
}
return sqlite3OsDelete(g.pVfs, zPath, dirSync);
}
/*
** Test for access permissions. Return true if the requested permission
** is available, or false otherwise.
*/
static int jtAccess(
sqlite3_vfs *pVfs,
const char *zPath,
int flags,
int *pResOut
){
return sqlite3OsAccess(g.pVfs, zPath, flags, pResOut);
}
/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (JT_MAX_PATHNAME+1) bytes.
*/
static int jtFullPathname(
sqlite3_vfs *pVfs,
const char *zPath,
int nOut,
char *zOut
){
return sqlite3OsFullPathname(g.pVfs, zPath, nOut, zOut);
}
/*
** Open the dynamic library located at zPath and return a handle.
*/
static void *jtDlOpen(sqlite3_vfs *pVfs, const char *zPath){
return g.pVfs->xDlOpen(g.pVfs, zPath);
}
/*
** Populate the buffer zErrMsg (size nByte bytes) with a human readable
** utf-8 string describing the most recent error encountered associated
** with dynamic libraries.
*/
static void jtDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
g.pVfs->xDlError(g.pVfs, nByte, zErrMsg);
}
/*
** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
*/
static void (*jtDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
return g.pVfs->xDlSym(g.pVfs, p, zSym);
}
/*
** Close the dynamic library handle pHandle.
*/
static void jtDlClose(sqlite3_vfs *pVfs, void *pHandle){
g.pVfs->xDlClose(g.pVfs, pHandle);
}
/*
** Populate the buffer pointed to by zBufOut with nByte bytes of
** random data.
*/
static int jtRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
return sqlite3OsRandomness(g.pVfs, nByte, zBufOut);
}
/*
** Sleep for nMicro microseconds. Return the number of microseconds
** actually slept.
*/
static int jtSleep(sqlite3_vfs *pVfs, int nMicro){
return sqlite3OsSleep(g.pVfs, nMicro);
}
/*
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int jtCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
return sqlite3OsCurrentTime(g.pVfs, pTimeOut);
}
/**************************************************************************
** Start of public API.
*/
/*
** Configure the jt VFS as a wrapper around the VFS named by parameter
** zWrap. If the isDefault parameter is true, then the jt VFS is installed
** as the new default VFS for SQLite connections. If isDefault is not
** true, then the jt VFS is installed as non-default. In this case it
** is available via its name, "jt".
*/
int jt_register(char *zWrap, int isDefault){
g.pVfs = sqlite3_vfs_find(zWrap);
if( g.pVfs==0 ){
return SQLITE_ERROR;
}
jt_vfs.szOsFile = sizeof(jt_file) + g.pVfs->szOsFile;
sqlite3_vfs_register(&jt_vfs, isDefault);
return SQLITE_OK;
}
/*
** Uninstall the jt VFS, if it is installed.
*/
void jt_unregister(void){
sqlite3_vfs_unregister(&jt_vfs);
}
#endif
|
the_stack_data/182952787.c | /*numPass=5, numTotal=5
Verdict:ACCEPTED, Visibility:1, Input:"4 hehe
6 hehehe", ExpOutput:"he", Output:"he"
Verdict:ACCEPTED, Visibility:1, Input:"4 abab
8 abababab", ExpOutput:"abab", Output:"abab"
Verdict:ACCEPTED, Visibility:1, Input:"4 heeh
6 hehehe", ExpOutput:"", Output:""
Verdict:ACCEPTED, Visibility:0, Input:"5 hello
6 hihihi", ExpOutput:"", Output:""
Verdict:ACCEPTED, Visibility:0, Input:"1 a
5 aaaaa", ExpOutput:"a", Output:"a"
*/
#include <stdio.h>
#include <stdlib.h>
int common_divisor(int ,int);//calculates the greatest common divisor given numbers
int check(char *,char *,int,int);//checks whether the gcd is the only occuring word in the string
int main(){
char *s1,*s2,*s3;
int l1,l2,i,gcd,a,b;
scanf("%d ",&l1);
s1=(char *)malloc(l1*sizeof(char));
scanf("%s\n%d",s1,&l2);
s2=(char *)malloc(l2*sizeof(char));
scanf("%s",s2);
gcd=common_divisor(l1,l2);
s3=(char *)malloc(gcd*sizeof(char));
for(i=0;i<gcd;i++)
s3[i]=s1[i];
a=check(s1,s3,l1,gcd);
b=check(s2,s3,l2,gcd);
if(a&&b)
printf("%s",s3);
else
printf("");
return 0;}
int common_divisor(int a,int b){
int c;
if(a<b){
c=a;
a=b;
b=c;}
while(a%b!=0){
a=a%b;
c=a;
a=b;
b=c;}
return b;}
int check(char *s,char *s1,int l1,int gcd){
int i,j,c=0;
for(i=0;i<l1;i=i+gcd)
for(j=0;j<gcd;j++)
if(s[i+j]==s1[j])
c++;
if(c==l1)
return 1;
else
return 0;} |
the_stack_data/242331029.c | #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int n, res;
scanf("%d", &n);
res = n%10;
while (n = n/10) {
res += n%10;
}
printf("%d\n", res);
return 0;
} |
the_stack_data/97013745.c | /* sidereal.c - created 2007 by inhaesio zha */
/* gcc -ansi -O3 -lcurses -o sidereal sidereal.c */
/* */
/* make position_index_from_observe_location/eight_from_eight do something */
/* smarter, something that observes more than one bit from each neighbor? */
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define EFE_LENGTH 32
#define RANDOM_SEED 5878 + 1 /* 0, 12, 14, 5878 + 1, ... */
#define GENOME_ADDRESS_SIZE 8
#define GENOME_LENGTH 256 /* 2^GENOME_ADDRESS_SIZE==GENOME_LENGTH */
#define WORLD_WIDTH 64
#define WORLD_HEIGHT 64
#define DO_MOVE 0
#define DO_MEET 1
#define GENE_INDEX_DISPLAY 2
#define GENE_INDEX_MOVE 3
#define GENE_INDEX_MEET 4
#define GENE_INDEX_MEET_WHO 5
#define GENE_INDEX_MEET_START 6
#define GENE_INDEX_MEET_LENGTH 7
#define CURSES_VISUALIZATION 1
#define CURSES_SOLID_COLORS 1
#define SLEEP_US 1 * 100000
struct meet_gene_t {
unsigned int address;
unsigned int length;
};
typedef struct meet_gene_t meet_gene_t;
struct display_gene_t {
unsigned int red;
unsigned int green;
unsigned int blue;
};
typedef struct display_gene_t display_gene_t;
struct position_t {
unsigned int x;
unsigned int y;
};
typedef struct position_t position_t;
struct relative_position_t {
int x;
int y;
};
typedef struct relative_position_t relative_position_t;
struct organism_t {
unsigned int *genome;
position_t position;
char face;
};
typedef struct organism_t organism_t;
struct world_t {
organism_t *organisms[WORLD_WIDTH][WORLD_HEIGHT];
};
typedef struct world_t world_t;
void destroy_organism(organism_t *organism);
void destroy_world(world_t *world);
char display_color(organism_t *organism);
unsigned int eight_from_eight(organism_t *organism, unsigned int uint_0,
unsigned int uint_1, unsigned int uint_2, unsigned int uint_3,
unsigned int uint_4, unsigned int uint_5, unsigned int uint_6,
unsigned int uint_7);
unsigned int gene_at_virtual_index(organism_t *organism,
unsigned int virtual_index);
unsigned int gene_start_address(organism_t *organism, unsigned int gene_index);
void iterate_organism(world_t *world, organism_t *organism);
void iterate_world(world_t *world);
void meet_organism(world_t *world, organism_t *organism);
void meet_organism_details(world_t *world, organism_t *organism_a,
organism_t *organism_b);
void move_organism(world_t *world, organism_t *organism);
organism_t *new_organism(unsigned int position_x, unsigned int position_y);
world_t *new_world();
organism_t *organism_at_virtual_coordinates(world_t *world, int virtual_x,
int virtual_y);
void parse_display_gene(organism_t *organism, unsigned int gene_start_address,
display_gene_t *display_gene);
void parse_meet_gene(organism_t *organism, unsigned int gene_start_address,
meet_gene_t *meet_gene);
unsigned int position_index_for_observe_location(world_t *world,
organism_t *organism, unsigned int observe_location);
relative_position_t relative_position_from_index(unsigned int index);
unsigned int random_unsigned_int(unsigned int range);
unsigned int unsigned_int_from_genome(organism_t *organism,
unsigned int gene_start_address, unsigned int gene_length);
unsigned int wrapped_index(int virtual_index, unsigned int range);
void destroy_organism(organism_t *organism)
{
free(organism->genome);
free(organism);
}
void destroy_world(world_t *world)
{
unsigned int each_x;
unsigned int each_y;
for (each_x = 0; each_x < WORLD_WIDTH; each_x++) {
for (each_y = 0; each_y < WORLD_HEIGHT; each_y++) {
destroy_organism(world->organisms[each_x][each_y]);
}
}
free(world);
}
char display_color(organism_t *organism)
{
unsigned int display_gene_start_address;
display_gene_t display_gene;
char c;
display_gene_start_address = gene_start_address(organism,
GENE_INDEX_DISPLAY);
parse_display_gene(organism, display_gene_start_address, &display_gene);
if ((display_gene.red > display_gene.blue)
&& (display_gene.red > display_gene.green)) {
c = 'r';
}
else if ((display_gene.green > display_gene.red)
&& (display_gene.green > display_gene.blue)) {
c = 'g';
}
else if ((display_gene.blue > display_gene.green)
&& (display_gene.blue > display_gene.red)) {
c = 'b';
}
else {
c = 'w';
}
return c;
}
unsigned int eight_from_eight(organism_t *organism, unsigned int uint_0,
unsigned int uint_1, unsigned int uint_2, unsigned int uint_3,
unsigned int uint_4, unsigned int uint_5, unsigned int uint_6,
unsigned int uint_7)
{
unsigned int cells[8][EFE_LENGTH];
unsigned int each_x;
unsigned int each_y;
unsigned int ca_in_0;
unsigned int ca_in_1;
unsigned int ca_in_2;
unsigned int ca_index_0;
unsigned int ca_index_1;
unsigned int ca_index_2;
unsigned int ca_out_address;
unsigned int ca_out;
unsigned int result;
unsigned int result_bit_0;
unsigned int result_bit_1;
unsigned int result_bit_2;
cells[0][0] = uint_0;
cells[1][0] = uint_1;
cells[2][0] = uint_2;
cells[3][0] = uint_3;
cells[4][0] = uint_4;
cells[5][0] = uint_5;
cells[6][0] = uint_6;
cells[7][0] = uint_7;
for (each_y = 1; each_y < EFE_LENGTH; each_y++) {
for (each_x = 0; each_x < 8; each_x++) {
ca_index_0 = wrapped_index(each_x - 1, 8);
ca_index_1 = each_x;
ca_index_2 = wrapped_index(each_x + 1, 8);
ca_in_0 = cells[ca_index_0][each_y - 1];
ca_in_1 = cells[ca_index_1][each_y - 1];
ca_in_2 = cells[ca_index_2][each_y - 1];
ca_out_address = (4 * ca_in_0) + (2 * ca_in_1) + ca_in_2;
ca_out = unsigned_int_from_genome(organism, ca_out_address, 1);
cells[each_x][each_y] = ca_out;
}
}
result_bit_0 = cells[0][EFE_LENGTH - 1];
result_bit_1 = cells[1][EFE_LENGTH - 1];
result_bit_2 = cells[2][EFE_LENGTH - 1];
result = (4 * result_bit_0) + (2 * result_bit_1) + result_bit_2;
return result;
}
unsigned int gene_at_virtual_index(organism_t *organism,
unsigned int virtual_index)
{
unsigned int actual_index;
actual_index = wrapped_index(virtual_index, GENOME_LENGTH);
return organism->genome[actual_index];
}
unsigned int gene_start_address(organism_t *organism, unsigned int gene_index)
{
unsigned int address_of_gene_header;
unsigned int start_address = 0;
unsigned int each_part_of_address;
unsigned int each_part_of_address_value = 1;
address_of_gene_header = GENOME_ADDRESS_SIZE * gene_index;
start_address = unsigned_int_from_genome(organism, address_of_gene_header,
GENOME_ADDRESS_SIZE);
return start_address;
}
void iterate_organism(world_t *world, organism_t *organism)
{
if (DO_MOVE) {
move_organism(world, organism);
}
if (DO_MEET) {
meet_organism(world, organism);
}
}
void iterate_world(world_t *world)
{
unsigned int each_x;
unsigned int each_y;
for (each_x = 0; each_x < WORLD_WIDTH; each_x++) {
for (each_y = 0; each_y < WORLD_HEIGHT; each_y++) {
iterate_organism(world, world->organisms[each_x][each_y]);
}
}
}
void meet_organism(world_t *world, organism_t *organism)
{
unsigned int exchange_position_index;
relative_position_t exchange_position_relative;
organism_t *organism_to_exchange_with;
exchange_position_index = position_index_for_observe_location(world,
organism, gene_start_address(organism, GENE_INDEX_MEET_WHO));
exchange_position_relative
= relative_position_from_index(exchange_position_index);
organism_to_exchange_with = organism_at_virtual_coordinates(world,
organism->position.x + exchange_position_relative.x,
organism->position.y + exchange_position_relative.y);
meet_organism_details(world, organism, organism_to_exchange_with);
}
void meet_organism_details(world_t *world, organism_t *organism_a,
organism_t *organism_b)
{
meet_gene_t meet_gene;
unsigned int meet_gene_start_address;
unsigned int each_gene;
unsigned int each_gene_virtual;
unsigned int temp_gene;
position_t temp_position;
meet_gene_start_address = gene_start_address(organism_a, GENE_INDEX_MEET);
parse_meet_gene(organism_a, meet_gene_start_address, &meet_gene);
for (each_gene = 0; each_gene < meet_gene.length; each_gene++) {
each_gene_virtual = wrapped_index(each_gene, GENOME_LENGTH);
organism_b->genome[each_gene_virtual]
= organism_a->genome[each_gene_virtual];
}
}
void move_organism(world_t *world, organism_t *organism)
{
unsigned int new_position_index;
relative_position_t new_position_relative;
organism_t *organism_to_switch_with;
unsigned int switch_to_x;
unsigned int switch_to_y;
new_position_index = position_index_for_observe_location(world, organism,
gene_start_address(organism, GENE_INDEX_MOVE));
new_position_relative = relative_position_from_index(new_position_index);
organism_to_switch_with = organism_at_virtual_coordinates(world,
organism->position.x + new_position_relative.x,
organism->position.y + new_position_relative.y);
switch_to_x = organism_to_switch_with->position.x;
switch_to_y = organism_to_switch_with->position.y;
world->organisms[switch_to_x][switch_to_y] = organism;
world->organisms[organism->position.x][organism->position.y]
= organism_to_switch_with;
/* this could be made cleaner...organisms don't necessarily have to know
their own position */
organism_to_switch_with->position.x = organism->position.x;
organism_to_switch_with->position.y = organism->position.y;
organism->position.x = switch_to_x;
organism->position.y = switch_to_y;
}
organism_t *new_organism(unsigned int position_x, unsigned int position_y)
{
organism_t *organism;
unsigned int gene;
organism = malloc(sizeof(organism_t));
organism->genome = malloc(sizeof(unsigned int) * GENOME_LENGTH);
organism->position.x = position_x;
organism->position.y = position_y;
organism->face = random_unsigned_int(6) + 42;
for (gene = 0; gene < GENOME_LENGTH; gene++) {
organism->genome[gene] = random_unsigned_int(2);
}
return organism;
}
world_t *new_world()
{
world_t *world;
unsigned int each_x;
unsigned int each_y;
world = malloc(sizeof(world_t));
for (each_x = 0; each_x < WORLD_WIDTH; each_x++) {
for (each_y = 0; each_y < WORLD_HEIGHT; each_y++) {
world->organisms[each_x][each_y] = new_organism(each_x, each_y);
}
}
return world;
}
organism_t *organism_at_virtual_coordinates(world_t *world, int virtual_x,
int virtual_y)
{
unsigned int real_x;
unsigned int real_y;
real_x = wrapped_index(virtual_x, WORLD_WIDTH);
real_y = wrapped_index(virtual_y, WORLD_HEIGHT);
return world->organisms[real_x][real_y];
}
void parse_display_gene(organism_t *organism, unsigned int gene_start_address,
display_gene_t *display_gene)
{
display_gene->red = unsigned_int_from_genome
(organism, gene_start_address + 0, 8);
display_gene->green = unsigned_int_from_genome
(organism, gene_start_address + 8, 8);
display_gene->blue = unsigned_int_from_genome
(organism, gene_start_address + 16, 8);
}
void parse_meet_gene(organism_t *organism, unsigned int gene_start_address,
meet_gene_t *meet_gene)
{
meet_gene->address = unsigned_int_from_genome
(organism, gene_start_address + 0, 8);
meet_gene->length = unsigned_int_from_genome
(organism, gene_start_address + 8, 8);
}
unsigned int position_index_for_observe_location(world_t *world,
organism_t *organism, unsigned int observe_location)
{
unsigned int observed_0;
unsigned int observed_1;
unsigned int observed_2;
unsigned int observed_3;
unsigned int observed_4;
unsigned int observed_5;
unsigned int observed_6;
unsigned int observed_7;
organism_t *organism_0;
organism_t *organism_1;
organism_t *organism_2;
organism_t *organism_3;
organism_t *organism_4;
organism_t *organism_5;
organism_t *organism_6;
organism_t *organism_7;
unsigned int new_position_index;
organism_0 = organism_at_virtual_coordinates(world,
organism->position.x - 1, organism->position.y - 1);
organism_1 = organism_at_virtual_coordinates(world,
organism->position.x + 0, organism->position.y - 1);
organism_2 = organism_at_virtual_coordinates(world,
organism->position.x + 1, organism->position.y - 1);
organism_3 = organism_at_virtual_coordinates(world,
organism->position.x + 1, organism->position.y + 0);
organism_4 = organism_at_virtual_coordinates(world,
organism->position.x + 1, organism->position.y + 1);
organism_5 = organism_at_virtual_coordinates(world,
organism->position.x + 0, organism->position.y + 1);
organism_6 = organism_at_virtual_coordinates(world,
organism->position.x - 1, organism->position.y + 1);
organism_7 = organism_at_virtual_coordinates(world,
organism->position.x - 1, organism->position.y + 0);
observed_0 = unsigned_int_from_genome(organism_0, observe_location, 1);
observed_1 = unsigned_int_from_genome(organism_1, observe_location, 1);
observed_2 = unsigned_int_from_genome(organism_2, observe_location, 1);
observed_3 = unsigned_int_from_genome(organism_3, observe_location, 1);
observed_4 = unsigned_int_from_genome(organism_4, observe_location, 1);
observed_5 = unsigned_int_from_genome(organism_5, observe_location, 1);
observed_6 = unsigned_int_from_genome(organism_6, observe_location, 1);
observed_7 = unsigned_int_from_genome(organism_7, observe_location, 1);
new_position_index = eight_from_eight(organism, observed_0, observed_1,
observed_2, observed_3, observed_4, observed_5, observed_6,
observed_7);
return new_position_index;
}
relative_position_t relative_position_from_index(unsigned int index)
{
relative_position_t position;
switch (index) {
case 0:
position.x = -1;
position.y = -1;
break;
case 1:
position.x = +0;
position.y = -1;
break;
case 2:
position.x = +1;
position.y = -1;
break;
case 3:
position.x = +1;
position.y = +0;
break;
case 4:
position.x = +1;
position.y = +1;
break;
case 5:
position.x = +0;
position.y = +1;
break;
case 6:
position.x = -1;
position.y = +1;
break;
case 7:
position.x = -1;
position.y = +0;
break;
}
return position;
}
unsigned int random_unsigned_int(unsigned int range)
{
return random() % range;
}
unsigned int unsigned_int_from_genome(organism_t *organism,
unsigned int gene_start_address, unsigned int gene_length)
{
unsigned int each_part_of_address;
unsigned int each_part_of_address_value = 1;
unsigned int r = 0;
unsigned int gene_end_address;
gene_end_address = gene_start_address + gene_length;
for (each_part_of_address = gene_start_address;
each_part_of_address < gene_end_address;
each_part_of_address++) {
r += each_part_of_address_value
* gene_at_virtual_index(organism, each_part_of_address);
each_part_of_address_value *= 2;
}
return r;
}
unsigned int wrapped_index(int virtual_index, unsigned int range)
{
unsigned int wrapped_index;
if (virtual_index >= (int) range) {
wrapped_index = virtual_index - range;
}
else if (virtual_index < 0) {
wrapped_index = range + virtual_index;
}
else {
wrapped_index = virtual_index;
}
return wrapped_index;
}
int main(int argc, char *argv[])
{
world_t *world;
unsigned int x;
unsigned int y;
char c;
char color;
srandom(RANDOM_SEED);
#if CURSES_VISUALIZATION
initscr();
start_color();
#if CURSES_SOLID_COLORS
init_pair(1, COLOR_BLACK, COLOR_RED);
init_pair(2, COLOR_BLACK, COLOR_GREEN);
init_pair(3, COLOR_BLACK, COLOR_BLUE);
init_pair(4, COLOR_BLACK, COLOR_WHITE);
init_pair(5, COLOR_BLACK, COLOR_BLACK);
#else
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_WHITE, COLOR_BLACK);
init_pair(5, COLOR_BLACK, COLOR_BLACK);
#endif
#endif
world = new_world();
while (1) {
#if CURSES_VISUALIZATION
for (x = 0; x < WORLD_WIDTH; x++) {
for (y = 0; y < WORLD_HEIGHT; y++) {
if (NULL == world->organisms[x][y]) {
color = 'x';
c = ' ';
}
else {
color = display_color(world->organisms[x][y]);
c = world->organisms[x][y]->face;
}
switch (color) {
case 'r':
mvaddch(y, x, c | COLOR_PAIR(1));
break;
case 'g':
mvaddch(y, x, c | COLOR_PAIR(2));
break;
case 'b':
mvaddch(y, x, c | COLOR_PAIR(3));
break;
case 'w':
mvaddch(y, x, c | COLOR_PAIR(4));
break;
default:
mvaddch(y, x, c | COLOR_PAIR(5));
break;
}
}
}
refresh();
usleep(SLEEP_US);
#endif
iterate_world(world);
}
#if CURSES_VISUALIZATION
endwin();
#endif
/* destroy_world(world); */
}
|
the_stack_data/36408.c | /*
* Copyright (c) 2016 - Qeo LLC
*
* The source code form of this Qeo Open Source Project component is subject
* to the terms of the Clear BSD license.
*
* You can redistribute it and/or modify it under the terms of the Clear BSD
* License (http://directory.fsf.org/wiki/License:ClearBSD). See LICENSE file
* for more details.
*
* The Qeo Open Source Project also includes third party Open Source Software.
* See LICENSE file for more details.
*/
/* ri_dtls.c -- RTPS over DTLS transports. */
#ifdef DDS_SECURITY
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#ifdef _WIN32
#include "win.h"
#define ERRNO WSAGetLastError()
#else
#include <unistd.h>
#include <errno.h>
#include <poll.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#define ERRNO errno
#endif
#include "sock.h"
#include "log.h"
#include "error.h"
#include "debug.h"
#include "openssl/bio.h"
#include "openssl/err.h"
#include "openssl/ssl.h"
#include "openssl/rand.h"
#include "security.h"
#ifdef DDS_NATIVE_SECURITY
#include "sec_data.h"
#endif
#include "rtps_ip.h"
#include "ri_data.h"
#include "ri_dtls.h"
#ifdef ANDROID
#include "sys/socket.h"
/* Type to represent a port. */
typedef uint16_t in_port_t;
#endif
#define DTLS_IDLE_CX_TIMEOUT 25 /* When this timer expires and there are
no messages received or sent (independently
counter), we assume that the connection
should come to an end. [sec]. */
#define COOKIE_SECRET_LENGTH 16
#define DTLS_MAX_RETRY_COUNT 2 /* # of retries we allow for DTLS timeouts */
/* #define NO_CERTIFICATE_TIME_VALIDITY_CHECK */
typedef enum {
DTLS_ROLE_ERR, /* Can't determine role -- error. */
DTLS_SERVER, /* Server side of the DTLS connection */
DTLS_CLIENT /* Client side of the DTLS connection */
} DTLS_CX_SIDE;
typedef enum {
DTLS_SERVER_RX, /* Server: wait for Client Hello. */
DTLS_ACCEPT, /* SData: Server Hello sent, wait on SSL_accept ().*/
DTLS_CONNECT, /* CData: Client Hello sent, wait on SSL_connect ().*/
DTLS_DATA /* SData/CData: active Data exchange. */
} DTLS_STATE;
typedef enum {
SSW_IDLE, /* Inactive, i.e. nothing to write. */
SSW_WWRITE, /* Wait until we can write (again). */
SSW_WREAD /* Wait until we can read. */
} SSW_STATE;
typedef enum {
TMR_NOT_RUNNING, /* Timer is not running */
TMR_DTLS_PROTOCOL, /* Timer is in use for handling DTLS protocol timeouts */
TMR_IDLE_CX /* Timer is counting messages to detect idle connections */
} TMR_STATE;
typedef enum {
SSR_IDLE, /* Inactive, i.e. no data ready for reading. */
SSR_WREAD, /* Wait until we can read again. */
SSR_WWRITE /* Wait until we can write. */
} SSR_STATE;
typedef struct {
SSL *ssl; /* SSL context. */
DTLS_STATE state; /* Current state. */
SSW_STATE wstate; /* Writer state. */
SSR_STATE rstate; /* Reader state. */
TMR_STATE tstate; /* Identify why the timer is currently running */
unsigned rcvd_msg_cnt; /* Number of received messages in last time window */
unsigned sent_msg_cnt; /* Number of sent messages in the last time window */
} DTLS_CX;
static SSL_CTX *dtls_server_ctx;
static SSL_CTX *dtls_client_ctx;
static int cookie_initialized;
static unsigned char cookie_secret [COOKIE_SECRET_LENGTH];
static in_port_t dtls_server_port; /* UDP port to use for our DTLS server(s) */
static IP_CX *dtls_v4_servers;
#ifdef DDS_IPV6
static IP_CX *dtls_v6_servers;
#endif
static IP_CX *dtls_pending_cx; /* list of connections attempts, not yet associated with their
respective server IP_CX. Note that this list is a mix of
IPv4 and IPv6 contexts. */
unsigned long dtls_rx_fd_count;
unsigned long dtls_server_fd_count;
int dtls_available = 1;
static char *dtls_cx_state_str [] = { /* See enum IP_CX_STATE */
"Closed", "Listen", "CAuth", "ConReq", "Connect", "WRetry", "SAuth", "Open"
};
/* Convert struct timeval * to Ticks_t. Result is rounded up with a single tick. */
#define TIMEVAL_TO_TICKS(tv) (((tv)->tv_sec) * TICKS_PER_SEC + (tv)->tv_usec / (1000 * TMR_UNIT_MS) + 1)
void rtps_dtls_init (void)
{
/* nada */
}
void rtps_dtls_finish (void)
{
/* nada */
}
/*#define LOG_DTLS_FSM ** Log DTLS usage details */
/*#define LOG_POLL_EVENTS ** Log poll events and state changes */
/*#define LOG_SSL_FSM ** Log SSL connection state changes */
/*#define LOG_CERT_CHAIN_DETAILS ** Log some details about the certificate when doing certificate verification */
/*#define LOG_CONNECTION_CHANGES ** Log any sort of changes in our own connections - can become very verbose */
/*#define LOG_SEARCH_CTX ** Log context searches, based on locators */
#ifdef LOG_DTLS_FSM
#define dtls_print(s) log_printf (RTPS_ID, 0, s)
#define dtls_print1(s,a) log_printf (RTPS_ID, 0, s,a)
#define dtls_print2(s,a1,a2) log_printf (RTPS_ID, 0, s,a1,a2)
#define dtls_print3(s,a1,a2,a3) log_printf (RTPS_ID, 0, s,a1,a2,a3)
#define dtls_print4(s,a1,a2,a3,a4) log_printf (RTPS_ID, 0, s,a1,a2,a3,a4)
#define dtls_fflush() log_flush (RTPS_ID, 0)
#else
#define dtls_print(s)
#define dtls_print1(s,a)
#define dtls_print2(s,a1,a2)
#define dtls_print3(s,a1,a2,a3)
#define dtls_print4(s,a1,a2,a3,a4)
#define dtls_fflush()
#endif
#ifdef LOG_SSL_FSM
static void rtps_dtls_info_callback (const SSL *ssl, int type, int val)
{
const char *str;
int w;
BIO *bio;
int fd;
bio = SSL_get_rbio (ssl);
fd = BIO_get_fd (bio, NULL);
w = type & ~SSL_ST_MASK;
if (w & SSL_ST_CONNECT)
str = "SSL_connect";
else if (w & SSL_ST_ACCEPT)
str = "SSL_accept";
else
str = "undefined";
if (type & SSL_CB_LOOP) {
log_printf (RTPS_ID, 0, "DTLS/SSL trace (fd %d): %s:%s\r\n", fd, str, SSL_state_string_long (ssl));
}
else if (type & SSL_CB_ALERT) {
str = (type & SSL_CB_READ) ? "read" : "write";
log_printf (RTPS_ID, 0, "DTLS/SSL trace (fd %d): alert %s:%s:%s\r\n", fd, str,
SSL_alert_type_string_long (val),
SSL_alert_desc_string_long (val));
}
else if (type & SSL_CB_EXIT) {
if (val == 0)
log_printf (RTPS_ID, 0, "DTLS/SSL trace (fd %d): %s:failed in %s\r\n", fd, str, SSL_state_string_long (ssl));
else if (val < 0)
log_printf (RTPS_ID, 0, "DTLS/SSL trace (fd %d): %s:error in %s\r\n", fd, str, SSL_state_string_long (ssl));
}
}
static void rtps_dtls_trace_openssl_fsm (SSL_CTX *ctx)
{
SSL_CTX_set_info_callback (ctx, rtps_dtls_info_callback);
}
#else
#define rtps_dtls_trace_openssl_fsm(ctx)
#endif
#ifdef LOG_POLL_EVENTS
static void dtls_dump_poll_events (int fd, short events)
{
log_printf (RTPS_ID, 0, "{ fd: %d -%s }\r\n", fd, dbg_poll_event_str (events));
}
#else
#define dtls_dump_poll_events(fd, events)
#endif
#ifdef LOG_CONNECTION_CHANGES
static void trace_connection_changes (void)
{
log_printf (RTPS_ID, 0, ">>>>>>>>>\r\n");
rtps_dtls_dump ();
log_printf (RTPS_ID, 0, "<<<<<<<<<\r\n");
}
#else
static void trace_connection_changes (void)
{
}
#endif
/* remove_from_ip_cx_list -- Remove target from headp list (connected through
'next' chain). */
static int remove_from_ip_cx_list (IP_CX **headp, IP_CX *target)
{
IP_CX *p, *pp;
if (!headp || !*headp)
return -1; /* empty list: nothing to do */
for (pp = NULL, p = *headp; p; pp = p, p = p->next) {
if (p == target)
break;
}
if (p) {
if (pp)
pp->next = p->next;
else
*headp = p->next;
p->next = NULL;
return 0;
}
return -1; /* not found */
}
static void rtps_dtls_dump_openssl_error_stack (const char *msg)
{
unsigned long err;
const char *file, *data;
int line, flags;
char buf[256];
log_printf (RTPS_ID, 0, "%s", msg);
while ((err = ERR_get_error_line_data (&file, &line, &data, &flags)))
log_printf (RTPS_ID, 0, " err %lu @ %s:%d -- %s\r\n", err, file, line,
ERR_error_string (err, buf));
}
static void rtps_dtls_shutdown_connection (IP_CX *cxp)
{
log_printf (RTPS_ID, 0, "DTLS(%u): Shutting down connection on [%d]\r\n", cxp->handle, cxp->fd);
rtps_dtls_cleanup_cx (cxp);
if (cxp->fd) {
sock_fd_remove_socket (cxp->fd);
close (cxp->fd);
}
if (cxp->handle) {
cxp->locator->locator.handle = 0;
#if 0
if (cxp->dst_loc) {
cxp->dst_loc->handle = 0;
cxp->dst_loc = NULL;
}
#endif
rtps_ip_free_handle (cxp->handle);
cxp->handle = 0;
}
if ((cxp->parent != cxp) && cxp->locator)
xfree (cxp->locator);
rtps_ip_free (cxp);
trace_connection_changes ();
}
static void rtps_dtls_timeout (uintptr_t arg);
static void rtps_dtls_start_idle_cx_timer (IP_CX *cxp)
{
DTLS_CX *dtls = cxp->sproto;
dtls_print2 ("DTLS-timer for h:%u fd:%d: start 'idle connection' timer\r\n", cxp->handle, cxp->fd);
dtls->rcvd_msg_cnt = dtls->sent_msg_cnt = 0;
dtls->tstate = TMR_IDLE_CX;
tmr_start (cxp->timer, DTLS_IDLE_CX_TIMEOUT * TICKS_PER_SEC, (uintptr_t) cxp, rtps_dtls_timeout);
}
static void rtps_dtls_start_protocol_timer (IP_CX *cxp)
{
DTLS_CX *dtls = cxp->sproto;
struct timeval to;
/*
* Note: we reuse (abuse?) dtls->rcvd_msg_cnt to count the number recurring DTLS timeouts. We
* do this to limit the overall timeout before a connection attempt timeout the DTLS-way, which is
* in the order of 10 minutes.
*/
if (DTLSv1_get_timeout (dtls->ssl, &to)) {
dtls_print2 ("DTLS-timer for h:%u fd:%d: start DTLS protocol timer\r\n", cxp->handle, cxp->fd);
tmr_start (cxp->timer, TIMEVAL_TO_TICKS (&to), (uintptr_t) cxp, rtps_dtls_timeout);
if (dtls->tstate == TMR_DTLS_PROTOCOL)
dtls->rcvd_msg_cnt++;
else {
dtls->tstate = TMR_DTLS_PROTOCOL;
dtls->rcvd_msg_cnt = 0;
}
}
}
static void rtps_dtls_timeout (uintptr_t arg)
{
IP_CX *cxp = (IP_CX *) arg;
DTLS_CX *dtls = cxp->sproto;
int error;
if (!dtls)
return;
dtls_print3 ("DTLS-timeout on h:%u fd:%d type %d\r\n", cxp->handle, cxp->fd, dtls->tstate);
switch (dtls->tstate) {
case TMR_IDLE_CX:
dtls_print2 (" #msgs rcvd = %u -- sent = %u\r\n", dtls->rcvd_msg_cnt, dtls->sent_msg_cnt);
if (dtls->rcvd_msg_cnt == 0) {
rtps_dtls_shutdown_connection (cxp);
/* !! do not access cxp anymore !! */
return;
}
else
rtps_dtls_start_idle_cx_timer (cxp);
break;
case TMR_DTLS_PROTOCOL:
dtls_print (" DTLS protocol timeout\r\n");
switch (DTLSv1_handle_timeout (dtls->ssl)) {
case 0:
dtls_print (" DTLS timer did not timeout (yet)\r\n");
rtps_dtls_start_protocol_timer (cxp);
break;
case 1:
if (dtls->rcvd_msg_cnt > DTLS_MAX_RETRY_COUNT) {
rtps_dtls_shutdown_connection (cxp);
return;
}
dtls_print (" DTLS timer handled\r\n");
rtps_dtls_start_protocol_timer (cxp);
break;
case -1:
default:
error = SSL_get_error (dtls->ssl, 0);
dtls_print1 (" DTLS_handle_timeout () failed - error = %d\r\n", error);
rtps_dtls_dump_openssl_error_stack ("Protocol timout error");
if (error != SSL_ERROR_NONE)
rtps_dtls_shutdown_connection (cxp);
/* !! do not access cxp anymore !! */
return;
}
break;
default:
dtls_print (" Unexpected timeout\r\n");
break;
}
}
/* rtps_dtls_socket -- Create a new socket and bind/connect it to the given
addresses. It is assumed that both addresses belong to
the same family. */
static int rtps_dtls_socket (struct sockaddr *bind_addr, struct sockaddr *connect_addr)
{
const int on = 1;
#ifdef DDS_IPV6
const int off = 0;
#endif
int fd;
socklen_t len;
fd = socket (bind_addr->sa_family, SOCK_DGRAM, 0);
if (fd < 0) {
perror ("rtps_dtls_socket (): socket () failure");
log_printf (RTPS_ID, 0, "rtps_dtls_socket: socket () failed - errno = %d.\r\n", ERRNO);
return (-1);
}
if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const char*) &on, (socklen_t) sizeof (on))) {
perror ("rtps_dtls_socket (): setsockopt () failure");
log_printf (RTPS_ID, 0, "setsockopt (REUSEADDR) failed - errno = %d.\r\n", ERRNO);
goto cleanup;
}
#ifndef WIN32
#ifdef SO_REUSEPORT
if (setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, (const void*) &on, (socklen_t) sizeof (on))) {
perror ("rtps_dtls_socket (): setsockopt () failure");
log_printf (RTPS_ID, 0, "setsockopt (REUSEPORT) failed - errno = %d.\r\n", ERRNO);
/* Don't cleanup if this fails. Some platforms don't support this
socket option. Example: raspberry pi arch linux kernel 3.6.11. */
/*goto cleanup;*/
}
#endif
#endif
len = sizeof (struct sockaddr_in);
#ifdef DDS_IPV6
if (bind_addr->sa_family == AF_INET6) {
if (setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &off, sizeof (off))) {
perror ("rtps_dtls_socket (): setsockopt () failure");
log_printf (RTPS_ID, 0, "setsockopt (IPV6_ONLY) failed - errno = %d.\r\n", ERRNO);
goto cleanup;
}
len = sizeof (struct sockaddr_in6);
}
#endif
if (bind (fd, bind_addr, len)) {
perror ("rtps_dtls_socket (): bind () failure");
log_printf (RTPS_ID, 0, "bind () failed - errno = %d.\r\n", ERRNO);
goto cleanup;
}
if (connect (fd, connect_addr, len)) {
perror ("rtps_dtls_socket (): connect () failure");
log_printf (RTPS_ID, 0, "connect () failed - errno = %d.\r\n", ERRNO);
goto cleanup;
}
return (fd);
cleanup:
close (fd);
return (-1);
}
static int set_socket_nonblocking (int fd)
{
int mode = fcntl (fd, F_GETFL, 0);
return ((mode != -1) ? fcntl (fd, F_SETFL, mode | O_NONBLOCK) : -1);
}
#ifdef DDS_IPV6
#define SA_LENGTH sizeof (struct sockaddr_in6)
#else
#define SA_LENGTH sizeof (struct sockaddr_in)
#endif
static void rtps_dtls_connect (IP_CX *cxp)
{
int error;
unsigned char sabuf [SA_LENGTH];
DTLS_CX *dtls = cxp->sproto;
int (*action) (SSL*);
char side;
if (dtls->state == DTLS_ACCEPT) {
action = SSL_accept;
side = 'S';
}
else if (dtls->state == DTLS_CONNECT) {
action = SSL_connect;
side = 'C';
} else
fatal_printf ("%s(): invalid value for dtls->state (%d)", __FUNCTION__, dtls->state);
dtls_print4 ("DTLS(%c) h:%u fd:%d %s() - Continue establishing the DTLS connection\r\n",
side, cxp->handle, cxp->fd, side == 'S' ? "SSL_accept" : "SSL_connect");
dtls_fflush ();
error = SSL_get_error (dtls->ssl, action (dtls->ssl));
rtps_dtls_start_protocol_timer (cxp);
switch (error) {
case SSL_ERROR_NONE:
if (accept_ssl_connection (dtls->ssl,
loc2sockaddr (
cxp->locator->locator.kind,
cxp->dst_port,
cxp->dst_addr,
sabuf),
cxp->id)
== DDS_AA_ACCEPTED) {
log_printf (RTPS_ID, 0, "DTLS.%c(%u): Connection accepted on [%d]!\r\n", side, cxp->handle, cxp->fd);
sock_fd_event_socket (cxp->fd, POLLOUT, 1); /* start sending enqueued data, if any */
dtls->state = DTLS_DATA;
cxp->cx_state = CXS_OPEN;
cxp->p_state = TDS_DATA;
trace_connection_changes ();
rtps_dtls_start_idle_cx_timer (cxp);
break;
}
log_printf (RTPS_ID, 0, "DTLS.%c(%u): Connection refused on [%d]!\r\n", side, cxp->handle, cxp->fd);
/* FALLTHRU */
case SSL_ERROR_ZERO_RETURN:
rtps_dtls_shutdown_connection (cxp);
break;
case SSL_ERROR_WANT_WRITE:
sock_fd_event_socket (cxp->fd, POLLOUT, 1);
break;
case SSL_ERROR_WANT_READ:
sock_fd_event_socket (cxp->fd, POLLOUT, 0);
break;
default:
log_printf (RTPS_ID, 0, "%s () error# %d\r\n", (side == 'S' ? "SSL_accept" : "SSL_connect"), error);
rtps_dtls_dump_openssl_error_stack (side == 'S' ? "DTLS(S): SSL_accept () error:" : "DTLS(C): SSL_connect () error:");
rtps_dtls_shutdown_connection (cxp);
break;
}
}
static void rtps_dtls_listen (IP_CX *cxp)
{
DTLS_CX *dtls = cxp->sproto;
unsigned char sabuf [SA_LENGTH];
int error;
dtls_print2 ("DTLS(S) h:%u fd:%d DTLSv1_listen()\r\n", cxp->handle, cxp->fd);
cxp->cx_state = CXS_LISTEN;
trace_connection_changes ();
error = SSL_get_error (dtls->ssl, DTLSv1_listen (dtls->ssl, (struct sockaddr *) sabuf));
rtps_dtls_start_protocol_timer (cxp);
switch (error) {
case SSL_ERROR_NONE:
dtls->state = DTLS_ACCEPT;
cxp->cx_state = CXS_CAUTH;
trace_connection_changes ();
/* This is an extra check to see if the handshake needs to be completed */
if (check_DTLS_handshake_initiator (loc2sockaddr (cxp->locator->locator.kind,
cxp->dst_port,
cxp->dst_addr,
sabuf),
cxp->id) == DDS_AA_ACCEPTED) {
/*
* We immediately try to process the second "Client Hello". Experiments showed that this
* avoid that we have to wait on a retransmit.
*/
rtps_dtls_connect (cxp);
break;
}
/* Validation failed, explicit fall-through to close connection. */
case SSL_ERROR_ZERO_RETURN:
rtps_dtls_shutdown_connection (cxp);
break;
case SSL_ERROR_WANT_WRITE:
sock_fd_event_socket (cxp->fd, POLLOUT, 1);
break;
case SSL_ERROR_WANT_READ:
sock_fd_event_socket (cxp->fd, POLLOUT, 0);
break;
default:
dtls_print2 ("%s () error# %d\r\n", __FUNCTION__, error);
rtps_dtls_dump_openssl_error_stack ("DTLSv1_listen ()");
rtps_dtls_shutdown_connection (cxp);
break;
}
}
/* rtps_dtls_send_msgs -- Attempt to send a single packet on a DTLS connection. */
static void rtps_dtls_send_msgs (IP_CX *cxp)
{
RMBUF *mp;
RME *mep;
RMREF *mrp;
DTLS_CX *dtls = (DTLS_CX *) cxp->sproto;
#ifdef MSG_TRACE
unsigned char *ap;
#endif
size_t len, n;
int error;
do {
dtls->wstate = SSW_IDLE;
/* Copy message to buffer. */
mrp = cxp->head;
if (!mrp) {
sock_fd_event_socket (cxp->fd, POLLOUT, 0);
return;
}
mp = mrp->message;
memcpy (rtps_tx_buf, &mp->header, sizeof (mp->header));
len = sizeof (mp->header);
for (mep = mp->first; mep; mep = mep->next) {
if ((mep->flags & RME_HEADER) != 0) {
n = sizeof (mep->header);
if (len + n > rtps_max_tx_size)
break;
memcpy (&rtps_tx_buf [len], &mep->header, n);
len += n;
}
if ((n = mep->length) != 0) {
if (len + n > rtps_max_tx_size)
break;
if (mep->data != mep->d && mep->db)
db_get_data (&rtps_tx_buf [len], mep->db, mep->data, 0, n - mep->pad);
else
memcpy (&rtps_tx_buf [len], mep->data, n - mep->pad);
len += n;
}
}
/* Transmit message. */
len = SSL_write (dtls->ssl, rtps_tx_buf, len);
error = SSL_get_error (dtls->ssl, len);
rtps_dtls_start_protocol_timer (cxp);
/* Check returned result. */
switch (error) {
case SSL_ERROR_NONE:
/* Write successful. */
#ifdef MSG_TRACE
if (cxp->trace || (mp->element.flags & RME_TRACE) != 0) {
ap = cxp->dst_addr;
if (cxp->locator->locator.kind == LOCATOR_KIND_UDPv4)
ap += 12;
rtps_ip_trace (cxp->handle, 'T',
&cxp->locator->locator,
ap, cxp->dst_port,
mp);
}
#endif
++dtls->sent_msg_cnt;
ADD_ULLONG (cxp->stats.octets_sent, (unsigned) len);
cxp->stats.packets_sent++;
cxp->head = mrp->next;
mrp->next = NULL;
rtps_unref_message (mrp);
break;
case SSL_ERROR_WANT_WRITE:
dtls->wstate = SSW_WWRITE;
sock_fd_event_socket (cxp->fd, POLLOUT, 1);
return;
case SSL_ERROR_WANT_READ:
dtls->wstate = SSW_WREAD;
sock_fd_event_socket (cxp->fd, POLLOUT, 0);
return;
case SSL_ERROR_ZERO_RETURN:
rtps_dtls_shutdown_connection (cxp);
return;
case SSL_ERROR_SSL:
default:
dtls_print2 ("SSL_write () error# %d fd %d\r\n", error, cxp->fd);
rtps_dtls_dump_openssl_error_stack ("SSL_write () error");
rtps_dtls_shutdown_connection (cxp);
/* cxp and dtls are freed now - do not access them anymore */
return;
}
}
while (cxp->head && dtls->wstate == SSW_IDLE);
if (!cxp->head)
sock_fd_event_socket (cxp->fd, POLLOUT, 0);
}
/* rtps_dtls_receive -- Attempt to receive packets from a DTLS connection. */
static void rtps_dtls_receive (IP_CX *cxp)
{
DTLS_CX *dtls = (DTLS_CX *) cxp->sproto;
ssize_t nread;
int error;
do {
dtls->rstate = SSR_IDLE;
nread = SSL_read (dtls->ssl, rtps_rx_buf, rtps_max_rx_size);
error = SSL_get_error (dtls->ssl, nread);
rtps_dtls_start_protocol_timer (cxp);
switch (error) {
case SSL_ERROR_NONE:
++dtls->rcvd_msg_cnt;
rtps_rx_buffer (cxp, cxp, rtps_rx_buf, nread);
break;
case SSL_ERROR_WANT_READ:
dtls->rstate = SSR_WREAD;
sock_fd_event_socket (cxp->fd, POLLOUT, 0);
break;
case SSL_ERROR_WANT_WRITE:
dtls->rstate = SSR_WWRITE;
sock_fd_event_socket (cxp->fd, POLLOUT, 1);
break;
case SSL_ERROR_ZERO_RETURN:
rtps_dtls_shutdown_connection (cxp);
return;
case SSL_ERROR_SSL:
default:
dtls_print2 ("SSL_read () error# %d fd %d\r\n", error, cxp->fd);
rtps_dtls_dump_openssl_error_stack ("SSL_read () error");
rtps_dtls_shutdown_connection (cxp);
/* cxp and dtls are freed now - do not access them anymore */
return;
}
}
while (SSL_pending (dtls->ssl) && dtls->rstate != SSR_WREAD);
}
/* rtps_dtls_complete_pending_cx -- Fill in the last details of a pending
connection. The end result is that pcxp is
removed from the list of pending connections
and added to the list of clients of a server
IP_CX. */
static void rtps_dtls_complete_pending_cx (IP_CX *pcxp, int fd)
{
IP_CX *scx;
char sa_buf [SA_LENGTH];
socklen_t sa_len = SA_LENGTH;
struct sockaddr *sap;
sap = (struct sockaddr *) sa_buf;
getsockname (fd, sap, &sa_len);
if (sap->sa_family == AF_INET) {
struct sockaddr_in *sa = (struct sockaddr_in *) sa_buf;
for (scx = dtls_v4_servers; scx; scx = scx->next) {
if (!memcmp(&scx->locator->locator.address [12], &sa->sin_addr, 4)
&& (scx->locator->locator.port == ntohs(sa->sin_port)))
break;
}
}
#ifdef DDS_IPV6
else if (sap->sa_family == AF_INET6) {
struct sockaddr_in6 *sa = (struct sockaddr_in6 *) sa_buf;
for (scx = dtls_v6_servers; scx; scx = scx->next) {
if (!memcmp(scx->locator->locator.address, &sa->sin6_addr, 16)
&& (scx->locator->locator.port == ntohs(sa->sin6_port)))
break;
}
}
#endif
else
scx = NULL;
if (!scx)
return;
memcpy (pcxp->locator->locator.address, scx->locator->locator.address, 16);
pcxp->parent = scx;
pcxp->id = scx->id;
/* remove pcxp from pending list !! */
if (remove_from_ip_cx_list (&dtls_pending_cx, pcxp)) {
dtls_print1 ("DTLS(%u): Failed to find back connection in list of pending connections\r\n", pcxp->handle);
}
pcxp->next = scx->clients;
scx->clients = pcxp;
}
/* rtps_dtls_rx_fd -- Function that should be called whenever the file
descriptor has DTLS receive data ready from a client. */
static void rtps_dtls_rx_fd (SOCKET fd, short revents, void *arg)
{
IP_CX *cxp = arg;
DTLS_CX *dtls = cxp->sproto;
ARG_NOT_USED (fd)
if (!dtls)
return;
dtls_dump_poll_events (fd, revents);
if (revents & (POLLERR | POLLNVAL | POLLHUP)) {
log_printf (RTPS_ID, 0, "DTLS: poll () returned error for [%d]. Connection closed.", fd);
rtps_dtls_shutdown_connection (cxp);
return;
}
dtls_rx_fd_count++;
if (!cxp->parent) {
rtps_dtls_complete_pending_cx (cxp, fd);
}
if (dtls->state == DTLS_SERVER_RX) {
rtps_dtls_listen (cxp);
}
else if (dtls->state == DTLS_ACCEPT || dtls->state == DTLS_CONNECT) {
rtps_dtls_connect (cxp);
}
else if (dtls->state == DTLS_DATA) {
/* In DATA state. */
if (((revents & POLLIN) != 0 && dtls->wstate != SSW_WREAD) ||
(dtls->rstate == SSR_WWRITE && (revents & POLLOUT) != 0)) {
rtps_dtls_receive (cxp);
}
else if (((revents & POLLOUT) != 0 && dtls->rstate != SSR_WWRITE) ||
(dtls->wstate == SSW_WREAD && (revents & POLLIN) != 0)) {
rtps_dtls_send_msgs (cxp);
}
#ifdef LOG_DTLS_FSM
else {
dtls_print ("DTLS: nothing to do!\r\n");
dtls_fflush ();
}
#endif
}
}
static int dtls_verify_callback (int ok, X509_STORE_CTX *store)
{
char data[256];
int depth;
X509 *cert;
depth = X509_STORE_CTX_get_error_depth (store);
cert = X509_STORE_CTX_get_current_cert (store);
#ifdef LOG_CERT_CHAIN_DETAILS
if (cert) {
X509_NAME_oneline (X509_get_subject_name (cert), data, sizeof (data));
log_printf (RTPS_ID, 0, "DTLS: depth %2i: subject = %s\r\n", depth, data);
X509_NAME_oneline (X509_get_issuer_name (cert), data, sizeof (data));
log_printf (RTPS_ID, 0, "DTLS: issuer = %s\r\n", data);
}
#endif
if (!ok) {
int err = X509_STORE_CTX_get_error (store);
if (cert)
X509_NAME_oneline (X509_get_subject_name (cert), data, sizeof (data));
else
strcpy (data, "<Unknown>");
err_printf ("err %i @ depth %i for issuer: %s\r\n\t%s\r\n", err, depth, data, X509_verify_cert_error_string (err));
#ifdef NO_CERTIFICATE_TIME_VALIDITY_CHECK
/* Exceptions */
if (err == X509_V_ERR_CERT_NOT_YET_VALID) {
#ifdef LOG_CERT_CHAIN_DETAILS
log_printf (SEC_ID, 0, "DTLS: Certificate verify callback. The certificate is not yet valid, but this is allowed. \r\n");
#endif
ok = 1;
}
if (err == X509_V_ERR_CERT_HAS_EXPIRED) {
ok = 1;
#ifdef LOG_CERT_CHAIN_DETAILS
log_printf (SEC_ID, 0, "DTLS: Certificate verify callback. The certificate has expired, but this is allowed. \r\n");
#endif
}
#endif
}
return (ok);
}
static int generate_cookie (SSL *ssl, unsigned char *cookie, unsigned *cookie_len)
{
unsigned char *buffer, result[EVP_MAX_MD_SIZE];
unsigned int length = 0, resultlength;
union {
struct sockaddr_storage ss;
struct sockaddr_in6 s6;
struct sockaddr_in s4;
} peer;
log_printf (RTPS_ID, 0, "dtls_generate_cookie () ...\r\n");
/* Initialize a random secret */
if (!cookie_initialized) {
if (!RAND_bytes (cookie_secret, COOKIE_SECRET_LENGTH)) {
fatal_printf ("error setting random cookie secret\n");
return (0);
}
cookie_initialized = 1;
}
/* Read peer information */
(void) BIO_dgram_get_peer (SSL_get_rbio (ssl), &peer);
/* Create buffer with peer's address and port */
length = 0;
switch (peer.ss.ss_family) {
case AF_INET:
length += sizeof (struct in_addr);
break;
case AF_INET6:
length += sizeof (struct in6_addr);
break;
default:
OPENSSL_assert (0);
break;
}
length += sizeof (in_port_t);
buffer = (unsigned char*) OPENSSL_malloc (length);
if (!buffer)
fatal_printf ("DDS: generate_cookie (): out of memory!");
switch (peer.ss.ss_family) {
case AF_INET:
memcpy (buffer, &peer.s4.sin_port, sizeof (in_port_t));
memcpy (buffer + sizeof (in_port_t), &peer.s4.sin_addr, sizeof (struct in_addr));
break;
case AF_INET6:
memcpy (buffer, &peer.s6.sin6_port, sizeof (in_port_t));
memcpy (buffer + sizeof (in_port_t), &peer.s6.sin6_addr, sizeof (struct in6_addr));
break;
default:
OPENSSL_assert (0);
break;
}
/* Calculate HMAC of buffer using the secret */
/*sign_with_private_key (NID_sha1, buffer, length,
&result [0], &resultlength, local_identity); */
HMAC (EVP_sha1 (),
(const void *) cookie_secret, COOKIE_SECRET_LENGTH,
(const unsigned char*) buffer, length,
result, &resultlength);
OPENSSL_free (buffer);
memcpy (cookie, result, resultlength);
*cookie_len = resultlength;
return (1);
}
static int verify_cookie (SSL *ssl, unsigned char *cookie, unsigned int cookie_len)
{
unsigned char *buffer, result[EVP_MAX_MD_SIZE];
unsigned int length = 0, resultlength;
union {
struct sockaddr_storage ss;
struct sockaddr_in6 s6;
struct sockaddr_in s4;
} peer;
log_printf (RTPS_ID, 0, "dtls_verify_cookie () ...\r\n");
/* If secret isn't initialized yet, the cookie can't be valid */
if (!cookie_initialized)
return (0);
/* Read peer information */
(void) BIO_dgram_get_peer (SSL_get_rbio (ssl), &peer);
/* Create buffer with peer's address and port */
length = 0;
switch (peer.ss.ss_family) {
case AF_INET:
length += sizeof (struct in_addr);
break;
case AF_INET6:
length += sizeof (struct in6_addr);
break;
default:
OPENSSL_assert (0);
break;
}
length += sizeof (in_port_t);
buffer = (unsigned char*) OPENSSL_malloc (length);
if (!buffer)
fatal_printf ("DDS: generate_cookie (): out of memory!");
switch (peer.ss.ss_family) {
case AF_INET:
memcpy (buffer, &peer.s4.sin_port, sizeof (in_port_t));
memcpy (buffer + sizeof (in_port_t), &peer.s4.sin_addr, sizeof (struct in_addr));
break;
case AF_INET6:
memcpy (buffer, &peer.s6.sin6_port, sizeof (in_port_t));
memcpy (buffer + sizeof (in_port_t), &peer.s6.sin6_addr, sizeof (struct in6_addr));
break;
default:
OPENSSL_assert (0);
break;
}
/* Calculate HMAC of buffer using the secret */
HMAC (EVP_sha1 (),
(const void*) cookie_secret, COOKIE_SECRET_LENGTH,
(const unsigned char*) buffer, length,
result, &resultlength);
OPENSSL_free (buffer);
if (cookie_len == resultlength && memcmp (result, cookie, resultlength) == 0)
return (1);
/* if (verify_signature (NID_sha1, buffer, length,
cookie, cookie_len, local_identity, ssl))
return (1); */
return (0);
}
#define DEPTH_CHECK 5
static SSL_CTX *rtps_dtls_create_dtls_ctx (DTLS_CX_SIDE purpose)
{
const SSL_METHOD *meth = NULL;
SSL_CTX *ctx;
X509 *cert;
#ifdef DDS_NATIVE_SECURITY
STACK_OF(X509) *ca_cert_list = NULL;
#else
X509 *ca_cert_list[10];
#endif
X509 *ca_cert_ptr = NULL;
int nbOfCA;
int j;
EVP_PKEY *privateKey;
/* load the certificates through the msecplug */
switch (purpose)
{
case DTLS_CLIENT:
meth = DTLSv1_client_method ();
break;
case DTLS_SERVER:
meth = DTLSv1_server_method ();
break;
default:
fatal_printf ("DTLS - %s () - invalid purpose for new SSL context", __FUNCTION__);
break;
}
if ((ctx = SSL_CTX_new (meth)) == NULL)
fatal_printf ("DTLS - %s () - Failed to create new SSL context", __FUNCTION__);
if (!SSL_CTX_set_cipher_list (ctx, "AES:!aNULL:!eNULL"))
fatal_printf ("DTLS %s (): failed to set cipher list", __FUNCTION__);
SSL_CTX_set_session_cache_mode (ctx, SSL_SESS_CACHE_OFF);
/* Put SSL_MODE_RELEASE_BUFFERS to decrease memory usage of DTLS
connections. */
SSL_CTX_set_mode (ctx, SSL_MODE_RELEASE_BUFFERS);
/* Using SSL_OP_NO_COMPRESSION should also decrease memory usage. */
SSL_CTX_set_options ( ctx, SSL_OP_NO_COMPRESSION);
get_certificate (&cert, local_identity);
if (!SSL_CTX_use_certificate (ctx, cert))
fatal_printf ("DTLS: no client cert found!");
/* for the client we have to add the client cert to the trusted ca certs */
if (purpose == DTLS_CLIENT) {
/* Add extra cert does not automatically up the reference */
SSL_CTX_add_extra_chain_cert (ctx, cert);
cert->references ++;
}
get_nb_of_CA_certificates (&nbOfCA, local_identity);
if (nbOfCA == 0)
fatal_printf("DTLS: Did not find any trusted CA certificates");
#ifdef DDS_NATIVE_SECURITY
get_CA_certificate_list (&ca_cert_list, local_identity);
#else
get_CA_certificate_list (&ca_cert_list[0], local_identity);
#endif
for (j = 0; j < nbOfCA ; j++) {
#ifdef DDS_NATIVE_SECURITY
ca_cert_ptr = sk_X509_value (ca_cert_list, j);
#else
ca_cert_ptr = ca_cert_list [j];
#endif
X509_STORE_add_cert (SSL_CTX_get_cert_store (ctx), ca_cert_ptr);
}
get_private_key (&privateKey, local_identity);
if (!SSL_CTX_use_PrivateKey (ctx, privateKey))
fatal_printf ("DTLS: no private key found!");
SSL_CTX_set_verify (ctx,
SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
dtls_verify_callback);
/*Check the private key*/
if (!SSL_CTX_check_private_key (ctx))
fatal_printf ("DTLS: invalid private key!");
SSL_CTX_set_verify_depth (ctx, DEPTH_CHECK);
SSL_CTX_set_read_ahead (ctx, 1);
if (purpose == DTLS_SERVER) {
SSL_CTX_set_cookie_generate_cb (ctx, generate_cookie);
SSL_CTX_set_cookie_verify_cb (ctx, verify_cookie);
}
rtps_dtls_trace_openssl_fsm (ctx);
#ifdef DDS_NATIVE_SECURITY
X509_free (cert);
sk_X509_pop_free (ca_cert_list, X509_free);
EVP_PKEY_free (privateKey);
#endif
return (ctx);
}
static void rtps_dtls_ctx_init (void)
{
log_printf (RTPS_ID, 0, "DTLS: Contexts initialized\r\n");
dds_ssl_init ();
dtls_server_ctx = rtps_dtls_create_dtls_ctx (DTLS_SERVER);
dtls_client_ctx = rtps_dtls_create_dtls_ctx (DTLS_CLIENT);
}
static void rtps_dtls_ctx_finish (void)
{
SSL_CTX_free (dtls_client_ctx);
SSL_CTX_free (dtls_server_ctx);
dtls_client_ctx = dtls_server_ctx = NULL;
dds_ssl_finish ();
log_printf (RTPS_ID, 0, "DTLS: Contexts freed\r\n");
}
#if 0
static void rtps_udp_remove_dtls_server (IP_CX *cxp)
{
dtls_print2 ("DTLS(%u): Removing DTLS.S on [%d].\r\n", cxp->handle, cxp->fd);
sock_fd_remove_socket (cxp->fd);
}
#endif
static DTLS_CX* rtps_dtls_new_dtls_cx (IP_CX *cxp, DTLS_CX_SIDE side)
{
DTLS_CX *dtls;
BIO *bio;
char sa_buf[SA_LENGTH];
socklen_t sa_len = SA_LENGTH;
dtls = xmalloc (sizeof (DTLS_CX));
if (!dtls) {
err_printf ("%s (): out of memory for DTLS context!", __FUNCTION__);
return (NULL);
}
if ((dtls->ssl = SSL_new ((side == DTLS_SERVER) ? dtls_server_ctx : dtls_client_ctx)) == NULL) {
err_printf ("%s (): failed to alloc SSL connection context", __FUNCTION__);
goto exit_failure;
}
if ((bio = BIO_new_dgram (cxp->fd, BIO_NOCLOSE)) == NULL) {
err_printf ("%s (): failed to alloc BIO", __FUNCTION__);
goto exit_failure2;
}
getpeername (cxp->fd, (struct sockaddr *) sa_buf, &sa_len);
(void) BIO_ctrl_set_connected (bio, 0, (struct sockaddr *) sa_buf);
SSL_set_bio (dtls->ssl, bio, bio);
dtls->state = (side == DTLS_SERVER ? DTLS_SERVER_RX : DTLS_CONNECT);
dtls->wstate = SSW_IDLE;
dtls->rstate = SSR_IDLE;
dtls->rcvd_msg_cnt = dtls->sent_msg_cnt = 0;
return (dtls);
exit_failure2:
SSL_free (dtls->ssl);
exit_failure:
xfree (dtls);
return (NULL);
}
/* rtps_dtls_new_ip_cx -- Allocate and prepare the context which represents a
connection locator: contains address/port of remote
party. */
static IP_CX *rtps_dtls_new_ip_cx (unsigned id, Locator_t *locator, DTLS_CX_SIDE side)
{
IP_CX *cxp;
struct sockaddr_in our_addr; /* Client IP address. */
struct sockaddr_in remote_addr; /* Server IP address. */
#ifdef DDS_IPV6
struct sockaddr_in6 our_addr_v6; /* Client IPv6 address. */
struct sockaddr_in6 remote_addr_v6; /* Server IPv6 address. */
char buf[128];
#endif
struct sockaddr *our_sa;
struct sockaddr *remote_sa;
cxp = rtps_ip_alloc ();
if (!cxp) {
err_printf ("%s (): out of IP connection contexts!", __FUNCTION__);
return (NULL);
}
cxp->locator = xmalloc (sizeof (LocatorNode_t));
if (!cxp->locator) {
err_printf ("%s (): out of memory for locator context!", __FUNCTION__);
goto nomem_loc;
}
/* Set our address parameters */
memset (cxp->locator, 0, sizeof (LocatorNode_t));
cxp->locator->users = 0;
cxp->locator->locator.kind = locator->kind;
/* cxp->locator->locator.address is implicitly kept at all zeroes, representing INADDR_ANY
* (or its IPv6 equivalent). It will be filled in as soon as the first message on this
* connection is received. */
cxp->locator->locator.port = dtls_server_port;
cxp->locator->locator.flags = LOCF_DATA | LOCF_META | LOCF_UCAST | LOCF_SECURE;
if (side == DTLS_SERVER)
cxp->locator->locator.flags |= LOCF_SERVER;
cxp->locator->locator.sproto = SECC_DTLS_UDP;
/* Set remote address parameters */
memcpy (cxp->dst_addr, locator->address, 16);
cxp->dst_port = locator->port;
cxp->has_dst_addr = 1;
cxp->associated = 1;
cxp->id = id;
cxp->cx_type = CXT_UDP_DTLS;
cxp->cx_mode = ICM_DATA;
cxp->cx_side = (side == DTLS_SERVER) ? ICS_SERVER : ICS_CLIENT;
cxp->cx_state = CXS_CLOSED;
cxp->p_state = TDS_WCXOK;
if ((cxp->timer = tmr_alloc ()) == NULL) {
err_printf ("%s (): out of memory for timer!", __FUNCTION__);
goto nomem_timer;
}
tmr_init (cxp->timer, (side == DTLS_SERVER) ? "DTLS.H" : "DTLS.C");
if (locator->kind == LOCATOR_KIND_UDPv4) {
/* Setup our socket address */
memset (&our_addr, 0, sizeof (our_addr));
our_addr.sin_family = AF_INET;
our_addr.sin_port = htons (dtls_server_port);
our_addr.sin_addr.s_addr = INADDR_ANY;
our_sa = (struct sockaddr *) &our_addr;
/* Setup remote socket address. */
memset (&remote_addr, 0, sizeof (remote_addr));
remote_addr.sin_family = AF_INET;
remote_addr.sin_port = htons (cxp->dst_port);
remote_addr.sin_addr.s_addr = ntohl ((cxp->dst_addr [12] << 24) |
(cxp->dst_addr [13] << 16) |
(cxp->dst_addr [14] << 8) |
cxp->dst_addr [15]);
remote_sa = (struct sockaddr *) &remote_addr;
}
#ifdef DDS_IPV6
else if (locator->kind == LOCATOR_KIND_UDPv6) {
/* Setup client socket address. */
memset (&our_addr_v6, 0, sizeof (our_addr_v6));
our_addr_v6.sin6_family = AF_INET6;
our_addr_v6.sin6_port = htons (dtls_server_port);
our_addr_v6.sin6_addr = in6addr_any;
our_sa = (struct sockaddr *) &our_addr_v6;
/* Setup server socket address. */
memset (&remote_addr_v6, 0, sizeof (remote_addr_v6));
remote_addr_v6.sin6_family = AF_INET6;
remote_addr_v6.sin6_port = htons (cxp->dst_port);
memcpy (&remote_addr_v6.sin6_addr, cxp->dst_addr, 16);
remote_sa = (struct sockaddr *) &remote_addr_v6;
log_printf (RTPS_ID, 0, "%s:%u)\r\n",
inet_ntop (AF_INET6, &cxp->dst_addr, buf, sizeof (buf)),
ntohs (cxp->dst_port));
}
#endif
else {
warn_printf ("%s (): unknown address family!", __FUNCTION__);
goto invalid_address_family;
}
cxp->fd = rtps_dtls_socket (our_sa, remote_sa);
if (cxp->fd < 0) {
goto no_socket;
}
if (set_socket_nonblocking (cxp->fd))
warn_printf ("%s (): can't set fd to non-blocking!", __FUNCTION__);
cxp->fd_owner = 1;
rtps_ip_new_handle (cxp);
cxp->locator->locator.handle = locator->handle = cxp->handle;
cxp->next = dtls_pending_cx;
dtls_pending_cx = cxp;
return (cxp);
no_socket:
invalid_address_family:
tmr_free (cxp->timer);
nomem_timer:
xfree (cxp->locator);
nomem_loc:
rtps_ip_free (cxp);
return (NULL);
}
/* locator_cmp -- Determine the 'smallest' locator, based on their address and
port. Return <0, ==0, >0 whether a < b, a == b, a > b
respectively. */
static int locator_cmp (Locator_t *a, Locator_t *b)
{
int r;
r = memcmp (a->address, b->address, sizeof (a->address));
if (!r)
r = a->port - b->port;
return (r);
}
/* dtls_locator -- Check if a locator is a secure DTLS locator. */
#define dtls_locator(lp) (((lp)->kind & (LOCATOR_KIND_UDPv4 | \
LOCATOR_KIND_UDPv6)) != 0 && \
((lp)->sproto & SECC_DTLS_UDP) != 0)
/* dtls_connection_role -- Uniquely determines whether we should play client or
server in the connection to the given peer locator.
We compare the order of our locator and their
locator to determine the role. */
static DTLS_CX_SIDE dtls_connection_role (Locator_t *lp, LocatorList_t *next)
{
IP_CX *scx;
LocatorRef_t *rp;
LocatorNode_t *np;
Locator_t *our_loc = NULL, *their_loc = NULL;
/* Determine their reference (ie 'smallest') locator. */
their_loc = lp;
if (lp->flags & LOCF_FCLIENT)
return (DTLS_CLIENT);
if (next)
foreach_locator (*next, rp, np) {
if (!dtls_locator (&np->locator))
break;
if (np->locator.flags & LOCF_FCLIENT)
return (DTLS_CLIENT);
if (locator_cmp (&np->locator, their_loc) < 0)
their_loc = &np->locator;
}
/* Determine our reference (ie 'smallest') locator. */
if (lp->kind == LOCATOR_KIND_UDPv4)
if (!dtls_v4_servers)
return (DTLS_ROLE_ERR);
else
scx = dtls_v4_servers;
#ifdef DDS_IPV6
else if (lp->kind == LOCATOR_KIND_UDPv6)
if (!dtls_v6_servers)
return (DTLS_ROLE_ERR);
else
scx = dtls_v6_servers;
#endif
else
return (DTLS_ROLE_ERR);
if (!scx)
return (DTLS_ROLE_ERR);
our_loc = &scx->locator->locator;
for (scx = scx->next; scx; scx = scx->next)
if (locator_cmp (&scx->locator->locator, our_loc) < 0)
our_loc = &scx->locator->locator;
return (locator_cmp (our_loc, their_loc) < 0 ? DTLS_SERVER : DTLS_CLIENT);
}
/* rtps_dtls_setup -- Setup connectivity with a new DTLS-based participant. */
static IP_CX *rtps_dtls_setup (unsigned id, Locator_t *locator, DTLS_CX_SIDE role)
{
IP_CX *cxp;
/*
* No matter what role we play in this connection attempt, in a next
* connection attempt, we will play the role of (DTLS) client. See
* dtls_connection_role ().
*/
locator->flags |= LOCF_FCLIENT;
cxp = rtps_dtls_new_ip_cx (id, locator, role);
if (!cxp)
return (NULL);
cxp->sproto = rtps_dtls_new_dtls_cx (cxp, role);
if (!cxp->sproto)
goto exit_failure;
sock_fd_add_socket (cxp->fd, POLLIN | POLLPRI | POLLOUT, rtps_dtls_rx_fd, cxp,
(role == DTLS_SERVER) ? "DDS.DTLS-S" : "DDS.DTLS-C");
rtps_dtls_start_idle_cx_timer (cxp);
log_printf (RTPS_ID, 0, "DTLS(%u): new connection on [%d] (%s) ",
cxp->handle, cxp->fd, role == DTLS_SERVER ? "server" : role == DTLS_CLIENT ? "client" : "<invalid>");
#ifdef DDS_DEBUG
log_printf (RTPS_ID, 0, "%s", locator_str (locator));
#endif
log_printf (RTPS_ID, 0, "\r\n");
trace_connection_changes ();
return (cxp);
exit_failure:
rtps_dtls_shutdown_connection (cxp);
return (NULL);
}
/* rtps_dtls_search_cx -- Search for an existing IP_CX, based on the given
locator. */
static IP_CX *rtps_dtls_search_cx (unsigned id, Locator_t *lp)
{
IP_CX *cxp = NULL;
#ifdef LOG_SEARCH_CTX
log_printf (RTPS_ID, 0, "DTLS: search ctx for locator ");
#ifdef DDS_DEBUG
log_printf (RTPS_ID, 0, "%s", locator_str (lp));
#endif
log_printf (RTPS_ID, 0, " (%u):\r\n\t", lp->handle);
#endif
#if 0
if (lp->handle) {
cxp = rtps_ip_from_handle (lp->handle);
#ifdef LOG_SEARCH_CTX
if (cxp)
log_printf (RTPS_ID, 0, "found via locator handle.");
#endif
}
#endif
if (!cxp && ((cxp = rtps_ip_lookup_peer (id, lp)) != NULL)) {
lp->handle = cxp->handle;
#ifdef LOG_SEARCH_CTX
log_printf (RTPS_ID, 0, "found via peer.");
}
else if (!cxp) {
log_printf (RTPS_ID, 0, "not found");
#endif
}
#ifdef LOG_SEARCH_CTX
log_printf (RTPS_ID, 0, "(%p)\r\n", (void *) cxp);
#endif
return (cxp); /* Note: can still be NULL! */
}
/* rtps_dtls_enqueue_msgs -- Enqueue msgs to a IP_CX. Returns 1 on success; 0
when no related IP_CX was found. */
static void rtps_dtls_enqueue_msgs (IP_CX *cxp, RMBUF *msgs)
{
RMREF *rp;
RMBUF *mp;
for (mp = msgs; mp; mp = mp->next) {
rp = rtps_ref_message (mp);
if (!rp)
return;
if (cxp->head)
cxp->tail->next = rp;
else
cxp->head = rp;
cxp->tail = rp;
}
}
/* rtps_dtls_server_rx_fd -- Function that attracts all traffic for which we do not (yet?)
have a dedicated socket available. A new context is
created as needed. */
static void rtps_dtls_server_rx_fd (SOCKET fd, short revents, void *arg)
{
char buf [256];
IP_CX *client_cxp, *cxp = (IP_CX *) arg;
Locator_t loc;
struct sockaddr_storage sa;
socklen_t sa_len = sizeof (sa);
ARG_NOT_USED (revents)
dtls_dump_poll_events (fd, revents);
dtls_server_fd_count++;
/*
* The message content will be ignored. The src address of the packet is used to setup
* a new connection. The DTLS retransmit mechanisms will make sure that subsequent
* messages will arrive at the new context.
*/
if (recvfrom (fd, buf, sizeof (buf), MSG_DONTWAIT, (struct sockaddr *)&sa, &sa_len) == -1)
return;
if (!sockaddr2loc (&loc, (struct sockaddr *) &sa))
return;
loc.handle = 0;
loc.flags = 0;
if ((client_cxp = rtps_dtls_search_cx (cxp->id, &loc)) != NULL) {
log_printf (RTPS_ID, 0, "DTLS(%u): ignoring message on [%d], state:%s\r\n",
client_cxp->handle, client_cxp->fd,
dtls_cx_state_str [client_cxp->cx_state]);
return; /* a subsequent message will be received by its true destination - ignore this one */
}
log_printf (RTPS_ID, 0, "DTLS: Creating new DTLS.H from server socket [%d]\r\n", fd);
rtps_dtls_setup (cxp->id, &loc, DTLS_SERVER);
return;
}
static void rtps_udp_add_dtls_server (IP_CX *cxp)
{
if (!dtls_client_ctx)
rtps_dtls_ctx_init ();
if (set_socket_nonblocking (cxp->fd))
warn_printf ("rtps_udp_add_dtls_server: can't set non-blocking!");
sock_fd_add_socket (cxp->fd, POLLIN | POLLPRI, rtps_dtls_server_rx_fd, cxp, "DDS.DTLS-S");
log_printf (RTPS_ID, 0, "DTLS: Server started on [%d].\r\n", cxp->fd);
}
/* rtps_dtls_send -- Send messages to the given set of secure locators. */
void rtps_dtls_send (unsigned id, Locator_t *lp, LocatorList_t *listp, RMBUF *msgs)
{
IP_CX *ucp;
DTLS_CX *dtls;
DTLS_CX_SIDE role; /* Role if we need a new connection(s) */
/* Get the connection role, i.e. whether we are client or server. */
if ((lp->flags & LOCF_FCLIENT) != 0)
role = DTLS_CLIENT;
else {
role = dtls_connection_role (lp, listp);
if (role == DTLS_ROLE_ERR) {
log_printf (RTPS_ID, 0, "DTLS: Could not determine role -- message dropped!\r\n");
rtps_free_messages (msgs);
return;
}
}
/* Send all messages to each destination locator. */
for (;;) {
ucp = rtps_dtls_search_cx (id, lp);
if (!ucp)
ucp = rtps_dtls_setup (id, lp, role);
if (ucp) {
/* Enqueue messages into context. */
rtps_dtls_enqueue_msgs (ucp, msgs);
/* Try to send messages immediately if ready. */
dtls = ucp->sproto;
if (dtls &&
dtls->state == DTLS_DATA &&
dtls->wstate == SSW_IDLE)
rtps_dtls_send_msgs (ucp);
}
/* If multiple destination locators, take the next one. */
if (listp && *listp) {
lp = &(*listp)->data->locator;
if (!dtls_locator (lp))
break;
*listp = (*listp)->next;
}
else
break;
}
}
void rtps_dtls_attach_server (IP_CX *cxp)
{
locator_lock (&cxp->locator->locator);
cxp->locator->locator.flags |= LOCF_SERVER;
locator_release (&cxp->locator->locator);
cxp->cx_type = CXT_UDP_DTLS;
cxp->cx_mode = ICM_ROOT;
cxp->cx_side = ICS_SERVER;
cxp->cx_state = CXS_CLOSED;
cxp->p_state = TDS_WCXOK;
trace_connection_changes ();
rtps_udp_add_dtls_server (cxp);
cxp->parent = cxp; /* parent pointing to itself means we're dealing with a DTLS.S */
if (cxp->locator->locator.kind == LOCATOR_KIND_UDPv4) {
cxp->next = dtls_v4_servers;
dtls_v4_servers = cxp;
}
#ifdef DDS_IPV6
else if (cxp->locator->locator.kind == LOCATOR_KIND_UDPv6) {
cxp->next = dtls_v6_servers;
dtls_v6_servers = cxp;
}
#endif
if (dtls_server_port != cxp->locator->locator.port) {
log_printf (RTPS_ID, 0, "DTLS: Changing server port from %d to %d\r\n", dtls_server_port, cxp->locator->locator.port);
dtls_server_port = cxp->locator->locator.port;
}
}
void rtps_dtls_detach_server (IP_CX *cxp)
{
ARG_NOT_USED (cxp);
/* TODO - inverse of rtps_dtls_attach_server () above
* 1- close all client connections
* 2- remove dtls server from list of servers
* 3- set locator to non-secure
* 4- ....
*/
}
void rtps_dtls_cleanup_cx (IP_CX *cxp)
{
DTLS_CX *dtls = cxp->sproto;
IP_CX *scx, **sl;
scx = cxp->parent;
if (scx == cxp) { /* DTLS.S : cleanup all connections derived from or linked to this connection */
sl = &dtls_v4_servers;
#ifdef DDS_IPV6
if (cxp->locator->locator.kind == LOCATOR_KIND_UDPv6)
sl = &dtls_v6_servers;
#endif
log_printf (RTPS_ID, 0, "DTLS(%u): cleaning up server on [%d]\r\n", cxp->handle, cxp->fd);
if (remove_from_ip_cx_list (sl, scx))
log_printf (RTPS_ID, 0, "%s(): could not find dtls server %p in list of dtls servers\r\n", __FUNCTION__, (void *) cxp);
while (scx->clients)
rtps_dtls_shutdown_connection (scx->clients);
return;
}
else if (scx) { /* DTLS.{C,H} : remove this connection from the list of sibling connections */
log_printf (RTPS_ID, 0, "DTLS(%u): cleaning up connection on [%d]\r\n", cxp->handle, cxp->fd);
if (remove_from_ip_cx_list (&scx->clients, cxp)) {
dtls_print ("DTLS: Failed to find back connection in list of sibling connections\r\n");
}
}
else { /* DTLS.{C,H}: remove this connection from list of pending connections */
log_printf (RTPS_ID, 0, "DTLS(%u): cleaning up pending connection on [%d]\r\n", cxp->handle, cxp->fd);
if (remove_from_ip_cx_list (&dtls_pending_cx, cxp)) {
dtls_print ("DTLS: Failed to find back connection in list of pending connections\r\n");
}
}
/*
* Be nice to the other side and shutdown the DTLS connection over the wire.
* However, we do not care whether we successfully sent the "close notify"
* over the wire. In the end, the other side will see that we are not sending
* them any messages anymore and it will close its side of the connection in
* a similar fashion.
*/
if (dtls) {
int error;
socklen_t err_len = sizeof (error);
if (getsockopt (cxp->fd, SOL_SOCKET, SO_ERROR, &error, &err_len) && (error != 0)) {
dtls_print2 ("DTLS(%u): Not sending shutdown on [%d] because socket is in error state.\r\n", cxp->handle, cxp->fd);
}
else {
dtls_print2 ("DTLS(%u): Sending shutdown on [%d].\r\n", cxp->handle, cxp->fd);
SSL_shutdown (dtls->ssl);
}
SSL_free (dtls->ssl); /* this also frees the used BIO */
xfree (dtls);
}
/* Free all pending messages */
rtps_unref_messages (cxp->head);
cxp->head = cxp->tail = NULL;
if (cxp->timer) {
tmr_stop (cxp->timer);
tmr_free (cxp->timer);
}
}
void rtps_dtls_final (void)
{
while (dtls_pending_cx)
rtps_dtls_shutdown_connection (dtls_pending_cx);
while (dtls_v4_servers)
rtps_dtls_shutdown_connection (dtls_v4_servers);
#ifdef DDS_IPV6
while (dtls_v6_servers)
rtps_dtls_shutdown_connection (dtls_v6_servers);
#endif
rtps_dtls_ctx_finish ();
}
/*
* Dumping data and statistics related to our DTLS servers and connections
*/
static void rtps_dtls_dump_cx_list (IP_CX *head)
{
IP_CX *cxp;
Locator_t loc;
const char *buf;
loc.sproto = SECC_DTLS_UDP;
if (head)
for (cxp = head; cxp; cxp = cxp->next) {
loc.kind = cxp->locator->locator.kind;
loc.port = cxp->dst_port;
loc.flags = LOCF_SECURE | ((cxp->cx_side == ICS_SERVER) ? LOCF_SERVER : 0);
memcpy (loc.address, cxp->dst_addr, sizeof (loc.address));
buf = locator_str (&loc);
log_printf (RTPS_ID, 0, "\tDTLS.%c(%u) to %s [%d] state: %s p:%p\r\n",
(cxp->cx_side == ICS_SERVER) ? 'H' : 'C',
cxp->handle,
buf,
cxp->fd,
dtls_cx_state_str [cxp->cx_state],
(void *) cxp);
}
else
log_printf (RTPS_ID, 0, "\t<No connections>\r\n");
}
static void rtps_dtls_dump_sx_list (IP_CX *head)
{
IP_CX *sxp;
const char *buf;
if (head)
for (sxp = head; sxp; sxp = sxp->next) {
buf = locator_str (&sxp->locator->locator);
log_printf (RTPS_ID, 0, " DTLS.S(%u) %s [%d] p:%p\r\n", sxp->handle, buf, sxp->fd, (void *) sxp);
rtps_dtls_dump_cx_list (sxp->clients);
}
else
log_printf (RTPS_ID, 0, " <None>\r\n");
}
void rtps_dtls_dump (void)
{
dbg_printf ("DTLS connection attempts:\r\n");
rtps_dtls_dump_cx_list (dtls_pending_cx);
dbg_printf ("DTLS v4 Servers:\r\n");
rtps_dtls_dump_sx_list (dtls_v4_servers);
#ifdef DDS_IPV6
dbg_printf ("DTLS v6 Servers:\r\n");
rtps_dtls_dump_sx_list (dtls_v6_servers);
#endif
}
#else
int dtls_available = 0;
#endif
|
the_stack_data/118577.c | #include <stdio.h>
#include <stdlib.h>
int powShort(int m, int n){
if(n==0){
return 1;
}
if(n%2==0){
return powShort(m*m, n/2);
}
else
{
return m*powShort(m*m, (n-1)/2);
}
}
int main(){
printf("%d", powShort(2, 9));
}
|
the_stack_data/37780.c | // ==========================================================================
//
// empty project
//
// (c) Wouter van Ooijen ([email protected]) 2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// ==========================================================================
int main( void ){} |
the_stack_data/923298.c | #include <stdio.h>
#define DIM 4
void add();
int main()
{
int a[DIM] = {2, 4, 5, 8};
int b[DIM] = {1, 0, 4, 6};
int c[DIM];
for (int i = 0; i < DIM; i++)
{
printf("%d ", a[i]);
}
printf("\n\n"); // Вывод первого массива
for (int i = 0; i < DIM; i++)
{
printf("%d ", b[i]);
}
printf("\n\n"); // Вывод второго массива
add(a, b, c, DIM); // Вызов функции
for (int i = 0; i < DIM; i++)
{
printf("%d ", c[i]);
}
printf("\n"); // Вывод нового массива
return 0;
}
void add(int a[], int b[], int c[], int dim)
{
for (int i = 0; i < DIM; i++)
{
c[i] = a[i] + b[i];
}
} |
the_stack_data/140764582.c | void one_argument();
void calls() {
one_argument(1); // GOOD: `one_argument` will accept and use the argument
one_argument(); // BAD: `one_argument` will receive an undefined value
}
void one_argument(int x);
|
the_stack_data/29544.c |
/* text version of maze 'mazefiles/binary/minos08f.maz'
generated by mazetool (c) Peter Harrison 2018
o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o
| | | | |
o---o o o---o o o o o---o o---o---o---o---o o o
| | | | | | | | | |
o---o---o o o o---o o---o o---o o o o---o o o
| | | | | | |
o o o o o---o o---o o---o o---o o o---o---o o
| | | | | | | | |
o o o---o o o---o o---o o---o---o o---o o---o o
| | | | | | |
o o---o o---o o o---o---o---o---o---o o o---o o o
| | | | | |
o o o---o o o---o---o o o---o---o o o---o---o o
| | | | | | | |
o o---o o o---o o o---o---o---o o o o---o---o---o
| | | | | | | | | |
o o o---o o o---o o o o o o o o---o o o
| | | | | | | | |
o o---o o---o---o o o---o---o---o o---o o---o o o
| | | | | | | | |
o o o o---o o---o---o o o---o---o o o---o---o o
| | | | | |
o o---o---o---o o---o o---o---o o o o---o---o---o o
| | | | | |
o o---o---o---o o---o---o---o o---o o---o o---o o o
| | | | | |
o o---o---o---o o---o---o---o o o---o---o o o o o
| | | | | | | | |
o o o o o---o o---o---o---o o---o o---o o o o
| | | | | | |
o o o o o---o---o---o---o---o o---o o---o o---o---o
| | | | | | | |
o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o
*/
int minos08f_maz[] ={
0x0E, 0x0A, 0x08, 0x08, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x08, 0x0A, 0x09, 0x0D, 0x0D,
0x0E, 0x08, 0x03, 0x05, 0x0D, 0x0C, 0x0B, 0x0C, 0x09, 0x0C, 0x09, 0x06, 0x0A, 0x01, 0x06, 0x01,
0x0E, 0x02, 0x0B, 0x05, 0x05, 0x06, 0x0A, 0x01, 0x06, 0x01, 0x06, 0x09, 0x0C, 0x02, 0x08, 0x01,
0x0C, 0x08, 0x0B, 0x05, 0x05, 0x0D, 0x0D, 0x06, 0x08, 0x02, 0x09, 0x06, 0x02, 0x08, 0x03, 0x05,
0x05, 0x05, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x01, 0x0C, 0x02, 0x08, 0x0B, 0x04, 0x0A, 0x01,
0x05, 0x04, 0x01, 0x05, 0x05, 0x05, 0x0C, 0x03, 0x06, 0x01, 0x0C, 0x01, 0x0E, 0x01, 0x0C, 0x03,
0x05, 0x07, 0x05, 0x05, 0x04, 0x03, 0x04, 0x0A, 0x08, 0x01, 0x05, 0x04, 0x09, 0x06, 0x02, 0x09,
0x05, 0x0D, 0x05, 0x05, 0x05, 0x0C, 0x03, 0x0C, 0x01, 0x06, 0x01, 0x05, 0x06, 0x09, 0x0C, 0x01,
0x07, 0x05, 0x06, 0x00, 0x03, 0x04, 0x09, 0x04, 0x03, 0x0E, 0x01, 0x06, 0x09, 0x06, 0x01, 0x07,
0x0E, 0x00, 0x08, 0x03, 0x0E, 0x01, 0x05, 0x06, 0x09, 0x0D, 0x05, 0x0D, 0x04, 0x09, 0x06, 0x09,
0x0F, 0x05, 0x05, 0x0C, 0x0A, 0x03, 0x04, 0x0A, 0x02, 0x03, 0x05, 0x05, 0x07, 0x04, 0x0B, 0x05,
0x0C, 0x00, 0x03, 0x05, 0x0C, 0x08, 0x03, 0x0C, 0x0A, 0x0A, 0x00, 0x02, 0x08, 0x02, 0x0B, 0x05,
0x05, 0x05, 0x0E, 0x02, 0x01, 0x04, 0x08, 0x00, 0x0A, 0x08, 0x00, 0x09, 0x04, 0x0A, 0x09, 0x05,
0x04, 0x02, 0x08, 0x0B, 0x05, 0x05, 0x05, 0x07, 0x0D, 0x05, 0x05, 0x04, 0x01, 0x0D, 0x05, 0x05,
0x05, 0x0E, 0x02, 0x0A, 0x01, 0x05, 0x06, 0x08, 0x03, 0x05, 0x06, 0x03, 0x05, 0x04, 0x02, 0x03,
0x07, 0x0E, 0x0A, 0x0A, 0x02, 0x02, 0x0A, 0x02, 0x0B, 0x06, 0x0A, 0x0A, 0x02, 0x02, 0x0A, 0x0B,
};
/* end of mazefile */
|
the_stack_data/145454250.c | unsigned char __500hz_16_wav[] = {
0x52, 0x49, 0x46, 0x46, 0x36, 0x2b, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45,
0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x11, 0x2b, 0x00, 0x00, 0x22, 0x56, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00,
0x64, 0x61, 0x74, 0x61, 0x12, 0x2b, 0x00, 0x00, 0xc0, 0x03, 0x5c, 0x23,
0x64, 0x45, 0x54, 0x60, 0x7f, 0x74, 0x73, 0x7e, 0xef, 0x7e, 0x83, 0x74,
0x50, 0x61, 0xb1, 0x45, 0xfa, 0x24, 0xcc, 0x00, 0xfe, 0xdc, 0x9d, 0xbb,
0x1b, 0xa0, 0x05, 0x8c, 0x8f,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0x92, 0x12, 0x84, 0x11, 0x80, 0x62, 0x86,
0x80, 0x96, 0x21, 0xaf, 0x48, 0xce, 0x70, 0xf1, 0xc6, 0x15, 0x5b, 0x38,
0x62, 0x56, 0x75, 0x6d, 0xb2, 0x7b, 0xf5, 0x7f, 0xe7, 0x79, 0x02, 0x6a,
0x92, 0x51, 0x8e, 0x32, 0x75, 0x0f, 0x1e, 0xeb, 0x76, 0xc8, 0x49, 0xaa,
0x05, 0x93, 0x8b, 0x84, 0x04, 0x80, 0xd3, 0x85, 0x79, 0x95, 0xb9, 0xad,
0x9b, 0xcc, 0xa1, 0xef, 0xfa, 0x13, 0xb6, 0x36, 0x09, 0x55, 0x7f, 0x6c,
0x36, 0x7b, 0xfe, 0x7f, 0x72, 0x7a, 0x06, 0x6b, 0xf9, 0x52, 0x3a, 0x34,
0x45, 0x11, 0xeb, 0xec, 0x1d, 0xca, 0xa6, 0xab, 0xfc, 0x93, 0x09, 0x85,
0x01, 0x80, 0x4a, 0x85, 0x7b, 0x94, 0x55, 0xac, 0xf0, 0xca, 0xd2, 0xed,
0x2c, 0x12, 0x0f, 0x35, 0xaa, 0x53, 0x85, 0x6b, 0xb5, 0x7a, 0xff, 0x7f,
0xf6, 0x7a, 0x03, 0x6c, 0x5a, 0x54, 0xe3, 0x35, 0x14, 0x13, 0xb9, 0xee,
0xc6, 0xcb, 0x07, 0xad, 0xfa, 0x94, 0x8e, 0x85, 0x02, 0x80, 0xc9, 0x84,
0x7f, 0x93, 0xf6, 0xaa, 0x49, 0xc9, 0x05, 0xec, 0x5e, 0x10, 0x64, 0x33,
0x46, 0x52, 0x85, 0x6a, 0x2d, 0x7a, 0xfa, 0x7f, 0x75, 0x7b, 0xfb, 0x6c,
0xb7, 0x55, 0x89, 0x37, 0xe1, 0x14, 0x88, 0xf0, 0x71, 0xcd, 0x6c, 0xae,
0xfc, 0x95, 0x18, 0x86, 0x0a, 0x80, 0x4e, 0x84, 0x8b, 0x92, 0x9c, 0xa9,
0xa4,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a, 0x05, 0x93, 0x8a, 0x84, 0x05, 0x80,
0xd2, 0x85, 0x79, 0x95, 0xb8, 0xad, 0x9a, 0xcc, 0xa1, 0xef, 0xfa, 0x13,
0xb6, 0x36, 0x09, 0x55, 0x7f, 0x6c, 0x37, 0x7b, 0xfd, 0x7f, 0x71, 0x7a,
0x06, 0x6b, 0xf8, 0x52, 0x3a, 0x34, 0x45, 0x11, 0xeb, 0xec, 0x1d, 0xca,
0xa6, 0xab, 0xfd, 0x93, 0x09, 0x85, 0x00, 0x80, 0x4a, 0x85, 0x7a, 0x94,
0x55, 0xac, 0xf0, 0xca, 0xd3, 0xed, 0x2c, 0x12, 0x0f, 0x35, 0xa9, 0x53,
0x86, 0x6b, 0xb5, 0x7a, 0xff, 0x7f, 0xf5, 0x7a, 0x03, 0x6c, 0x59, 0x54,
0xe3, 0x35, 0x14, 0x13, 0xba, 0xee, 0xc5, 0xcb, 0x07, 0xad, 0xf9, 0x94,
0x8f, 0x85, 0x02, 0x80, 0xc8, 0x84, 0x80, 0x93, 0xf7, 0xaa, 0x49, 0xc9,
0x05, 0xec, 0x5e, 0x10, 0x64, 0x33, 0x46, 0x52, 0x86, 0x6a, 0x2d, 0x7a,
0xfa, 0x7f, 0x74, 0x7b, 0xfa, 0x6c, 0xb7, 0x55, 0x89, 0x37, 0xe1, 0x14,
0x89, 0xf0, 0x70, 0xcd, 0x6c, 0xae, 0xfc, 0x95, 0x19, 0x86, 0x0a, 0x80,
0x4d, 0x84, 0x8a, 0x92, 0x9c, 0xa9, 0xa4, 0xc7, 0x38, 0xea, 0x8e, 0x0e,
0xb7, 0x31, 0xde, 0x50, 0x7f, 0x69, 0x9e, 0x79, 0xee, 0x7f, 0xec, 0x7b,
0xec, 0x6d, 0x10, 0x57, 0x2c, 0x39, 0xac, 0x16, 0x59, 0xf2, 0x1f, 0xcf,
0xd6, 0xaf, 0x04, 0x97, 0xaa, 0x86, 0x1a, 0x80, 0xd8, 0x83, 0x9b, 0x91,
0x45, 0x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bd, 0x78,
0xed, 0x67, 0xbb, 0x4e, 0x2f, 0x2f, 0xd5, 0x0b, 0x88, 0xe7, 0x33, 0xc5,
0x9c, 0xa7, 0x26, 0x91, 0xa1, 0x83, 0x22, 0x80, 0xf6, 0x86, 0x8b, 0x97,
0x8e, 0xb0, 0xf6, 0xcf, 0x41, 0xf3, 0x92, 0x17, 0xfc, 0x39, 0xba, 0x57,
0x64, 0x6e, 0x26, 0x7c, 0xe6, 0x7f, 0x55, 0x79, 0xfb, 0x68, 0x28, 0x50,
0xe0, 0x30, 0xa6, 0x0d, 0x53, 0xe9, 0xd2, 0xc6, 0xf0, 0xa8, 0x13, 0x92,
0x13, 0x84, 0x10, 0x80, 0x61, 0x86, 0x80, 0x96, 0x22, 0xaf, 0x48, 0xce,
0x71, 0xf1, 0xc7, 0x15, 0x5b, 0x38, 0x63, 0x56, 0x73, 0x6d, 0xb2, 0x7b,
0xf5, 0x7f, 0xe6, 0x79, 0x03, 0x6a, 0x93, 0x51, 0x8f, 0x32, 0x76, 0x0f,
0x1e, 0xeb, 0x75, 0xc8, 0x48, 0xaa, 0x04, 0x93, 0x8a, 0x84, 0x05, 0x80,
0xd2, 0x85, 0x7a, 0x95, 0xb8, 0xad, 0x9b, 0xcc, 0xa2, 0xef, 0xf9, 0x13,
0xb6, 0x36, 0x08, 0x55, 0x80, 0x6c, 0x36, 0x7b, 0xfd, 0x7f, 0x71, 0x7a,
0x06, 0x6b, 0xf8, 0x52, 0x3a, 0x34, 0x45, 0x11, 0xeb, 0xec, 0x1c, 0xca,
0xa6, 0xab, 0xfc, 0x93, 0x09, 0x85, 0x00, 0x80, 0x4a, 0x85, 0x79, 0x94,
0x55, 0xac, 0xf0, 0xca, 0xd3, 0xed, 0x2c, 0x12, 0x0f, 0x35, 0xa9, 0x53,
0x84, 0x6b, 0xb4, 0x7a, 0xff, 0x7f, 0xf6, 0x7a, 0x03, 0x6c, 0x59, 0x54,
0xe3, 0x35, 0x13, 0x13, 0xba, 0xee, 0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 0xe6, 0x7f,
0x55, 0x79, 0xfb, 0x68, 0x29, 0x50, 0xe0, 0x30, 0xa6, 0x0d, 0x53, 0xe9,
0xd3, 0xc6, 0xf0, 0xa8, 0x13, 0x92, 0x12, 0x84, 0x11, 0x80, 0x61, 0x86,
0x7f, 0x96, 0x21, 0xaf, 0x47, 0xce, 0x71, 0xf1, 0xc6, 0x15, 0x5b, 0x38,
0x63, 0x56, 0x74, 0x6d, 0xb2, 0x7b, 0xf4, 0x7f, 0xe6, 0x79, 0x03, 0x6a,
0x92, 0x51, 0x8f, 0x32, 0x76, 0x0f, 0x1f, 0xeb, 0x76, 0xc8, 0x48, 0xaa,
0x04, 0x93, 0x8b, 0x84, 0x05, 0x80, 0xd2, 0x85, 0x7a, 0x95, 0xb8, 0xad,
0x9b, 0xcc, 0xa0, 0xef, 0xfa, 0x13, 0xb6, 0x36, 0x09, 0x55, 0x80, 0x6c,
0x36, 0x7b, 0xfd, 0x7f, 0x71, 0x7a, 0x06, 0x6b, 0xf9, 0x52, 0x3a, 0x34,
0x45, 0x11, 0xeb, 0xec, 0x1d, 0xca, 0xa5, 0xab, 0xfc, 0x93, 0x09, 0x85,
0x00, 0x80, 0x4a, 0x85, 0x7a, 0x94, 0x55, 0xac, 0xf1, 0xca, 0xd3, 0xed,
0x2c, 0x12, 0x0e, 0x35, 0xa9, 0x53, 0x86, 0x6b, 0xb5, 0x7a, 0xff, 0x7f,
0xf6, 0x7a, 0x03, 0x6c, 0x59, 0x54, 0xe2, 0x35, 0x14, 0x13, 0xb9, 0xee,
0xc5, 0xcb, 0x07, 0xad, 0xfa, 0x94, 0x8e, 0x85, 0x02, 0x80, 0xc8, 0x84,
0x80, 0x93, 0xf6, 0xaa, 0x49, 0xc9, 0x05, 0xec, 0x5e, 0x10, 0x64, 0x33,
0x46, 0x52, 0x84, 0x6a, 0x2d, 0x7a, 0xfa, 0x7f, 0x75, 0x7b, 0xfb, 0x6c,
0xb7, 0x55, 0x89, 0x37, 0xe0, 0x14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 0x80, 0xf5, 0x86, 0x8b, 0x97, 0x8d, 0xb0, 0xf7, 0xcf, 0x41, 0xf3,
0x92, 0x17, 0xfd, 0x39, 0xba, 0x57, 0x63, 0x6e, 0x25, 0x7c, 0xe5, 0x7f,
0x54, 0x79, 0xfa, 0x68, 0x28, 0x50, 0xe0, 0x30, 0xa6, 0x0d, 0x54, 0xe9,
0xd3, 0xc6, 0xf0, 0xa8, 0x13, 0x92, 0x12, 0x84, 0x11, 0x80, 0x61, 0x86,
0x80, 0x96, 0x21, 0xaf, 0x47, 0xce, 0x71, 0xf1, 0xc6, 0x15, 0x5b, 0x38,
0x63, 0x56, 0x74, 0x6d, 0xb1, 0x7b, 0xf5, 0x7f, 0xe6, 0x79, 0x03, 0x6a,
0x93, 0x51, 0x8e, 0x32, 0x76, 0x0f, 0x1e, 0xeb, 0x77, 0xc8, 0x48, 0xaa,
0x04, 0x93, 0x8a, 0x84, 0x06, 0x80, 0xd3, 0x85, 0x7a, 0x95, 0xb8, 0xad,
0x9b, 0xcc, 0xa1, 0xef, 0xfa, 0x13, 0xb6, 0x36, 0x09, 0x55, 0x80, 0x6c,
0x36, 0x7b, 0xfd, 0x7f, 0x71, 0x7a, 0x06, 0x6b, 0xf8, 0x52, 0x3a, 0x34,
0x45, 0x11, 0xed, 0xec, 0x1c, 0xca, 0xa5, 0xab, 0xfc, 0x93, 0x09, 0x85,
0x01, 0x80, 0x4a, 0x85, 0x79, 0x94, 0x55, 0xac, 0xf0, 0xca, 0xd3, 0xed,
0x2c, 0x12, 0x0f, 0x35, 0xaa, 0x53, 0x86, 0x6b, 0xb4, 0x7a, 0xff, 0x7f,
0xf6, 0x7a, 0x03, 0x6c, 0x5a, 0x54, 0xe3, 0x35, 0x14, 0x13, 0xba, 0xee,
0xc5, 0xcb, 0x06, 0xad, 0xf9, 0x94, 0x8e, 0x85, 0x02, 0x80, 0xc9, 0x84,
0x80, 0x93, 0xf6, 0xaa, 0x49, 0xc9, 0x05, 0xec, 0x5f, 0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x0f, 0x80, 0x62, 0x86, 0x7f, 0x96, 0x23, 0xaf, 0x46, 0xce,
0x72, 0xf1, 0xc5, 0x15, 0x5d, 0x38, 0x61, 0x56, 0x75, 0x6d, 0xb0, 0x7b,
0xf6, 0x7f, 0xe6, 0x79, 0x03, 0x6a, 0x94, 0x51, 0x8d, 0x32, 0x78, 0x0f,
0x1c, 0xeb, 0x7a, 0xc8, 0x43, 0xaa, 0x0a, 0x93, 0x85, 0x84, 0x0c, 0x80,
0xca, 0x85, 0x83, 0x95, 0xb0, 0xad, 0xa5, 0xcc, 0x96, 0xef, 0x06, 0x14,
0xaa, 0x36, 0x14, 0x55, 0x74, 0x6c, 0x41, 0x7b, 0xf4, 0x7f, 0x79, 0x7a,
0xff, 0x6a, 0xfc, 0x52, 0x38, 0x34, 0x44, 0x11, 0xf1, 0xec, 0x12, 0xca,
0xb5, 0xab, 0xe6, 0x93, 0x27, 0x85, 0x00, 0x80, 0x82, 0x85, 0x2c, 0x94,
0xc4, 0xac, 0x41, 0xca, 0x1a, 0xef
};
unsigned int __500hz_16_wav_len = 11070;
|
the_stack_data/95449375.c | #include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
printf("%d", n/5+n/25+n/125);
return 0;
} |
the_stack_data/25138656.c | /* xtcidu - reads a short ASCII label using an X window and emits said
* label to stdout. this has probably already been written by someone
* else, but it is good xlib practice */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <ctype.h>
#include <err.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
enum { HKEY_DONE, HKEY_MORE };
#ifndef OUTPUT_BUFFER_LEN
#define OUTPUT_BUFFER_LEN 63
#endif
#define DINGBELL XBell(X_Disp, 50)
void emit_help(void);
int handle_key(XEvent *);
unsigned long x_color_pixel(char *);
unsigned long x_bg(void);
unsigned long x_fg(void);
void x_destroy(void);
void x_font(XFontStruct **, int *, int *);
void x_init(char *, char *, char *, char *);
Display *X_Disp; // XOpenDisplay
int X_Snum; // DefaultScreen
Window X_Win; // main window
GC X_Gc; // " " graphics context
unsigned long Current;
char Output[OUTPUT_BUFFER_LEN + 1];
int Text_X = 5;
int Text_Y = 5;
char *Flag_Badchars; // -B
char *Flag_Bg; // -b
char *Flag_Fg; // -f
char *Flag_Font; // -F
int Flag_Nonewline; // -n
int main(int argc, char *argv[]) {
XEvent xev;
int ch, status = EXIT_SUCCESS;
#ifdef __OpenBSD__
if (pledge("rpath stdio unix", NULL) == -1) err(1, "pledge failed");
#endif
while ((ch = getopt(argc, argv, "h?B:F:b:f:n")) != -1) {
switch (ch) {
case 'B': Flag_Badchars = optarg; break;
case 'F': Flag_Font = optarg; break;
case 'b': Flag_Bg = optarg; break;
case 'f': Flag_Fg = optarg; break;
case 'n': Flag_Nonewline = 1; break;
case 'h':
case '?':
default: emit_help();
}
}
argc -= optind;
argv += optind;
// both MacPorts and OpenBSD have this font:
// xlsfonts | sort > a
// ...
// comm -12 a b
if (!Flag_Font) Flag_Font = "lucidasanstypewriter-bold-24";
x_init("xtcidu", "Xt", "Xtcidu", "Xtcidu");
while (1) {
XNextEvent(X_Disp, &xev);
switch (xev.type) {
case Expose:
if (xev.xexpose.count != 0) break;
if (Output[0] == '\0')
XDrawString(X_Disp, X_Win, X_Gc, Text_X, Text_Y, "label:", 6);
break;
case KeyPress:
if (handle_key(&xev) == HKEY_DONE) goto DONE;
break;
}
}
DONE:
x_destroy();
#ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1) err(1, "pledge failed");
#endif
if (Output[0] != '\0') {
if (!Flag_Nonewline) Output[Current++] = '\n';
write(STDOUT_FILENO, Output, Current);
} else {
// did not get a string?? report this to caller
status = 1;
}
exit(status);
}
void emit_help(void) {
fputs("Usage: xtcidu [-B badchars] [-F font] [-b bg] [-f fg] [-n]\n",
stderr);
exit(EX_USAGE);
}
inline int handle_key(XEvent *xevp) {
char bytes[3], *bcp;
int count, isbad;
unsigned long oldcur = Current;
count = XLookupString(&xevp->xkey, bytes, sizeof(bytes), NULL, NULL);
if (count == 1) { // printable character -- ascii(7)
switch (bytes[0]) {
case 8: // backspace
if (Current == 0) {
DINGBELL;
break;
}
Output[--Current] = '\0';
break;
case 13: // enter -- accepts the label, if there is one
if (Current == 0) {
DINGBELL;
break;
}
return HKEY_DONE;
default:
if (!isprint(bytes[0])) break;
// so `-B /` can prevent '/' from appearing in a label that
// is then used as a filename (the precise need this script
// is aimed at)
if (Flag_Badchars) {
bcp = Flag_Badchars;
isbad = 0;
while (*bcp != '\0') {
if (bytes[0] == *bcp) {
DINGBELL;
isbad = 1;
break;
}
bcp++;
}
if (isbad) break;
}
if (Current >= OUTPUT_BUFFER_LEN) {
DINGBELL;
break;
}
Output[Current++] = bytes[0];
}
}
if (Current != oldcur) {
XClearWindow(X_Disp, X_Win);
XDrawString(X_Disp, X_Win, X_Gc, Text_X, Text_Y, Output, Current);
}
return HKEY_MORE;
}
inline unsigned long x_color_pixel(char *name) {
XColor exact, closest;
XAllocNamedColor(X_Disp, XDefaultColormap(X_Disp, X_Snum), name, &exact,
&closest);
return closest.pixel;
}
inline unsigned long x_bg(void) {
return Flag_Bg ? x_color_pixel(Flag_Bg) : WhitePixel(X_Disp, X_Snum);
}
inline unsigned long x_fg(void) {
return Flag_Fg ? x_color_pixel(Flag_Fg) : BlackPixel(X_Disp, X_Snum);
}
inline void x_destroy(void) {
XUnmapWindow(X_Disp, X_Win);
XDestroyWindow(X_Disp, X_Win);
XCloseDisplay(X_Disp);
}
inline void x_font(XFontStruct **font, int *width, int *height) {
XCharStruct xcs;
int dir, asc, dsc;
if (!(*font = XLoadQueryFont(X_Disp, Flag_Font)))
errx(1, "XLoadQueryFont failed for '%s'", Flag_Font);
// "Q" as it goes up pretty high and has at least something of a
// dangly bit below it and is a single character for the width
// multiplication which is not perfect but hopefully is good enough
XTextExtents(*font, "Q", 1, &dir, &asc, &dsc, &xcs);
if (xcs.width < 1) errx(1, "invalid no-width font '%s'", Flag_Font);
// TODO may need to limit the width (or the buffer, or more likely
// use a smaller font size) if this turns out to be too wide. or
// support -geometry and leave that and the font up to the caller...
*width = xcs.width * OUTPUT_BUFFER_LEN;
*height = xcs.ascent + xcs.descent;
}
inline void x_init(char *window_name, char *icon_name, char *res_name,
char *res_class) {
XClassHint *class;
XFontStruct *font;
XGCValues gcvals;
XSetWindowAttributes attr;
XSizeHints wmsize;
XTextProperty windowName, iconName;
XWMHints wmhints;
int est_width, est_height;
unsigned long fg, bg, mask;
if (!(X_Disp = XOpenDisplay(NULL))) errx(EX_OSERR, "XOpenDisplay failed");
X_Snum = DefaultScreen(X_Disp);
bg = x_bg();
fg = x_fg();
attr.background_pixel = bg;
attr.border_pixel = BlackPixel(X_Disp, X_Snum);
attr.event_mask = ExposureMask | KeyPressMask;
mask = CWBackPixel | CWBorderPixel | CWEventMask;
x_font(&font, &est_width, &est_height);
Text_Y += est_height;
X_Win =
XCreateWindow(X_Disp, RootWindow(X_Disp, X_Snum), 0, 0, est_width,
est_height * 2.6, 1, DefaultDepth(X_Disp, X_Snum),
InputOutput, DefaultVisual(X_Disp, X_Snum), mask, &attr);
wmsize.flags = USPosition | USSize;
wmhints.initial_state = NormalState;
wmhints.flags = StateHint;
XStringListToTextProperty(&window_name, 1, &windowName);
XStringListToTextProperty(&icon_name, 1, &iconName);
if (!(class = XAllocClassHint())) err(1, "XAllocClassHint failed");
class->res_name = res_name;
class->res_class = res_class;
XSetWMProperties(X_Disp, X_Win, &windowName, &iconName, NULL, 0, &wmsize,
&wmhints, class);
// XFree(class);
gcvals.background = WhitePixel(X_Disp, X_Snum);
gcvals.foreground = BlackPixel(X_Disp, X_Snum);
mask = GCForeground | GCBackground;
X_Gc = XCreateGC(X_Disp, X_Win, mask, &gcvals);
XSetForeground(X_Disp, X_Gc, fg);
XSetBackground(X_Disp, X_Gc, bg);
XSetFont(X_Disp, X_Gc, font->fid);
XMapWindow(X_Disp, X_Win);
}
|
the_stack_data/173578097.c | // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s
// Test FreeBSD kernel printf extensions.
int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2)));
void check_freebsd_kernel_extensions(int i, long l, char *s)
{
// %b expects an int and a char *
freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning
freebsd_kernel_printf("reg=%b\n", l, "\10\2BITTWO\1BITONE\n"); // expected-warning{{format specifies type 'int' but the argument has type 'long'}}
freebsd_kernel_printf("reg=%b\n", i, l); // expected-warning{{format specifies type 'char *' but the argument has type 'long'}}
freebsd_kernel_printf("reg=%b\n", i); // expected-warning{{more '%' conversions than data arguments}}
freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n", l); // expected-warning{{data argument not used by format string}}
// %D expects an unsigned char * and a char *
freebsd_kernel_printf("%6D", s, ":"); // no-warning
freebsd_kernel_printf("%6D", i, ":"); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}}
freebsd_kernel_printf("%6D", s, i); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
freebsd_kernel_printf("%6D", s); // expected-warning{{more '%' conversions than data arguments}}
freebsd_kernel_printf("%6D", s, ":", i); // expected-warning{{data argument not used by format string}}
freebsd_kernel_printf("%*D", 42, s, ":"); // no-warning
freebsd_kernel_printf("%*D", 42, i, ":"); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}}
freebsd_kernel_printf("%*D", 42, s, i); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
freebsd_kernel_printf("%*D", 42, s); // expected-warning{{more '%' conversions than data arguments}}
freebsd_kernel_printf("%*D", 42, s, ":", i); // expected-warning{{data argument not used by format string}}
// %r expects an int
freebsd_kernel_printf("%r", i); // no-warning
freebsd_kernel_printf("%r", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}}
freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
freebsd_kernel_printf("%lr", l); // no-warning
// %y expects an int
freebsd_kernel_printf("%y", i); // no-warning
freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}}
freebsd_kernel_printf("%ly", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
freebsd_kernel_printf("%ly", l); // no-warning
}
|
the_stack_data/1178462.c | /*
* Copyright (C) 2007-2021 Intel Corporation.
* SPDX-License-Identifier: MIT
*/
#include <stdlib.h>
#if !defined(__GNUC__)
extern void movdqa_test(char* p);
#endif
int main(int argc, char** argv)
{
char a[1000];
/* get in to the buffer and then align it by 16 */
static const size_t align16_mask = (16 - 1);
/* Integer type size_t defined to have size of pointer */
char* b = (char*)(((size_t)a + align16_mask) & ~align16_mask);
/* generate one aligned move and one unaligned move. The alignchk tool
* should catch the latter one. */
#if defined(__GNUC__)
char* c = b + 1;
asm volatile("movdqa %%xmm0, %0" : "=m"(*b) : : "%xmm0");
asm volatile("movdqa %%xmm0, %0" : "=m"(*c) : : "%xmm0");
#else
movdqa_test(b);
#endif
}
|
the_stack_data/66840.c | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
//printf("Programming");
//printf("I love apple.\n");
char str[100];
scanf("%s", str);
printf("I love %s\n", str);
return 0;
} |
the_stack_data/566651.c | // compile: clang -fopenmp test2.c -o test
// triggers warnings about __kmpc_* series function calls, but works
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// extern .....
void init(float *a, int N);
void axpy_omp_parallel_for_gpu(int *gtid, int *btid, const float a, float *A, const float *B, float *C, int n);
int main(int argc, char *argv[])
{
// arrays on device
float *dA, *dB, *dC;
// other elements
int n = 1024;
float a = 3.14;
// init A and B and C
// memory allocation
dA = (float*)malloc(n*sizeof(float));
dB = (float*)malloc(n*sizeof(float));
dC = (float*)malloc(n*sizeof(float));
// init function calls
init(dA, n);
init(dB, n);
init(dC, n);
// OpenMP code block starts:
int gtid;
__kmpc_begin(NULL, 0);
gtid = __kmpc_global_thread_num();
__kmpc_fork_call(NULL, 5, axpy_omp_parallel_for_gpu, a, dA, dB, dC, n);
__kmpc_end(NULL);
/* test: check result */
printf("Selected result of A, B, C, a*A + B: %f, %f, %f, %f\n", dA[1], dB[1], dC[1], a*dA[1]+dB[1]);
return 0;
}
void init(float *a, int N) {
int s;
for (s = 0; s < N; s++) a[s] = rand() / (float)RAND_MAX;
}
void axpy_omp_parallel_for_gpu(int *gtid, int *btid, const float a, float *A, const float *B, float *C, int n) {
int i, j;
int last, lower, upper, stride;
last = 0;
__kmpc_for_static_init_4(NULL, *gtid, 33, &last, &lower, &upper, &stride, 1, 4);
for (i = lower; i <= upper; i++) {
C[i] = 3.14 * A[i] + B[i]; // a * A[i] is not working
printf("%d\n", *gtid);
}
__kmpc_for_static_fini(NULL, *gtid);
}
|
the_stack_data/168893940.c | #include<stdio.h>
#include<math.h>
main()
{ int num,rem,bin=0,i=0;
printf("Enter a number");
scanf("%d",&num);
while(num!=0)
{ rem=num%10;
bin=bin+rem*pow(2,i);
num=num/10;
i++;
}
printf("%d",bin);
}
|
the_stack_data/117327281.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/time.h>
#define PROCESSES 10
typedef struct{
int occurences[10];
char word[10][20];
char path[10][150];
} shMemStruct;
int make_children(int n) {
pid_t pid;
int i;
pid_t pidF = getpid();
for (i = 0; i < n; i++) {
pid = fork();
if (pid < 0)
return -1;
else if (pid == 0)
return i;
else if (getpid() == pidF && i == n - 1)
return pidF;
}
return 0;
}
int main(void) {
shMemStruct *shMemObj;
int structSize = sizeof(shMemStruct);
shm_unlink ("/ex13");
int fd = shm_open("/ex13", O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
if (fd == -1) {
printf("Error opening shared memory. Please check writer.c!\n");
exit(EXIT_FAILURE);
}
ftruncate(fd, structSize);
shMemObj = (shMemStruct*) mmap(NULL, structSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if(shMemObj == NULL) {
printf("Could not retreive info from shared memory! -Exiting-\n");
return -1;
}
FILE *lyrics;
char haystack[1200];
strcpy(shMemObj->word[0], "close");
strcpy(shMemObj->word[1], "far");
strcpy(shMemObj->word[2], "heart");
strcpy(shMemObj->word[3], "Forever");
strcpy(shMemObj->word[4], "nothing");
strcpy(shMemObj->word[5], "else");
strcpy(shMemObj->word[6], "matters");
strcpy(shMemObj->word[7], "different");
strcpy(shMemObj->word[8], "cared");
strcpy(shMemObj->word[9], "what");
int id = make_children(PROCESSES);
int i;
for (i = 0; i < PROCESSES; i++) {
sprintf(shMemObj -> path[i], "file%d.txt", i);
if (id == i) {
lyrics = fopen(shMemObj->path[i], "r"); //"r" read option
while(fgets(haystack, sizeof(haystack), lyrics) != NULL){
if(strstr(haystack, shMemObj->word[i]) != NULL){ //Needle in the haystack
shMemObj->occurences[i]++;
}
}
fclose(lyrics);
exit(EXIT_SUCCESS);
}
}
for (i = 0; i < PROCESSES; i++) {
wait(NULL);
}
for (i = 0; i < PROCESSES; i++) {
printf("Child %d found %d occurrences of word: %s\n", i, shMemObj->occurences[i], shMemObj->word[i]);
}
if (munmap((void *) shMemObj, structSize) < 0) {
printf("Error unmapping at munmap()!\n");
exit(EXIT_FAILURE);
}
if (close(fd) < 0) {
printf("Error at close()!\n");
exit(EXIT_FAILURE);
}
return 0;
}
|
the_stack_data/9511769.c | #include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int val;
struct node* next;
} node;
typedef struct list
{
node *head;
} list;
void print(list l)
{
while(l.head!=NULL)
{
printf("%d ",l.head->val);
l.head=l.head->next;
}
}
list l;
void append(list *l, int k)
{
if (l->head==NULL) {
l->head=malloc(sizeof(node));
l->head->val=k;
return;
}
node* tmp = l->head;
node* prv = NULL;
while(tmp!=NULL)
{
prv=tmp;
tmp=tmp->next;
}
tmp=malloc(sizeof(node));
tmp->val=k;
tmp->next=NULL;
prv->next=tmp;
}
int getListLength(list* l) {
int i=0;
node* tmp = l->head;
while (tmp!=NULL) i++,tmp=tmp->next;
return i;
}
int findKthFromEnd(int k, list l) {
int len = getListLength(&l);
node* tmp = l.head;
int i=0;
while (i++!=len-k) {
tmp=tmp->next;
}
return tmp->val;
}
|
the_stack_data/84055.c | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h> // strlen()
#include <stdlib.h>
unsigned to_decimal(const char bi[]);
void print_binary(const unsigned char num);
int main()
{
/*
Regular Logical Operators : &&, ||, and !
Bitwise Logical Operators :
- Bitwise NOT ~
- Bitwise AND &
- Bitwise OR |
- Bitwise EXCLUSIVE OR ^
*/
unsigned char i = to_decimal("00000110");
unsigned char mask = to_decimal("00000101");
print_binary(i);
print_binary(mask);
print_binary(i | mask); // Bitwise OR (binary operator)
print_binary(i ^ mask); // Bitwise XOR (binary operator)
/*
The bitwise NOT, or complement, is a unary operation
that performs logical negation on each bit,
forming the ones' complement of the given binary value.
*/
print_binary(~i); // Bitwise NOT (unary operator)
return 0;
}
void print_binary(const unsigned char num)
{
printf("Decimal %3d \t== Binary ", num);
const size_t bits = sizeof(num) * 8;
for (size_t i = 0; i < bits; ++i) {
const unsigned int mask = (int)pow(2, bits - 1 - i);
if ((num & mask) == mask)
printf("%d", 1);
else
printf("%d", 0);
}
printf("\n");
}
unsigned to_decimal(const char bi[])
{
const size_t bits = strlen(bi);
unsigned sum = 0;
for (size_t i = 0; i < bits; ++i) {
if (bi[i] == '1')
sum += (int)pow(2, bits - 1 - i);
else if (bi[i] != '0') {
printf("Wrong character : %c", bi[i]);
exit(1);
}
}
return sum;
}
|
the_stack_data/724950.c | #include<stdio.h>
int main() {
int mat;
float h,vh,s=0;
scanf("%d %f %f",&mat,&h,&vh);
getchar();
while((mat!=0)&&(h!=0)&&(vh!=0)){
s=h*vh;
printf("%d %.2f\n",mat,s);
scanf("%d %f %f",&mat,&h,&vh);
getchar();
}
return 0;
} |
the_stack_data/43255.c | /* $OpenBSD: s_cexp.c,v 1.6 2013/07/03 04:46:36 espie Exp $ */
/*
* Copyright (c) 2008 Stephen L. Moshier <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* cexp()
*
* Complex exponential function
*
*
*
* SYNOPSIS:
*
* double complex cexp ();
* double complex z, w;
*
* w = cexp (z);
*
*
*
* DESCRIPTION:
*
* Returns the exponential of the complex argument z
* into the complex result w.
*
* If
* z = x + iy,
* r = exp(x),
*
* then
*
* w = r cos y + i r sin y.
*
*
* ACCURACY:
*
* Relative error:
* arithmetic domain # trials peak rms
* DEC -10,+10 8700 3.7e-17 1.1e-17
* IEEE -10,+10 30000 3.0e-16 8.7e-17
*
*/
#include <complex.h>
#include <float.h>
#include <math.h>
double complex
cexp(double complex z)
{
double complex w;
double r, x, y;
x = creal (z);
y = cimag (z);
r = exp (x);
w = r * cos (y) + r * sin (y) * I;
return (w);
}
#if LDBL_MANT_DIG == DBL_MANT_DIG
__strong_alias(cexpl, cexp);
#endif /* LDBL_MANT_DIG == DBL_MANT_DIG */
|
the_stack_data/64513.c | #include <stdio.h>
#include <string.h>
int main(){
int skip = 3;
char parola[50];
int j=0;
int i=0;
char alfabeto[26]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
printf("Inserisci la parola da crittografare: \n");
scanf("%s",parola);
for(i=0;i<26; i++){
if(parola[j] == alfabeto[i]){
if(i+skip>26){
printf("%c",alfabeto[i+skip-26]);
}else{
printf("%c",alfabeto[i+skip]);
}
j++;
i=-1;
}
}
printf("\n");
} |
the_stack_data/105968.c | /* Copyright (C) 2012-2020 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
extern void foo (void);
int
main (void)
{
foo ();
return 0;
}
|
the_stack_data/48575833.c | /* Taxonomy Classification: 0000040000000000000200 */
/*
* WRITE/READ 0 write
* WHICH BOUND 0 upper
* DATA TYPE 0 char
* MEMORY LOCATION 0 stack
* SCOPE 0 same
* CONTAINER 4 array of structs
* POINTER 0 no
* INDEX COMPLEXITY 0 constant
* ADDRESS COMPLEXITY 0 constant
* LENGTH COMPLEXITY 0 N/A
* ADDRESS ALIAS 0 none
* INDEX ALIAS 0 none
* LOCAL CONTROL FLOW 0 none
* SECONDARY CONTROL FLOW 0 none
* LOOP STRUCTURE 0 no
* LOOP COMPLEXITY 0 N/A
* ASYNCHRONY 0 no
* TAINT 0 no
* RUNTIME ENV. DEPENDENCE 0 no
* MAGNITUDE 2 8 bytes
* CONTINUOUS/DISCRETE 0 discrete
* SIGNEDNESS 0 no
*/
/*
Copyright 2004 M.I.T.
Permission is hereby granted, without written agreement or royalty fee, to use,
copy, modify, and distribute this software and its documentation for any
purpose, provided that the above copyright notice and the following three
paragraphs appear in all copies of this software.
IN NO EVENT SHALL M.I.T. BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE
AND ITS DOCUMENTATION, EVEN IF M.I.T. HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMANGE.
M.I.T. SPECIFICALLY DISCLAIMS ANY WARRANTIES INCLUDING, BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
AND NON-INFRINGEMENT.
THE SOFTWARE IS PROVIDED ON AN "AS-IS" BASIS AND M.I.T. HAS NO OBLIGATION TO
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
typedef struct
{
char buf[10];
int int_field;
} my_struct;
int main(int argc, char *argv[])
{
my_struct array_buf[5];
/* BAD */
array_buf[4].buf[17] = 'A';
return 0;
}
|
the_stack_data/3261486.c | #include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int nthreads, tid;
omp_set_num_threads(8);
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
} /* All threads join master thread and disband */
}
|
the_stack_data/5196.c | /** Instituto Federal do Rio Grande do Sul - Prof. Renan Guedes Maidana
* Trabalho 2 - Estrutura de Dados 2
*
* Busca em grafos: Custo mínimo e Dijkstra
*
* Aluno: Gabriel Alves de Lima
* Data: 06/07/2019
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INFINITE 200 // Definição de número "infinito" para montar a matriz de custos
#define MAX_NODE 10 // Número máximo de nodos para criação das matrizes de custo e adjacência
// Declaração das matrizes de custo e adjacência
int adj[MAX_NODE][MAX_NODE];
int cost[MAX_NODE][MAX_NODE];
/** Função para ler a representação do grafo de um arquivo de texto
O grafo é descrito da seguinte maneira, por exemplo:
2
node:0
1,10
node:1
Onde a primeira linha é o numero total de nós. O restante da linhas
detalha o nos em "node:x", e abaixo quais são seus sucessores e pesos.
Ex: Abaixo, o no 0 possui um sucessor no nodo 1, com peso de comunicacao de 10.
Já o no 1 nao possui sucessores.
node:0
1,10
node:1
Você deve implementar o código que irá realizar o cálculo das matrizes de custo e adjacência,
conforme dados presentes no arquivo.
*/
int loadGraph(char* filename){
// Iremos carregar o grafo a partir de um arquivo de texto estruturado, conforme
// estrutura indicada acima
FILE *f = fopen(filename, "rt");
char line[20];
if (f == NULL){
printf("Problemas na leitura do arquivo %s\n", filename);
return -1;
}
// Consideramos que a primeira linha do arquivo é o número de nodos
fgets(line, 100, f); // o 'fgets' lê até 99 caracteres, ou até o '\n'
int n_nodes = atoi(line);
// Inicializamos a matriz de adjacência e a lista de nodos visitados com zeros (até o número de nós especificado no arquivo)
// Utiliza-se somente parte da matriz total de MAX_NODE vs MAX_NODE
int i, j;
for(i=0; i<n_nodes; i++){
for(j=0; j<n_nodes; j++){
adj[i][j] = 0;
cost[i][j] = INFINITE;
}
}
// VOCÊ DEVE: Continuar lendo o arquivo até o final e calcular matrizes de adjacência e custo
// + um espaço para o NULL do final
const size_t nodo_size = MAX_NODE/10; ///@var nodo_size Tamanho mínimo pra guardar os caracteres do nodo escritos em decimal
char *nodo_str = malloc(nodo_size); ///@var nodo Variável que armazena o nodo do qual as próximas linhas do arquivo se referenciam
int nodo;
int nodo_adj;
int nodo_adj_custo;
while(fgets(line, 100, f) != NULL){
if(strstr(line, "node:") != NULL) { // Checa se é o começo de de um novo nodo
strncpy(nodo_str, &line[5], nodo_size); // Copia o valor depois de 'nodo:' para a variavel nodo
continue; // Se já fez o que devia, então vai pra próxima linha!
}
nodo = atoi(nodo_str); // Faz o 'parse' do nodo que estava em string para integer
nodo_adj = atoi(strtok(line, ",")); // Quebra a linha em duas metades, a primeira é o nodo com o qual há uma adjecencia
nodo_adj_custo = atoi(strtok(NULL, ",")); // A segunda metade é o custo
adj[nodo][nodo_adj] = 1; // Altera a matriz de adjecencia com a informação nova
cost[nodo][nodo_adj] = nodo_adj_custo; // Altera a matriz de custos com a informação nova
}
// Fecha o arquivo de texto do grafo
fclose(f);
// Retorna o numero de nodos
return n_nodes;
}
/**
* Imprime as matrizes de custo e adjecencia
*
* @param n_nodes Número de nodos
*/
void _imprimirMatrizes(int n_nodes) {
int i, j;
printf("\nMatriz de adjecencia:");
for(i=0; i<n_nodes; i++){
printf("\n");
for(j=0; j<n_nodes; j++){
printf("%4d ", adj[i][j]);
}
}
printf("\n");
printf("\nMatriz de custo:");
for(i=0; i<n_nodes; i++) {
printf("\n");
for (j = 0; j < n_nodes; j++) {
printf("%4d ", cost[i][j]);
}
}
}
/** VOCÊ DEVE: Implementar o algoritmo de busca em grafos por custo mínimo
*
* Parâmetros:
* n_nodes - numero total de nodos no grafo
* start - nodo inicial para busca
* goal - nodo objetivo (destino) da busca
*
* Saída:
* O caminho no grafo, do "start" até o "goal", segundo o algoritmo de busca em grafos por custo mínimo
*/
void custo_minimo(int n_nodes, int start, int goal){
int i, j; // Pivôs
int pos_minimo;
start == goal ? printf("%d", start) : printf("%d -> ", start); // Firula pra não imprimir a setinha se start == goal
for(i = start; i < n_nodes;) {
pos_minimo = 0; // Define a posição do menor
for(j = 0; j < n_nodes; j++) {
if(cost[i][j] < cost[i][pos_minimo]) {
pos_minimo = j;
}
}
i = pos_minimo;
if(i == goal) {
printf("%d", i);
return;
}
printf("%d -> ", pos_minimo);
}
fflush(stdout); // Dar flush no buffer do stdout só pra garantir que vai imprimir tudo
}
/** VOCÊ DEVE: Implementar o algoritmo de Dijkstra para busca em grafos
*
* Parâmetros:
* n_nodes - numero total de nodos no grafo
* start - nodo inicial para busca
* goal - nodo objetivo (destino) da busca
*
* Saída:
* O caminho no grafo, do "start" até o "goal", segundo o algoritmo de Dijkstra
*/
void dijkstra(int n_nodes, int start, int goal) {
if (n_nodes < 1) { return; }
if (n_nodes == 1 || start == goal) {
printf("%d", start);
return;
}
/* Inicialização das variáveis */
int menorCusto[n_nodes]; /// @var int[] menorCusto Array que armazena o menor custo para cada nodo
int precedentes[n_nodes]; /// @var int[] precedentes Array que armazena o o nodo anterior de acordo com o menor custo
int visitados[n_nodes]; /// @var int[] visitados Array que armazena um boolean (0 ou 1) indicando se o novo já foi visitado
// Inicializa as informações referentes ao primeiro nodo
menorCusto[0] = 0;
precedentes[0] = 0;
visitados[0] = 0;
for (int i = 1; i < n_nodes; i++) {
// Inicializa custos, precedentes e se foi visitado nos outros nodos
menorCusto[i] = INFINITE;
precedentes[i] = -1;
visitados[i] = 0;
}
int pivo = 0;
int menor;
while (precedentes[0] == 0) {
menor = -1;
visitados[pivo] = 1;
// Procura todos nodos adjecentes e calcula os custos
for (int i = 0; i < n_nodes; i++) {
// Se não é um nodo adjecente ou se foi visitado, vai pro próximo
if (!adj[pivo][i]) { continue; }
// Se o resultado do calculo de menor custo entre esse precedente for menor que o menor custo encontrado
// até então para o nodo 'i', substitui no 'menorCusto' e no 'precedentes'
if (cost[pivo][i] + menorCusto[pivo] < menorCusto[i]) {
menorCusto[i] = cost[pivo][i] + menorCusto[pivo];
precedentes[i] = pivo;
}
// Verifica se esse é o próximo nodo que deve ser visitado
if (menorCusto[i] > menor && !visitados[i]) {
menor = i;
}
}
// Se verificou todos nodos adjecentes
if (menor == -1) {
if (pivo == precedentes[pivo]) {
// Percorreu o grafo inteiro e voltou ao start
break;
}
// Volta para o nodo anterior
pivo = precedentes[pivo];
}
// Se ainda há um nodo que ainda não foi explorado
else {
pivo = menor;
}
}
// Imprime o caminho:
if (precedentes[goal] == -1) {
printf("Não encontrou o destino\n");
return;
}
pivo = goal;
int caminho[n_nodes];
int count = 0;
// Monta o array com os caminhos
while (precedentes[pivo] != pivo) {
caminho[count++] = pivo;
pivo = precedentes[pivo];
}
caminho[count] = precedentes[pivo];
// E, finalmente, imprime os caminhos
for (int i = count; i > 0; i--) {
printf("%d -> ", caminho[i]);
}
printf("%d", caminho[0]);
fflush(stdout); // Só pra garantir
}
// Função main
int main(int argc, char** args){
// Obtém grafo do arquivo "grafo.txt", já calculando as matrizes
int n_nodes = loadGraph("grafo3.txt");
_imprimirMatrizes(n_nodes);
printf("\n");
// Busca no grafo inicia no nodo 0, com objetivo de chegar no nodo 3
int start = 0, goal = 3; //grafo.txt
//int start = 0, goal=3; //grafo2.txt
printf("\nCusto mínimo: \n");
custo_minimo(n_nodes, start, goal);
printf("\n");
printf("\nDijkstra: \n");
dijkstra(n_nodes, start, goal);
// Fim! Boas férias!
// Valeu fessor!
return 0;
}
|
the_stack_data/155520.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char * x;
int foo;
x = (char *) malloc (10);
strcpy (x, "123456789");
foo = strlen (x+10);
x [foo] = 1; /* we just just use foo to force execution of strlen */
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
|
the_stack_data/68887795.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LENGTH_AUX 100
#define PATH_MAX 1024
void NameDir(char *);
int NumTopos(char *);
void ListarDir(char *, char *);
int contenidoString(char *);
int DirValid(char *);
int Parser(char *, char *);
int NumLines(FILE *);
int NumNodes(char *);
void ReadStats(FILE *, int, char *, char *);
int IsAstats(char *);
int main() {
FILE *fp;
int status,z,i, num_topo, aux_parser;
char name_dir[50]; //name of the root directory
char path[PATH_MAX]; //var aux to get info from pipe
char **name_dir_dinamica = NULL; // pointer for dynamic reservation
char comando_string[50]; //To open the pipe with the name of the root directory that the user writes, if not, Topologia_Brite will be used
//Name root directory
NameDir(name_dir);
//Number of topologies
num_topo = NumTopos(name_dir);
printf("\n\n %d Topologies detected..\n\n", num_topo);
printf("\n\nPress enter to continue...");
while(getchar() != '\n');
//Dynamic reservation of the two-dimensional array for the names of each topology
name_dir_dinamica = (char **)malloc(num_topo * sizeof(char *));
if (name_dir_dinamica == NULL) {
system("clear");
printf("Error there is not enough space in the memory...");
printf("\n\nPress enter to continue..."); // Equivalent to system ("pause"); in windows
while(getchar() != '\n'); //
exit(-1);
}
for (i = 0; i < num_topo; i++) {
name_dir_dinamica[i] = (char *)malloc(50);
}
strcpy(comando_string, "cd ");
strcat(comando_string, name_dir);
strcat(comando_string, " && ls -l | grep ^d");
fp = popen(comando_string, "r"); //Open pipe to get as input and output of the prompt to the command: cd name_dir
if (fp == NULL) // && ls -l | grep ^d inside the root directory.
exit(-1);
i = 0 ;
while (fgets(path, PATH_MAX, fp) != NULL) {
z=contenidoString(path); //Check if it is a directory to each line that reads
if (z == 1) {
ListarDir(path, name_dir_dinamica[i]);
i++;
}
}
system("mkdir Omnetpp_workspace");
//Starts parser
for (i = 0; i < num_topo; i++) {
aux_parser = Parser(name_dir_dinamica[i], name_dir);
if (aux_parser == 0) {
printf("\nError in the parsing of the topology%s \n", name_dir_dinamica[i]);
}
}
//Free pipe
status = pclose(fp);
if (status == -1) {
exit(-1);
}
//Free dynamic reserve
for (i = 0; i < num_topo; i++) {
free(name_dir_dinamica[i]);
}
free(name_dir_dinamica);
printf("\n\n\n ---- Work finished ----\n\n\n");
printf("\n\npress enter to continue...");
while(getchar() != '\n');
return 0;
}
void NameDir(char * name_dir) {
char aux_sn = '\0';
//Name of root directory
while (aux_sn != 's' && aux_sn != 'n') {
system("clear");
printf("Is your root directory: Data ? [s/n] : ");
scanf("%c", &aux_sn);
while (getchar() != '\n');
}
if (aux_sn == 'n') {
system("clear");
printf("Indicate the name of the root directory: ");
gets(name_dir);
aux_sn = '\0';
while (aux_sn != 's' && aux_sn != 'n') {
printf("\n\nConfirm, %s is your root directory? [s/n] : ", name_dir);
scanf("%c", &aux_sn);
while (getchar() != '\n');
}
if (aux_sn == 'n') {
system("clear");
printf("Indicate for the last time the name of the root directory:");
gets(name_dir);
aux_sn = '\0';
while (aux_sn != 's' && aux_sn != 'n') {
printf("\n\nConfirm, %s is your root directory? [s/n] : ", name_dir);
scanf("%c", &aux_sn);
while (getchar() != '\n');
}
if (aux_sn == 'n') {
system("clear");
printf("\nThe number of attempts to enter the name of the directory has been exceeded, closing the program ..\n\n\n");
printf("\n\npress enter to continue...");
while(getchar() != '\n');
exit(1);
}
}
}
else {
strcpy(name_dir, "Data");
}
}
int NumTopos(char * name_dir) {
FILE *fp;
int status, z, num_topo = 0;
char path[PATH_MAX]; //var aux to get info from pipe
char comando_string[50];
strcpy(comando_string,"cd ");
strcat(comando_string, name_dir);
strcat(comando_string, " && ls -l | grep ^d");
fp = popen(comando_string, "r");
if (fp == NULL)
exit(-1);
while (fgets(path, PATH_MAX, fp) != NULL) {
z = contenidoString(path);
if (z == 1) {
num_topo++;
}
}
status = pclose(fp);
if (status == -1) {
exit(-1);
}
return num_topo;
}
int contenidoString(char * path) { //Just check if the first character of each string in the list if it is a directory
int z = 0;
if(path[0] == 'd'){
z = 1;
}
return z;
}
void ListarDir(char * path, char *name_dir) {
char *pt_aux = NULL;
int counter_aux = 1;
pt_aux = strtok(path, " "); /*Split string */
while (counter_aux < 10) {
switch (counter_aux)
{
case 9:
strcpy(name_dir, pt_aux);
break;
}
counter_aux++;
pt_aux = strtok(NULL, " ");
}
}
int Parser(char * name_topo, char *directory_root_name) {
int z = 1, num_nodes_topo = 0;
FILE *Stats_File = NULL;
char path_statsfile_toParse[100];
char name_topo_aux[30];
name_topo[strlen(name_topo) - 1] = '\0';
strcpy(path_statsfile_toParse, "./");
strcat(path_statsfile_toParse, directory_root_name);
strcat(path_statsfile_toParse, "/");
strcat(path_statsfile_toParse, name_topo);
strcat(path_statsfile_toParse, "/");
strcat(path_statsfile_toParse, name_topo);
strcat(path_statsfile_toParse, "_stats.txt");
strcpy(name_topo_aux, name_topo);
num_nodes_topo = NumNodes(name_topo_aux);
Stats_File = fopen(path_statsfile_toParse, "wt+");
if (Stats_File == NULL) {
printf("ERROR, cant create stats file. . .\n");
printf("\n\npress enter to continue...");
while(getchar() != '\n');
exit(-1);
}
while (num_nodes_topo != 0) {
ReadStats(Stats_File, num_nodes_topo, directory_root_name, name_topo);
num_nodes_topo--;
}
////
fclose(Stats_File);
return z;
}
int NumLines(FILE * File_toRead) {
int num_lines = 0;
char str_aux[LENGTH_AUX];
//Number of lines reading
while (!feof(File_toRead)) {
num_lines++;
fgets(str_aux, LENGTH_AUX, File_toRead);
}
rewind(File_toRead);
return num_lines - 1; //"-1" due to "\n" at the end
}
int NumNodes(char * NameTopo) {
char * pt_aux = NULL;
int counter_aux = 0, nodes = 0;
pt_aux = strtok(NameTopo, "-");
while (counter_aux != 3) {
switch (counter_aux)
{
case 2:
nodes = atoi(pt_aux);
break;
}
counter_aux++;
pt_aux = strtok(NULL, "-");
}
return nodes;
}
void ReadStats(FILE * Stats_File, int num_node, char * directory_root_name, char * name_topo) {
FILE *Data_File = NULL;
char path_statsfile_toParse[100];
char aux_num_node[12];
char stats_line_topo[200];
int z = 0;
strcpy(path_statsfile_toParse, "./");
strcat(path_statsfile_toParse, directory_root_name);
strcat(path_statsfile_toParse, "/");
strcat(path_statsfile_toParse, name_topo);
strcat(path_statsfile_toParse, "/");
strcat(path_statsfile_toParse, name_topo);
strcat(path_statsfile_toParse, "[nodo");
sprintf(aux_num_node, "%d", num_node);
strcat(path_statsfile_toParse, aux_num_node);
strcat(path_statsfile_toParse, "].txt");
Data_File = fopen(path_statsfile_toParse, "r");
if (Data_File == NULL) {
printf("ERROR, cant create stats file. . .\n");
printf("\n\nPress enter to continue...");
while(getchar() != '\n');
exit(-1);
}
while (fgets(stats_line_topo, PATH_MAX, Data_File) != NULL) {
z = IsAstats(stats_line_topo);
if (z == 1) {
fprintf(Stats_File, stats_line_topo);
fprintf(Stats_File, "\n");
}
}
fclose(Data_File);
}
int IsAstats(char * str) {
int aux = 0;
if (str[0] == '-') {
aux = 1;
}
return aux;
}
|
the_stack_data/68888783.c | /**
******************************************************************************
* @file USB_Device/HID_Standalone/Src/usbd_desc.c
* @author MCD Application Team
* @version V1.0.2
* @date 06-May-2016
* @brief This file provides the USBD descriptors and string formatting method.
******************************************************************************
* @attention
*
* <h2><center>© Copyright � 2016 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#ifdef USBCON
/* Includes ------------------------------------------------------------------*/
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_conf.h"
#include "utils.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
//ID
#define USBD_LANGID_STRING 0x409 //1033
#if USBD_VID == 0x2341
#define USBD_MANUFACTURER_STRING "Arduino LLC"
#elif USBD_VID == 0x2A03
#define USBD_MANUFACTURER_STRING "Arduino srl"
#elif USBD_VID == 0x0483
#define USBD_MANUFACTURER_STRING "STMicroelectronics"
#elif !defined(USB_MANUFACTURER)
// Fall through to unknown if no manufacturer name was provided in a macro
#define USBD_MANUFACTURER_STRING "Unknown"
#else
#define USBD_MANUFACTURER_STRING USB_MANUFACTURER
#endif
#ifdef USBD_USE_HID_COMPOSITE
#define USBD_HID_PRODUCT_HS_STRING CONCATS(USB_PRODUCT, "HID in HS Mode")
#define USBD_HID_PRODUCT_FS_STRING CONCATS(USB_PRODUCT, "HID in FS Mode")
#define USBD_HID_CONFIGURATION_HS_STRING CONCATS(USB_PRODUCT, "HID Config")
#define USBD_HID_INTERFACE_HS_STRING CONCATS(USB_PRODUCT, "HID Interface")
#define USBD_HID_CONFIGURATION_FS_STRING CONCATS(USB_PRODUCT, "HID Config")
#define USBD_HID_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "HID Interface")
/* Private macro -------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
static uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
static uint8_t *USBD_HID_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
static uint8_t *USBD_HID_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
static uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
static uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
static uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
#ifdef USB_SUPPORT_USER_STRING_DESC
static uint8_t *USBD_HID_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
#endif /* USB_SUPPORT_USER_STRING_DESC */
/* Private variables ---------------------------------------------------------*/
USBD_DescriptorsTypeDef HID_Desc = {
USBD_HID_DeviceDescriptor,
USBD_HID_LangIDStrDescriptor,
USBD_HID_ManufacturerStrDescriptor,
USBD_HID_ProductStrDescriptor,
USBD_HID_SerialStrDescriptor,
USBD_HID_ConfigStrDescriptor,
USBD_HID_InterfaceStrDescriptor,
};
#endif //USBD_USE_HID_COMPOSITE
/* USB Standard Device Descriptor */
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
__ALIGN_BEGIN static uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
0x12, /* bLength */
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
0x00, /* bcdUSB */
0x02,
0x00, /* bDeviceClass */
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
LOBYTE(USBD_VID), /* idVendor */
HIBYTE(USBD_VID), /* idVendor */
LOBYTE(USBD_PID), /* idVendor */
HIBYTE(USBD_PID), /* idVendor */
0x00, /* bcdDevice rel. 2.00 */
0x02,
USBD_IDX_MFC_STR, /* Index of manufacturer string */
USBD_IDX_PRODUCT_STR, /* Index of product string */
USBD_IDX_SERIAL_STR, /* Index of serial number string */
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
}; /* USB_DeviceDescriptor */
/* USB Standard Device Descriptor */
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
__ALIGN_BEGIN static uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
USB_LEN_LANGID_STR_DESC,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING),
};
static uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
{
USB_SIZ_STRING_SERIAL,
USB_DESC_TYPE_STRING,
};
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
__ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
/* Private functions ---------------------------------------------------------*/
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
static void Get_SerialNum(void);
#ifdef USBD_USE_HID_COMPOSITE
/**
* @brief Returns the device descriptor.
* @param speed: Current device speed
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
*length = sizeof(USBD_DeviceDesc);
return (uint8_t*)USBD_DeviceDesc;
}
/**
* @brief Returns the LangID string descriptor.
* @param speed: Current device speed
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
*length = sizeof(USBD_LangIDDesc);
return (uint8_t*)USBD_LangIDDesc;
}
/**
* @brief Returns the product string descriptor.
* @param speed: Current device speed
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_HID_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == USBD_SPEED_HIGH)
{
USBD_GetString((uint8_t *)USBD_HID_PRODUCT_HS_STRING, USBD_StrDesc, length);
}
else
{
USBD_GetString((uint8_t *)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length);
}
return USBD_StrDesc;
}
/**
* @brief Returns the manufacturer string descriptor.
* @param speed: Current device speed
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief Returns the serial number string descriptor.
* @param speed: Current device speed
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
*length = USB_SIZ_STRING_SERIAL;
/* Update the serial number string descriptor with the data from the unique ID*/
Get_SerialNum();
return (uint8_t*)USBD_StringSerial;
}
/**
* @brief Returns the configuration string descriptor.
* @param speed: Current device speed
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == USBD_SPEED_HIGH)
{
USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
}
else
{
USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
}
return USBD_StrDesc;
}
/**
* @brief Returns the interface string descriptor.
* @param speed: Current device speed
* @param length: Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == USBD_SPEED_HIGH)
{
USBD_GetString((uint8_t *)USBD_HID_INTERFACE_HS_STRING, USBD_StrDesc, length);
}
else
{
USBD_GetString((uint8_t *)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length);
}
return USBD_StrDesc;
}
#endif //USBD_USE_HID_COMPOSITE
/**
* @brief Create the serial number string descriptor
* @param None
* @retval None
*/
static void Get_SerialNum(void)
{
uint32_t deviceserial0, deviceserial1, deviceserial2;
deviceserial0 = *(uint32_t*)DEVICE_ID1;
deviceserial1 = *(uint32_t*)DEVICE_ID2;
deviceserial2 = *(uint32_t*)DEVICE_ID3;
deviceserial0 += deviceserial2;
if (deviceserial0 != 0)
{
IntToUnicode (deviceserial0, (uint8_t*)&USBD_StringSerial[2] ,8);
IntToUnicode (deviceserial1, (uint8_t*)&USBD_StringSerial[18] ,4);
}
}
/**
* @brief Convert Hex 32Bits value into char
* @param value: value to convert
* @param pbuf: pointer to the buffer
* @param len: buffer length
* @retval None
*/
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
{
uint8_t idx = 0;
for( idx = 0 ; idx < len ; idx ++)
{
if( ((value >> 28)) < 0xA )
{
pbuf[ 2* idx] = (value >> 28) + '0';
}
else
{
pbuf[2* idx] = (value >> 28) + 'A' - 10;
}
value = value << 4;
pbuf[ 2* idx + 1] = 0;
}
}
#endif // USBCON
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/95287.c | #include <stdio.h>
#include <stdlib.h>
int fibo(int n)
{
if (n == 0 || n == 1)
return 1;
return fibo(n - 1) + fibo(n - 2);
}
int main()
{
int n;
printf("Unesite n: ");
scanf("%d", &n);
printf("%d-ti element Finacijevog niza je: %d", n, fibo(n - 1));
return 0;
}
|
the_stack_data/115832.c | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
double
getdetlatimeofday(struct timeval *begin, struct timeval *end)
{
return (end->tv_sec + end->tv_usec * 1.0 / 1000000) -
(begin->tv_sec + begin->tv_usec * 1.0 / 1000000);
}
int main(int argc, char *argv[])
{
int fd;
long i, size, count, sum, n;
char *buf;
size_t len;
struct timeval begin, end;
struct sockaddr_un un;
if (argc != 3)
{
printf("usage: ./udsd <size> <count>\n");
return 1;
}
size = atoi(argv[1]);
count = atoi(argv[2]);
buf = malloc(size);
memset(&un, 0, sizeof(un));
if (fork() == 0)
{
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
unlink("./udsd-ipc");
un.sun_family = AF_UNIX;
strcpy(un.sun_path, "./udsd-ipc");
len = offsetof(struct sockaddr_un, sun_path) + strlen("./udsd-ipc");
if (bind(fd, (struct sockaddr *)&un, len) == -1)
{
perror("bind");
return 1;
}
sum = 0;
for (i = 0; i < count; i++) {
n = recvfrom(fd, buf, size, 0,NULL,NULL);
if (n == 0)
{
break;
}
else if (n == -1)
{
perror("read");
return 1;
}
sum += n;
}
if (sum != count * size)
{
fprintf(stderr, "sum error: %ld != %ld\n", sum, count * size);
return 1;
}
}
else
{
sleep(1);
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
un.sun_family = AF_UNIX;
strcpy(un.sun_path, "./udsd-ipc");
len = offsetof(struct sockaddr_un, sun_path) + strlen("./udsd-ipc");
gettimeofday(&begin, NULL);
for (i = 0; i < count; i++)
{
if (sendto(fd, buf, size, 0, (struct sockaddr *)&un, len) != size) {
perror("sendto");
return 1;
}
}
gettimeofday(&end, NULL);
double tm = getdetlatimeofday(&begin, &end);
printf("duration %lf\n", tm);
printf("%.0fMB/s %.0fMbps %.0fmsg/s\n",
(long)count * size * 1.0 / (tm * 1024 * 1024),
(long)count * size * 1.0 * 8 / (tm * 1024 * 1024),
count * 1.0 / tm);
}
return 0;
}
|
the_stack_data/74449.c | /*
* Copyright (c) 2021 Synopsys.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifdef CONFIG_MULTITHREADING
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/mutex.h>
#include <zephyr/logging/log.h>
#include <../lib/src/c/inc/internal/thread.h>
#ifndef CONFIG_USERSPACE
#define ARCMWDT_DYN_LOCK_SZ (sizeof(struct k_mutex))
#define ARCMWDT_MAX_DYN_LOCKS 10
K_MEM_SLAB_DEFINE(z_arcmwdt_lock_slab, ARCMWDT_DYN_LOCK_SZ, ARCMWDT_MAX_DYN_LOCKS, sizeof(void *));
#endif /* !CONFIG_USERSPACE */
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
void _mwmutex_create(_lock_t *mutex_ptr)
{
bool alloc_fail;
#ifdef CONFIG_USERSPACE
*mutex_ptr = k_object_alloc(K_OBJ_MUTEX);
alloc_fail = (*mutex_ptr == NULL);
#else
alloc_fail = !!k_mem_slab_alloc(&z_arcmwdt_lock_slab, mutex_ptr, K_NO_WAIT);
#endif /* CONFIG_USERSPACE */
if (alloc_fail) {
LOG_ERR("MWDT lock allocation failed");
k_panic();
}
k_mutex_init((struct k_mutex *)*mutex_ptr);
}
void _mwmutex_delete(_lock_t *mutex_ptr)
{
__ASSERT_NO_MSG(mutex_ptr != NULL);
#ifdef CONFIG_USERSPACE
k_object_release(mutex_ptr);
#else
k_mem_slab_free(&z_arcmwdt_lock_slab, mutex_ptr);
#endif /* CONFIG_USERSPACE */
}
void _mwmutex_lock(_lock_t mutex)
{
__ASSERT_NO_MSG(mutex != NULL);
k_mutex_lock((struct k_mutex *)mutex, K_FOREVER);
}
void _mwmutex_unlock(_lock_t mutex)
{
__ASSERT_NO_MSG(mutex != NULL);
k_mutex_unlock((struct k_mutex *)mutex);
}
#endif /* CONFIG_MULTITHREADING */
|
the_stack_data/40761985.c | //
// author: Michael Brockus
// gmail : <[email protected]>
//
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
//
// The calloc() function allocates memory much like malloc()
// function except the following differences:
//
// (1) When you call the calloc() function, you need to pass 2
// parameters: the first one specify the number of elements
// and the second one specify the size of each element. The
// product of these parameters determines the size of the
// memory block is allocated.
//
// (2) The memory block allocated by the calloc() function is
// initialized to zero.
//
// The following example demonstrates how to use the
// calloc() function to allocate memory for a dynamic
// array:
//
int *arr, *pa;
int size;
puts("Enter the size of the array:");
scanf("%i", &size);
arr = (int *)calloc(size, sizeof(int));
if (arr == NULL)
{
fprintf(stderr, "%s\n", "error occurred: out of memory");
return EXIT_FAILURE;
}
pa = arr;
for (unsigned int index = 0; index < size; ++index)
{
*pa++ = rand();
}
for (unsigned int index = 0; index < size; ++index)
{
printf("a[%d] = %d\n", index, *(arr + index));
}
free(arr);
return EXIT_SUCCESS;
} // end of function main
|
the_stack_data/156393305.c |
#include <stdio.h>
void scilab_rt_contour_i2i2d2d0d0d0s0i2i2d0_(int in00, int in01, int matrixin0[in00][in01],
int in10, int in11, int matrixin1[in10][in11],
int in20, int in21, double matrixin2[in20][in21],
double scalarin0,
double scalarin1,
double scalarin2,
char* scalarin3,
int in30, int in31, int matrixin3[in30][in31],
int in40, int in41, int matrixin4[in40][in41],
double scalarin4)
{
int i;
int j;
int val0 = 0;
int val1 = 0;
double val2 = 0;
int val3 = 0;
int val4 = 0;
for (i = 0; i < in00; ++i) {
for (j = 0; j < in01; ++j) {
val0 += matrixin0[i][j];
}
}
printf("%d", val0);
for (i = 0; i < in10; ++i) {
for (j = 0; j < in11; ++j) {
val1 += matrixin1[i][j];
}
}
printf("%d", val1);
for (i = 0; i < in20; ++i) {
for (j = 0; j < in21; ++j) {
val2 += matrixin2[i][j];
}
}
printf("%f", val2);
printf("%f", scalarin0);
printf("%f", scalarin1);
printf("%f", scalarin2);
printf("%s", scalarin3);
for (i = 0; i < in30; ++i) {
for (j = 0; j < in31; ++j) {
val3 += matrixin3[i][j];
}
}
printf("%d", val3);
for (i = 0; i < in40; ++i) {
for (j = 0; j < in41; ++j) {
val4 += matrixin4[i][j];
}
}
printf("%d", val4);
printf("%f", scalarin4);
}
|
the_stack_data/52087.c |
/* { dg-do compile } */
/* { dg-options "-Wuninitialized -O2" } */
int g;
void bar();
void blah(int);
int foo (int n, int l, int m, int r)
{
int v;
if (n > 10)
v = r;
if (m) g++;
else bar();
if ( (n > 10) && (l < 100))
blah(v); /* { dg-bogus "uninitialized" "bogus warning" } */
if ( n > 100 )
blah(v); /* { dg-bogus "uninitialized" "bogus warning" } */
return 0;
}
int foo_2 (int n, int l, int m, int r)
{
int v;
if (n > 10)
v = r;
if (m) g++;
else bar();
if ( n < 10)
blah (v); /* { dg-warning "uninitialized" "warning" } */
return 0;
}
|
the_stack_data/179831684.c | /* This file was automatically generated by CasADi.
The CasADi copyright holders make no ownership claim of its contents. */
#ifdef __cplusplus
extern "C" {
#endif
/* How to prefix internal symbols */
#ifdef CASADI_CODEGEN_PREFIX
#define CASADI_NAMESPACE_CONCAT(NS, ID) _CASADI_NAMESPACE_CONCAT(NS, ID)
#define _CASADI_NAMESPACE_CONCAT(NS, ID) NS ## ID
#define CASADI_PREFIX(ID) CASADI_NAMESPACE_CONCAT(CODEGEN_PREFIX, ID)
#else
#define CASADI_PREFIX(ID) long_cost_y_fun_jac_ut_xt_ ## ID
#endif
#include <math.h>
#ifndef casadi_real
#define casadi_real double
#endif
#ifndef casadi_int
#define casadi_int int
#endif
/* Add prefix to internal symbols */
#define casadi_f0 CASADI_PREFIX(f0)
#define casadi_s0 CASADI_PREFIX(s0)
#define casadi_s1 CASADI_PREFIX(s1)
#define casadi_s2 CASADI_PREFIX(s2)
#define casadi_s3 CASADI_PREFIX(s3)
#define casadi_s4 CASADI_PREFIX(s4)
#define casadi_sq CASADI_PREFIX(sq)
/* Symbol visibility in DLLs */
#ifndef CASADI_SYMBOL_EXPORT
#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#if defined(STATIC_LINKED)
#define CASADI_SYMBOL_EXPORT
#else
#define CASADI_SYMBOL_EXPORT __declspec(dllexport)
#endif
#elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
#define CASADI_SYMBOL_EXPORT __attribute__ ((visibility ("default")))
#else
#define CASADI_SYMBOL_EXPORT
#endif
#endif
casadi_real casadi_sq(casadi_real x) { return x*x;}
static const casadi_int casadi_s0[7] = {3, 1, 0, 3, 0, 1, 2};
static const casadi_int casadi_s1[5] = {1, 1, 0, 1, 0};
static const casadi_int casadi_s2[9] = {5, 1, 0, 5, 0, 1, 2, 3, 4};
static const casadi_int casadi_s3[10] = {6, 1, 0, 6, 0, 1, 2, 3, 4, 5};
static const casadi_int casadi_s4[16] = {4, 6, 0, 2, 3, 4, 5, 6, 7, 1, 2, 1, 2, 3, 3, 0};
/* long_cost_y_fun_jac_ut_xt:(i0[3],i1,i2[5])->(o0[6],o1[4x6,7nz]) */
static int casadi_f0(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem) {
casadi_real a0, a1, a2, a3, a4, a5, a6;
a0=arg[2]? arg[2][2] : 0;
a1=arg[0]? arg[0][0] : 0;
a0=(a0-a1);
a2=2.;
a3=arg[2]? arg[2][4] : 0;
a2=(a2*a3);
a3=arg[0]? arg[0][1] : 0;
a4=(a2*a3);
a5=casadi_sq(a3);
a6=1.9620000000000001e+01;
a5=(a5/a6);
a4=(a4+a5);
a5=4.;
a4=(a4+a5);
a0=(a0-a4);
a4=10.;
a4=(a3+a4);
a0=(a0/a4);
if (res[0]!=0) res[0][0]=a0;
if (res[0]!=0) res[0][1]=a1;
if (res[0]!=0) res[0][2]=a3;
a1=arg[0]? arg[0][2] : 0;
if (res[0]!=0) res[0][3]=a1;
a5=20.;
a6=arg[2]? arg[2][3] : 0;
a1=(a1-a6);
a1=(a5*a1);
if (res[0]!=0) res[0][4]=a1;
a1=arg[1]? arg[1][0] : 0;
if (res[0]!=0) res[0][5]=a1;
a1=(1./a4);
a1=(-a1);
if (res[1]!=0) res[1][0]=a1;
a1=5.0968399592252800e-02;
a3=(a3+a3);
a1=(a1*a3);
a2=(a2+a1);
a2=(a2/a4);
a0=(a0/a4);
a2=(a2+a0);
a2=(-a2);
if (res[1]!=0) res[1][1]=a2;
a2=1.;
if (res[1]!=0) res[1][2]=a2;
if (res[1]!=0) res[1][3]=a2;
if (res[1]!=0) res[1][4]=a2;
if (res[1]!=0) res[1][5]=a5;
if (res[1]!=0) res[1][6]=a2;
return 0;
}
CASADI_SYMBOL_EXPORT int long_cost_y_fun_jac_ut_xt(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem){
return casadi_f0(arg, res, iw, w, mem);
}
CASADI_SYMBOL_EXPORT int long_cost_y_fun_jac_ut_xt_alloc_mem(void) {
return 0;
}
CASADI_SYMBOL_EXPORT int long_cost_y_fun_jac_ut_xt_init_mem(int mem) {
return 0;
}
CASADI_SYMBOL_EXPORT void long_cost_y_fun_jac_ut_xt_free_mem(int mem) {
}
CASADI_SYMBOL_EXPORT int long_cost_y_fun_jac_ut_xt_checkout(void) {
return 0;
}
CASADI_SYMBOL_EXPORT void long_cost_y_fun_jac_ut_xt_release(int mem) {
}
CASADI_SYMBOL_EXPORT void long_cost_y_fun_jac_ut_xt_incref(void) {
}
CASADI_SYMBOL_EXPORT void long_cost_y_fun_jac_ut_xt_decref(void) {
}
CASADI_SYMBOL_EXPORT casadi_int long_cost_y_fun_jac_ut_xt_n_in(void) { return 3;}
CASADI_SYMBOL_EXPORT casadi_int long_cost_y_fun_jac_ut_xt_n_out(void) { return 2;}
CASADI_SYMBOL_EXPORT casadi_real long_cost_y_fun_jac_ut_xt_default_in(casadi_int i){
switch (i) {
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const char* long_cost_y_fun_jac_ut_xt_name_in(casadi_int i){
switch (i) {
case 0: return "i0";
case 1: return "i1";
case 2: return "i2";
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const char* long_cost_y_fun_jac_ut_xt_name_out(casadi_int i){
switch (i) {
case 0: return "o0";
case 1: return "o1";
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const casadi_int* long_cost_y_fun_jac_ut_xt_sparsity_in(casadi_int i) {
switch (i) {
case 0: return casadi_s0;
case 1: return casadi_s1;
case 2: return casadi_s2;
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const casadi_int* long_cost_y_fun_jac_ut_xt_sparsity_out(casadi_int i) {
switch (i) {
case 0: return casadi_s3;
case 1: return casadi_s4;
default: return 0;
}
}
CASADI_SYMBOL_EXPORT int long_cost_y_fun_jac_ut_xt_work(casadi_int *sz_arg, casadi_int* sz_res, casadi_int *sz_iw, casadi_int *sz_w) {
if (sz_arg) *sz_arg = 3;
if (sz_res) *sz_res = 2;
if (sz_iw) *sz_iw = 0;
if (sz_w) *sz_w = 0;
return 0;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
|
the_stack_data/170451762.c | // Arduino Signal Filtering Library
// Copyright 2012-2013 Jeroen Doggen ([email protected])
// filterCalculate.c - small test program to verify some filter calculations
#include <stdio.h>
/* Convert an int to it's binary representation
Source: http://stackoverflow.com/questions/111928/is-there-a-printf-converter-to-print-in-binary-format
*/
int tmp, data;
int _v[2];
char *int2bin(int num, int pad)
{
char *str = malloc(sizeof(char) * (pad+1));
if (str) {
str[pad]='\0';
while (--pad>=0) {
str[pad] = num & 1 ? '1' : '0';
num >>= 1;
}
} else {
return "";
}
return str;
}
void printAndCalculate(int data)
{
printf("Incoming data: %d\n",data);
printf("Previous samples: %d, %d, %d \n",_v[0],_v[1],_v[2]);
tmp = (data * 662828L);
printf("tmp1: %d \n",tmp); //tmp=662828
printf("tmp1: %s \n",int2bin(tmp, 32)); //tmp=662828
tmp = ((data * 662828L) >> 4);
printf("tmp2: %d \n",tmp); //tmp=41426
printf("tmp2: %s \n",int2bin(tmp, 32)); //tmp=662828L
tmp = ((((data * 662828L) >> 4) + ((_v[0] * -540791L) >> 1) + (_v[1] * 628977L))+262144);
printf("tmp3: %d \n",tmp); //tmp=303570
printf("tmp3: %s \n",int2bin(tmp, 32)); //tmp=662828L
tmp = ((((data * 662828L) >> 4) + ((_v[0] * -540791L) >> 1) + (_v[1] * 628977L))+262144) >> 19;
printf("tmp4: %d \n",tmp); //tmp=0
printf("tmp4: %s \n\n",int2bin(tmp, 32)); //tmp=662828L
}
void main()
{
_v[0]=0;
_v[1]=0;
_v[2]=0;
printAndCalculate(1);
printAndCalculate(512);
printAndCalculate(1023);
_v[0]=1023;
_v[1]=1023;
_v[2]=1023;
printAndCalculate(1);
printAndCalculate(512);
printAndCalculate(1023);
}
|
the_stack_data/432729.c | #include <stdio.h>
int main(void) {
int numero;
printf("Digite um numero \n");
scanf("%d",&numero);
if(numero >= 0 && numero <= 100){
printf("Numero encontrado entre 0 e 100");
}else{
printf("Numero invalido");
}
return 0;
} |
the_stack_data/165769428.c | // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
struct p {
char a;
int b;
} __attribute__ ((packed));
struct p t = { 1, 10 };
struct p u;
int main () {
// CHECK: align 1
// CHECK: align 1
int tmp = t.b;
u.b = tmp;
return tmp;
}
|
the_stack_data/67324016.c | //
// Created by j on 19-1-4.
//
/* convert.c -- 自动类型转换 */
#include <stdio.h>
int main(void) {
char ch;
int i;
float fl;
fl = i = ch = 'C';
printf("ch = %c, i = %d, fl = %2.2f\n",ch,i,fl);
ch = ch + 1;
i = fl + 2 * ch;
fl = 2.0 * ch + i;
printf("ch = %c, i = %d, fl = %2.2f\n",ch,i,fl);
ch = 5212205.17;
printf("Now ch = %c\n",ch);
return 0;
}
|
the_stack_data/117328297.c | #include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
int l;
void squeeze(char *s) {
int i=0;
while (s[i] != '\0') {
if (s[i]==' ' || s[i]=='\t' || s[i]=='\n') {
i=i+1;
while (s[i]==' ' || s[i]=='\t' || s[i]=='\n') {
s[i] = s[i+1];
i=i+1;
}
}
i = i+1;
}
}
int fibb(long int n){
if(n>2) return fibb(n-1)*fibb(n-2)*fibb(n-3);
return 1;
}
long unsigned int* readFromFile(FILE *ptr){
//char* str = (char*)malloc(sizeof(char)*6000);
int i=0;
long unsigned int input;
long unsigned int* arr = (long unsigned int*)malloc(sizeof(long unsigned int)*10);
while(fscanf(ptr, "%lu", &input)==1){
arr[i]=input;
i++;
}
l=i;
return arr;
}
int main(void){
struct timeval t1, t2;
double time;
FILE *ptr = fopen("input.txt","r");
FILE *ptw = fopen("force.dat","w");
long unsigned int *arr = readFromFile(ptr);
printf("%d\n", l);
for(int i=0; i<l;i++){
gettimeofday(&t1, NULL);
fibb(arr[i]);
gettimeofday(&t2, NULL);
time=((t2.tv_sec-t1.tv_sec)*1000.0);
time+=((t2.tv_usec-t1.tv_usec)/1000.0);
fprintf(ptw , "%lu \t\t\t\t\t\t\t\t %f \n", arr[i], time);
}
}
|
the_stack_data/1254142.c | #ifdef HW_RVL
#include <gccore.h>
#include <ogc/usb.h>
#define USB_CLASS_XBOX360 0xFF
#define XBOX360_VID 0x045e
#define XBOX360_PID 0x028e
static bool setup = false;
static bool replugRequired = false;
static s32 deviceId = 0;
static u8 endpoint_in = 0x81;
static u8 endpoint_out = 0x01; // some controllers require 0x02 (updated below)
static u8 bMaxPacketSize = 20;
static u8 bConfigurationValue = 1;
static u8 ATTRIBUTE_ALIGN(32) buf[20];
static bool isReading = false;
static u32 jp = 0;
static u8 player = 0;
static u32 xboxButtonCount = 0;
static bool nextPlayer = false;
static u8 getEndpoint(usb_devdesc devdesc)
{
if (devdesc.configurations == NULL || devdesc.configurations->interfaces == NULL ||
devdesc.configurations->interfaces->endpoints == NULL)
{
return -1;
}
return devdesc.configurations->interfaces->endpoints->bEndpointAddress;
}
static bool isXBOX360(usb_device_entry dev)
{
return dev.vid == XBOX360_VID && dev.pid == XBOX360_PID;
}
static bool isXBOX360Gamepad(usb_devdesc devdesc)
{
return devdesc.idVendor == XBOX360_VID && devdesc.idProduct == XBOX360_PID && getEndpoint(devdesc) == endpoint_in;
}
static int read(s32 device_id, u8 endpoint, u8 bMaxPacketSize0);
static void start_reading(s32 device_id, u8 endpoint, u8 bMaxPacketSize0)
{
if (isReading)
{
// already reading
return;
}
isReading = true;
read(deviceId, endpoint_in, bMaxPacketSize0);
}
static void stop_reading()
{
isReading = false;
}
static int read_cb(int res, void *usrdata)
{
if (!isReading)
{
// stop reading
return 1;
}
// NOTE: The four startup messages have res = 3 and can be ignored
// Button layout
// A=3,10
// B=3,20
// X=3,40
// Y=3,80
// Up=2,01
// Right=2,08
// Left=2,04
// Down=2,02
// L=3,01
// R=3,02
// L2=4,FF ; analog trigger
// R3=5,FF ; analog trigger
// L3=2,40 ; left hat button
// L3=2,80 ; right hat button
// XBOX=3,04
// Start=2,10
// Back=2,20
// LStickX=6/7,FF ; <low byte>,<high byte>
// LStickY=8/9,FF
// RStickX=10/11,FF
// RStickY=12/13,FF
if (res == 20)
{
jp = 0;
jp |= ((buf[2] & 0x01) == 0x01) ? PAD_BUTTON_UP : 0;
jp |= ((buf[2] & 0x02) == 0x02) ? PAD_BUTTON_DOWN : 0;
jp |= ((buf[2] & 0x04) == 0x04) ? PAD_BUTTON_LEFT : 0;
jp |= ((buf[2] & 0x08) == 0x08) ? PAD_BUTTON_RIGHT : 0;
jp |= ((buf[3] & 0x10) == 0x10) ? PAD_BUTTON_B : 0; // XBOX360 A button maps to B
jp |= ((buf[3] & 0x20) == 0x20) ? PAD_BUTTON_A : 0; // XBOX360 B button maps to A
jp |= ((buf[3] & 0x40) == 0x40) ? PAD_BUTTON_Y : 0; // XBOX360 X button maps to Y
jp |= ((buf[3] & 0x80) == 0x80) ? PAD_BUTTON_X : 0; // XBOX360 Y button maps to X
jp |= ((buf[3] & 0x01) == 0x01) ? PAD_TRIGGER_L : 0;
jp |= ((buf[3] & 0x02) == 0x02) ? PAD_TRIGGER_R : 0;
jp |= ((buf[2] & 0x10) == 0x10) ? PAD_BUTTON_START : 0;
jp |= ((buf[2] & 0x20) == 0x20) ? PAD_TRIGGER_Z : 0; // XBOX360 back button maps to Z
// triggers
jp |= (buf[4] > 128) ? PAD_TRIGGER_L : 0;
jp |= (buf[5] > 128) ? PAD_TRIGGER_R : 0;
// left stick
int16_t lx = (buf[7] << 8) | buf[6]; // [-32768, 32767]
int16_t ly = (buf[9] << 8) | buf[8]; // [-32768, 32767]
jp |= (ly > 16384) ? PAD_BUTTON_UP : 0;
jp |= (ly < -16384) ? PAD_BUTTON_DOWN : 0;
jp |= (lx < -16384) ? PAD_BUTTON_LEFT : 0;
jp |= (lx > 16384) ? PAD_BUTTON_RIGHT : 0;
// right stick
int16_t rx = (buf[11] << 8) | buf[10]; // [-32768, 32767]
int16_t ry = (buf[13] << 8) | buf[12]; // [-32768, 32767]
jp |= (ry > 16384) ? PAD_BUTTON_UP : 0;
jp |= (ry < -16384) ? PAD_BUTTON_DOWN : 0;
jp |= (rx < -16384) ? PAD_BUTTON_LEFT : 0;
jp |= (rx > 16384) ? PAD_BUTTON_RIGHT : 0;
// XBOX button to switch to next player
if ((buf[3] & 0x04) == 0x04)
{
xboxButtonCount++;
// count = 2 means you have to push the button 1x to switch players
// count = 10 means you have to push the button 5x to switch players
if (xboxButtonCount >= 2)
{
nextPlayer = true;
xboxButtonCount = 0;
}
}
}
// read again
read(deviceId, endpoint_in, bMaxPacketSize);
return 1;
}
// never call directly
static int read(s32 device_id, u8 endpoint, u8 bMaxPacketSize0)
{
// need to use async, because USB_ReadIntrMsg() blocks until a button is pressed
return USB_ReadIntrMsgAsync(device_id, endpoint, sizeof(buf), buf, &read_cb, NULL);
}
static void turnOnLED()
{
uint8_t ATTRIBUTE_ALIGN(32) buf[] = { 0x01, 0x03, 0x06 + player };
USB_WriteIntrMsg(deviceId, endpoint_out, sizeof(buf), buf);
}
static void increasePlayer()
{
player++;
if (player > 3)
{
player = 0;
}
turnOnLED();
}
void rumble(s32 device_id, u8 left, u8 right)
{
uint8_t ATTRIBUTE_ALIGN(32) buf[] = { 0x00, 0x08, 0x00, left, right, 0x00, 0x00, 0x00 };
USB_WriteIntrMsg(deviceId, endpoint_out, sizeof(buf), buf);
}
static int removal_cb(int result, void *usrdata)
{
s32 fd = (s32) usrdata;
if (fd == deviceId)
{
stop_reading();
deviceId = 0;
}
return 1;
}
// adapted from RetroArch input/drivers_hid/wiiusb_hid.c#wiiusb_get_description()
void wiiusb_get_description(usb_device_entry *device, usb_devdesc *devdesc)
{
unsigned char c;
unsigned i, k;
for (c = 0; c < devdesc->bNumConfigurations; c++)
{
const usb_configurationdesc *config = &devdesc->configurations[c];
for (i = 0; i < (int)config->bNumInterfaces; i++)
{
const usb_interfacedesc *inter = &config->interfaces[i];
for (k = 0; k < (int)inter->bNumEndpoints; k++)
{
const usb_endpointdesc *epdesc = &inter->endpoints[k];
bool is_int = (epdesc->bmAttributes & 0x03) == USB_ENDPOINT_INTERRUPT;
bool is_out = (epdesc->bEndpointAddress & 0x80) == USB_ENDPOINT_OUT;
bool is_in = (epdesc->bEndpointAddress & 0x80) == USB_ENDPOINT_IN;
if (is_int)
{
if (is_in)
{
//endpoint_in = epdesc->bEndpointAddress;
//endpoint_in_max_size = epdesc->wMaxPacketSize;
}
if (is_out)
{
endpoint_out = epdesc->bEndpointAddress;
//endpoint_out_max_size = epdesc->wMaxPacketSize;
}
}
}
break;
}
}
}
static void open()
{
if (deviceId != 0)
{
return;
}
usb_device_entry dev_entry[8];
u8 dev_count;
if (USB_GetDeviceList(dev_entry, 8, USB_CLASS_XBOX360, &dev_count) < 0)
{
return;
}
for (int i = 0; i < dev_count; ++i)
{
if (!isXBOX360(dev_entry[i]))
{
continue;
}
s32 fd;
if (USB_OpenDevice(dev_entry[i].device_id, dev_entry[i].vid, dev_entry[i].pid, &fd) < 0)
{
continue;
}
usb_devdesc devdesc;
if (USB_GetDescriptors(fd, &devdesc) < 0)
{
// You have to replug the XBOX360 controller!
replugRequired = true;
USB_CloseDevice(&fd);
break;
}
if (isXBOX360Gamepad(devdesc) && USB_SetConfiguration(fd, bConfigurationValue) >= 0)
{
deviceId = fd;
replugRequired = false;
wiiusb_get_description(&dev_entry[i], &devdesc);
turnOnLED();
USB_DeviceRemovalNotifyAsync(fd, &removal_cb, (void*) fd);
break;
}
else
{
USB_CloseDevice(&fd);
}
}
setup = true;
}
void XBOX360_ScanPads()
{
if (deviceId == 0)
{
return;
}
start_reading(deviceId, endpoint_in, bMaxPacketSize);
}
u32 XBOX360_ButtonsHeld(int chan)
{
if(!setup)
{
open();
}
if (deviceId == 0)
{
return 0;
}
if (nextPlayer)
{
nextPlayer = false;
increasePlayer();
}
if (chan != player)
{
return 0;
}
return jp;
}
char* XBOX360_Status()
{
open();
if (replugRequired)
return "please replug";
return deviceId ? "connected" : "not found";
}
#endif
|
the_stack_data/61076005.c | /* File: mp-lock.c
*
* Purpose: A parallel program that uses OpenMP lock
*
* Compile: gcc -g -Wall -fopenmp mp-lock.c -o mp-lock
* Run: ./mp-lock
*
* Input:
* Output:
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
/*--------------------------------------------------------------------*/
/* main */
/*--------------------------------------------------------------------*/
int main(int argc, char* argv[]) {
int sumx = 1;
int sumy = 2;
omp_lock_t lock;
omp_init_lock(&lock);
# pragma omp parallel num_threads(4) shared(sumx,sumy)
{
omp_set_lock(&lock);
sumx += omp_get_thread_num();
sumy += omp_get_thread_num();
omp_unset_lock(&lock);
}
printf("sumx = %d, sumy = %d\n",sumx,sumy);
omp_destroy_lock(&lock);
return 0;
}
|
the_stack_data/24801.c | // calculating e^x , x and n (no. of terms)
#include <stdio.h>
int main()
{
int n;
double x;
scanf("%d", &n);
scanf("%lf", &x);
double sum = 1.00;
double temp = 1;
// e^x
for (int i = 1; i <= n; i++)
{
temp = (temp * x * 1.00) / (i * 1.0);
sum += temp;
}
printf("%.8lf\n", sum);
} |
the_stack_data/69856.c | typedef unsigned int uint;
double bittruncate(double sum, uint nbits);
double do_sum_omp_wbittrunc(double* restrict var, long ncells, uint nbits)
{
// Serial sum
double sum = 0.0;
#pragma omp parallel for reduction(+: sum)
for (long i = 0; i < ncells; i++){
sum += var[i];
}
sum = bittruncate(sum, nbits);
return(sum);
}
|
the_stack_data/25137640.c | #include <stdio.h>
int main()
{
int a, n, soma = 0;
scanf("%d %d", &a, &n);
while(n <= 0)
scanf("%d", &n);
for(int i = 0; i <= n - 1; i++)
{
soma += a + i;
}
printf("%d\n", soma);
return 0;
}
|
the_stack_data/173577081.c | #if TEST___PROGNAME
int
main(void)
{
extern char *__progname;
return !__progname;
}
#endif /* TEST___PROGNAME */
#if TEST_ARC4RANDOM
#include <stdlib.h>
int
main(void)
{
return (arc4random() + 1) ? 0 : 1;
}
#endif /* TEST_ARC4RANDOM */
#if TEST_B64_NTOP
#include <netinet/in.h>
#include <resolv.h>
int
main(void)
{
const char *src = "hello world";
char output[1024];
return b64_ntop((const unsigned char *)src, 11, output, sizeof(output)) > 0 ? 0 : 1;
}
#endif /* TEST_B64_NTOP */
#if TEST_CAPSICUM
#include <sys/capsicum.h>
int
main(void)
{
cap_enter();
return(0);
}
#endif /* TEST_CAPSICUM */
#if TEST_ERR
/*
* Copyright (c) 2015 Ingo Schwarze <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <err.h>
int
main(void)
{
warnx("%d. warnx", 1);
warn("%d. warn", 2);
err(0, "%d. err", 3);
/* NOTREACHED */
return 1;
}
#endif /* TEST_ERR */
#if TEST_EXPLICIT_BZERO
#include <string.h>
int
main(void)
{
char foo[10];
explicit_bzero(foo, sizeof(foo));
return(0);
}
#endif /* TEST_EXPLICIT_BZERO */
#if TEST_GETPROGNAME
#include <stdlib.h>
int
main(void)
{
const char * progname;
progname = getprogname();
return progname == NULL;
}
#endif /* TEST_GETPROGNAME */
#if TEST_INFTIM
/*
* Linux doesn't (always?) have this.
*/
#include <poll.h>
#include <stdio.h>
int
main(void)
{
printf("INFTIM is defined to be %ld\n", (long)INFTIM);
return 0;
}
#endif /* TEST_INFTIM */
#if TEST_MD5
#include <sys/types.h>
#include <md5.h>
int main(void)
{
MD5_CTX ctx;
MD5Init(&ctx);
MD5Update(&ctx, "abcd", 4);
return 0;
}
#endif /* TEST_MD5 */
#if TEST_MEMMEM
#define _GNU_SOURCE
#include <string.h>
int
main(void)
{
char *a = memmem("hello, world", strlen("hello, world"), "world", strlen("world"));
return(NULL == a);
}
#endif /* TEST_MEMMEM */
#if TEST_MEMRCHR
#if defined(__linux__) || defined(__MINT__)
#define _GNU_SOURCE /* See test-*.c what needs this. */
#endif
#include <string.h>
int
main(void)
{
const char *buf = "abcdef";
void *res;
res = memrchr(buf, 'a', strlen(buf));
return(NULL == res ? 1 : 0);
}
#endif /* TEST_MEMRCHR */
#if TEST_MEMSET_S
#include <string.h>
int main(void)
{
char buf[10];
memset_s(buf, 0, 'c', sizeof(buf));
return 0;
}
#endif /* TEST_MEMSET_S */
#if TEST_PATH_MAX
/*
* POSIX allows PATH_MAX to not be defined, see
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html;
* the GNU Hurd is an example of a system not having it.
*
* Arguably, it would be better to test sysconf(_SC_PATH_MAX),
* but since the individual *.c files include "config.h" before
* <limits.h>, overriding an excessive value of PATH_MAX from
* "config.h" is impossible anyway, so for now, the simplest
* fix is to provide a value only on systems not having any.
* So far, we encountered no system defining PATH_MAX to an
* impractically large value, even though POSIX explicitly
* allows that.
*
* The real fix would be to replace all static buffers of size
* PATH_MAX by dynamically allocated buffers. But that is
* somewhat intrusive because it touches several files and
* because it requires changing struct mlink in mandocdb.c.
* So i'm postponing that for now.
*/
#include <limits.h>
#include <stdio.h>
int
main(void)
{
printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
return 0;
}
#endif /* TEST_PATH_MAX */
#if TEST_PLEDGE
#include <unistd.h>
int
main(void)
{
return !!pledge("stdio", NULL);
}
#endif /* TEST_PLEDGE */
#if TEST_PROGRAM_INVOCATION_SHORT_NAME
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <errno.h>
int
main(void)
{
return !program_invocation_short_name;
}
#endif /* TEST_PROGRAM_INVOCATION_SHORT_NAME */
#if TEST_REALLOCARRAY
#include <stdlib.h>
int
main(void)
{
return !reallocarray(NULL, 2, 2);
}
#endif /* TEST_REALLOCARRAY */
#if TEST_RECALLOCARRAY
#include <stdlib.h>
int
main(void)
{
return !recallocarray(NULL, 0, 2, 2);
}
#endif /* TEST_RECALLOCARRAY */
#if TEST_SANDBOX_INIT
#include <sandbox.h>
int
main(void)
{
char *ep;
int rc;
rc = sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, &ep);
if (-1 == rc)
sandbox_free_error(ep);
return(-1 == rc);
}
#endif /* TEST_SANDBOX_INIT */
#if TEST_SECCOMP_FILTER
#include <sys/prctl.h>
#include <linux/seccomp.h>
#include <errno.h>
int
main(void)
{
prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, 0);
return(EFAULT == errno ? 0 : 1);
}
#endif /* TEST_SECCOMP_FILTER */
#if TEST_SOCK_NONBLOCK
/*
* Linux doesn't (always?) have this.
*/
#include <sys/socket.h>
int
main(void)
{
int fd[2];
socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fd);
return 0;
}
#endif /* TEST_SOCK_NONBLOCK */
#if TEST_STRLCAT
#include <string.h>
int
main(void)
{
char buf[3] = "a";
return ! (strlcat(buf, "b", sizeof(buf)) == 2 &&
buf[0] == 'a' && buf[1] == 'b' && buf[2] == '\0');
}
#endif /* TEST_STRLCAT */
#if TEST_STRLCPY
#include <string.h>
int
main(void)
{
char buf[2] = "";
return ! (strlcpy(buf, "a", sizeof(buf)) == 1 &&
buf[0] == 'a' && buf[1] == '\0');
}
#endif /* TEST_STRLCPY */
#if TEST_STRNDUP
#include <string.h>
int
main(void)
{
const char *foo = "bar";
char *baz;
baz = strndup(foo, 1);
return(0 != strcmp(baz, "b"));
}
#endif /* TEST_STRNDUP */
#if TEST_STRNLEN
#include <string.h>
int
main(void)
{
const char *foo = "bar";
size_t sz;
sz = strnlen(foo, 1);
return(1 != sz);
}
#endif /* TEST_STRNLEN */
#if TEST_STRTONUM
/*
* Copyright (c) 2015 Ingo Schwarze <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
int
main(void)
{
const char *errstr;
if (strtonum("1", 0, 2, &errstr) != 1)
return 1;
if (errstr != NULL)
return 2;
if (strtonum("1x", 0, 2, &errstr) != 0)
return 3;
if (errstr == NULL)
return 4;
if (strtonum("2", 0, 1, &errstr) != 0)
return 5;
if (errstr == NULL)
return 6;
if (strtonum("0", 1, 2, &errstr) != 0)
return 7;
if (errstr == NULL)
return 8;
return 0;
}
#endif /* TEST_STRTONUM */
#if TEST_SYS_QUEUE
#include <sys/queue.h>
struct foo {
int bar;
TAILQ_ENTRY(foo) entries;
};
TAILQ_HEAD(fooq, foo);
int
main(void)
{
struct fooq foo_q;
TAILQ_INIT(&foo_q);
return 0;
}
#endif /* TEST_SYS_QUEUE */
#if TEST_SYSTRACE
#include <sys/param.h>
#include <dev/systrace.h>
#include <stdlib.h>
int
main(void)
{
return(0);
}
#endif /* TEST_SYSTRACE */
#if TEST_ZLIB
#include <stddef.h>
#include <zlib.h>
int
main(void)
{
gzFile gz;
if (NULL == (gz = gzopen("/dev/null", "w")))
return(1);
gzputs(gz, "foo");
gzclose(gz);
return(0);
}
#endif /* TEST_ZLIB */
|
the_stack_data/26552.c | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <mqueue.h>
#define name "/q2uque"
#define MSG_STOP "/0"
#define MAX_SIZE 1000
int main(int argc, char **argv) {
mqd_t mq1;
char buffer[MAX_SIZE];
mq1 = mq_open(name, O_WRONLY|O_CREAT, 0644, NULL);
if (mq1 == -1) {
perror("mq1 error:\n");
exit(1);
}
do {
for (int i=0; i<sizeof(buffer); i++) {
buffer[i] = '\0';
}
printf("Enter some text: ");
fgets(buffer, MAX_SIZE, stdin);
int send = mq_send(mq1, buffer, strlen(buffer)+1, 0);
if (send < 0) {
perror("message:\n");
exit(1);
}
if (strncmp(buffer, "exit", 4) == 0) {
break;
}
} while (1);
return 0;
}
|
the_stack_data/147929.c | /* Copyright 2019-2020 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
int
main ()
{
asm ("main_label: .globl main_label");
return 0;
}
|
the_stack_data/62636927.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2013 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation nor the names of its contributors may be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
END_LEGAL */
/*
* This application is used by the test: "child_process_injection.test"
* This application is used to check the correctness of a successfull Pin injection to a child process.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
pid_t pid = fork();
if (pid == 0)
{
char *childArgvArray[2];
char * s = (char *)("/bin/date");
childArgvArray[0] = (char * )s;
childArgvArray[1] = NULL;
execv(s, childArgvArray);
fprintf(stdout, "%s\n", "Child report: Execve failed ");
}
else
{
int status;
waitpid(pid, &status, 0);
if (status !=0)
fprintf(stdout, "%s%d\n", "Parent report: Child process failed. Status of the child process is "
, WEXITSTATUS(status));
else
fprintf(stdout, "%s\n", "Parent report: Child process exited successfully");
}
return 0;
}
|
the_stack_data/130227.c | /**----------------------------------------------------------------------------\
| Split a string into an array of strings. |
+------------------------------------------------------------------------------+
| Usage: |
| char **strings = explode("Explode me!"); |
| while(*strings) printf("%s\n", *strings++); |
| |
| Result: |
| Explode |
| me! |
+---------+---------+--------+-------------------------------------------------+
| @param | char* | input | string to be turned into an array. |
| @param | char* | delim | Delimiter which will split the string. |
| @return | char** | result | Array of strings. |
\---------+---------+--------+------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* explode() arguments. */
typedef struct {
const char *input;
const char *delim;
} explode_args;
/* explode() macro. */
#define explode(...) explode((explode_args){__VA_ARGS__})
/* explode() function. */
char** (explode)(explode_args arg){
/* Required argument. */
if(!sizeof arg.input) return NULL;
/* Default delimiter argument. */
arg.delim = (arg.delim && arg.delim[0] != '\0') ? arg.delim : " ";
/* Input string is the same as the delimiter. */
if(arg.input == arg.delim) return NULL;
/* Tokenize string. */
char *token = strtok(strdup(arg.input), arg.delim);
/* Build array. */
char **result = malloc(sizeof(*result));
int count = 0;
while(1){
/* Append array with next word. */
result[count++] = token ? strdup(token) : token;
if(!token) break;
/* Get next word. */
token = strtok(NULL, arg.delim);
/* Enlarge array. */
size_t size_new = ((size_t)count + 1) * sizeof(*result);
char **result_new = realloc(result, size_new);
if(result_new == NULL){
printf("Unable to allocate %u bytes at: %p.\n", (int)size_new, (void*)&result);
free(result);
continue;
}
result = result_new;
}
/* Done. */
return result;
}
/**----------------------------------------------------------------------------\
| Example usage. |
\-----------------------------------------------------------------------------*/
#include <unistd.h>
char *readline();
int main(int argc, char **argv){
/* Get a string from the user. */
printf("Please enter a string (or leave blank to show example):\n");
char *input = readline();
/* Remove trailing LF/CRLF. */
size_t length = strlen(input);
while(length && ((input[length - 1] == '\n') || (input[length - 1] == '\r'))){
input[length - 1] = '\0';
length = strlen(input);
}
/* Default string if nothing is entered. */
if(input[0] == '\0'){
input = strdup("Explode me; this is an example of an array of strings made from a single exploded string!");
if(input == NULL){
printf("Unable to allocate memory at: %p.\n", (void*)&input);
return 1;
}
}
/* Get a delimiter from the user. */
printf("Please enter a delimiter (or leave blank to use space):\n");
char *delim = readline();
/* Remove trailing LF/CRLF. */
length = strlen(delim);
while(length && ((delim[length - 1] == '\n') || (delim[length - 1] == '\r'))){
delim[length - 1] = '\0';
length = strlen(delim);
}
/* Explode string. */
char **strings = explode(input, delim);
/* Cleanup. */
if(input[0] != '\0') free(input);
if(delim[0] != '\0') free(delim);
/* Print array of strings. */
int i = 0;
printf("[\n");
do{
/* Output. */
printf(" \"%s\"", strings[i]);
if(strings[i] != '\0') printf(", ");
printf("\n");
/* Cleanup. */
free(strings[i]);
}while(strings[i++] != '\0');
printf("]");
/* Cleanup. */
free(strings);
/* Done. */
sleep(10);
return 0;
}
/**----------------------------------------------------------------------------\
| Utility function for example usage. |
| Read user input character-by-character dynamically. |
\-----------------------------------------------------------------------------*/
char *readline(){
char *output = "";
while(1){
/* Get character. */
char character = fgetc(stdin);
if(character == '\n') break;
/* Get string. */
char *original = output;
/* Convert into mutable C-string pointer. */
char *append = strdup((char*)&character);
/* Get strings' lengths. */
size_t original_size = strlen(original);
size_t append_size = strlen(append);
/* Ensure we captured only one character; append NUL byte. */
if(append_size > 1){
append[1] = '\0';
append_size = 1;
}
/* Allocate memory for output string. */
output = malloc(original_size + append_size + 1);
/* Write string to memory. */
memcpy(output, original, original_size);
memcpy(output + original_size, append, append_size + 1);
}
return output;
}
|
the_stack_data/38796.c | // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
// END.
// CHECK: private unnamed_addr constant [8 x i8] c"v_ann_{{.}}\00", section "llvm.metadata"
// CHECK: private unnamed_addr constant [8 x i8] c"v_ann_{{.}}\00", section "llvm.metadata"
struct foo {
int v __attribute__((annotate("v_ann_0"))) __attribute__((annotate("v_ann_1")));
};
static struct foo gf;
int main(int argc, char **argv) {
struct foo f;
f.v = argc;
// CHECK: getelementptr inbounds %struct.foo* %f, i32 0, i32 0
// CHECK-NEXT: bitcast i32* {{.*}} to i8*
// CHECK-NEXT: call i8* @llvm.ptr.annotation.p0i8({{.*}}str{{.*}}str{{.*}}i32 8)
// CHECK-NEXT: bitcast i8* {{.*}} to i32*
// CHECK-NEXT: bitcast i32* {{.*}} to i8*
// CHECK-NEXT: call i8* @llvm.ptr.annotation.p0i8({{.*}}str{{.*}}str{{.*}}i32 8)
// CHECK-NEXT: bitcast i8* {{.*}} to i32*
gf.v = argc;
// CHECK: bitcast i32* getelementptr inbounds (%struct.foo* @gf, i32 0, i32 0) to i8*
// CHECK-NEXT: call i8* @llvm.ptr.annotation.p0i8({{.*}}str{{.*}}str{{.*}}i32 8)
return 0;
}
|
the_stack_data/117561.c | #include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#define PORT 8080
int main(int argc, char const *argv[])
{
int server_fd, new_socket, valread;
struct sockaddr_in address;
int opt = 1;
int addrlen = sizeof(address);
char buffer[1024] = {0};
char *hello = "Greetings from the Server side";
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
{
perror("socket failed");
exit(EXIT_FAILURE);
}
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT,
&opt, sizeof(opt)))
{
perror("setsockopt");
exit(EXIT_FAILURE);
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons( PORT );
if (bind(server_fd, (struct sockaddr *)&address,
sizeof(address))<0)
{
perror("bind failed");
exit(EXIT_FAILURE);
}
if (listen(server_fd, 3) < 0)
{
perror("listen");
exit(EXIT_FAILURE);
}
if ((new_socket = accept(server_fd, (struct sockaddr *)&address,
(socklen_t*)&addrlen))<0)
{
perror("accept");
exit(EXIT_FAILURE);
}
valread = read( new_socket , buffer, 1024);
printf("%s\n",buffer );
send(new_socket , hello , strlen(hello) , 0 );
printf("Greetings message sent\n");
return 0;
}
|
the_stack_data/538987.c | char *p;
char accessA(unsigned i) {
return *(p+i);
}
void recursion(unsigned i) {
if (accessA(i) > 0) return;
recursion(i++);
}
int main () {
unsigned i = 0;
unsigned a[10];
p = a;
recursion(0);
}
|
the_stack_data/150142134.c | // REQUIRES: shell
// Check that lld gets "-lto_library".
// (Separate test file since darwin-ld-lto requires system-darwin but this
// test doesn't require that.)
// Check that -object_lto_path is passed correctly to ld64
// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld -target x86_64-apple-darwin10 \
// RUN: %s -flto=full -### 2>&1 \
// RUN: | FileCheck -check-prefix=FULL_LTO_OBJECT_PATH %s
// FULL_LTO_OBJECT_PATH: {{ld(.exe)?"}}
// FULL_LTO_OBJECT_PATH-SAME: "-object_path_lto"
// FULL_LTO_OBJECT_PATH-SAME: {{cc\-[a-zA-Z0-9_]+.o}}"
// RUN: %clang -fuse-ld=lld -B%S/Inputs/lld -target x86_64-apple-darwin10 \
// RUN: %s -flto=thin -### 2>&1 \
// RUN: | FileCheck -check-prefix=THIN_LTO_OBJECT_PATH %s
// THIN_LTO_OBJECT_PATH: {{ld(.exe)?"}}
// THIN_LTO_OBJECT_PATH-SAME: "-object_path_lto"
// THIN_LTO_OBJECT_PATH-SAME: {{thinlto\-[a-zA-Z0-9_]+}}
|
the_stack_data/212642133.c | /* Zing Zhu's Oyster Farm */
#include <stdio.h>
typedef char bool;
#define TRUE 1
#define FALSE 0
typedef struct {
bool fill;
bool wall[4];
} cell;
typedef struct {
int x1, x2, y1, y2;
int h;
} segment;
typedef struct {
int x, y;
} point;
cell c[1004][1004];
segment s[2000];
int n;
int w;
int xmin, ymin, xmax, ymax;
#define MAXV 3000
typedef struct {
point q[MAXV];
int first;
int last;
int count;
} queue;
queue q;
void init_queue() {
q.first = 0;
q.last = MAXV-1;
q.count = 0;
}
void enqueue(int x, int y) {
q.last = (q.last + 1) % MAXV;
q.q[q.last].x = x; q. q[q.last].y = y;
q.count++;
}
void dequeue(int *x, int *y) {
*x = q.q[q.first].x;
*y = q.q[q.first].y;
q.first = (q.first+1) % MAXV;
q.count--;
}
bool empty() {
if (q. count <= 0) return TRUE;
return FALSE;
}
void BFS(int x1, int y1) {
int x, y;
init_queue();
c[x1][y1].fill = TRUE;
enqueue(x1, y1);
while (!empty()) {
dequeue(&x, &y);
if ((x-1 >= xmin-1) && (!c[x][y].wall[1]) && (!c[x-1][y].fill)) {
enqueue(x-1, y);
c[x-1][y].fill = TRUE;
}
if ((y-1 >= ymin-1) && (!c[x][y].wall[0]) && (!c[x][y-1].fill)) {
enqueue(x, y-1);
c[x][y-1].fill = TRUE;
}
if ((x+1 <= xmax) && (!c[x][y].wall[3]) && (!c[x+1][y].fill)) {
enqueue(x+1, y);
c[x+1][y].fill = TRUE;
}
if ((y+1 <= ymax) && (!c[x][y].wall[2]) && (!c[x][y+1].fill)) {
enqueue(x, y+1);
c[x][y+1].fill = TRUE;
}
}
}
int main() {
int i, j, k;
int x1, y1, x2, y2;
int area;
while (scanf("%d", &n)) {
if (!n) break;
xmin = ymin = 100000;
xmax = ymax = -1;
for (i = 0; i < n; i++) {
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &s[i].h);
x1 += 502; x2 += 502; y1 += 502; y2 += 502;
if (x2 < x1) { k = x1; x1 = x2; x2 = k; }
if (y2 < y1) { k = y1; y1 = y2; y2 = k; }
s[i].x1 = x1; s[i].y1 = y1; s[i].x2 = x2; s[i].y2 = y2;
if (x1 < xmin) xmin = x1; if (x2 > xmax) xmax = x2;
if (y1 < ymin) ymin = y1; if (y2 > ymax) ymax = y2;
}
scanf("%d", &w);
for (i = xmin-1; i <= xmax; i++)
for (j = ymin-1; j <= ymax; j++) {
c[i][j].fill = FALSE;
for (k = 0; k < 4; k++) c[i][j].wall[k] = FALSE;
}
for (i = 0; i < n; i++)
if (s[i].h >= w) {
if (s[i].x1 == s[i].x2) {
for (j = s[i].y1; j < s[i].y2; j++) {
c[s[i].x1][j].wall[1] = TRUE;
c[s[i].x1-1][j].wall[3] = TRUE;
}
}
else {
for (j = s[i].x1; j < s[i].x2; j++) {
c[j][s[i].y1].wall[0] = TRUE;
c[j][s[i].y1-1].wall[2] = TRUE;
}
}
}
BFS(xmax, ymax);
area = 0;
for (i = xmin; i <= xmax; i++)
for (j = ymin; j <= ymax; j++)
if (!c[i][j].fill) area++;
printf("%d\n", area);
}
return 0;
}
|
the_stack_data/132951696.c | #include <stdio.h>
#include <limits.h>
int main() {
printf("Bits of type char: %d\n", CHAR_BIT);
printf("Maximum numeric value of type char: %d\n", CHAR_MAX);
printf("Minimum numeric value of type char: %d\n", CHAR_MIN);
printf("Maximum value of type signed char: %d\n", SCHAR_MAX);
printf("Minimum value of type signed char: %d\n", SCHAR_MIN);
printf("Maximum value of type unsigned short: %u\n", (unsigned) UCHAR_MAX);
printf("Maximum value of type short: %d\n", SHRT_MAX);
printf("Minimum value of type short: %d\n", SHRT_MIN);
printf("Maximum value of type unsigned short: %u\n", (unsigned) USHRT_MAX);
printf("Maximum value of type int: %d\n", INT_MAX);
printf("Minimum value of type int: %d\n", INT_MIN);
printf("Maximum value of type unsigned int: %u\n", UINT_MAX);
printf("Maximum value of type long: %ld\n", LONG_MAX);
printf("Minimum value of type long: %ld\n", LONG_MIN);
printf("Maximum value of type unsigned long: %lu\n", ULONG_MAX);
}
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.