hexsha
stringlengths 40
40
| repo
stringlengths 5
105
| path
stringlengths 3
173
| license
sequence | language
stringclasses 1
value | identifier
stringlengths 1
438
| return_type
stringlengths 1
106
⌀ | original_string
stringlengths 21
40.7k
| original_docstring
stringlengths 18
13.4k
| docstring
stringlengths 11
3.24k
| docstring_tokens
sequence | code
stringlengths 14
20.4k
| code_tokens
sequence | short_docstring
stringlengths 0
4.36k
| short_docstring_tokens
sequence | comment
sequence | parameters
list | docstring_params
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
30166b9261693dc5ca9053eaae33fbe1bf286d08 | mattialancellotti/PasswdManager | src/stats.c | [
"MIT"
] | C | print | void | void print(const passwd_t *passwd_info) {
printf("\n%s===CONSECUTIVE CHARACTERS===%s \n"
"\t| Consecutive upper case chars: %d\n"
"\t| Consecutive lower case chars: %d\n"
"\t| Consecutive digits: %d \n"
"\t| Consecutive signs: %d \n",
RED, RESET, passwd_info->cons_u_char, passwd_info->cons_l_char,
passwd_info->cons_digit, passwd_info->cons_sign);
printf("\n%s===REPEATED CHARACTERS===%s \n"
"\t| Repeated upper case chars: %d\n"
"\t| Repeated lower case chars: %d\n"
"\t| Repeated digits: %d \n"
"\t| Repeated signs: %d \n",
RED, RESET, passwd_info->repeated_u_char, passwd_info->repeated_l_char,
passwd_info->repeated_digit, passwd_info->repeated_sign);
printf("\n%s===NUMBER OF EACH TYPE===%s \n"
"\t| Number of upper case chars: %d\n"
"\t| Number of lower case chars: %d\n"
"\t| Number of digits: %d \n"
"\t| Number of signs: %d \n",
RED, RESET, passwd_info->number_u_char, passwd_info->number_l_char,
passwd_info->number_digit, passwd_info->number_sign);
} | /* You really have to make this look better */ | You really have to make this look better | [
"You",
"really",
"have",
"to",
"make",
"this",
"look",
"better"
] | void print(const passwd_t *passwd_info) {
printf("\n%s===CONSECUTIVE CHARACTERS===%s \n"
"\t| Consecutive upper case chars: %d\n"
"\t| Consecutive lower case chars: %d\n"
"\t| Consecutive digits: %d \n"
"\t| Consecutive signs: %d \n",
RED, RESET, passwd_info->cons_u_char, passwd_info->cons_l_char,
passwd_info->cons_digit, passwd_info->cons_sign);
printf("\n%s===REPEATED CHARACTERS===%s \n"
"\t| Repeated upper case chars: %d\n"
"\t| Repeated lower case chars: %d\n"
"\t| Repeated digits: %d \n"
"\t| Repeated signs: %d \n",
RED, RESET, passwd_info->repeated_u_char, passwd_info->repeated_l_char,
passwd_info->repeated_digit, passwd_info->repeated_sign);
printf("\n%s===NUMBER OF EACH TYPE===%s \n"
"\t| Number of upper case chars: %d\n"
"\t| Number of lower case chars: %d\n"
"\t| Number of digits: %d \n"
"\t| Number of signs: %d \n",
RED, RESET, passwd_info->number_u_char, passwd_info->number_l_char,
passwd_info->number_digit, passwd_info->number_sign);
} | [
"void",
"print",
"(",
"const",
"passwd_t",
"*",
"passwd_info",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
",",
"RED",
",",
"RESET",
",",
"passwd_info",
"->",
"cons_u_char",
",",
"passwd_info",
"->",
"cons_l_char",
",",
"passwd_info",
"->",
"cons_digit",
",",
"passwd_info",
"->",
"cons_sign",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
",",
"RED",
",",
"RESET",
",",
"passwd_info",
"->",
"repeated_u_char",
",",
"passwd_info",
"->",
"repeated_l_char",
",",
"passwd_info",
"->",
"repeated_digit",
",",
"passwd_info",
"->",
"repeated_sign",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
"\"",
"\\t",
"\\n",
"\"",
",",
"RED",
",",
"RESET",
",",
"passwd_info",
"->",
"number_u_char",
",",
"passwd_info",
"->",
"number_l_char",
",",
"passwd_info",
"->",
"number_digit",
",",
"passwd_info",
"->",
"number_sign",
")",
";",
"}"
] | You really have to make this look better | [
"You",
"really",
"have",
"to",
"make",
"this",
"look",
"better"
] | [] | [
{
"param": "passwd_info",
"type": "passwd_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "passwd_info",
"type": "passwd_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
71d8968cfdbcdd5e7da13c31421c3e009dd55cdf | mattialancellotti/PasswdManager | src/pwman.c | [
"MIT"
] | C | pm_init_hash | int | int pm_init_hash(const char *hash_file)
{
char *passwd = NULL, *verification_passwd = NULL;
char *hash = NULL;
/* Ask the user the password twice to make sure it's the correct one. */
/* TODO: Password validation */
printf("Insert a password: ");
passwd = ask_pass();
printf("\nInsert the password again: ");
verification_passwd = ask_pass();
/* The passwords are not the same */
if (strcmp(passwd, verification_passwd)) {
free(passwd);
free(verification_passwd);
putchar('\n');
return -1;
}
/*
* If the user has entered a valid password that same password is being
* hashed through the `hash_password` function in crypto.c
*/
hash = hash_password(passwd);
/* Writing the hash password to the file */
file_t *file = mcreate(hash_file);
int werr = cwrite(file->fd, hash, 0);
int cerr = mclose(file);
printf("\nThe password manager is good to go.\n");
free(passwd);
free(verification_passwd);
free(hash);
return 0;
} | /*
* TODO:
* - Avoid passing known directories like db, hash files via argument
* when it's a global variable.
*/ | - Avoid passing known directories like db, hash files via argument
when it's a global variable. | [
"-",
"Avoid",
"passing",
"known",
"directories",
"like",
"db",
"hash",
"files",
"via",
"argument",
"when",
"it",
"'",
"s",
"a",
"global",
"variable",
"."
] | int pm_init_hash(const char *hash_file)
{
char *passwd = NULL, *verification_passwd = NULL;
char *hash = NULL;
printf("Insert a password: ");
passwd = ask_pass();
printf("\nInsert the password again: ");
verification_passwd = ask_pass();
if (strcmp(passwd, verification_passwd)) {
free(passwd);
free(verification_passwd);
putchar('\n');
return -1;
}
hash = hash_password(passwd);
file_t *file = mcreate(hash_file);
int werr = cwrite(file->fd, hash, 0);
int cerr = mclose(file);
printf("\nThe password manager is good to go.\n");
free(passwd);
free(verification_passwd);
free(hash);
return 0;
} | [
"int",
"pm_init_hash",
"(",
"const",
"char",
"*",
"hash_file",
")",
"{",
"char",
"*",
"passwd",
"=",
"NULL",
",",
"*",
"verification_passwd",
"=",
"NULL",
";",
"char",
"*",
"hash",
"=",
"NULL",
";",
"printf",
"(",
"\"",
"\"",
")",
";",
"passwd",
"=",
"ask_pass",
"(",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"verification_passwd",
"=",
"ask_pass",
"(",
")",
";",
"if",
"(",
"strcmp",
"(",
"passwd",
",",
"verification_passwd",
")",
")",
"{",
"free",
"(",
"passwd",
")",
";",
"free",
"(",
"verification_passwd",
")",
";",
"putchar",
"(",
"'",
"\\n",
"'",
")",
";",
"return",
"-1",
";",
"}",
"hash",
"=",
"hash_password",
"(",
"passwd",
")",
";",
"file_t",
"*",
"file",
"=",
"mcreate",
"(",
"hash_file",
")",
";",
"int",
"werr",
"=",
"cwrite",
"(",
"file",
"->",
"fd",
",",
"hash",
",",
"0",
")",
";",
"int",
"cerr",
"=",
"mclose",
"(",
"file",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"free",
"(",
"passwd",
")",
";",
"free",
"(",
"verification_passwd",
")",
";",
"free",
"(",
"hash",
")",
";",
"return",
"0",
";",
"}"
] | TODO:
- Avoid passing known directories like db, hash files via argument
when it's a global variable. | [
"TODO",
":",
"-",
"Avoid",
"passing",
"known",
"directories",
"like",
"db",
"hash",
"files",
"via",
"argument",
"when",
"it",
"'",
"s",
"a",
"global",
"variable",
"."
] | [
"/* Ask the user the password twice to make sure it's the correct one. */",
"/* TODO: Password validation */",
"/* The passwords are not the same */",
"/*\n * If the user has entered a valid password that same password is being\n * hashed through the `hash_password` function in crypto.c\n */",
"/* Writing the hash password to the file */"
] | [
{
"param": "hash_file",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "hash_file",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
1c93b0e3c8df856f05a09b0416dd9b12cb2d7d34 | mjosaarinen/bitpat | autoc.c | [
"BSD-2-Clause"
] | C | eval_s1 | double | double eval_s1(double f, double d, double s2, double x)
{
double ai, bi;
double u = sqrt(2.0 * s2);
double t = 1.0 / u; // scale factor
double tc = ceil(TAILCUT_TAU * sqrt(s2));
double erfs = 0.0;
double exps = 0.0;
int i, l;
// run sum x-f - tc ... x-f + tc
ai = t * (x - f - tc);
bi = t * (x - f - d - tc);
l = 2 * tc + 1; // include +-tc (and zero)
for (i = 0; i < l; i++) {
erfs += ai * erf(ai) - bi * erf(bi);
exps += exp(-ai*ai) - exp(-bi*bi);
ai += t;
bi += t;
}
// 1/sqrt(Pi)
erfs += 0.56418958354775628694807945156077258584 * exps;
return u * erfs / 2.0;
} | // === computation of s1 integral
// (f, d, s2) parameters
// x point where computed | computation of s1 integral
(f, d, s2) parameters
x point where computed | [
"computation",
"of",
"s1",
"integral",
"(",
"f",
"d",
"s2",
")",
"parameters",
"x",
"point",
"where",
"computed"
] | double eval_s1(double f, double d, double s2, double x)
{
double ai, bi;
double u = sqrt(2.0 * s2);
double t = 1.0 / u;
double tc = ceil(TAILCUT_TAU * sqrt(s2));
double erfs = 0.0;
double exps = 0.0;
int i, l;
ai = t * (x - f - tc);
bi = t * (x - f - d - tc);
l = 2 * tc + 1;
for (i = 0; i < l; i++) {
erfs += ai * erf(ai) - bi * erf(bi);
exps += exp(-ai*ai) - exp(-bi*bi);
ai += t;
bi += t;
}
erfs += 0.56418958354775628694807945156077258584 * exps;
return u * erfs / 2.0;
} | [
"double",
"eval_s1",
"(",
"double",
"f",
",",
"double",
"d",
",",
"double",
"s2",
",",
"double",
"x",
")",
"{",
"double",
"ai",
",",
"bi",
";",
"double",
"u",
"=",
"sqrt",
"(",
"2.0",
"*",
"s2",
")",
";",
"double",
"t",
"=",
"1.0",
"/",
"u",
";",
"double",
"tc",
"=",
"ceil",
"(",
"TAILCUT_TAU",
"*",
"sqrt",
"(",
"s2",
")",
")",
";",
"double",
"erfs",
"=",
"0.0",
";",
"double",
"exps",
"=",
"0.0",
";",
"int",
"i",
",",
"l",
";",
"ai",
"=",
"t",
"*",
"(",
"x",
"-",
"f",
"-",
"tc",
")",
";",
"bi",
"=",
"t",
"*",
"(",
"x",
"-",
"f",
"-",
"d",
"-",
"tc",
")",
";",
"l",
"=",
"2",
"*",
"tc",
"+",
"1",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"erfs",
"+=",
"ai",
"*",
"erf",
"(",
"ai",
")",
"-",
"bi",
"*",
"erf",
"(",
"bi",
")",
";",
"exps",
"+=",
"exp",
"(",
"-",
"ai",
"*",
"ai",
")",
"-",
"exp",
"(",
"-",
"bi",
"*",
"bi",
")",
";",
"ai",
"+=",
"t",
";",
"bi",
"+=",
"t",
";",
"}",
"erfs",
"+=",
"0.56418958354775628694807945156077258584",
"*",
"exps",
";",
"return",
"u",
"*",
"erfs",
"/",
"2.0",
";",
"}"
] | computation of s1 integral
(f, d, s2) parameters
x point where computed | [
"computation",
"of",
"s1",
"integral",
"(",
"f",
"d",
"s2",
")",
"parameters",
"x",
"point",
"where",
"computed"
] | [
"//\tscale factor",
"//\trun sum x-f - tc ... x-f + tc",
"//\tinclude +-tc (and zero)",
"//\t1/sqrt(Pi)"
] | [
{
"param": "f",
"type": "double"
},
{
"param": "d",
"type": "double"
},
{
"param": "s2",
"type": "double"
},
{
"param": "x",
"type": "double"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "f",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "d",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "s2",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
1c93b0e3c8df856f05a09b0416dd9b12cb2d7d34 | mjosaarinen/bitpat | autoc.c | [
"BSD-2-Clause"
] | C | ck_eval | double | double ck_eval(double f, double d, double s2, int k)
{
if (k == 0)
return 2.0 * d - 1.0;
// scale f and s2 as per theorem 1
f *= (double) k;
s2 *= (double) k;
f -= floor(f);
if (f > 0.5)
f = 1.0 - f;
return 4.0 * ( eval_s1(f, d, s2, d) - eval_s1(f, d, s2, 0.0) - d ) + 1.0;
} | // === Evaluate autocorrelation Ck from a definite integral.
// (f, d, s2) parameters
// k distance | Evaluate autocorrelation Ck from a definite integral.
(f, d, s2) parameters
k distance | [
"Evaluate",
"autocorrelation",
"Ck",
"from",
"a",
"definite",
"integral",
".",
"(",
"f",
"d",
"s2",
")",
"parameters",
"k",
"distance"
] | double ck_eval(double f, double d, double s2, int k)
{
if (k == 0)
return 2.0 * d - 1.0;
f *= (double) k;
s2 *= (double) k;
f -= floor(f);
if (f > 0.5)
f = 1.0 - f;
return 4.0 * ( eval_s1(f, d, s2, d) - eval_s1(f, d, s2, 0.0) - d ) + 1.0;
} | [
"double",
"ck_eval",
"(",
"double",
"f",
",",
"double",
"d",
",",
"double",
"s2",
",",
"int",
"k",
")",
"{",
"if",
"(",
"k",
"==",
"0",
")",
"return",
"2.0",
"*",
"d",
"-",
"1.0",
";",
"f",
"*=",
"(",
"double",
")",
"k",
";",
"s2",
"*=",
"(",
"double",
")",
"k",
";",
"f",
"-=",
"floor",
"(",
"f",
")",
";",
"if",
"(",
"f",
">",
"0.5",
")",
"f",
"=",
"1.0",
"-",
"f",
";",
"return",
"4.0",
"*",
"(",
"eval_s1",
"(",
"f",
",",
"d",
",",
"s2",
",",
"d",
")",
"-",
"eval_s1",
"(",
"f",
",",
"d",
",",
"s2",
",",
"0.0",
")",
"-",
"d",
")",
"+",
"1.0",
";",
"}"
] | Evaluate autocorrelation Ck from a definite integral. | [
"Evaluate",
"autocorrelation",
"Ck",
"from",
"a",
"definite",
"integral",
"."
] | [
"//\tscale f and s2 as per theorem 1"
] | [
{
"param": "f",
"type": "double"
},
{
"param": "d",
"type": "double"
},
{
"param": "s2",
"type": "double"
},
{
"param": "k",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "f",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "d",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "s2",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "k",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
69d5e653c53044dae542288fed4cdb7f806e5e4c | ghsecuritylab/AliOS-LoRa | platform/mcu/fm33A0xx/HAL/soc/uart.c | [
"Apache-2.0"
] | C | hal_uart_init | int32_t | int32_t hal_uart_init(uart_dev_t *uart)
{
UART_SInitTypeDef UART_para;
RCC_ClocksType RCC_Clocks;
UARTx_Type *UARTx = NULL;
if (uart->port > UART_5)
{
return EIO;
}
if ((uart->config.data_width > DATA_WIDTH_9BIT ||
uart->config.data_width <= DATA_WIDTH_6BIT) ||
(uart->config.parity > EVEN_PARITY) ||
(uart->config.stop_bits > STOP_BITS_2) ||
(uart->config.flow_control > FLOW_CONTROL_CTS_RTS) ||
(uart->config.mode > MODE_TX_RX))
{
return EIO;
}
RCC_PERCLK_SetableEx(UARTCOMCLK, ENABLE); //UART0~5 all clk enable
switch (uart->port)
{
case UART_0:
RCC_PERCLK_SetableEx(UART0CLK, ENABLE); //UARTx clk enable
// UART0 IO config
AltFunIO(UART0RX_Port, UART0RX_Pin, 0); //UART0 RX
AltFunIO(UART0TX_Port, UART0TX_Pin, 0); //UART0 TX
/*NVIC interrupt config*/
NVIC_DisableIRQ(UART0_IRQn);
//NVIC_SetPriority(UART0_IRQn,2);//interrupt priority config
//NVIC_EnableIRQ(UART0_IRQn);
UARTx = UART0;
break;
case UART_1:
RCC_PERCLK_SetableEx(UART1CLK, ENABLE); //UARTx clk enable
// UART1 IO config
AltFunIO(UART1RX_Port, UART1RX_Pin, 0); //UART1 RX
AltFunIO(UART1TX_Port, UART1TX_Pin, 0); //UART1 TX
/*NVIC interrupt config*/
NVIC_DisableIRQ(UART1_IRQn);
//NVIC_SetPriority(UART1_IRQn,2);//interrupt priority config
//NVIC_EnableIRQ(UART1_IRQn);
UARTx = UART1;
break;
case UART_2:
RCC_PERCLK_SetableEx(UART2CLK, ENABLE); //UARTx clk enable
// UART2 IO config
AltFunIO(UART2RX_Port, UART2RX_Pin, 0); //UART2 RX
AltFunIO(UART2TX_Port, UART2TX_Pin, 0); //UART2 TX
/*NVIC interrupt config*/
NVIC_DisableIRQ(UART2_IRQn);
//NVIC_SetPriority(UART2_IRQn,2);//interrupt priority config
//NVIC_EnableIRQ(UART2_IRQn);
UARTx = UART2;
break;
case UART_3:
RCC_PERCLK_SetableEx(UART3CLK, ENABLE); //UARTx clk enable
// UART3 IO config
AltFunIO(UART3RX_Port, UART3RX_Pin, 0); //UART3 RX
AltFunIO(UART3TX_Port, UART3TX_Pin, 0); //UART3 TX
/*NVIC interrupt config*/
NVIC_DisableIRQ(UART3_IRQn);
//NVIC_SetPriority(UART3_IRQn,2);//interrupt priority config
//NVIC_EnableIRQ(UART3_IRQn);
UARTx = UART3;
break;
case UART_4:
RCC_PERCLK_SetableEx(UART4CLK, ENABLE); //UARTx clk enable
// UART4 IO config
AltFunIO(UART4RX_Port, UART4RX_Pin, 0); //UART4 RX
AltFunIO(UART4TX_Port, UART4TX_Pin, 0); //UART4 TX
/*NVIC interrupt config*/
NVIC_DisableIRQ(UART4_IRQn);
//NVIC_SetPriority(UART4_IRQn,2);//
//NVIC_EnableIRQ(UART4_IRQn);
UARTx = UART4;
break;
case UART_5:
RCC_PERCLK_SetableEx(UART5CLK, ENABLE); //UARTx clk enable
// UART5 IO config
AltFunIO(UART5RX_Port, UART5RX_Pin, 0); //UART5 RX
AltFunIO(UART5TX_Port, UART5TX_Pin, 0); //UART5 TX
/*NVIC interrupt config*/
NVIC_DisableIRQ(UART5_IRQn);
//NVIC_SetPriority(UART5_IRQn,2);//interrupt priority config
//NVIC_EnableIRQ(UART5_IRQn);
UARTx = UART5;
break;
default:
break;
}
//UART init config
UART_para.BaudRate = uart->config.baud_rate; //baud rate
UART_para.DataBit = (UART_DataBitTypeDef)(uart->config.data_width - DATA_WIDTH_7BIT); //data bit
UART_para.ParityBit = (UART_ParityBitTypeDef) uart->config.parity; //parity
UART_para.StopBit = (UART_StopBitTypeDef) uart->config.stop_bits; //stop bits
RCC_GetClocksFreq(&RCC_Clocks);//get APBClock
UART_SInit(UARTx, &UART_para, RCC_Clocks.APBCLK_Frequency); //uart init
if (MODE_TX == uart->config.mode)
{
UARTx_TXSTA_TXEN_Setable(UARTx, ENABLE); //send enable
}
else if (MODE_TX == uart->config.mode)
{
UARTx_RXSTA_RXEN_Setable(UARTx, ENABLE); //recv enable
}
else
{
UARTx_RXSTA_RXEN_Setable(UARTx, ENABLE); //recv enable
UARTx_TXSTA_TXEN_Setable(UARTx, ENABLE); //send enable
}
return 0;
} | /**
* Initialises a UART interface
*
*
* @param[in] uart the interface which should be initialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/ | Initialises a UART interface
@param[in] uart the interface which should be initialised
@return 0 : on success, EIO : if an error occurred with any step | [
"Initialises",
"a",
"UART",
"interface",
"@param",
"[",
"in",
"]",
"uart",
"the",
"interface",
"which",
"should",
"be",
"initialised",
"@return",
"0",
":",
"on",
"success",
"EIO",
":",
"if",
"an",
"error",
"occurred",
"with",
"any",
"step"
] | int32_t hal_uart_init(uart_dev_t *uart)
{
UART_SInitTypeDef UART_para;
RCC_ClocksType RCC_Clocks;
UARTx_Type *UARTx = NULL;
if (uart->port > UART_5)
{
return EIO;
}
if ((uart->config.data_width > DATA_WIDTH_9BIT ||
uart->config.data_width <= DATA_WIDTH_6BIT) ||
(uart->config.parity > EVEN_PARITY) ||
(uart->config.stop_bits > STOP_BITS_2) ||
(uart->config.flow_control > FLOW_CONTROL_CTS_RTS) ||
(uart->config.mode > MODE_TX_RX))
{
return EIO;
}
RCC_PERCLK_SetableEx(UARTCOMCLK, ENABLE);
switch (uart->port)
{
case UART_0:
RCC_PERCLK_SetableEx(UART0CLK, ENABLE);
AltFunIO(UART0RX_Port, UART0RX_Pin, 0);
AltFunIO(UART0TX_Port, UART0TX_Pin, 0);
NVIC_DisableIRQ(UART0_IRQn);
UARTx = UART0;
break;
case UART_1:
RCC_PERCLK_SetableEx(UART1CLK, ENABLE);
AltFunIO(UART1RX_Port, UART1RX_Pin, 0);
AltFunIO(UART1TX_Port, UART1TX_Pin, 0);
NVIC_DisableIRQ(UART1_IRQn);
UARTx = UART1;
break;
case UART_2:
RCC_PERCLK_SetableEx(UART2CLK, ENABLE);
AltFunIO(UART2RX_Port, UART2RX_Pin, 0);
AltFunIO(UART2TX_Port, UART2TX_Pin, 0);
NVIC_DisableIRQ(UART2_IRQn);
UARTx = UART2;
break;
case UART_3:
RCC_PERCLK_SetableEx(UART3CLK, ENABLE);
AltFunIO(UART3RX_Port, UART3RX_Pin, 0);
AltFunIO(UART3TX_Port, UART3TX_Pin, 0);
NVIC_DisableIRQ(UART3_IRQn);
UARTx = UART3;
break;
case UART_4:
RCC_PERCLK_SetableEx(UART4CLK, ENABLE);
AltFunIO(UART4RX_Port, UART4RX_Pin, 0);
AltFunIO(UART4TX_Port, UART4TX_Pin, 0);
NVIC_DisableIRQ(UART4_IRQn);
UARTx = UART4;
break;
case UART_5:
RCC_PERCLK_SetableEx(UART5CLK, ENABLE);
AltFunIO(UART5RX_Port, UART5RX_Pin, 0);
AltFunIO(UART5TX_Port, UART5TX_Pin, 0);
NVIC_DisableIRQ(UART5_IRQn);
UARTx = UART5;
break;
default:
break;
}
UART_para.BaudRate = uart->config.baud_rate;
UART_para.DataBit = (UART_DataBitTypeDef)(uart->config.data_width - DATA_WIDTH_7BIT);
UART_para.ParityBit = (UART_ParityBitTypeDef) uart->config.parity;
UART_para.StopBit = (UART_StopBitTypeDef) uart->config.stop_bits;
RCC_GetClocksFreq(&RCC_Clocks);
UART_SInit(UARTx, &UART_para, RCC_Clocks.APBCLK_Frequency);
if (MODE_TX == uart->config.mode)
{
UARTx_TXSTA_TXEN_Setable(UARTx, ENABLE);
}
else if (MODE_TX == uart->config.mode)
{
UARTx_RXSTA_RXEN_Setable(UARTx, ENABLE);
}
else
{
UARTx_RXSTA_RXEN_Setable(UARTx, ENABLE);
UARTx_TXSTA_TXEN_Setable(UARTx, ENABLE);
}
return 0;
} | [
"int32_t",
"hal_uart_init",
"(",
"uart_dev_t",
"*",
"uart",
")",
"{",
"UART_SInitTypeDef",
"UART_para",
";",
"RCC_ClocksType",
"RCC_Clocks",
";",
"UARTx_Type",
"*",
"UARTx",
"=",
"NULL",
";",
"if",
"(",
"uart",
"->",
"port",
">",
"UART_5",
")",
"{",
"return",
"EIO",
";",
"}",
"if",
"(",
"(",
"uart",
"->",
"config",
".",
"data_width",
">",
"DATA_WIDTH_9BIT",
"||",
"uart",
"->",
"config",
".",
"data_width",
"<=",
"DATA_WIDTH_6BIT",
")",
"||",
"(",
"uart",
"->",
"config",
".",
"parity",
">",
"EVEN_PARITY",
")",
"||",
"(",
"uart",
"->",
"config",
".",
"stop_bits",
">",
"STOP_BITS_2",
")",
"||",
"(",
"uart",
"->",
"config",
".",
"flow_control",
">",
"FLOW_CONTROL_CTS_RTS",
")",
"||",
"(",
"uart",
"->",
"config",
".",
"mode",
">",
"MODE_TX_RX",
")",
")",
"{",
"return",
"EIO",
";",
"}",
"RCC_PERCLK_SetableEx",
"(",
"UARTCOMCLK",
",",
"ENABLE",
")",
";",
"switch",
"(",
"uart",
"->",
"port",
")",
"{",
"case",
"UART_0",
":",
"RCC_PERCLK_SetableEx",
"(",
"UART0CLK",
",",
"ENABLE",
")",
";",
"AltFunIO",
"(",
"UART0RX_Port",
",",
"UART0RX_Pin",
",",
"0",
")",
";",
"AltFunIO",
"(",
"UART0TX_Port",
",",
"UART0TX_Pin",
",",
"0",
")",
";",
"NVIC_DisableIRQ",
"(",
"UART0_IRQn",
")",
";",
"UARTx",
"=",
"UART0",
";",
"break",
";",
"case",
"UART_1",
":",
"RCC_PERCLK_SetableEx",
"(",
"UART1CLK",
",",
"ENABLE",
")",
";",
"AltFunIO",
"(",
"UART1RX_Port",
",",
"UART1RX_Pin",
",",
"0",
")",
";",
"AltFunIO",
"(",
"UART1TX_Port",
",",
"UART1TX_Pin",
",",
"0",
")",
";",
"NVIC_DisableIRQ",
"(",
"UART1_IRQn",
")",
";",
"UARTx",
"=",
"UART1",
";",
"break",
";",
"case",
"UART_2",
":",
"RCC_PERCLK_SetableEx",
"(",
"UART2CLK",
",",
"ENABLE",
")",
";",
"AltFunIO",
"(",
"UART2RX_Port",
",",
"UART2RX_Pin",
",",
"0",
")",
";",
"AltFunIO",
"(",
"UART2TX_Port",
",",
"UART2TX_Pin",
",",
"0",
")",
";",
"NVIC_DisableIRQ",
"(",
"UART2_IRQn",
")",
";",
"UARTx",
"=",
"UART2",
";",
"break",
";",
"case",
"UART_3",
":",
"RCC_PERCLK_SetableEx",
"(",
"UART3CLK",
",",
"ENABLE",
")",
";",
"AltFunIO",
"(",
"UART3RX_Port",
",",
"UART3RX_Pin",
",",
"0",
")",
";",
"AltFunIO",
"(",
"UART3TX_Port",
",",
"UART3TX_Pin",
",",
"0",
")",
";",
"NVIC_DisableIRQ",
"(",
"UART3_IRQn",
")",
";",
"UARTx",
"=",
"UART3",
";",
"break",
";",
"case",
"UART_4",
":",
"RCC_PERCLK_SetableEx",
"(",
"UART4CLK",
",",
"ENABLE",
")",
";",
"AltFunIO",
"(",
"UART4RX_Port",
",",
"UART4RX_Pin",
",",
"0",
")",
";",
"AltFunIO",
"(",
"UART4TX_Port",
",",
"UART4TX_Pin",
",",
"0",
")",
";",
"NVIC_DisableIRQ",
"(",
"UART4_IRQn",
")",
";",
"UARTx",
"=",
"UART4",
";",
"break",
";",
"case",
"UART_5",
":",
"RCC_PERCLK_SetableEx",
"(",
"UART5CLK",
",",
"ENABLE",
")",
";",
"AltFunIO",
"(",
"UART5RX_Port",
",",
"UART5RX_Pin",
",",
"0",
")",
";",
"AltFunIO",
"(",
"UART5TX_Port",
",",
"UART5TX_Pin",
",",
"0",
")",
";",
"NVIC_DisableIRQ",
"(",
"UART5_IRQn",
")",
";",
"UARTx",
"=",
"UART5",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"UART_para",
".",
"BaudRate",
"=",
"uart",
"->",
"config",
".",
"baud_rate",
";",
"UART_para",
".",
"DataBit",
"=",
"(",
"UART_DataBitTypeDef",
")",
"(",
"uart",
"->",
"config",
".",
"data_width",
"-",
"DATA_WIDTH_7BIT",
")",
";",
"UART_para",
".",
"ParityBit",
"=",
"(",
"UART_ParityBitTypeDef",
")",
"uart",
"->",
"config",
".",
"parity",
";",
"UART_para",
".",
"StopBit",
"=",
"(",
"UART_StopBitTypeDef",
")",
"uart",
"->",
"config",
".",
"stop_bits",
";",
"RCC_GetClocksFreq",
"(",
"&",
"RCC_Clocks",
")",
";",
"UART_SInit",
"(",
"UARTx",
",",
"&",
"UART_para",
",",
"RCC_Clocks",
".",
"APBCLK_Frequency",
")",
";",
"if",
"(",
"MODE_TX",
"==",
"uart",
"->",
"config",
".",
"mode",
")",
"{",
"UARTx_TXSTA_TXEN_Setable",
"(",
"UARTx",
",",
"ENABLE",
")",
";",
"}",
"else",
"if",
"(",
"MODE_TX",
"==",
"uart",
"->",
"config",
".",
"mode",
")",
"{",
"UARTx_RXSTA_RXEN_Setable",
"(",
"UARTx",
",",
"ENABLE",
")",
";",
"}",
"else",
"{",
"UARTx_RXSTA_RXEN_Setable",
"(",
"UARTx",
",",
"ENABLE",
")",
";",
"UARTx_TXSTA_TXEN_Setable",
"(",
"UARTx",
",",
"ENABLE",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Initialises a UART interface | [
"Initialises",
"a",
"UART",
"interface"
] | [
"//UART0~5 all clk enable\r",
"//UARTx clk enable\r",
"//\tUART0 IO config\r",
"//UART0 RX\r",
"//UART0 TX\r",
"/*NVIC interrupt config*/",
"//NVIC_SetPriority(UART0_IRQn,2);//interrupt priority config\r",
"//NVIC_EnableIRQ(UART0_IRQn);\t\r",
"//UARTx clk enable\t\r",
"//\tUART1 IO config\r",
"//UART1 RX\r",
"//UART1 TX\r",
"/*NVIC interrupt config*/",
"//NVIC_SetPriority(UART1_IRQn,2);//interrupt priority config\r",
"//NVIC_EnableIRQ(UART1_IRQn);\t\r",
"//UARTx clk enable\r",
"//\tUART2 IO config\r",
"//UART2 RX\r",
"//UART2 TX\r",
"/*NVIC interrupt config*/",
"//NVIC_SetPriority(UART2_IRQn,2);//interrupt priority config\r",
"//NVIC_EnableIRQ(UART2_IRQn);\t\r",
"//UARTx clk enable\r",
"//\tUART3 IO config\r",
"//UART3 RX\r",
"//UART3 TX\r",
"/*NVIC interrupt config*/",
"//NVIC_SetPriority(UART3_IRQn,2);//interrupt priority config\r",
"//NVIC_EnableIRQ(UART3_IRQn);\t\r",
"//UARTx clk enable\t\r",
"//\tUART4 IO config\r",
"//UART4 RX\r",
"//UART4 TX\r",
"/*NVIC interrupt config*/",
"//NVIC_SetPriority(UART4_IRQn,2);//\r",
"//NVIC_EnableIRQ(UART4_IRQn);\t\r",
"//UARTx clk enable\t\r",
"//\tUART5 IO config\r",
"//UART5 RX\r",
"//UART5 TX\r",
"/*NVIC interrupt config*/",
"//NVIC_SetPriority(UART5_IRQn,2);//interrupt priority config\r",
"//NVIC_EnableIRQ(UART5_IRQn);\t\r",
"//UART init config\r",
"//baud rate\r",
"//data bit\r",
"//parity\r",
"//stop bits\r",
"//get APBClock\r",
"//uart init\r",
"//send enable\r",
"//recv enable\r",
"//recv enable\r",
"//send enable\r"
] | [
{
"param": "uart",
"type": "uart_dev_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "uart",
"type": "uart_dev_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
69d5e653c53044dae542288fed4cdb7f806e5e4c | ghsecuritylab/AliOS-LoRa | platform/mcu/fm33A0xx/HAL/soc/uart.c | [
"Apache-2.0"
] | C | hal_uart_recv | int32_t | int32_t hal_uart_recv(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t timeout)
{
uint32_t recv_size = 0;
UARTx_Type *UARTx = NULL;
uint32_t lastTick;
uint8_t *buf = (uint8_t *)data;
//param check
if ((NULL == uart) ||
(NULL == data))
{
return EIO;
}
switch (uart->port)
{
case UART_0:
UARTx = UART0;
break;
case UART_1:
UARTx = UART1;
break;
case UART_2:
UARTx = UART2;
break;
case UART_3:
UARTx = UART3;
break;
case UART_4:
UARTx = UART4;
break;
case UART_5:
UARTx = UART5;
break;
default:
return EIO;
}
lastTick = SysTick->VAL;
while (recv_size < expect_size)
{
IWDT_Clr(); //feed dog
if(SET == UARTx_RXBUFSTA_RXFF_Chk(UARTx)) //wait for a byte
{
buf[recv_size] = UARTx_RXREG_Read(UARTx); //read recv register
recv_size++;
}
if ((lastTick - SysTick->VAL > (timeout * ((__SYSTEM_CLOCK/1000)))) &&
(recv_size < expect_size))
{
return EIO;
}
}
return 0;
} | /**
* Receive data on a UART interface
*
* @param[in] uart the UART interface
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] expect_size number of bytes to receive
* @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER
* if you want to wait forever
*
* @return 0 : on success, EIO : if an error occurred with any step
*/ | Receive data on a UART interface
@param[in] uart the UART interface
@param[out] data pointer to the buffer which will store incoming data
@param[in] expect_size number of bytes to receive
@param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER
if you want to wait forever
@return 0 : on success, EIO : if an error occurred with any step | [
"Receive",
"data",
"on",
"a",
"UART",
"interface",
"@param",
"[",
"in",
"]",
"uart",
"the",
"UART",
"interface",
"@param",
"[",
"out",
"]",
"data",
"pointer",
"to",
"the",
"buffer",
"which",
"will",
"store",
"incoming",
"data",
"@param",
"[",
"in",
"]",
"expect_size",
"number",
"of",
"bytes",
"to",
"receive",
"@param",
"[",
"in",
"]",
"timeout",
"timeout",
"in",
"milisecond",
"set",
"this",
"value",
"to",
"HAL_WAIT_FOREVER",
"if",
"you",
"want",
"to",
"wait",
"forever",
"@return",
"0",
":",
"on",
"success",
"EIO",
":",
"if",
"an",
"error",
"occurred",
"with",
"any",
"step"
] | int32_t hal_uart_recv(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t timeout)
{
uint32_t recv_size = 0;
UARTx_Type *UARTx = NULL;
uint32_t lastTick;
uint8_t *buf = (uint8_t *)data;
if ((NULL == uart) ||
(NULL == data))
{
return EIO;
}
switch (uart->port)
{
case UART_0:
UARTx = UART0;
break;
case UART_1:
UARTx = UART1;
break;
case UART_2:
UARTx = UART2;
break;
case UART_3:
UARTx = UART3;
break;
case UART_4:
UARTx = UART4;
break;
case UART_5:
UARTx = UART5;
break;
default:
return EIO;
}
lastTick = SysTick->VAL;
while (recv_size < expect_size)
{
IWDT_Clr();
if(SET == UARTx_RXBUFSTA_RXFF_Chk(UARTx))
{
buf[recv_size] = UARTx_RXREG_Read(UARTx);
recv_size++;
}
if ((lastTick - SysTick->VAL > (timeout * ((__SYSTEM_CLOCK/1000)))) &&
(recv_size < expect_size))
{
return EIO;
}
}
return 0;
} | [
"int32_t",
"hal_uart_recv",
"(",
"uart_dev_t",
"*",
"uart",
",",
"void",
"*",
"data",
",",
"uint32_t",
"expect_size",
",",
"uint32_t",
"timeout",
")",
"{",
"uint32_t",
"recv_size",
"=",
"0",
";",
"UARTx_Type",
"*",
"UARTx",
"=",
"NULL",
";",
"uint32_t",
"lastTick",
";",
"uint8_t",
"*",
"buf",
"=",
"(",
"uint8_t",
"*",
")",
"data",
";",
"if",
"(",
"(",
"NULL",
"==",
"uart",
")",
"||",
"(",
"NULL",
"==",
"data",
")",
")",
"{",
"return",
"EIO",
";",
"}",
"switch",
"(",
"uart",
"->",
"port",
")",
"{",
"case",
"UART_0",
":",
"UARTx",
"=",
"UART0",
";",
"break",
";",
"case",
"UART_1",
":",
"UARTx",
"=",
"UART1",
";",
"break",
";",
"case",
"UART_2",
":",
"UARTx",
"=",
"UART2",
";",
"break",
";",
"case",
"UART_3",
":",
"UARTx",
"=",
"UART3",
";",
"break",
";",
"case",
"UART_4",
":",
"UARTx",
"=",
"UART4",
";",
"break",
";",
"case",
"UART_5",
":",
"UARTx",
"=",
"UART5",
";",
"break",
";",
"default",
":",
"return",
"EIO",
";",
"}",
"lastTick",
"=",
"SysTick",
"->",
"VAL",
";",
"while",
"(",
"recv_size",
"<",
"expect_size",
")",
"{",
"IWDT_Clr",
"(",
")",
";",
"if",
"(",
"SET",
"==",
"UARTx_RXBUFSTA_RXFF_Chk",
"(",
"UARTx",
")",
")",
"{",
"buf",
"[",
"recv_size",
"]",
"=",
"UARTx_RXREG_Read",
"(",
"UARTx",
")",
";",
"recv_size",
"++",
";",
"}",
"if",
"(",
"(",
"lastTick",
"-",
"SysTick",
"->",
"VAL",
">",
"(",
"timeout",
"*",
"(",
"(",
"__SYSTEM_CLOCK",
"/",
"1000",
")",
")",
")",
")",
"&&",
"(",
"recv_size",
"<",
"expect_size",
")",
")",
"{",
"return",
"EIO",
";",
"}",
"}",
"return",
"0",
";",
"}"
] | Receive data on a UART interface | [
"Receive",
"data",
"on",
"a",
"UART",
"interface"
] | [
"//param check\r",
"//feed dog\r",
"//wait for a byte\r",
"//read recv register\r"
] | [
{
"param": "uart",
"type": "uart_dev_t"
},
{
"param": "data",
"type": "void"
},
{
"param": "expect_size",
"type": "uint32_t"
},
{
"param": "timeout",
"type": "uint32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "uart",
"type": "uart_dev_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "expect_size",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "timeout",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
69d5e653c53044dae542288fed4cdb7f806e5e4c | ghsecuritylab/AliOS-LoRa | platform/mcu/fm33A0xx/HAL/soc/uart.c | [
"Apache-2.0"
] | C | hal_uart_recv_II | int32_t | int32_t hal_uart_recv_II(uart_dev_t *uart, void *data, uint32_t expect_size,
uint32_t *recv_size, uint32_t timeout)
{
uint32_t recv_index = 0;
UARTx_Type *UARTx = NULL;
uint32_t lastTick;
uint8_t *buf = (uint8_t *)data;
//param check
if ((NULL == uart) ||
(NULL == data))
{
return EIO;
}
switch (uart->port)
{
case UART_0:
UARTx = UART0;
break;
case UART_1:
UARTx = UART1;
break;
case UART_2:
UARTx = UART2;
break;
case UART_3:
UARTx = UART3;
break;
case UART_4:
UARTx = UART4;
break;
case UART_5:
UARTx = UART5;
break;
default:
return EIO;
}
lastTick = SysTick->VAL;
while (recv_index < expect_size)
{
IWDT_Clr(); //feed dog
if(SET == UARTx_RXBUFSTA_RXFF_Chk(UARTx)) //wait for a byte
{
buf[recv_index] = UARTx_RXREG_Read(UARTx); //read register
recv_index++;
}
if ((lastTick - SysTick->VAL > (timeout * ((__SYSTEM_CLOCK/1000)))) &&
(recv_index < expect_size))
{
*recv_size = recv_index;
return EIO;
}
}
return 0;
} | /**
* Receive data on a UART interface
*
* @param[in] uart the UART interface
* @param[out] data pointer to the buffer which will store incoming data
* @param[in] expect_size number of bytes to receive
* @param[out] recv_size number of bytes received
* @param[in] timeout timeout in milisecond, set this value to HAL_WAIT_FOREVER
* if you want to wait forever
*
* @return 0 : on success, EIO : if an error occurred with any step
*/ | Receive data on a UART interface
@return 0 : on success, EIO : if an error occurred with any step | [
"Receive",
"data",
"on",
"a",
"UART",
"interface",
"@return",
"0",
":",
"on",
"success",
"EIO",
":",
"if",
"an",
"error",
"occurred",
"with",
"any",
"step"
] | int32_t hal_uart_recv_II(uart_dev_t *uart, void *data, uint32_t expect_size,
uint32_t *recv_size, uint32_t timeout)
{
uint32_t recv_index = 0;
UARTx_Type *UARTx = NULL;
uint32_t lastTick;
uint8_t *buf = (uint8_t *)data;
if ((NULL == uart) ||
(NULL == data))
{
return EIO;
}
switch (uart->port)
{
case UART_0:
UARTx = UART0;
break;
case UART_1:
UARTx = UART1;
break;
case UART_2:
UARTx = UART2;
break;
case UART_3:
UARTx = UART3;
break;
case UART_4:
UARTx = UART4;
break;
case UART_5:
UARTx = UART5;
break;
default:
return EIO;
}
lastTick = SysTick->VAL;
while (recv_index < expect_size)
{
IWDT_Clr();
if(SET == UARTx_RXBUFSTA_RXFF_Chk(UARTx))
{
buf[recv_index] = UARTx_RXREG_Read(UARTx);
recv_index++;
}
if ((lastTick - SysTick->VAL > (timeout * ((__SYSTEM_CLOCK/1000)))) &&
(recv_index < expect_size))
{
*recv_size = recv_index;
return EIO;
}
}
return 0;
} | [
"int32_t",
"hal_uart_recv_II",
"(",
"uart_dev_t",
"*",
"uart",
",",
"void",
"*",
"data",
",",
"uint32_t",
"expect_size",
",",
"uint32_t",
"*",
"recv_size",
",",
"uint32_t",
"timeout",
")",
"{",
"uint32_t",
"recv_index",
"=",
"0",
";",
"UARTx_Type",
"*",
"UARTx",
"=",
"NULL",
";",
"uint32_t",
"lastTick",
";",
"uint8_t",
"*",
"buf",
"=",
"(",
"uint8_t",
"*",
")",
"data",
";",
"if",
"(",
"(",
"NULL",
"==",
"uart",
")",
"||",
"(",
"NULL",
"==",
"data",
")",
")",
"{",
"return",
"EIO",
";",
"}",
"switch",
"(",
"uart",
"->",
"port",
")",
"{",
"case",
"UART_0",
":",
"UARTx",
"=",
"UART0",
";",
"break",
";",
"case",
"UART_1",
":",
"UARTx",
"=",
"UART1",
";",
"break",
";",
"case",
"UART_2",
":",
"UARTx",
"=",
"UART2",
";",
"break",
";",
"case",
"UART_3",
":",
"UARTx",
"=",
"UART3",
";",
"break",
";",
"case",
"UART_4",
":",
"UARTx",
"=",
"UART4",
";",
"break",
";",
"case",
"UART_5",
":",
"UARTx",
"=",
"UART5",
";",
"break",
";",
"default",
":",
"return",
"EIO",
";",
"}",
"lastTick",
"=",
"SysTick",
"->",
"VAL",
";",
"while",
"(",
"recv_index",
"<",
"expect_size",
")",
"{",
"IWDT_Clr",
"(",
")",
";",
"if",
"(",
"SET",
"==",
"UARTx_RXBUFSTA_RXFF_Chk",
"(",
"UARTx",
")",
")",
"{",
"buf",
"[",
"recv_index",
"]",
"=",
"UARTx_RXREG_Read",
"(",
"UARTx",
")",
";",
"recv_index",
"++",
";",
"}",
"if",
"(",
"(",
"lastTick",
"-",
"SysTick",
"->",
"VAL",
">",
"(",
"timeout",
"*",
"(",
"(",
"__SYSTEM_CLOCK",
"/",
"1000",
")",
")",
")",
")",
"&&",
"(",
"recv_index",
"<",
"expect_size",
")",
")",
"{",
"*",
"recv_size",
"=",
"recv_index",
";",
"return",
"EIO",
";",
"}",
"}",
"return",
"0",
";",
"}"
] | Receive data on a UART interface | [
"Receive",
"data",
"on",
"a",
"UART",
"interface"
] | [
"//param check\r",
"//feed dog\r",
"//wait for a byte\r",
"//read register\r"
] | [
{
"param": "uart",
"type": "uart_dev_t"
},
{
"param": "data",
"type": "void"
},
{
"param": "expect_size",
"type": "uint32_t"
},
{
"param": "recv_size",
"type": "uint32_t"
},
{
"param": "timeout",
"type": "uint32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "uart",
"type": "uart_dev_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "expect_size",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "recv_size",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "timeout",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
69d5e653c53044dae542288fed4cdb7f806e5e4c | ghsecuritylab/AliOS-LoRa | platform/mcu/fm33A0xx/HAL/soc/uart.c | [
"Apache-2.0"
] | C | hal_uart_finalize | int32_t | int32_t hal_uart_finalize(uart_dev_t *uart)
{
UARTx_Type *UARTx = NULL;
if (NULL == uart)
{
return EIO;
}
switch (uart->port)
{
case UART_0:
UARTx = UART0;
break;
case UART_1:
UARTx = UART1;
break;
case UART_2:
UARTx = UART2;
break;
case UART_3:
UARTx = UART3;
break;
case UART_4:
UARTx = UART4;
break;
case UART_5:
UARTx = UART5;
break;
default:
return EIO;
}
UARTx_Deinit(UARTx);
return 0;
} | /**
* Deinitialises a UART interface
*
* @param[in] uart the interface which should be deinitialised
*
* @return 0 : on success, EIO : if an error occurred with any step
*/ | Deinitialises a UART interface
@param[in] uart the interface which should be deinitialised
@return 0 : on success, EIO : if an error occurred with any step | [
"Deinitialises",
"a",
"UART",
"interface",
"@param",
"[",
"in",
"]",
"uart",
"the",
"interface",
"which",
"should",
"be",
"deinitialised",
"@return",
"0",
":",
"on",
"success",
"EIO",
":",
"if",
"an",
"error",
"occurred",
"with",
"any",
"step"
] | int32_t hal_uart_finalize(uart_dev_t *uart)
{
UARTx_Type *UARTx = NULL;
if (NULL == uart)
{
return EIO;
}
switch (uart->port)
{
case UART_0:
UARTx = UART0;
break;
case UART_1:
UARTx = UART1;
break;
case UART_2:
UARTx = UART2;
break;
case UART_3:
UARTx = UART3;
break;
case UART_4:
UARTx = UART4;
break;
case UART_5:
UARTx = UART5;
break;
default:
return EIO;
}
UARTx_Deinit(UARTx);
return 0;
} | [
"int32_t",
"hal_uart_finalize",
"(",
"uart_dev_t",
"*",
"uart",
")",
"{",
"UARTx_Type",
"*",
"UARTx",
"=",
"NULL",
";",
"if",
"(",
"NULL",
"==",
"uart",
")",
"{",
"return",
"EIO",
";",
"}",
"switch",
"(",
"uart",
"->",
"port",
")",
"{",
"case",
"UART_0",
":",
"UARTx",
"=",
"UART0",
";",
"break",
";",
"case",
"UART_1",
":",
"UARTx",
"=",
"UART1",
";",
"break",
";",
"case",
"UART_2",
":",
"UARTx",
"=",
"UART2",
";",
"break",
";",
"case",
"UART_3",
":",
"UARTx",
"=",
"UART3",
";",
"break",
";",
"case",
"UART_4",
":",
"UARTx",
"=",
"UART4",
";",
"break",
";",
"case",
"UART_5",
":",
"UARTx",
"=",
"UART5",
";",
"break",
";",
"default",
":",
"return",
"EIO",
";",
"}",
"UARTx_Deinit",
"(",
"UARTx",
")",
";",
"return",
"0",
";",
"}"
] | Deinitialises a UART interface | [
"Deinitialises",
"a",
"UART",
"interface"
] | [] | [
{
"param": "uart",
"type": "uart_dev_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "uart",
"type": "uart_dev_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
de7ca5a6708751c2c58810737567d5e134a72cd2 | eschmar/chipkit-pong | sound.c | [
"BSD-3-Clause"
] | C | tone | void | void tone(int note, int volumeParam) {
if (note == 0) {
PR3 = 0;
OC1R = 0;
OC1RS = 0;
} else {
int frequency = (int) 625000 / note;
int volume = (int) frequency / volumeParam;
PR3 = frequency;
OC1R = volume;
OC1RS = volume;
}
} | /*
* Generate sound with specific note
* The buzzer must be connected to PIN 3
*/ | Generate sound with specific note
The buzzer must be connected to PIN 3 | [
"Generate",
"sound",
"with",
"specific",
"note",
"The",
"buzzer",
"must",
"be",
"connected",
"to",
"PIN",
"3"
] | void tone(int note, int volumeParam) {
if (note == 0) {
PR3 = 0;
OC1R = 0;
OC1RS = 0;
} else {
int frequency = (int) 625000 / note;
int volume = (int) frequency / volumeParam;
PR3 = frequency;
OC1R = volume;
OC1RS = volume;
}
} | [
"void",
"tone",
"(",
"int",
"note",
",",
"int",
"volumeParam",
")",
"{",
"if",
"(",
"note",
"==",
"0",
")",
"{",
"PR3",
"=",
"0",
";",
"OC1R",
"=",
"0",
";",
"OC1RS",
"=",
"0",
";",
"}",
"else",
"{",
"int",
"frequency",
"=",
"(",
"int",
")",
"625000",
"/",
"note",
";",
"int",
"volume",
"=",
"(",
"int",
")",
"frequency",
"/",
"volumeParam",
";",
"PR3",
"=",
"frequency",
";",
"OC1R",
"=",
"volume",
";",
"OC1RS",
"=",
"volume",
";",
"}",
"}"
] | Generate sound with specific note
The buzzer must be connected to PIN 3 | [
"Generate",
"sound",
"with",
"specific",
"note",
"The",
"buzzer",
"must",
"be",
"connected",
"to",
"PIN",
"3"
] | [] | [
{
"param": "note",
"type": "int"
},
{
"param": "volumeParam",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "note",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "volumeParam",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d157448b6c27feebc3f3eb007a7fdead5a89c596 | eschmar/chipkit-pong | helpers.c | [
"BSD-3-Clause"
] | C | enableTimer2 | void | void enableTimer2(int period, int priority, int prescaling, int interrupts) {
T2CON = 0x0; // stop timer
TMR2 = 0; // clear timer
PR2 = period; // set period
IPCSET(2) = priority; // set priority
IFSCLR(0) = 0x100; // reset timer interrupt status flag
// enable timer interrupts
if (interrupts == 1) { IECSET(0) = 0x100; }
// set prescaling
T2CONSET = prescaling << 4;
// enable
T2CONSET = 0x8000;
} | /**
* Set up and start timer 2
*/ | Set up and start timer 2 | [
"Set",
"up",
"and",
"start",
"timer",
"2"
] | void enableTimer2(int period, int priority, int prescaling, int interrupts) {
T2CON = 0x0;
TMR2 = 0;
PR2 = period;
IPCSET(2) = priority;
IFSCLR(0) = 0x100;
if (interrupts == 1) { IECSET(0) = 0x100; }
T2CONSET = prescaling << 4;
T2CONSET = 0x8000;
} | [
"void",
"enableTimer2",
"(",
"int",
"period",
",",
"int",
"priority",
",",
"int",
"prescaling",
",",
"int",
"interrupts",
")",
"{",
"T2CON",
"=",
"0x0",
";",
"TMR2",
"=",
"0",
";",
"PR2",
"=",
"period",
";",
"IPCSET",
"(",
"2",
")",
"=",
"priority",
";",
"IFSCLR",
"(",
"0",
")",
"=",
"0x100",
";",
"if",
"(",
"interrupts",
"==",
"1",
")",
"{",
"IECSET",
"(",
"0",
")",
"=",
"0x100",
";",
"}",
"T2CONSET",
"=",
"prescaling",
"<<",
"4",
";",
"T2CONSET",
"=",
"0x8000",
";",
"}"
] | Set up and start timer 2 | [
"Set",
"up",
"and",
"start",
"timer",
"2"
] | [
"// stop timer",
"// clear timer",
"// set period",
"// set priority",
"// reset timer interrupt status flag",
"// enable timer interrupts",
"// set prescaling",
"// enable"
] | [
{
"param": "period",
"type": "int"
},
{
"param": "priority",
"type": "int"
},
{
"param": "prescaling",
"type": "int"
},
{
"param": "interrupts",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "period",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "priority",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "prescaling",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "interrupts",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d157448b6c27feebc3f3eb007a7fdead5a89c596 | eschmar/chipkit-pong | helpers.c | [
"BSD-3-Clause"
] | C | enableTimer3 | void | void enableTimer3(int period, int priority, int prescaling, int interrupts) {
T3CON = 0x0; // stop timer
TMR3 = 0; // clear timer
PR3 = period; // set period
IPCSET(3) = priority; // set priority
IFSCLR(0) = 0x1000; // reset timer interrupt status flag
// enable timer interrupts
if (interrupts == 1) { IECSET(0) = 0x1000; }
// set prescaling
T3CONSET = prescaling << 4;
// enable
T3CONSET = 0x8000;
} | /**
* Set up and start timer 3
*/ | Set up and start timer 3 | [
"Set",
"up",
"and",
"start",
"timer",
"3"
] | void enableTimer3(int period, int priority, int prescaling, int interrupts) {
T3CON = 0x0;
TMR3 = 0;
PR3 = period;
IPCSET(3) = priority;
IFSCLR(0) = 0x1000;
if (interrupts == 1) { IECSET(0) = 0x1000; }
T3CONSET = prescaling << 4;
T3CONSET = 0x8000;
} | [
"void",
"enableTimer3",
"(",
"int",
"period",
",",
"int",
"priority",
",",
"int",
"prescaling",
",",
"int",
"interrupts",
")",
"{",
"T3CON",
"=",
"0x0",
";",
"TMR3",
"=",
"0",
";",
"PR3",
"=",
"period",
";",
"IPCSET",
"(",
"3",
")",
"=",
"priority",
";",
"IFSCLR",
"(",
"0",
")",
"=",
"0x1000",
";",
"if",
"(",
"interrupts",
"==",
"1",
")",
"{",
"IECSET",
"(",
"0",
")",
"=",
"0x1000",
";",
"}",
"T3CONSET",
"=",
"prescaling",
"<<",
"4",
";",
"T3CONSET",
"=",
"0x8000",
";",
"}"
] | Set up and start timer 3 | [
"Set",
"up",
"and",
"start",
"timer",
"3"
] | [
"// stop timer",
"// clear timer",
"// set period",
"// set priority",
"// reset timer interrupt status flag",
"// enable timer interrupts",
"// set prescaling",
"// enable"
] | [
{
"param": "period",
"type": "int"
},
{
"param": "priority",
"type": "int"
},
{
"param": "prescaling",
"type": "int"
},
{
"param": "interrupts",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "period",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "priority",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "prescaling",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "interrupts",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | proc_mapstacks | void | void proc_mapstacks(pagetable_t kpgtbl) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
char* pa = kalloc();
if (pa == 0)
panic("kalloc");
uint64 va = KSTACK((int)(p - proc));
kvmmap(kpgtbl, va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
}
} | // Allocate a page for each process's kernel stack.
// Map it high in memory, followed by an invalid
// guard page. | Allocate a page for each process's kernel stack.
Map it high in memory, followed by an invalid
guard page. | [
"Allocate",
"a",
"page",
"for",
"each",
"process",
"'",
"s",
"kernel",
"stack",
".",
"Map",
"it",
"high",
"in",
"memory",
"followed",
"by",
"an",
"invalid",
"guard",
"page",
"."
] | void proc_mapstacks(pagetable_t kpgtbl) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
char* pa = kalloc();
if (pa == 0)
panic("kalloc");
uint64 va = KSTACK((int)(p - proc));
kvmmap(kpgtbl, va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
}
} | [
"void",
"proc_mapstacks",
"(",
"pagetable_t",
"kpgtbl",
")",
"{",
"struct",
"proc",
"*",
"p",
";",
"for",
"(",
"p",
"=",
"proc",
";",
"p",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"p",
"++",
")",
"{",
"char",
"*",
"pa",
"=",
"kalloc",
"(",
")",
";",
"if",
"(",
"pa",
"==",
"0",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"uint64",
"va",
"=",
"KSTACK",
"(",
"(",
"int",
")",
"(",
"p",
"-",
"proc",
")",
")",
";",
"kvmmap",
"(",
"kpgtbl",
",",
"va",
",",
"(",
"uint64",
")",
"pa",
",",
"PGSIZE",
",",
"PTE_R",
"|",
"PTE_W",
")",
";",
"}",
"}"
] | Allocate a page for each process's kernel stack. | [
"Allocate",
"a",
"page",
"for",
"each",
"process",
"'",
"s",
"kernel",
"stack",
"."
] | [] | [
{
"param": "kpgtbl",
"type": "pagetable_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "kpgtbl",
"type": "pagetable_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | procinit | void | void procinit(void) {
struct proc* p;
initlock(&pid_lock, "nextpid");
initlock(&wait_lock, "wait_lock");
for (p = proc; p < &proc[NPROC]; p++) {
initlock(&p->lock, "proc");
// Default to priority 1
p->priority = 1;
p->kstack = KSTACK((int)(p - proc));
}
} | // initialize the proc table at boot time. | initialize the proc table at boot time. | [
"initialize",
"the",
"proc",
"table",
"at",
"boot",
"time",
"."
] | void procinit(void) {
struct proc* p;
initlock(&pid_lock, "nextpid");
initlock(&wait_lock, "wait_lock");
for (p = proc; p < &proc[NPROC]; p++) {
initlock(&p->lock, "proc");
p->priority = 1;
p->kstack = KSTACK((int)(p - proc));
}
} | [
"void",
"procinit",
"(",
"void",
")",
"{",
"struct",
"proc",
"*",
"p",
";",
"initlock",
"(",
"&",
"pid_lock",
",",
"\"",
"\"",
")",
";",
"initlock",
"(",
"&",
"wait_lock",
",",
"\"",
"\"",
")",
";",
"for",
"(",
"p",
"=",
"proc",
";",
"p",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"p",
"++",
")",
"{",
"initlock",
"(",
"&",
"p",
"->",
"lock",
",",
"\"",
"\"",
")",
";",
"p",
"->",
"priority",
"=",
"1",
";",
"p",
"->",
"kstack",
"=",
"KSTACK",
"(",
"(",
"int",
")",
"(",
"p",
"-",
"proc",
")",
")",
";",
"}",
"}"
] | initialize the proc table at boot time. | [
"initialize",
"the",
"proc",
"table",
"at",
"boot",
"time",
"."
] | [
"// Default to priority 1"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | mycpu | null | struct cpu*
mycpu(void) {
int id = cpuid();
struct cpu* c = &cpus[id];
return c;
} | // Return this CPU's cpu struct.
// Interrupts must be disabled. | Return this CPU's cpu struct.
Interrupts must be disabled. | [
"Return",
"this",
"CPU",
"'",
"s",
"cpu",
"struct",
".",
"Interrupts",
"must",
"be",
"disabled",
"."
] | struct cpu*
mycpu(void) {
int id = cpuid();
struct cpu* c = &cpus[id];
return c;
} | [
"struct",
"cpu",
"*",
"mycpu",
"(",
"void",
")",
"{",
"int",
"id",
"=",
"cpuid",
"(",
")",
";",
"struct",
"cpu",
"*",
"c",
"=",
"&",
"cpus",
"[",
"id",
"]",
";",
"return",
"c",
";",
"}"
] | Return this CPU's cpu struct. | [
"Return",
"this",
"CPU",
"'",
"s",
"cpu",
"struct",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | myproc | null | struct proc*
myproc(void) {
push_off();
struct cpu* c = mycpu();
struct proc* p = c->proc;
pop_off();
return p;
} | // Return the current struct proc *, or zero if none. | Return the current struct proc *, or zero if none. | [
"Return",
"the",
"current",
"struct",
"proc",
"*",
"or",
"zero",
"if",
"none",
"."
] | struct proc*
myproc(void) {
push_off();
struct cpu* c = mycpu();
struct proc* p = c->proc;
pop_off();
return p;
} | [
"struct",
"proc",
"*",
"myproc",
"(",
"void",
")",
"{",
"push_off",
"(",
")",
";",
"struct",
"cpu",
"*",
"c",
"=",
"mycpu",
"(",
")",
";",
"struct",
"proc",
"*",
"p",
"=",
"c",
"->",
"proc",
";",
"pop_off",
"(",
")",
";",
"return",
"p",
";",
"}"
] | Return the current struct proc *, or zero if none. | [
"Return",
"the",
"current",
"struct",
"proc",
"*",
"or",
"zero",
"if",
"none",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | allocproc | null | static struct proc*
allocproc(void) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if (p->state == UNUSED) {
goto found;
} else {
release(&p->lock);
}
}
return 0;
found:
p->pid = allocpid();
p->state = USED;
p->priority = 1;
// Allocate a trapframe page.
if ((p->trapframe = (struct trapframe*)kalloc()) == 0) {
freeproc(p);
release(&p->lock);
return 0;
}
// An empty user page table.
p->pagetable = proc_pagetable(p);
if (p->pagetable == 0) {
freeproc(p);
release(&p->lock);
return 0;
}
// Set up new context to start executing at forkret,
// which returns to user space.
memset(&p->context, 0, sizeof(p->context));
p->context.ra = (uint64)forkret;
p->context.sp = p->kstack + PGSIZE;
return p;
} | // Look in the process table for an UNUSED proc.
// If found, initialize state required to run in the kernel,
// and return with p->lock held.
// If there are no free procs, or a memory allocation fails, return 0. | Look in the process table for an UNUSED proc.
If found, initialize state required to run in the kernel,
and return with p->lock held.
If there are no free procs, or a memory allocation fails, return 0. | [
"Look",
"in",
"the",
"process",
"table",
"for",
"an",
"UNUSED",
"proc",
".",
"If",
"found",
"initialize",
"state",
"required",
"to",
"run",
"in",
"the",
"kernel",
"and",
"return",
"with",
"p",
"-",
">",
"lock",
"held",
".",
"If",
"there",
"are",
"no",
"free",
"procs",
"or",
"a",
"memory",
"allocation",
"fails",
"return",
"0",
"."
] | static struct proc*
allocproc(void) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if (p->state == UNUSED) {
goto found;
} else {
release(&p->lock);
}
}
return 0;
found:
p->pid = allocpid();
p->state = USED;
p->priority = 1;
if ((p->trapframe = (struct trapframe*)kalloc()) == 0) {
freeproc(p);
release(&p->lock);
return 0;
}
p->pagetable = proc_pagetable(p);
if (p->pagetable == 0) {
freeproc(p);
release(&p->lock);
return 0;
}
memset(&p->context, 0, sizeof(p->context));
p->context.ra = (uint64)forkret;
p->context.sp = p->kstack + PGSIZE;
return p;
} | [
"static",
"struct",
"proc",
"*",
"allocproc",
"(",
"void",
")",
"{",
"struct",
"proc",
"*",
"p",
";",
"for",
"(",
"p",
"=",
"proc",
";",
"p",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"p",
"++",
")",
"{",
"acquire",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"if",
"(",
"p",
"->",
"state",
"==",
"UNUSED",
")",
"{",
"goto",
"found",
";",
"}",
"else",
"{",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"}",
"}",
"return",
"0",
";",
"found",
":",
"p",
"->",
"pid",
"=",
"allocpid",
"(",
")",
";",
"p",
"->",
"state",
"=",
"USED",
";",
"p",
"->",
"priority",
"=",
"1",
";",
"if",
"(",
"(",
"p",
"->",
"trapframe",
"=",
"(",
"struct",
"trapframe",
"*",
")",
"kalloc",
"(",
")",
")",
"==",
"0",
")",
"{",
"freeproc",
"(",
"p",
")",
";",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"return",
"0",
";",
"}",
"p",
"->",
"pagetable",
"=",
"proc_pagetable",
"(",
"p",
")",
";",
"if",
"(",
"p",
"->",
"pagetable",
"==",
"0",
")",
"{",
"freeproc",
"(",
"p",
")",
";",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"return",
"0",
";",
"}",
"memset",
"(",
"&",
"p",
"->",
"context",
",",
"0",
",",
"sizeof",
"(",
"p",
"->",
"context",
")",
")",
";",
"p",
"->",
"context",
".",
"ra",
"=",
"(",
"uint64",
")",
"forkret",
";",
"p",
"->",
"context",
".",
"sp",
"=",
"p",
"->",
"kstack",
"+",
"PGSIZE",
";",
"return",
"p",
";",
"}"
] | Look in the process table for an UNUSED proc. | [
"Look",
"in",
"the",
"process",
"table",
"for",
"an",
"UNUSED",
"proc",
"."
] | [
"// Allocate a trapframe page.",
"// An empty user page table.",
"// Set up new context to start executing at forkret,",
"// which returns to user space."
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | freeproc | void | static void
freeproc(struct proc* p) {
if (p->trapframe)
kfree((void*)p->trapframe);
p->trapframe = 0;
if (p->pagetable)
proc_freepagetable(p->pagetable, p->sz);
p->pagetable = 0;
p->sz = 0;
p->pid = 0;
p->parent = 0;
p->name[0] = 0;
p->chan = 0;
p->killed = 0;
p->xstate = 0;
p->state = UNUSED;
} | // free a proc structure and the data hanging from it,
// including user pages.
// p->lock must be held. | free a proc structure and the data hanging from it,
including user pages.
p->lock must be held. | [
"free",
"a",
"proc",
"structure",
"and",
"the",
"data",
"hanging",
"from",
"it",
"including",
"user",
"pages",
".",
"p",
"-",
">",
"lock",
"must",
"be",
"held",
"."
] | static void
freeproc(struct proc* p) {
if (p->trapframe)
kfree((void*)p->trapframe);
p->trapframe = 0;
if (p->pagetable)
proc_freepagetable(p->pagetable, p->sz);
p->pagetable = 0;
p->sz = 0;
p->pid = 0;
p->parent = 0;
p->name[0] = 0;
p->chan = 0;
p->killed = 0;
p->xstate = 0;
p->state = UNUSED;
} | [
"static",
"void",
"freeproc",
"(",
"struct",
"proc",
"*",
"p",
")",
"{",
"if",
"(",
"p",
"->",
"trapframe",
")",
"kfree",
"(",
"(",
"void",
"*",
")",
"p",
"->",
"trapframe",
")",
";",
"p",
"->",
"trapframe",
"=",
"0",
";",
"if",
"(",
"p",
"->",
"pagetable",
")",
"proc_freepagetable",
"(",
"p",
"->",
"pagetable",
",",
"p",
"->",
"sz",
")",
";",
"p",
"->",
"pagetable",
"=",
"0",
";",
"p",
"->",
"sz",
"=",
"0",
";",
"p",
"->",
"pid",
"=",
"0",
";",
"p",
"->",
"parent",
"=",
"0",
";",
"p",
"->",
"name",
"[",
"0",
"]",
"=",
"0",
";",
"p",
"->",
"chan",
"=",
"0",
";",
"p",
"->",
"killed",
"=",
"0",
";",
"p",
"->",
"xstate",
"=",
"0",
";",
"p",
"->",
"state",
"=",
"UNUSED",
";",
"}"
] | free a proc structure and the data hanging from it,
including user pages. | [
"free",
"a",
"proc",
"structure",
"and",
"the",
"data",
"hanging",
"from",
"it",
"including",
"user",
"pages",
"."
] | [] | [
{
"param": "p",
"type": "struct proc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p",
"type": "struct proc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | proc_pagetable | pagetable_t | pagetable_t
proc_pagetable(struct proc* p) {
pagetable_t pagetable;
// An empty page table.
pagetable = uvmcreate();
if (pagetable == 0)
return 0;
// map the trampoline code (for system call return)
// at the highest user virtual address.
// only the supervisor uses it, on the way
// to/from user space, so not PTE_U.
if (mappages(pagetable, TRAMPOLINE, PGSIZE,
(uint64)trampoline, PTE_R | PTE_X) < 0) {
uvmfree(pagetable, 0);
return 0;
}
// map the trapframe just below TRAMPOLINE, for trampoline.S.
if (mappages(pagetable, TRAPFRAME, PGSIZE,
(uint64)(p->trapframe), PTE_R | PTE_W) < 0) {
uvmunmap(pagetable, TRAMPOLINE, 1, 0);
uvmfree(pagetable, 0);
return 0;
}
return pagetable;
} | // Create a user page table for a given process,
// with no user memory, but with trampoline pages. | Create a user page table for a given process,
with no user memory, but with trampoline pages. | [
"Create",
"a",
"user",
"page",
"table",
"for",
"a",
"given",
"process",
"with",
"no",
"user",
"memory",
"but",
"with",
"trampoline",
"pages",
"."
] | pagetable_t
proc_pagetable(struct proc* p) {
pagetable_t pagetable;
pagetable = uvmcreate();
if (pagetable == 0)
return 0;
if (mappages(pagetable, TRAMPOLINE, PGSIZE,
(uint64)trampoline, PTE_R | PTE_X) < 0) {
uvmfree(pagetable, 0);
return 0;
}
if (mappages(pagetable, TRAPFRAME, PGSIZE,
(uint64)(p->trapframe), PTE_R | PTE_W) < 0) {
uvmunmap(pagetable, TRAMPOLINE, 1, 0);
uvmfree(pagetable, 0);
return 0;
}
return pagetable;
} | [
"pagetable_t",
"proc_pagetable",
"(",
"struct",
"proc",
"*",
"p",
")",
"{",
"pagetable_t",
"pagetable",
";",
"pagetable",
"=",
"uvmcreate",
"(",
")",
";",
"if",
"(",
"pagetable",
"==",
"0",
")",
"return",
"0",
";",
"if",
"(",
"mappages",
"(",
"pagetable",
",",
"TRAMPOLINE",
",",
"PGSIZE",
",",
"(",
"uint64",
")",
"trampoline",
",",
"PTE_R",
"|",
"PTE_X",
")",
"<",
"0",
")",
"{",
"uvmfree",
"(",
"pagetable",
",",
"0",
")",
";",
"return",
"0",
";",
"}",
"if",
"(",
"mappages",
"(",
"pagetable",
",",
"TRAPFRAME",
",",
"PGSIZE",
",",
"(",
"uint64",
")",
"(",
"p",
"->",
"trapframe",
")",
",",
"PTE_R",
"|",
"PTE_W",
")",
"<",
"0",
")",
"{",
"uvmunmap",
"(",
"pagetable",
",",
"TRAMPOLINE",
",",
"1",
",",
"0",
")",
";",
"uvmfree",
"(",
"pagetable",
",",
"0",
")",
";",
"return",
"0",
";",
"}",
"return",
"pagetable",
";",
"}"
] | Create a user page table for a given process,
with no user memory, but with trampoline pages. | [
"Create",
"a",
"user",
"page",
"table",
"for",
"a",
"given",
"process",
"with",
"no",
"user",
"memory",
"but",
"with",
"trampoline",
"pages",
"."
] | [
"// An empty page table.",
"// map the trampoline code (for system call return)",
"// at the highest user virtual address.",
"// only the supervisor uses it, on the way",
"// to/from user space, so not PTE_U.",
"// map the trapframe just below TRAMPOLINE, for trampoline.S."
] | [
{
"param": "p",
"type": "struct proc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p",
"type": "struct proc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | proc_freepagetable | void | void proc_freepagetable(pagetable_t pagetable, uint64 sz) {
uvmunmap(pagetable, TRAMPOLINE, 1, 0);
uvmunmap(pagetable, TRAPFRAME, 1, 0);
uvmfree(pagetable, sz);
} | // Free a process's page table, and free the
// physical memory it refers to. | Free a process's page table, and free the
physical memory it refers to. | [
"Free",
"a",
"process",
"'",
"s",
"page",
"table",
"and",
"free",
"the",
"physical",
"memory",
"it",
"refers",
"to",
"."
] | void proc_freepagetable(pagetable_t pagetable, uint64 sz) {
uvmunmap(pagetable, TRAMPOLINE, 1, 0);
uvmunmap(pagetable, TRAPFRAME, 1, 0);
uvmfree(pagetable, sz);
} | [
"void",
"proc_freepagetable",
"(",
"pagetable_t",
"pagetable",
",",
"uint64",
"sz",
")",
"{",
"uvmunmap",
"(",
"pagetable",
",",
"TRAMPOLINE",
",",
"1",
",",
"0",
")",
";",
"uvmunmap",
"(",
"pagetable",
",",
"TRAPFRAME",
",",
"1",
",",
"0",
")",
";",
"uvmfree",
"(",
"pagetable",
",",
"sz",
")",
";",
"}"
] | Free a process's page table, and free the
physical memory it refers to. | [
"Free",
"a",
"process",
"'",
"s",
"page",
"table",
"and",
"free",
"the",
"physical",
"memory",
"it",
"refers",
"to",
"."
] | [] | [
{
"param": "pagetable",
"type": "pagetable_t"
},
{
"param": "sz",
"type": "uint64"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pagetable",
"type": "pagetable_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "sz",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | userinit | void | void userinit(void) {
struct proc* p;
p = allocproc();
initproc = p;
// allocate one user page and copy init's instructions
// and data into it.
uvminit(p->pagetable, initcode, sizeof(initcode));
p->sz = PGSIZE;
// prepare for the very first "return" from kernel to user.
p->trapframe->epc = 0; // user program counter
p->trapframe->sp = PGSIZE; // user stack pointer
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
p->state = RUNNABLE;
release(&p->lock);
} | // Set up first user process. | Set up first user process. | [
"Set",
"up",
"first",
"user",
"process",
"."
] | void userinit(void) {
struct proc* p;
p = allocproc();
initproc = p;
uvminit(p->pagetable, initcode, sizeof(initcode));
p->sz = PGSIZE;
p->trapframe->epc = 0;
p->trapframe->sp = PGSIZE;
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
p->state = RUNNABLE;
release(&p->lock);
} | [
"void",
"userinit",
"(",
"void",
")",
"{",
"struct",
"proc",
"*",
"p",
";",
"p",
"=",
"allocproc",
"(",
")",
";",
"initproc",
"=",
"p",
";",
"uvminit",
"(",
"p",
"->",
"pagetable",
",",
"initcode",
",",
"sizeof",
"(",
"initcode",
")",
")",
";",
"p",
"->",
"sz",
"=",
"PGSIZE",
";",
"p",
"->",
"trapframe",
"->",
"epc",
"=",
"0",
";",
"p",
"->",
"trapframe",
"->",
"sp",
"=",
"PGSIZE",
";",
"safestrcpy",
"(",
"p",
"->",
"name",
",",
"\"",
"\"",
",",
"sizeof",
"(",
"p",
"->",
"name",
")",
")",
";",
"p",
"->",
"cwd",
"=",
"namei",
"(",
"\"",
"\"",
")",
";",
"p",
"->",
"state",
"=",
"RUNNABLE",
";",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"}"
] | Set up first user process. | [
"Set",
"up",
"first",
"user",
"process",
"."
] | [
"// allocate one user page and copy init's instructions",
"// and data into it.",
"// prepare for the very first \"return\" from kernel to user.",
"// user program counter",
"// user stack pointer"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | growproc | int | int growproc(int n) {
uint sz;
struct proc* p = myproc();
sz = p->sz;
if (n > 0) {
if ((sz = uvmalloc(p->pagetable, sz, sz + n)) == 0) {
return -1;
}
} else if (n < 0) {
sz = uvmdealloc(p->pagetable, sz, sz + n);
}
p->sz = sz;
return 0;
} | // Grow or shrink user memory by n bytes.
// Return 0 on success, -1 on failure. | Grow or shrink user memory by n bytes.
Return 0 on success, -1 on failure. | [
"Grow",
"or",
"shrink",
"user",
"memory",
"by",
"n",
"bytes",
".",
"Return",
"0",
"on",
"success",
"-",
"1",
"on",
"failure",
"."
] | int growproc(int n) {
uint sz;
struct proc* p = myproc();
sz = p->sz;
if (n > 0) {
if ((sz = uvmalloc(p->pagetable, sz, sz + n)) == 0) {
return -1;
}
} else if (n < 0) {
sz = uvmdealloc(p->pagetable, sz, sz + n);
}
p->sz = sz;
return 0;
} | [
"int",
"growproc",
"(",
"int",
"n",
")",
"{",
"uint",
"sz",
";",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"sz",
"=",
"p",
"->",
"sz",
";",
"if",
"(",
"n",
">",
"0",
")",
"{",
"if",
"(",
"(",
"sz",
"=",
"uvmalloc",
"(",
"p",
"->",
"pagetable",
",",
"sz",
",",
"sz",
"+",
"n",
")",
")",
"==",
"0",
")",
"{",
"return",
"-1",
";",
"}",
"}",
"else",
"if",
"(",
"n",
"<",
"0",
")",
"{",
"sz",
"=",
"uvmdealloc",
"(",
"p",
"->",
"pagetable",
",",
"sz",
",",
"sz",
"+",
"n",
")",
";",
"}",
"p",
"->",
"sz",
"=",
"sz",
";",
"return",
"0",
";",
"}"
] | Grow or shrink user memory by n bytes. | [
"Grow",
"or",
"shrink",
"user",
"memory",
"by",
"n",
"bytes",
"."
] | [] | [
{
"param": "n",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "n",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | fork | int | int fork(void) {
int i, pid;
struct proc* np;
struct proc* p = myproc();
// Allocate process.
if ((np = allocproc()) == 0) {
return -1;
}
// Point child memory to parent memory through copy-on-write
if (uvmcow(p->pagetable, np->pagetable, p->sz) < 0) {
freeproc(np);
release(&np->lock);
return -1;
}
np->sz = p->sz;
// Inherit priority level
np->priority = p->priority;
// copy saved user registers.
*(np->trapframe) = *(p->trapframe);
// Cause fork to return 0 in the child.
np->trapframe->a0 = 0;
// increment reference counts on open file descriptors.
for (i = 0; i < NOFILE; i++)
if (p->ofile[i])
np->ofile[i] = filedup(p->ofile[i]);
np->cwd = idup(p->cwd);
safestrcpy(np->name, p->name, sizeof(p->name));
pid = np->pid;
release(&np->lock);
acquire(&wait_lock);
np->parent = p;
release(&wait_lock);
acquire(&np->lock);
np->state = RUNNABLE;
release(&np->lock);
return pid;
} | // Create a new process, copying the parent.
// Sets up child kernel stack to return as if from fork() system call. | Create a new process, copying the parent.
Sets up child kernel stack to return as if from fork() system call. | [
"Create",
"a",
"new",
"process",
"copying",
"the",
"parent",
".",
"Sets",
"up",
"child",
"kernel",
"stack",
"to",
"return",
"as",
"if",
"from",
"fork",
"()",
"system",
"call",
"."
] | int fork(void) {
int i, pid;
struct proc* np;
struct proc* p = myproc();
if ((np = allocproc()) == 0) {
return -1;
}
if (uvmcow(p->pagetable, np->pagetable, p->sz) < 0) {
freeproc(np);
release(&np->lock);
return -1;
}
np->sz = p->sz;
np->priority = p->priority;
*(np->trapframe) = *(p->trapframe);
np->trapframe->a0 = 0;
for (i = 0; i < NOFILE; i++)
if (p->ofile[i])
np->ofile[i] = filedup(p->ofile[i]);
np->cwd = idup(p->cwd);
safestrcpy(np->name, p->name, sizeof(p->name));
pid = np->pid;
release(&np->lock);
acquire(&wait_lock);
np->parent = p;
release(&wait_lock);
acquire(&np->lock);
np->state = RUNNABLE;
release(&np->lock);
return pid;
} | [
"int",
"fork",
"(",
"void",
")",
"{",
"int",
"i",
",",
"pid",
";",
"struct",
"proc",
"*",
"np",
";",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"if",
"(",
"(",
"np",
"=",
"allocproc",
"(",
")",
")",
"==",
"0",
")",
"{",
"return",
"-1",
";",
"}",
"if",
"(",
"uvmcow",
"(",
"p",
"->",
"pagetable",
",",
"np",
"->",
"pagetable",
",",
"p",
"->",
"sz",
")",
"<",
"0",
")",
"{",
"freeproc",
"(",
"np",
")",
";",
"release",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"return",
"-1",
";",
"}",
"np",
"->",
"sz",
"=",
"p",
"->",
"sz",
";",
"np",
"->",
"priority",
"=",
"p",
"->",
"priority",
";",
"*",
"(",
"np",
"->",
"trapframe",
")",
"=",
"*",
"(",
"p",
"->",
"trapframe",
")",
";",
"np",
"->",
"trapframe",
"->",
"a0",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"NOFILE",
";",
"i",
"++",
")",
"if",
"(",
"p",
"->",
"ofile",
"[",
"i",
"]",
")",
"np",
"->",
"ofile",
"[",
"i",
"]",
"=",
"filedup",
"(",
"p",
"->",
"ofile",
"[",
"i",
"]",
")",
";",
"np",
"->",
"cwd",
"=",
"idup",
"(",
"p",
"->",
"cwd",
")",
";",
"safestrcpy",
"(",
"np",
"->",
"name",
",",
"p",
"->",
"name",
",",
"sizeof",
"(",
"p",
"->",
"name",
")",
")",
";",
"pid",
"=",
"np",
"->",
"pid",
";",
"release",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"acquire",
"(",
"&",
"wait_lock",
")",
";",
"np",
"->",
"parent",
"=",
"p",
";",
"release",
"(",
"&",
"wait_lock",
")",
";",
"acquire",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"np",
"->",
"state",
"=",
"RUNNABLE",
";",
"release",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"return",
"pid",
";",
"}"
] | Create a new process, copying the parent. | [
"Create",
"a",
"new",
"process",
"copying",
"the",
"parent",
"."
] | [
"// Allocate process.",
"// Point child memory to parent memory through copy-on-write",
"// Inherit priority level",
"// copy saved user registers.",
"// Cause fork to return 0 in the child.",
"// increment reference counts on open file descriptors."
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | reparent | void | void reparent(struct proc* p) {
struct proc* pp;
for (pp = proc; pp < &proc[NPROC]; pp++) {
if (pp->parent == p) {
pp->parent = initproc;
wakeup(initproc);
}
}
} | // Pass p's abandoned children to init.
// Caller must hold wait_lock. | Pass p's abandoned children to init.
Caller must hold wait_lock. | [
"Pass",
"p",
"'",
"s",
"abandoned",
"children",
"to",
"init",
".",
"Caller",
"must",
"hold",
"wait_lock",
"."
] | void reparent(struct proc* p) {
struct proc* pp;
for (pp = proc; pp < &proc[NPROC]; pp++) {
if (pp->parent == p) {
pp->parent = initproc;
wakeup(initproc);
}
}
} | [
"void",
"reparent",
"(",
"struct",
"proc",
"*",
"p",
")",
"{",
"struct",
"proc",
"*",
"pp",
";",
"for",
"(",
"pp",
"=",
"proc",
";",
"pp",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"pp",
"++",
")",
"{",
"if",
"(",
"pp",
"->",
"parent",
"==",
"p",
")",
"{",
"pp",
"->",
"parent",
"=",
"initproc",
";",
"wakeup",
"(",
"initproc",
")",
";",
"}",
"}",
"}"
] | Pass p's abandoned children to init. | [
"Pass",
"p",
"'",
"s",
"abandoned",
"children",
"to",
"init",
"."
] | [] | [
{
"param": "p",
"type": "struct proc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p",
"type": "struct proc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | exit | void | void exit(int status) {
struct proc* p = myproc();
if (p == initproc)
panic("init exiting");
// Close all open files.
for (int fd = 0; fd < NOFILE; fd++) {
if (p->ofile[fd]) {
struct file* f = p->ofile[fd];
fileclose(f);
p->ofile[fd] = 0;
}
}
begin_op();
iput(p->cwd);
end_op();
p->cwd = 0;
acquire(&wait_lock);
// Give any children to init.
reparent(p);
// Parent might be sleeping in wait().
wakeup(p->parent);
acquire(&p->lock);
p->xstate = status;
p->state = ZOMBIE;
release(&wait_lock);
// Jump into the scheduler, never to return.
sched();
panic("zombie exit");
} | // Exit the current process. Does not return.
// An exited process remains in the zombie state
// until its parent calls wait(). | Exit the current process. Does not return.
An exited process remains in the zombie state
until its parent calls wait(). | [
"Exit",
"the",
"current",
"process",
".",
"Does",
"not",
"return",
".",
"An",
"exited",
"process",
"remains",
"in",
"the",
"zombie",
"state",
"until",
"its",
"parent",
"calls",
"wait",
"()",
"."
] | void exit(int status) {
struct proc* p = myproc();
if (p == initproc)
panic("init exiting");
for (int fd = 0; fd < NOFILE; fd++) {
if (p->ofile[fd]) {
struct file* f = p->ofile[fd];
fileclose(f);
p->ofile[fd] = 0;
}
}
begin_op();
iput(p->cwd);
end_op();
p->cwd = 0;
acquire(&wait_lock);
reparent(p);
wakeup(p->parent);
acquire(&p->lock);
p->xstate = status;
p->state = ZOMBIE;
release(&wait_lock);
sched();
panic("zombie exit");
} | [
"void",
"exit",
"(",
"int",
"status",
")",
"{",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"if",
"(",
"p",
"==",
"initproc",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"for",
"(",
"int",
"fd",
"=",
"0",
";",
"fd",
"<",
"NOFILE",
";",
"fd",
"++",
")",
"{",
"if",
"(",
"p",
"->",
"ofile",
"[",
"fd",
"]",
")",
"{",
"struct",
"file",
"*",
"f",
"=",
"p",
"->",
"ofile",
"[",
"fd",
"]",
";",
"fileclose",
"(",
"f",
")",
";",
"p",
"->",
"ofile",
"[",
"fd",
"]",
"=",
"0",
";",
"}",
"}",
"begin_op",
"(",
")",
";",
"iput",
"(",
"p",
"->",
"cwd",
")",
";",
"end_op",
"(",
")",
";",
"p",
"->",
"cwd",
"=",
"0",
";",
"acquire",
"(",
"&",
"wait_lock",
")",
";",
"reparent",
"(",
"p",
")",
";",
"wakeup",
"(",
"p",
"->",
"parent",
")",
";",
"acquire",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"p",
"->",
"xstate",
"=",
"status",
";",
"p",
"->",
"state",
"=",
"ZOMBIE",
";",
"release",
"(",
"&",
"wait_lock",
")",
";",
"sched",
"(",
")",
";",
"panic",
"(",
"\"",
"\"",
")",
";",
"}"
] | Exit the current process. | [
"Exit",
"the",
"current",
"process",
"."
] | [
"// Close all open files.",
"// Give any children to init.",
"// Parent might be sleeping in wait().",
"// Jump into the scheduler, never to return."
] | [
{
"param": "status",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "status",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | wait | int | int wait(uint64 addr) {
struct proc* np;
int havekids, pid;
struct proc* p = myproc();
acquire(&wait_lock);
for (;;) {
// Scan through table looking for exited children.
havekids = 0;
for (np = proc; np < &proc[NPROC]; np++) {
if (np->parent == p) {
// make sure the child isn't still in exit() or swtch().
acquire(&np->lock);
havekids = 1;
if (np->state == ZOMBIE) {
// Found one.
pid = np->pid;
if (addr != 0 && copyout(p->pagetable, addr, (char*)&np->xstate,
sizeof(np->xstate)) < 0) {
release(&np->lock);
release(&wait_lock);
return -1;
}
freeproc(np);
release(&np->lock);
release(&wait_lock);
return pid;
}
release(&np->lock);
}
}
// No point waiting if we don't have any children.
if (!havekids || p->killed) {
release(&wait_lock);
return -1;
}
// Wait for a child to exit.
sleep(p, &wait_lock); //DOC: wait-sleep
}
} | // Wait for a child process to exit and return its pid.
// Return -1 if this process has no children. | Wait for a child process to exit and return its pid.
Return -1 if this process has no children. | [
"Wait",
"for",
"a",
"child",
"process",
"to",
"exit",
"and",
"return",
"its",
"pid",
".",
"Return",
"-",
"1",
"if",
"this",
"process",
"has",
"no",
"children",
"."
] | int wait(uint64 addr) {
struct proc* np;
int havekids, pid;
struct proc* p = myproc();
acquire(&wait_lock);
for (;;) {
havekids = 0;
for (np = proc; np < &proc[NPROC]; np++) {
if (np->parent == p) {
acquire(&np->lock);
havekids = 1;
if (np->state == ZOMBIE) {
pid = np->pid;
if (addr != 0 && copyout(p->pagetable, addr, (char*)&np->xstate,
sizeof(np->xstate)) < 0) {
release(&np->lock);
release(&wait_lock);
return -1;
}
freeproc(np);
release(&np->lock);
release(&wait_lock);
return pid;
}
release(&np->lock);
}
}
if (!havekids || p->killed) {
release(&wait_lock);
return -1;
}
sleep(p, &wait_lock);
}
} | [
"int",
"wait",
"(",
"uint64",
"addr",
")",
"{",
"struct",
"proc",
"*",
"np",
";",
"int",
"havekids",
",",
"pid",
";",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"acquire",
"(",
"&",
"wait_lock",
")",
";",
"for",
"(",
";",
";",
")",
"{",
"havekids",
"=",
"0",
";",
"for",
"(",
"np",
"=",
"proc",
";",
"np",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"np",
"++",
")",
"{",
"if",
"(",
"np",
"->",
"parent",
"==",
"p",
")",
"{",
"acquire",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"havekids",
"=",
"1",
";",
"if",
"(",
"np",
"->",
"state",
"==",
"ZOMBIE",
")",
"{",
"pid",
"=",
"np",
"->",
"pid",
";",
"if",
"(",
"addr",
"!=",
"0",
"&&",
"copyout",
"(",
"p",
"->",
"pagetable",
",",
"addr",
",",
"(",
"char",
"*",
")",
"&",
"np",
"->",
"xstate",
",",
"sizeof",
"(",
"np",
"->",
"xstate",
")",
")",
"<",
"0",
")",
"{",
"release",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"release",
"(",
"&",
"wait_lock",
")",
";",
"return",
"-1",
";",
"}",
"freeproc",
"(",
"np",
")",
";",
"release",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"release",
"(",
"&",
"wait_lock",
")",
";",
"return",
"pid",
";",
"}",
"release",
"(",
"&",
"np",
"->",
"lock",
")",
";",
"}",
"}",
"if",
"(",
"!",
"havekids",
"||",
"p",
"->",
"killed",
")",
"{",
"release",
"(",
"&",
"wait_lock",
")",
";",
"return",
"-1",
";",
"}",
"sleep",
"(",
"p",
",",
"&",
"wait_lock",
")",
";",
"}",
"}"
] | Wait for a child process to exit and return its pid. | [
"Wait",
"for",
"a",
"child",
"process",
"to",
"exit",
"and",
"return",
"its",
"pid",
"."
] | [
"// Scan through table looking for exited children.",
"// make sure the child isn't still in exit() or swtch().",
"// Found one.",
"// No point waiting if we don't have any children.",
"// Wait for a child to exit.",
"//DOC: wait-sleep"
] | [
{
"param": "addr",
"type": "uint64"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "addr",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | scheduler2 | void | void scheduler2(void) {
struct proc* p;
struct cpu* c = mycpu();
c->proc = 0;
for (;;) {
// Avoid deadlock by ensuring that devices can interrupt.
intr_on();
for (p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if (p->state == RUNNABLE) {
// Switch to chosen process. It is the process's job
// to release its lock and then reacquire it
// before jumping back to us.
p->state = RUNNING;
c->proc = p;
swtch(&c->context, &p->context);
// Process is done running for now.
// It should have changed its p->state before coming back.
c->proc = 0;
}
release(&p->lock);
}
}
} | // Per-CPU process scheduler.
// Each CPU calls scheduler() after setting itself up.
// Scheduler never returns. It loops, doing:
// - choose a process to run.
// - swtch to start running that process.
// - eventually that process transfers control
// via swtch back to the scheduler. | Per-CPU process scheduler.
Each CPU calls scheduler() after setting itself up.
Scheduler never returns. It loops, doing:
choose a process to run.
swtch to start running that process.
eventually that process transfers control
via swtch back to the scheduler. | [
"Per",
"-",
"CPU",
"process",
"scheduler",
".",
"Each",
"CPU",
"calls",
"scheduler",
"()",
"after",
"setting",
"itself",
"up",
".",
"Scheduler",
"never",
"returns",
".",
"It",
"loops",
"doing",
":",
"choose",
"a",
"process",
"to",
"run",
".",
"swtch",
"to",
"start",
"running",
"that",
"process",
".",
"eventually",
"that",
"process",
"transfers",
"control",
"via",
"swtch",
"back",
"to",
"the",
"scheduler",
"."
] | void scheduler2(void) {
struct proc* p;
struct cpu* c = mycpu();
c->proc = 0;
for (;;) {
intr_on();
for (p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if (p->state == RUNNABLE) {
p->state = RUNNING;
c->proc = p;
swtch(&c->context, &p->context);
c->proc = 0;
}
release(&p->lock);
}
}
} | [
"void",
"scheduler2",
"(",
"void",
")",
"{",
"struct",
"proc",
"*",
"p",
";",
"struct",
"cpu",
"*",
"c",
"=",
"mycpu",
"(",
")",
";",
"c",
"->",
"proc",
"=",
"0",
";",
"for",
"(",
";",
";",
")",
"{",
"intr_on",
"(",
")",
";",
"for",
"(",
"p",
"=",
"proc",
";",
"p",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"p",
"++",
")",
"{",
"acquire",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"if",
"(",
"p",
"->",
"state",
"==",
"RUNNABLE",
")",
"{",
"p",
"->",
"state",
"=",
"RUNNING",
";",
"c",
"->",
"proc",
"=",
"p",
";",
"swtch",
"(",
"&",
"c",
"->",
"context",
",",
"&",
"p",
"->",
"context",
")",
";",
"c",
"->",
"proc",
"=",
"0",
";",
"}",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"}",
"}",
"}"
] | Per-CPU process scheduler. | [
"Per",
"-",
"CPU",
"process",
"scheduler",
"."
] | [
"// Avoid deadlock by ensuring that devices can interrupt.",
"// Switch to chosen process. It is the process's job",
"// to release its lock and then reacquire it",
"// before jumping back to us.",
"// Process is done running for now.",
"// It should have changed its p->state before coming back."
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | sched | void | void sched(void) {
int intena;
struct proc* p = myproc();
if (!holding(&p->lock))
panic("sched p->lock");
if (mycpu()->noff != 1)
panic("sched locks");
if (p->state == RUNNING)
panic("sched running");
if (intr_get())
panic("sched interruptible");
intena = mycpu()->intena;
swtch(&p->context, &mycpu()->context);
mycpu()->intena = intena;
} | // Switch to scheduler. Must hold only p->lock
// and have changed proc->state. Saves and restores
// intena because intena is a property of this
// kernel thread, not this CPU. It should
// be proc->intena and proc->noff, but that would
// break in the few places where a lock is held but
// there's no process. | Switch to scheduler. Must hold only p->lock
and have changed proc->state. Saves and restores
intena because intena is a property of this
kernel thread, not this CPU. It should
be proc->intena and proc->noff, but that would
break in the few places where a lock is held but
there's no process. | [
"Switch",
"to",
"scheduler",
".",
"Must",
"hold",
"only",
"p",
"-",
">",
"lock",
"and",
"have",
"changed",
"proc",
"-",
">",
"state",
".",
"Saves",
"and",
"restores",
"intena",
"because",
"intena",
"is",
"a",
"property",
"of",
"this",
"kernel",
"thread",
"not",
"this",
"CPU",
".",
"It",
"should",
"be",
"proc",
"-",
">",
"intena",
"and",
"proc",
"-",
">",
"noff",
"but",
"that",
"would",
"break",
"in",
"the",
"few",
"places",
"where",
"a",
"lock",
"is",
"held",
"but",
"there",
"'",
"s",
"no",
"process",
"."
] | void sched(void) {
int intena;
struct proc* p = myproc();
if (!holding(&p->lock))
panic("sched p->lock");
if (mycpu()->noff != 1)
panic("sched locks");
if (p->state == RUNNING)
panic("sched running");
if (intr_get())
panic("sched interruptible");
intena = mycpu()->intena;
swtch(&p->context, &mycpu()->context);
mycpu()->intena = intena;
} | [
"void",
"sched",
"(",
"void",
")",
"{",
"int",
"intena",
";",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"if",
"(",
"!",
"holding",
"(",
"&",
"p",
"->",
"lock",
")",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"mycpu",
"(",
")",
"->",
"noff",
"!=",
"1",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"p",
"->",
"state",
"==",
"RUNNING",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"intr_get",
"(",
")",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"intena",
"=",
"mycpu",
"(",
")",
"->",
"intena",
";",
"swtch",
"(",
"&",
"p",
"->",
"context",
",",
"&",
"mycpu",
"(",
")",
"->",
"context",
")",
";",
"mycpu",
"(",
")",
"->",
"intena",
"=",
"intena",
";",
"}"
] | Switch to scheduler. | [
"Switch",
"to",
"scheduler",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | yield | void | void yield(void) {
struct proc* p = myproc();
acquire(&p->lock);
p->state = RUNNABLE;
sched();
release(&p->lock);
} | // Give up the CPU for one scheduling round. | Give up the CPU for one scheduling round. | [
"Give",
"up",
"the",
"CPU",
"for",
"one",
"scheduling",
"round",
"."
] | void yield(void) {
struct proc* p = myproc();
acquire(&p->lock);
p->state = RUNNABLE;
sched();
release(&p->lock);
} | [
"void",
"yield",
"(",
"void",
")",
"{",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"acquire",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"p",
"->",
"state",
"=",
"RUNNABLE",
";",
"sched",
"(",
")",
";",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"}"
] | Give up the CPU for one scheduling round. | [
"Give",
"up",
"the",
"CPU",
"for",
"one",
"scheduling",
"round",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | forkret | void | void forkret(void) {
static int first = 1;
// Still holding p->lock from scheduler.
release(&myproc()->lock);
if (first) {
// File system initialization must be run in the context of a
// regular process (e.g., because it calls sleep), and thus cannot
// be run from main().
first = 0;
fsinit(ROOTDEV);
}
usertrapret();
} | // A fork child's very first scheduling by scheduler()
// will swtch to forkret. | A fork child's very first scheduling by scheduler()
will swtch to forkret. | [
"A",
"fork",
"child",
"'",
"s",
"very",
"first",
"scheduling",
"by",
"scheduler",
"()",
"will",
"swtch",
"to",
"forkret",
"."
] | void forkret(void) {
static int first = 1;
release(&myproc()->lock);
if (first) {
first = 0;
fsinit(ROOTDEV);
}
usertrapret();
} | [
"void",
"forkret",
"(",
"void",
")",
"{",
"static",
"int",
"first",
"=",
"1",
";",
"release",
"(",
"&",
"myproc",
"(",
")",
"->",
"lock",
")",
";",
"if",
"(",
"first",
")",
"{",
"first",
"=",
"0",
";",
"fsinit",
"(",
"ROOTDEV",
")",
";",
"}",
"usertrapret",
"(",
")",
";",
"}"
] | A fork child's very first scheduling by scheduler()
will swtch to forkret. | [
"A",
"fork",
"child",
"'",
"s",
"very",
"first",
"scheduling",
"by",
"scheduler",
"()",
"will",
"swtch",
"to",
"forkret",
"."
] | [
"// Still holding p->lock from scheduler.",
"// File system initialization must be run in the context of a",
"// regular process (e.g., because it calls sleep), and thus cannot",
"// be run from main()."
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | sleep | void | void sleep(void* chan, struct spinlock* lk) {
struct proc* p = myproc();
// Must acquire p->lock in order to
// change p->state and then call sched.
// Once we hold p->lock, we can be
// guaranteed that we won't miss any wakeup
// (wakeup locks p->lock),
// so it's okay to release lk.
acquire(&p->lock); //DOC: sleeplock1
release(lk);
// Go to sleep.
p->chan = chan;
p->state = SLEEPING;
sched();
// Tidy up.
p->chan = 0;
// Reacquire original lock.
release(&p->lock);
acquire(lk);
} | // Atomically release lock and sleep on chan.
// Reacquires lock when awakened. | Atomically release lock and sleep on chan.
Reacquires lock when awakened. | [
"Atomically",
"release",
"lock",
"and",
"sleep",
"on",
"chan",
".",
"Reacquires",
"lock",
"when",
"awakened",
"."
] | void sleep(void* chan, struct spinlock* lk) {
struct proc* p = myproc();
acquire(&p->lock);
release(lk);
p->chan = chan;
p->state = SLEEPING;
sched();
p->chan = 0;
release(&p->lock);
acquire(lk);
} | [
"void",
"sleep",
"(",
"void",
"*",
"chan",
",",
"struct",
"spinlock",
"*",
"lk",
")",
"{",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"acquire",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"release",
"(",
"lk",
")",
";",
"p",
"->",
"chan",
"=",
"chan",
";",
"p",
"->",
"state",
"=",
"SLEEPING",
";",
"sched",
"(",
")",
";",
"p",
"->",
"chan",
"=",
"0",
";",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"acquire",
"(",
"lk",
")",
";",
"}"
] | Atomically release lock and sleep on chan. | [
"Atomically",
"release",
"lock",
"and",
"sleep",
"on",
"chan",
"."
] | [
"// Must acquire p->lock in order to",
"// change p->state and then call sched.",
"// Once we hold p->lock, we can be",
"// guaranteed that we won't miss any wakeup",
"// (wakeup locks p->lock),",
"// so it's okay to release lk.",
"//DOC: sleeplock1",
"// Go to sleep.",
"// Tidy up.",
"// Reacquire original lock."
] | [
{
"param": "chan",
"type": "void"
},
{
"param": "lk",
"type": "struct spinlock"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "chan",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "lk",
"type": "struct spinlock",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | wakeup | void | void wakeup(void* chan) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
if (p != myproc()) {
acquire(&p->lock);
if (p->state == SLEEPING && p->chan == chan) {
p->state = RUNNABLE;
}
release(&p->lock);
}
}
} | // Wake up all processes sleeping on chan.
// Must be called without any p->lock. | Wake up all processes sleeping on chan.
Must be called without any p->lock. | [
"Wake",
"up",
"all",
"processes",
"sleeping",
"on",
"chan",
".",
"Must",
"be",
"called",
"without",
"any",
"p",
"-",
">",
"lock",
"."
] | void wakeup(void* chan) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
if (p != myproc()) {
acquire(&p->lock);
if (p->state == SLEEPING && p->chan == chan) {
p->state = RUNNABLE;
}
release(&p->lock);
}
}
} | [
"void",
"wakeup",
"(",
"void",
"*",
"chan",
")",
"{",
"struct",
"proc",
"*",
"p",
";",
"for",
"(",
"p",
"=",
"proc",
";",
"p",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"p",
"++",
")",
"{",
"if",
"(",
"p",
"!=",
"myproc",
"(",
")",
")",
"{",
"acquire",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"if",
"(",
"p",
"->",
"state",
"==",
"SLEEPING",
"&&",
"p",
"->",
"chan",
"==",
"chan",
")",
"{",
"p",
"->",
"state",
"=",
"RUNNABLE",
";",
"}",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"}",
"}",
"}"
] | Wake up all processes sleeping on chan. | [
"Wake",
"up",
"all",
"processes",
"sleeping",
"on",
"chan",
"."
] | [] | [
{
"param": "chan",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "chan",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | kill | int | int kill(int pid) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if (p->pid == pid) {
p->killed = 1;
if (p->state == SLEEPING) {
// Wake process from sleep().
p->state = RUNNABLE;
}
release(&p->lock);
return 0;
}
release(&p->lock);
}
return -1;
} | // Kill the process with the given pid.
// The victim won't exit until it tries to return
// to user space (see usertrap() in trap.c). | Kill the process with the given pid.
The victim won't exit until it tries to return
to user space in trap.c). | [
"Kill",
"the",
"process",
"with",
"the",
"given",
"pid",
".",
"The",
"victim",
"won",
"'",
"t",
"exit",
"until",
"it",
"tries",
"to",
"return",
"to",
"user",
"space",
"in",
"trap",
".",
"c",
")",
"."
] | int kill(int pid) {
struct proc* p;
for (p = proc; p < &proc[NPROC]; p++) {
acquire(&p->lock);
if (p->pid == pid) {
p->killed = 1;
if (p->state == SLEEPING) {
p->state = RUNNABLE;
}
release(&p->lock);
return 0;
}
release(&p->lock);
}
return -1;
} | [
"int",
"kill",
"(",
"int",
"pid",
")",
"{",
"struct",
"proc",
"*",
"p",
";",
"for",
"(",
"p",
"=",
"proc",
";",
"p",
"<",
"&",
"proc",
"[",
"NPROC",
"]",
";",
"p",
"++",
")",
"{",
"acquire",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"if",
"(",
"p",
"->",
"pid",
"==",
"pid",
")",
"{",
"p",
"->",
"killed",
"=",
"1",
";",
"if",
"(",
"p",
"->",
"state",
"==",
"SLEEPING",
")",
"{",
"p",
"->",
"state",
"=",
"RUNNABLE",
";",
"}",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"return",
"0",
";",
"}",
"release",
"(",
"&",
"p",
"->",
"lock",
")",
";",
"}",
"return",
"-1",
";",
"}"
] | Kill the process with the given pid. | [
"Kill",
"the",
"process",
"with",
"the",
"given",
"pid",
"."
] | [
"// Wake process from sleep()."
] | [
{
"param": "pid",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pid",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e0c31e823aba59bcb069d54a05d20ba0fab31c51 | evad1n/xv6-riscv | kernel/proc.c | [
"MIT-0"
] | C | either_copyin | int | int either_copyin(void* dst, int user_src, uint64 src, uint64 len) {
struct proc* p = myproc();
if (user_src) {
return copyin(p->pagetable, dst, src, len);
} else {
memmove(dst, (char*)src, len);
return 0;
}
} | // Copy from either a user address, or kernel address,
// depending on usr_src.
// Returns 0 on success, -1 on error. | Copy from either a user address, or kernel address,
depending on usr_src.
Returns 0 on success, -1 on error. | [
"Copy",
"from",
"either",
"a",
"user",
"address",
"or",
"kernel",
"address",
"depending",
"on",
"usr_src",
".",
"Returns",
"0",
"on",
"success",
"-",
"1",
"on",
"error",
"."
] | int either_copyin(void* dst, int user_src, uint64 src, uint64 len) {
struct proc* p = myproc();
if (user_src) {
return copyin(p->pagetable, dst, src, len);
} else {
memmove(dst, (char*)src, len);
return 0;
}
} | [
"int",
"either_copyin",
"(",
"void",
"*",
"dst",
",",
"int",
"user_src",
",",
"uint64",
"src",
",",
"uint64",
"len",
")",
"{",
"struct",
"proc",
"*",
"p",
"=",
"myproc",
"(",
")",
";",
"if",
"(",
"user_src",
")",
"{",
"return",
"copyin",
"(",
"p",
"->",
"pagetable",
",",
"dst",
",",
"src",
",",
"len",
")",
";",
"}",
"else",
"{",
"memmove",
"(",
"dst",
",",
"(",
"char",
"*",
")",
"src",
",",
"len",
")",
";",
"return",
"0",
";",
"}",
"}"
] | Copy from either a user address, or kernel address,
depending on usr_src. | [
"Copy",
"from",
"either",
"a",
"user",
"address",
"or",
"kernel",
"address",
"depending",
"on",
"usr_src",
"."
] | [] | [
{
"param": "dst",
"type": "void"
},
{
"param": "user_src",
"type": "int"
},
{
"param": "src",
"type": "uint64"
},
{
"param": "len",
"type": "uint64"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dst",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "user_src",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "src",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80b60f608919314bc9277055355dcc63140be07d | evad1n/xv6-riscv | kernel/kalloc.c | [
"MIT-0"
] | C | kfree | void | void
kfree(void *pa)
{
struct run *r;
if(((uint64)pa % PGSIZE) != 0 || (char*)pa < end || (uint64)pa >= PHYSTOP)
panic("kfree");
r = (struct run*)pa;
acquire(&kmem.lock);
// Char underflow wraps to 255, so we don't want that...
if(kmem.pg_refcount[PA2RIDX(pa)] > 0)
kmem.pg_refcount[PA2RIDX(pa)]--;
/* Only free if there are no more references to the page */
if (kmem.pg_refcount[PA2RIDX(pa)] == 0)
{
// Fill with junk to catch dangling refs.
memset(pa, 1, PGSIZE);
r->next = kmem.freelist;
kmem.freelist = r;
kmem.free_pages++; // Increment num free pages
}
release(&kmem.lock);
} | // Free the page of physical memory pointed at by v,
// which normally should have been returned by a
// call to kalloc(). (The exception is when
// initializing the allocator; see kinit above.) | Free the page of physical memory pointed at by v,
which normally should have been returned by a
call to kalloc(). (The exception is when
initializing the allocator; see kinit above.) | [
"Free",
"the",
"page",
"of",
"physical",
"memory",
"pointed",
"at",
"by",
"v",
"which",
"normally",
"should",
"have",
"been",
"returned",
"by",
"a",
"call",
"to",
"kalloc",
"()",
".",
"(",
"The",
"exception",
"is",
"when",
"initializing",
"the",
"allocator",
";",
"see",
"kinit",
"above",
".",
")"
] | void
kfree(void *pa)
{
struct run *r;
if(((uint64)pa % PGSIZE) != 0 || (char*)pa < end || (uint64)pa >= PHYSTOP)
panic("kfree");
r = (struct run*)pa;
acquire(&kmem.lock);
if(kmem.pg_refcount[PA2RIDX(pa)] > 0)
kmem.pg_refcount[PA2RIDX(pa)]--;
if (kmem.pg_refcount[PA2RIDX(pa)] == 0)
{
memset(pa, 1, PGSIZE);
r->next = kmem.freelist;
kmem.freelist = r;
kmem.free_pages++;
}
release(&kmem.lock);
} | [
"void",
"kfree",
"(",
"void",
"*",
"pa",
")",
"{",
"struct",
"run",
"*",
"r",
";",
"if",
"(",
"(",
"(",
"uint64",
")",
"pa",
"%",
"PGSIZE",
")",
"!=",
"0",
"||",
"(",
"char",
"*",
")",
"pa",
"<",
"end",
"||",
"(",
"uint64",
")",
"pa",
">=",
"PHYSTOP",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"r",
"=",
"(",
"struct",
"run",
"*",
")",
"pa",
";",
"acquire",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"if",
"(",
"kmem",
".",
"pg_refcount",
"[",
"PA2RIDX",
"(",
"pa",
")",
"]",
">",
"0",
")",
"kmem",
".",
"pg_refcount",
"[",
"PA2RIDX",
"(",
"pa",
")",
"]",
"--",
";",
"if",
"(",
"kmem",
".",
"pg_refcount",
"[",
"PA2RIDX",
"(",
"pa",
")",
"]",
"==",
"0",
")",
"{",
"memset",
"(",
"pa",
",",
"1",
",",
"PGSIZE",
")",
";",
"r",
"->",
"next",
"=",
"kmem",
".",
"freelist",
";",
"kmem",
".",
"freelist",
"=",
"r",
";",
"kmem",
".",
"free_pages",
"++",
";",
"}",
"release",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"}"
] | Free the page of physical memory pointed at by v,
which normally should have been returned by a
call to kalloc(). | [
"Free",
"the",
"page",
"of",
"physical",
"memory",
"pointed",
"at",
"by",
"v",
"which",
"normally",
"should",
"have",
"been",
"returned",
"by",
"a",
"call",
"to",
"kalloc",
"()",
"."
] | [
"// Char underflow wraps to 255, so we don't want that...",
"/* Only free if there are no more references to the page */",
"// Fill with junk to catch dangling refs.",
"// Increment num free pages"
] | [
{
"param": "pa",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pa",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80b60f608919314bc9277055355dcc63140be07d | evad1n/xv6-riscv | kernel/kalloc.c | [
"MIT-0"
] | C | kalloc | void | void *
kalloc(void)
{
struct run *r;
acquire(&kmem.lock);
r = kmem.freelist;
if(r)
{
kmem.freelist = r->next;
// Decrement free pages
kmem.free_pages--;
// Set reference count to 1
kmem.pg_refcount[PA2RIDX(r)] = 1;
}
release(&kmem.lock);
if(r)
memset((char*)r, 5, PGSIZE); // fill with junk
return (void*)r;
} | // Allocate one 4096-byte page of physical memory.
// Returns a pointer that the kernel can use.
// Returns 0 if the memory cannot be allocated. | Allocate one 4096-byte page of physical memory.
Returns a pointer that the kernel can use.
Returns 0 if the memory cannot be allocated. | [
"Allocate",
"one",
"4096",
"-",
"byte",
"page",
"of",
"physical",
"memory",
".",
"Returns",
"a",
"pointer",
"that",
"the",
"kernel",
"can",
"use",
".",
"Returns",
"0",
"if",
"the",
"memory",
"cannot",
"be",
"allocated",
"."
] | void *
kalloc(void)
{
struct run *r;
acquire(&kmem.lock);
r = kmem.freelist;
if(r)
{
kmem.freelist = r->next;
kmem.free_pages--;
kmem.pg_refcount[PA2RIDX(r)] = 1;
}
release(&kmem.lock);
if(r)
memset((char*)r, 5, PGSIZE);
return (void*)r;
} | [
"void",
"*",
"kalloc",
"(",
"void",
")",
"{",
"struct",
"run",
"*",
"r",
";",
"acquire",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"r",
"=",
"kmem",
".",
"freelist",
";",
"if",
"(",
"r",
")",
"{",
"kmem",
".",
"freelist",
"=",
"r",
"->",
"next",
";",
"kmem",
".",
"free_pages",
"--",
";",
"kmem",
".",
"pg_refcount",
"[",
"PA2RIDX",
"(",
"r",
")",
"]",
"=",
"1",
";",
"}",
"release",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"if",
"(",
"r",
")",
"memset",
"(",
"(",
"char",
"*",
")",
"r",
",",
"5",
",",
"PGSIZE",
")",
";",
"return",
"(",
"void",
"*",
")",
"r",
";",
"}"
] | Allocate one 4096-byte page of physical memory. | [
"Allocate",
"one",
"4096",
"-",
"byte",
"page",
"of",
"physical",
"memory",
"."
] | [
"// Decrement free pages",
"// Set reference count to 1",
"// fill with junk"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
80b60f608919314bc9277055355dcc63140be07d | evad1n/xv6-riscv | kernel/kalloc.c | [
"MIT-0"
] | C | num_free_pages | int | int num_free_pages(void)
{
acquire(&kmem.lock);
int num = kmem.free_pages;
release(&kmem.lock);
return num;
} | /* Returns the total number of free pages in the kernel */ | Returns the total number of free pages in the kernel | [
"Returns",
"the",
"total",
"number",
"of",
"free",
"pages",
"in",
"the",
"kernel"
] | int num_free_pages(void)
{
acquire(&kmem.lock);
int num = kmem.free_pages;
release(&kmem.lock);
return num;
} | [
"int",
"num_free_pages",
"(",
"void",
")",
"{",
"acquire",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"int",
"num",
"=",
"kmem",
".",
"free_pages",
";",
"release",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"return",
"num",
";",
"}"
] | Returns the total number of free pages in the kernel | [
"Returns",
"the",
"total",
"number",
"of",
"free",
"pages",
"in",
"the",
"kernel"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
80b60f608919314bc9277055355dcc63140be07d | evad1n/xv6-riscv | kernel/kalloc.c | [
"MIT-0"
] | C | incref | int | int incref(uint64 pa)
{
acquire(&kmem.lock);
int count = ++kmem.pg_refcount[PA2RIDX(pa)];
release(&kmem.lock);
return count;
} | /* Increments the reference counter for the page at the physical address pa */ | Increments the reference counter for the page at the physical address pa | [
"Increments",
"the",
"reference",
"counter",
"for",
"the",
"page",
"at",
"the",
"physical",
"address",
"pa"
] | int incref(uint64 pa)
{
acquire(&kmem.lock);
int count = ++kmem.pg_refcount[PA2RIDX(pa)];
release(&kmem.lock);
return count;
} | [
"int",
"incref",
"(",
"uint64",
"pa",
")",
"{",
"acquire",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"int",
"count",
"=",
"++",
"kmem",
".",
"pg_refcount",
"[",
"PA2RIDX",
"(",
"pa",
")",
"]",
";",
"release",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"return",
"count",
";",
"}"
] | Increments the reference counter for the page at the physical address pa | [
"Increments",
"the",
"reference",
"counter",
"for",
"the",
"page",
"at",
"the",
"physical",
"address",
"pa"
] | [] | [
{
"param": "pa",
"type": "uint64"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pa",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80b60f608919314bc9277055355dcc63140be07d | evad1n/xv6-riscv | kernel/kalloc.c | [
"MIT-0"
] | C | decref | int | int decref(uint64 pa)
{
acquire(&kmem.lock);
int count = --kmem.pg_refcount[PA2RIDX(pa)];
release(&kmem.lock);
return count;
} | /* Decrements the reference counter for the page at the physical address pa */ | Decrements the reference counter for the page at the physical address pa | [
"Decrements",
"the",
"reference",
"counter",
"for",
"the",
"page",
"at",
"the",
"physical",
"address",
"pa"
] | int decref(uint64 pa)
{
acquire(&kmem.lock);
int count = --kmem.pg_refcount[PA2RIDX(pa)];
release(&kmem.lock);
return count;
} | [
"int",
"decref",
"(",
"uint64",
"pa",
")",
"{",
"acquire",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"int",
"count",
"=",
"--",
"kmem",
".",
"pg_refcount",
"[",
"PA2RIDX",
"(",
"pa",
")",
"]",
";",
"release",
"(",
"&",
"kmem",
".",
"lock",
")",
";",
"return",
"count",
";",
"}"
] | Decrements the reference counter for the page at the physical address pa | [
"Decrements",
"the",
"reference",
"counter",
"for",
"the",
"page",
"at",
"the",
"physical",
"address",
"pa"
] | [] | [
{
"param": "pa",
"type": "uint64"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pa",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b4f14bae7ad50e6812978358ecc7599fb88ea7e5 | evad1n/xv6-riscv | kernel/vm.c | [
"MIT-0"
] | C | walkaddr | uint64 | uint64
walkaddr(pagetable_t pagetable, uint64 va)
{
pte_t *pte;
uint64 pa;
if(va >= MAXVA)
return 0;
pte = walk(pagetable, va, 0);
if(pte == 0)
return 0;
if(!(*pte & PTE_V))
return 0;
if((*pte & PTE_U) == 0)
return 0;
pa = PTE2PA(*pte);
return pa;
} | // Look up a virtual address, return the physical address,
// or 0 if not mapped.
// Can only be used to look up user pages. | Look up a virtual address, return the physical address,
or 0 if not mapped.
Can only be used to look up user pages. | [
"Look",
"up",
"a",
"virtual",
"address",
"return",
"the",
"physical",
"address",
"or",
"0",
"if",
"not",
"mapped",
".",
"Can",
"only",
"be",
"used",
"to",
"look",
"up",
"user",
"pages",
"."
] | uint64
walkaddr(pagetable_t pagetable, uint64 va)
{
pte_t *pte;
uint64 pa;
if(va >= MAXVA)
return 0;
pte = walk(pagetable, va, 0);
if(pte == 0)
return 0;
if(!(*pte & PTE_V))
return 0;
if((*pte & PTE_U) == 0)
return 0;
pa = PTE2PA(*pte);
return pa;
} | [
"uint64",
"walkaddr",
"(",
"pagetable_t",
"pagetable",
",",
"uint64",
"va",
")",
"{",
"pte_t",
"*",
"pte",
";",
"uint64",
"pa",
";",
"if",
"(",
"va",
">=",
"MAXVA",
")",
"return",
"0",
";",
"pte",
"=",
"walk",
"(",
"pagetable",
",",
"va",
",",
"0",
")",
";",
"if",
"(",
"pte",
"==",
"0",
")",
"return",
"0",
";",
"if",
"(",
"!",
"(",
"*",
"pte",
"&",
"PTE_V",
")",
")",
"return",
"0",
";",
"if",
"(",
"(",
"*",
"pte",
"&",
"PTE_U",
")",
"==",
"0",
")",
"return",
"0",
";",
"pa",
"=",
"PTE2PA",
"(",
"*",
"pte",
")",
";",
"return",
"pa",
";",
"}"
] | Look up a virtual address, return the physical address,
or 0 if not mapped. | [
"Look",
"up",
"a",
"virtual",
"address",
"return",
"the",
"physical",
"address",
"or",
"0",
"if",
"not",
"mapped",
"."
] | [] | [
{
"param": "pagetable",
"type": "pagetable_t"
},
{
"param": "va",
"type": "uint64"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pagetable",
"type": "pagetable_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "va",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b4f14bae7ad50e6812978358ecc7599fb88ea7e5 | evad1n/xv6-riscv | kernel/vm.c | [
"MIT-0"
] | C | uvmunmap | void | void
uvmunmap(pagetable_t pagetable, uint64 va, uint64 npages, int do_free)
{
uint64 a;
pte_t *pte;
if((va % PGSIZE) != 0)
panic("uvmunmap: not aligned");
for(a = va; a < va + npages*PGSIZE; a += PGSIZE){
if((pte = walk(pagetable, a, 0)) == 0)
panic("uvmunmap: walk");
if(!(*pte & PTE_V))
panic("uvmunmap: not mapped");
if(PTE_FLAGS(*pte) == PTE_V)
panic("uvmunmap: not a leaf");
if(do_free){
uint64 pa = PTE2PA(*pte);
kfree((void*)pa);
}
*pte = 0;
}
} | // Remove npages of mappings starting from va. va must be
// page-aligned. The mappings must exist.
// Optionally free the physical memory. | Remove npages of mappings starting from va. va must be
page-aligned. The mappings must exist.
Optionally free the physical memory. | [
"Remove",
"npages",
"of",
"mappings",
"starting",
"from",
"va",
".",
"va",
"must",
"be",
"page",
"-",
"aligned",
".",
"The",
"mappings",
"must",
"exist",
".",
"Optionally",
"free",
"the",
"physical",
"memory",
"."
] | void
uvmunmap(pagetable_t pagetable, uint64 va, uint64 npages, int do_free)
{
uint64 a;
pte_t *pte;
if((va % PGSIZE) != 0)
panic("uvmunmap: not aligned");
for(a = va; a < va + npages*PGSIZE; a += PGSIZE){
if((pte = walk(pagetable, a, 0)) == 0)
panic("uvmunmap: walk");
if(!(*pte & PTE_V))
panic("uvmunmap: not mapped");
if(PTE_FLAGS(*pte) == PTE_V)
panic("uvmunmap: not a leaf");
if(do_free){
uint64 pa = PTE2PA(*pte);
kfree((void*)pa);
}
*pte = 0;
}
} | [
"void",
"uvmunmap",
"(",
"pagetable_t",
"pagetable",
",",
"uint64",
"va",
",",
"uint64",
"npages",
",",
"int",
"do_free",
")",
"{",
"uint64",
"a",
";",
"pte_t",
"*",
"pte",
";",
"if",
"(",
"(",
"va",
"%",
"PGSIZE",
")",
"!=",
"0",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"for",
"(",
"a",
"=",
"va",
";",
"a",
"<",
"va",
"+",
"npages",
"*",
"PGSIZE",
";",
"a",
"+=",
"PGSIZE",
")",
"{",
"if",
"(",
"(",
"pte",
"=",
"walk",
"(",
"pagetable",
",",
"a",
",",
"0",
")",
")",
"==",
"0",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"!",
"(",
"*",
"pte",
"&",
"PTE_V",
")",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"PTE_FLAGS",
"(",
"*",
"pte",
")",
"==",
"PTE_V",
")",
"panic",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"do_free",
")",
"{",
"uint64",
"pa",
"=",
"PTE2PA",
"(",
"*",
"pte",
")",
";",
"kfree",
"(",
"(",
"void",
"*",
")",
"pa",
")",
";",
"}",
"*",
"pte",
"=",
"0",
";",
"}",
"}"
] | Remove npages of mappings starting from va. va must be
page-aligned. | [
"Remove",
"npages",
"of",
"mappings",
"starting",
"from",
"va",
".",
"va",
"must",
"be",
"page",
"-",
"aligned",
"."
] | [] | [
{
"param": "pagetable",
"type": "pagetable_t"
},
{
"param": "va",
"type": "uint64"
},
{
"param": "npages",
"type": "uint64"
},
{
"param": "do_free",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pagetable",
"type": "pagetable_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "va",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "npages",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "do_free",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b4f14bae7ad50e6812978358ecc7599fb88ea7e5 | evad1n/xv6-riscv | kernel/vm.c | [
"MIT-0"
] | C | handle_cowpagefault | uint64 | uint64 handle_cowpagefault(uint64 va, struct proc* p)
{
va = PGROUNDDOWN(va);
pte_t *pte;
// Check to make sure va is in legal range
if(va >= MAXVA || (pte = walk(p->pagetable, va, 0)) == 0 || !(*pte & PTE_V) || !(*pte & PTE_U))
{
printf("Illegal memory access from process %d with pid %d\n", p->name, p->pid);
p->killed = 1;
return 0;
}
// Already is writable...
if(*pte & PTE_W){
printf("va: %p\n", va);
panic("Page fault already writeable");
}
uint64 pa = PTE2PA(*pte);
int refs = getref(pa);
// If process does not share a page
if(refs == 1)
{
// Simply allow writing
*pte |= PTE_W;
// Flush TLB
sfence_vma();
return pa;
}
// If process does share pages
else if (refs > 1)
{
// Save flags for mapping later
uint64 flags = PTE_FLAGS(*pte);
// allocate a new memory page for the process
char *mem;
if((mem = kalloc()) == 0) {
printf("Page fault out of memory, kill proc %s with pid %d\n", p->name, p->pid);
p->killed = 1;
return 0;
}
// Unmap current page => has side effect of calling kfree() which decrements counter for us
uvmunmap(p->pagetable, va, 1, 1);
// copy the memory from the old page to the new page
memmove(mem, (void *)pa, PGSIZE);
// Remap new physical memory to the virtual memory
// or the PTE_W flag so we can write to it now
mappages(p->pagetable, va, PGSIZE, (uint64)mem, flags | PTE_W);
// Flush TLB
sfence_vma();
return (uint64)mem;
}
// Bad reference count
else
{
printf("ref count: %d\n", refs);
panic("Page fault reference count bad value");
}
} | // Makes a shared page into a new copy that is writable
// Returns the physical address of the memory | Makes a shared page into a new copy that is writable
Returns the physical address of the memory | [
"Makes",
"a",
"shared",
"page",
"into",
"a",
"new",
"copy",
"that",
"is",
"writable",
"Returns",
"the",
"physical",
"address",
"of",
"the",
"memory"
] | uint64 handle_cowpagefault(uint64 va, struct proc* p)
{
va = PGROUNDDOWN(va);
pte_t *pte;
if(va >= MAXVA || (pte = walk(p->pagetable, va, 0)) == 0 || !(*pte & PTE_V) || !(*pte & PTE_U))
{
printf("Illegal memory access from process %d with pid %d\n", p->name, p->pid);
p->killed = 1;
return 0;
}
if(*pte & PTE_W){
printf("va: %p\n", va);
panic("Page fault already writeable");
}
uint64 pa = PTE2PA(*pte);
int refs = getref(pa);
if(refs == 1)
{
*pte |= PTE_W;
sfence_vma();
return pa;
}
else if (refs > 1)
{
uint64 flags = PTE_FLAGS(*pte);
char *mem;
if((mem = kalloc()) == 0) {
printf("Page fault out of memory, kill proc %s with pid %d\n", p->name, p->pid);
p->killed = 1;
return 0;
}
uvmunmap(p->pagetable, va, 1, 1);
memmove(mem, (void *)pa, PGSIZE);
mappages(p->pagetable, va, PGSIZE, (uint64)mem, flags | PTE_W);
sfence_vma();
return (uint64)mem;
}
else
{
printf("ref count: %d\n", refs);
panic("Page fault reference count bad value");
}
} | [
"uint64",
"handle_cowpagefault",
"(",
"uint64",
"va",
",",
"struct",
"proc",
"*",
"p",
")",
"{",
"va",
"=",
"PGROUNDDOWN",
"(",
"va",
")",
";",
"pte_t",
"*",
"pte",
";",
"if",
"(",
"va",
">=",
"MAXVA",
"||",
"(",
"pte",
"=",
"walk",
"(",
"p",
"->",
"pagetable",
",",
"va",
",",
"0",
")",
")",
"==",
"0",
"||",
"!",
"(",
"*",
"pte",
"&",
"PTE_V",
")",
"||",
"!",
"(",
"*",
"pte",
"&",
"PTE_U",
")",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"p",
"->",
"name",
",",
"p",
"->",
"pid",
")",
";",
"p",
"->",
"killed",
"=",
"1",
";",
"return",
"0",
";",
"}",
"if",
"(",
"*",
"pte",
"&",
"PTE_W",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"va",
")",
";",
"panic",
"(",
"\"",
"\"",
")",
";",
"}",
"uint64",
"pa",
"=",
"PTE2PA",
"(",
"*",
"pte",
")",
";",
"int",
"refs",
"=",
"getref",
"(",
"pa",
")",
";",
"if",
"(",
"refs",
"==",
"1",
")",
"{",
"*",
"pte",
"|=",
"PTE_W",
";",
"sfence_vma",
"(",
")",
";",
"return",
"pa",
";",
"}",
"else",
"if",
"(",
"refs",
">",
"1",
")",
"{",
"uint64",
"flags",
"=",
"PTE_FLAGS",
"(",
"*",
"pte",
")",
";",
"char",
"*",
"mem",
";",
"if",
"(",
"(",
"mem",
"=",
"kalloc",
"(",
")",
")",
"==",
"0",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"p",
"->",
"name",
",",
"p",
"->",
"pid",
")",
";",
"p",
"->",
"killed",
"=",
"1",
";",
"return",
"0",
";",
"}",
"uvmunmap",
"(",
"p",
"->",
"pagetable",
",",
"va",
",",
"1",
",",
"1",
")",
";",
"memmove",
"(",
"mem",
",",
"(",
"void",
"*",
")",
"pa",
",",
"PGSIZE",
")",
";",
"mappages",
"(",
"p",
"->",
"pagetable",
",",
"va",
",",
"PGSIZE",
",",
"(",
"uint64",
")",
"mem",
",",
"flags",
"|",
"PTE_W",
")",
";",
"sfence_vma",
"(",
")",
";",
"return",
"(",
"uint64",
")",
"mem",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"refs",
")",
";",
"panic",
"(",
"\"",
"\"",
")",
";",
"}",
"}"
] | Makes a shared page into a new copy that is writable
Returns the physical address of the memory | [
"Makes",
"a",
"shared",
"page",
"into",
"a",
"new",
"copy",
"that",
"is",
"writable",
"Returns",
"the",
"physical",
"address",
"of",
"the",
"memory"
] | [
"// Check to make sure va is in legal range",
"// Already is writable...",
"// If process does not share a page",
"// Simply allow writing",
"// Flush TLB",
"// If process does share pages",
"// Save flags for mapping later",
"// allocate a new memory page for the process",
"// Unmap current page => has side effect of calling kfree() which decrements counter for us",
"// copy the memory from the old page to the new page",
"// Remap new physical memory to the virtual memory",
"// or the PTE_W flag so we can write to it now",
"// Flush TLB",
"// Bad reference count"
] | [
{
"param": "va",
"type": "uint64"
},
{
"param": "p",
"type": "struct proc"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "va",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "p",
"type": "struct proc",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b4f14bae7ad50e6812978358ecc7599fb88ea7e5 | evad1n/xv6-riscv | kernel/vm.c | [
"MIT-0"
] | C | copyout | int | int
copyout(pagetable_t pagetable, uint64 dstva, char *src, uint64 len)
{
uint64 n, va0, pa0;
pte_t* pte;
while(len > 0){
va0 = PGROUNDDOWN(dstva);
if(va0 >= MAXVA)
return -1;
pte = walk(pagetable, va0, 0);
if(pte == 0)
return -1;
if(!(*pte & PTE_V))
return -1;
if((*pte & PTE_U) == 0)
return -1;
pa0 = PTE2PA(*pte);
// If it is not writable then copy it into new page
// We don't want to modify shared pages memory
if (((*pte & PTE_W) == 0) && (*pte & PTE_COW))
{
pa0 = handle_cowpagefault(va0, myproc());
}
n = PGSIZE - (dstva - va0);
if(n > len)
n = len;
memmove((void *)(pa0 + (dstva - va0)), src, n);
len -= n;
src += n;
dstva = va0 + PGSIZE;
}
return 0;
} | // Copy from kernel to user.
// Copy len bytes from src to virtual address dstva in a given page table.
// Return 0 on success, -1 on error. | Copy from kernel to user.
Copy len bytes from src to virtual address dstva in a given page table.
Return 0 on success, -1 on error. | [
"Copy",
"from",
"kernel",
"to",
"user",
".",
"Copy",
"len",
"bytes",
"from",
"src",
"to",
"virtual",
"address",
"dstva",
"in",
"a",
"given",
"page",
"table",
".",
"Return",
"0",
"on",
"success",
"-",
"1",
"on",
"error",
"."
] | int
copyout(pagetable_t pagetable, uint64 dstva, char *src, uint64 len)
{
uint64 n, va0, pa0;
pte_t* pte;
while(len > 0){
va0 = PGROUNDDOWN(dstva);
if(va0 >= MAXVA)
return -1;
pte = walk(pagetable, va0, 0);
if(pte == 0)
return -1;
if(!(*pte & PTE_V))
return -1;
if((*pte & PTE_U) == 0)
return -1;
pa0 = PTE2PA(*pte);
if (((*pte & PTE_W) == 0) && (*pte & PTE_COW))
{
pa0 = handle_cowpagefault(va0, myproc());
}
n = PGSIZE - (dstva - va0);
if(n > len)
n = len;
memmove((void *)(pa0 + (dstva - va0)), src, n);
len -= n;
src += n;
dstva = va0 + PGSIZE;
}
return 0;
} | [
"int",
"copyout",
"(",
"pagetable_t",
"pagetable",
",",
"uint64",
"dstva",
",",
"char",
"*",
"src",
",",
"uint64",
"len",
")",
"{",
"uint64",
"n",
",",
"va0",
",",
"pa0",
";",
"pte_t",
"*",
"pte",
";",
"while",
"(",
"len",
">",
"0",
")",
"{",
"va0",
"=",
"PGROUNDDOWN",
"(",
"dstva",
")",
";",
"if",
"(",
"va0",
">=",
"MAXVA",
")",
"return",
"-1",
";",
"pte",
"=",
"walk",
"(",
"pagetable",
",",
"va0",
",",
"0",
")",
";",
"if",
"(",
"pte",
"==",
"0",
")",
"return",
"-1",
";",
"if",
"(",
"!",
"(",
"*",
"pte",
"&",
"PTE_V",
")",
")",
"return",
"-1",
";",
"if",
"(",
"(",
"*",
"pte",
"&",
"PTE_U",
")",
"==",
"0",
")",
"return",
"-1",
";",
"pa0",
"=",
"PTE2PA",
"(",
"*",
"pte",
")",
";",
"if",
"(",
"(",
"(",
"*",
"pte",
"&",
"PTE_W",
")",
"==",
"0",
")",
"&&",
"(",
"*",
"pte",
"&",
"PTE_COW",
")",
")",
"{",
"pa0",
"=",
"handle_cowpagefault",
"(",
"va0",
",",
"myproc",
"(",
")",
")",
";",
"}",
"n",
"=",
"PGSIZE",
"-",
"(",
"dstva",
"-",
"va0",
")",
";",
"if",
"(",
"n",
">",
"len",
")",
"n",
"=",
"len",
";",
"memmove",
"(",
"(",
"void",
"*",
")",
"(",
"pa0",
"+",
"(",
"dstva",
"-",
"va0",
")",
")",
",",
"src",
",",
"n",
")",
";",
"len",
"-=",
"n",
";",
"src",
"+=",
"n",
";",
"dstva",
"=",
"va0",
"+",
"PGSIZE",
";",
"}",
"return",
"0",
";",
"}"
] | Copy from kernel to user. | [
"Copy",
"from",
"kernel",
"to",
"user",
"."
] | [
"// If it is not writable then copy it into new page",
"// We don't want to modify shared pages memory"
] | [
{
"param": "pagetable",
"type": "pagetable_t"
},
{
"param": "dstva",
"type": "uint64"
},
{
"param": "src",
"type": "char"
},
{
"param": "len",
"type": "uint64"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pagetable",
"type": "pagetable_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dstva",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "src",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len",
"type": "uint64",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
9dc00ced4eac0f2937b114f2342c0a1d55cb9075 | chinjui/gym_torcs | vtorcs-RL-color/src/drivers/berniw2/berniw.h | [
"MIT"
] | C | queryAngleToTrack | double | inline double queryAngleToTrack(tCarElt * car)
{
double angle = RtTrackSideTgAngleL(&(car->_trkPos)) - car->_yaw;
NORM_PI_PI(angle);
return angle;
} | /* compute the angle between the track and the car */ | compute the angle between the track and the car | [
"compute",
"the",
"angle",
"between",
"the",
"track",
"and",
"the",
"car"
] | inline double queryAngleToTrack(tCarElt * car)
{
double angle = RtTrackSideTgAngleL(&(car->_trkPos)) - car->_yaw;
NORM_PI_PI(angle);
return angle;
} | [
"inline",
"double",
"queryAngleToTrack",
"(",
"tCarElt",
"*",
"car",
")",
"{",
"double",
"angle",
"=",
"RtTrackSideTgAngleL",
"(",
"&",
"(",
"car",
"->",
"_trkPos",
")",
")",
"-",
"car",
"->",
"_yaw",
";",
"NORM_PI_PI",
"(",
"angle",
")",
";",
"return",
"angle",
";",
"}"
] | compute the angle between the track and the car | [
"compute",
"the",
"angle",
"between",
"the",
"track",
"and",
"the",
"car"
] | [] | [
{
"param": "car",
"type": "tCarElt"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "car",
"type": "tCarElt",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
9dc00ced4eac0f2937b114f2342c0a1d55cb9075 | chinjui/gym_torcs | vtorcs-RL-color/src/drivers/berniw2/berniw.h | [
"MIT"
] | C | radius | double | inline double radius(double x1, double y1, double x2, double y2, double x3, double y3)
{
double dx1 = x2 - x1;
double dy1 = y2 - y1;
double dx2 = x3 - x2;
double dy2 = y3 - y2;
//double z = (dy1*dx2 - dx1*dy2);
double z = dx1*dy2 - dy1*dx2;
if (z != 0.0) {
double k = (dx2*(x3-x1) - dy2*(y1-y3))/z;
return sign(z)*sqrt((1.0+k*k)*(dx1*dx1+dy1*dy1))/2.0;
} else {
return FLT_MAX;
}
} | /* compute the radius given three points */ | compute the radius given three points | [
"compute",
"the",
"radius",
"given",
"three",
"points"
] | inline double radius(double x1, double y1, double x2, double y2, double x3, double y3)
{
double dx1 = x2 - x1;
double dy1 = y2 - y1;
double dx2 = x3 - x2;
double dy2 = y3 - y2;
double z = dx1*dy2 - dy1*dx2;
if (z != 0.0) {
double k = (dx2*(x3-x1) - dy2*(y1-y3))/z;
return sign(z)*sqrt((1.0+k*k)*(dx1*dx1+dy1*dy1))/2.0;
} else {
return FLT_MAX;
}
} | [
"inline",
"double",
"radius",
"(",
"double",
"x1",
",",
"double",
"y1",
",",
"double",
"x2",
",",
"double",
"y2",
",",
"double",
"x3",
",",
"double",
"y3",
")",
"{",
"double",
"dx1",
"=",
"x2",
"-",
"x1",
";",
"double",
"dy1",
"=",
"y2",
"-",
"y1",
";",
"double",
"dx2",
"=",
"x3",
"-",
"x2",
";",
"double",
"dy2",
"=",
"y3",
"-",
"y2",
";",
"double",
"z",
"=",
"dx1",
"*",
"dy2",
"-",
"dy1",
"*",
"dx2",
";",
"if",
"(",
"z",
"!=",
"0.0",
")",
"{",
"double",
"k",
"=",
"(",
"dx2",
"*",
"(",
"x3",
"-",
"x1",
")",
"-",
"dy2",
"*",
"(",
"y1",
"-",
"y3",
")",
")",
"/",
"z",
";",
"return",
"sign",
"(",
"z",
")",
"*",
"sqrt",
"(",
"(",
"1.0",
"+",
"k",
"*",
"k",
")",
"*",
"(",
"dx1",
"*",
"dx1",
"+",
"dy1",
"*",
"dy1",
")",
")",
"/",
"2.0",
";",
"}",
"else",
"{",
"return",
"FLT_MAX",
";",
"}",
"}"
] | compute the radius given three points | [
"compute",
"the",
"radius",
"given",
"three",
"points"
] | [
"//double z = (dy1*dx2 - dx1*dy2);"
] | [
{
"param": "x1",
"type": "double"
},
{
"param": "y1",
"type": "double"
},
{
"param": "x2",
"type": "double"
},
{
"param": "y2",
"type": "double"
},
{
"param": "x3",
"type": "double"
},
{
"param": "y3",
"type": "double"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "x1",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "y1",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x2",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "y2",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x3",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "y3",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e444acb8323ffcb2bdbb8a9d69323cd98d477224 | chinjui/gym_torcs | vtorcs-RL-color/src/libs/txml/xmlparse.c | [
"MIT"
] | C | storeAtts | null | static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc,
const XML_Char *tagName, const char *s)
{
ELEMENT_TYPE *elementType = 0;
int nDefaultAtts = 0;
const XML_Char **appAtts;
int i;
int n;
if (tagName) {
elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagName, 0);
if (elementType)
nDefaultAtts = elementType->nDefaultAtts;
}
n = XmlGetAttributes(enc, s, attsSize, atts);
if (n + nDefaultAtts > attsSize) {
int oldAttsSize = attsSize;
attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
atts = (ATTRIBUTE*)realloc((void *)atts, attsSize * sizeof(ATTRIBUTE));
if (!atts)
return XML_ERROR_NO_MEMORY;
if (n > oldAttsSize)
XmlGetAttributes(enc, s, n, atts);
}
appAtts = (const XML_Char **)atts;
for (i = 0; i < n; i++) {
ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name,
atts[i].name
+ XmlNameLength(enc, atts[i].name));
if (!attId)
return XML_ERROR_NO_MEMORY;
if ((attId->name)[-1]) {
if (enc == encoding)
eventPtr = atts[i].name;
return XML_ERROR_DUPLICATE_ATTRIBUTE;
}
(attId->name)[-1] = 1;
appAtts[i << 1] = attId->name;
if (!atts[i].normalized) {
enum XML_Error result;
int isCdata = 1;
if (attId->maybeTokenized) {
int j;
for (j = 0; j < nDefaultAtts; j++) {
if (attId == elementType->defaultAtts[j].id) {
isCdata = elementType->defaultAtts[j].isCdata;
break;
}
}
}
result = storeAttributeValue(parser, enc, isCdata,
atts[i].valuePtr, atts[i].valueEnd,
&tempPool);
if (result)
return result;
if (tagName) {
appAtts[(i << 1) + 1] = poolStart(&tempPool);
poolFinish(&tempPool);
}
else
poolDiscard(&tempPool);
}
else if (tagName) {
appAtts[(i << 1) + 1] = poolStoreString(&tempPool, enc, atts[i].valuePtr, atts[i].valueEnd);
if (appAtts[(i << 1) + 1] == 0)
return XML_ERROR_NO_MEMORY;
poolFinish(&tempPool);
}
}
if (tagName) {
int j;
for (j = 0; j < nDefaultAtts; j++) {
const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + j;
if (!(da->id->name)[-1] && da->value) {
(da->id->name)[-1] = 1;
appAtts[i << 1] = da->id->name;
appAtts[(i << 1) + 1] = da->value;
i++;
}
}
appAtts[i << 1] = 0;
}
while (i-- > 0)
((XML_Char *)appAtts[i << 1])[-1] = 0;
return XML_ERROR_NONE;
} | /* If tagName is non-null, build a real list of attributes,
otherwise just check the attributes for well-formedness. */ | If tagName is non-null, build a real list of attributes,
otherwise just check the attributes for well-formedness. | [
"If",
"tagName",
"is",
"non",
"-",
"null",
"build",
"a",
"real",
"list",
"of",
"attributes",
"otherwise",
"just",
"check",
"the",
"attributes",
"for",
"well",
"-",
"formedness",
"."
] | static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc,
const XML_Char *tagName, const char *s)
{
ELEMENT_TYPE *elementType = 0;
int nDefaultAtts = 0;
const XML_Char **appAtts;
int i;
int n;
if (tagName) {
elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagName, 0);
if (elementType)
nDefaultAtts = elementType->nDefaultAtts;
}
n = XmlGetAttributes(enc, s, attsSize, atts);
if (n + nDefaultAtts > attsSize) {
int oldAttsSize = attsSize;
attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
atts = (ATTRIBUTE*)realloc((void *)atts, attsSize * sizeof(ATTRIBUTE));
if (!atts)
return XML_ERROR_NO_MEMORY;
if (n > oldAttsSize)
XmlGetAttributes(enc, s, n, atts);
}
appAtts = (const XML_Char **)atts;
for (i = 0; i < n; i++) {
ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name,
atts[i].name
+ XmlNameLength(enc, atts[i].name));
if (!attId)
return XML_ERROR_NO_MEMORY;
if ((attId->name)[-1]) {
if (enc == encoding)
eventPtr = atts[i].name;
return XML_ERROR_DUPLICATE_ATTRIBUTE;
}
(attId->name)[-1] = 1;
appAtts[i << 1] = attId->name;
if (!atts[i].normalized) {
enum XML_Error result;
int isCdata = 1;
if (attId->maybeTokenized) {
int j;
for (j = 0; j < nDefaultAtts; j++) {
if (attId == elementType->defaultAtts[j].id) {
isCdata = elementType->defaultAtts[j].isCdata;
break;
}
}
}
result = storeAttributeValue(parser, enc, isCdata,
atts[i].valuePtr, atts[i].valueEnd,
&tempPool);
if (result)
return result;
if (tagName) {
appAtts[(i << 1) + 1] = poolStart(&tempPool);
poolFinish(&tempPool);
}
else
poolDiscard(&tempPool);
}
else if (tagName) {
appAtts[(i << 1) + 1] = poolStoreString(&tempPool, enc, atts[i].valuePtr, atts[i].valueEnd);
if (appAtts[(i << 1) + 1] == 0)
return XML_ERROR_NO_MEMORY;
poolFinish(&tempPool);
}
}
if (tagName) {
int j;
for (j = 0; j < nDefaultAtts; j++) {
const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + j;
if (!(da->id->name)[-1] && da->value) {
(da->id->name)[-1] = 1;
appAtts[i << 1] = da->id->name;
appAtts[(i << 1) + 1] = da->value;
i++;
}
}
appAtts[i << 1] = 0;
}
while (i-- > 0)
((XML_Char *)appAtts[i << 1])[-1] = 0;
return XML_ERROR_NONE;
} | [
"static",
"enum",
"XML_Error",
"storeAtts",
"(",
"XML_Parser",
"parser",
",",
"const",
"ENCODING",
"*",
"enc",
",",
"const",
"XML_Char",
"*",
"tagName",
",",
"const",
"char",
"*",
"s",
")",
"{",
"ELEMENT_TYPE",
"*",
"elementType",
"=",
"0",
";",
"int",
"nDefaultAtts",
"=",
"0",
";",
"const",
"XML_Char",
"*",
"*",
"appAtts",
";",
"int",
"i",
";",
"int",
"n",
";",
"if",
"(",
"tagName",
")",
"{",
"elementType",
"=",
"(",
"ELEMENT_TYPE",
"*",
")",
"lookup",
"(",
"&",
"dtd",
".",
"elementTypes",
",",
"tagName",
",",
"0",
")",
";",
"if",
"(",
"elementType",
")",
"nDefaultAtts",
"=",
"elementType",
"->",
"nDefaultAtts",
";",
"}",
"n",
"=",
"XmlGetAttributes",
"(",
"enc",
",",
"s",
",",
"attsSize",
",",
"atts",
")",
";",
"if",
"(",
"n",
"+",
"nDefaultAtts",
">",
"attsSize",
")",
"{",
"int",
"oldAttsSize",
"=",
"attsSize",
";",
"attsSize",
"=",
"n",
"+",
"nDefaultAtts",
"+",
"INIT_ATTS_SIZE",
";",
"atts",
"=",
"(",
"ATTRIBUTE",
"*",
")",
"realloc",
"(",
"(",
"void",
"*",
")",
"atts",
",",
"attsSize",
"*",
"sizeof",
"(",
"ATTRIBUTE",
")",
")",
";",
"if",
"(",
"!",
"atts",
")",
"return",
"XML_ERROR_NO_MEMORY",
";",
"if",
"(",
"n",
">",
"oldAttsSize",
")",
"XmlGetAttributes",
"(",
"enc",
",",
"s",
",",
"n",
",",
"atts",
")",
";",
"}",
"appAtts",
"=",
"(",
"const",
"XML_Char",
"*",
"*",
")",
"atts",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"ATTRIBUTE_ID",
"*",
"attId",
"=",
"getAttributeId",
"(",
"parser",
",",
"enc",
",",
"atts",
"[",
"i",
"]",
".",
"name",
",",
"atts",
"[",
"i",
"]",
".",
"name",
"+",
"XmlNameLength",
"(",
"enc",
",",
"atts",
"[",
"i",
"]",
".",
"name",
")",
")",
";",
"if",
"(",
"!",
"attId",
")",
"return",
"XML_ERROR_NO_MEMORY",
";",
"if",
"(",
"(",
"attId",
"->",
"name",
")",
"[",
"-1",
"]",
")",
"{",
"if",
"(",
"enc",
"==",
"encoding",
")",
"eventPtr",
"=",
"atts",
"[",
"i",
"]",
".",
"name",
";",
"return",
"XML_ERROR_DUPLICATE_ATTRIBUTE",
";",
"}",
"(",
"attId",
"->",
"name",
")",
"[",
"-1",
"]",
"=",
"1",
";",
"appAtts",
"[",
"i",
"<<",
"1",
"]",
"=",
"attId",
"->",
"name",
";",
"if",
"(",
"!",
"atts",
"[",
"i",
"]",
".",
"normalized",
")",
"{",
"enum",
"XML_Error",
"result",
";",
"int",
"isCdata",
"=",
"1",
";",
"if",
"(",
"attId",
"->",
"maybeTokenized",
")",
"{",
"int",
"j",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"nDefaultAtts",
";",
"j",
"++",
")",
"{",
"if",
"(",
"attId",
"==",
"elementType",
"->",
"defaultAtts",
"[",
"j",
"]",
".",
"id",
")",
"{",
"isCdata",
"=",
"elementType",
"->",
"defaultAtts",
"[",
"j",
"]",
".",
"isCdata",
";",
"break",
";",
"}",
"}",
"}",
"result",
"=",
"storeAttributeValue",
"(",
"parser",
",",
"enc",
",",
"isCdata",
",",
"atts",
"[",
"i",
"]",
".",
"valuePtr",
",",
"atts",
"[",
"i",
"]",
".",
"valueEnd",
",",
"&",
"tempPool",
")",
";",
"if",
"(",
"result",
")",
"return",
"result",
";",
"if",
"(",
"tagName",
")",
"{",
"appAtts",
"[",
"(",
"i",
"<<",
"1",
")",
"+",
"1",
"]",
"=",
"poolStart",
"(",
"&",
"tempPool",
")",
";",
"poolFinish",
"(",
"&",
"tempPool",
")",
";",
"}",
"else",
"poolDiscard",
"(",
"&",
"tempPool",
")",
";",
"}",
"else",
"if",
"(",
"tagName",
")",
"{",
"appAtts",
"[",
"(",
"i",
"<<",
"1",
")",
"+",
"1",
"]",
"=",
"poolStoreString",
"(",
"&",
"tempPool",
",",
"enc",
",",
"atts",
"[",
"i",
"]",
".",
"valuePtr",
",",
"atts",
"[",
"i",
"]",
".",
"valueEnd",
")",
";",
"if",
"(",
"appAtts",
"[",
"(",
"i",
"<<",
"1",
")",
"+",
"1",
"]",
"==",
"0",
")",
"return",
"XML_ERROR_NO_MEMORY",
";",
"poolFinish",
"(",
"&",
"tempPool",
")",
";",
"}",
"}",
"if",
"(",
"tagName",
")",
"{",
"int",
"j",
";",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"nDefaultAtts",
";",
"j",
"++",
")",
"{",
"const",
"DEFAULT_ATTRIBUTE",
"*",
"da",
"=",
"elementType",
"->",
"defaultAtts",
"+",
"j",
";",
"if",
"(",
"!",
"(",
"da",
"->",
"id",
"->",
"name",
")",
"[",
"-1",
"]",
"&&",
"da",
"->",
"value",
")",
"{",
"(",
"da",
"->",
"id",
"->",
"name",
")",
"[",
"-1",
"]",
"=",
"1",
";",
"appAtts",
"[",
"i",
"<<",
"1",
"]",
"=",
"da",
"->",
"id",
"->",
"name",
";",
"appAtts",
"[",
"(",
"i",
"<<",
"1",
")",
"+",
"1",
"]",
"=",
"da",
"->",
"value",
";",
"i",
"++",
";",
"}",
"}",
"appAtts",
"[",
"i",
"<<",
"1",
"]",
"=",
"0",
";",
"}",
"while",
"(",
"i",
"--",
">",
"0",
")",
"(",
"(",
"XML_Char",
"*",
")",
"appAtts",
"[",
"i",
"<<",
"1",
"]",
")",
"[",
"-1",
"]",
"=",
"0",
";",
"return",
"XML_ERROR_NONE",
";",
"}"
] | If tagName is non-null, build a real list of attributes,
otherwise just check the attributes for well-formedness. | [
"If",
"tagName",
"is",
"non",
"-",
"null",
"build",
"a",
"real",
"list",
"of",
"attributes",
"otherwise",
"just",
"check",
"the",
"attributes",
"for",
"well",
"-",
"formedness",
"."
] | [] | [
{
"param": "parser",
"type": "XML_Parser"
},
{
"param": "enc",
"type": "ENCODING"
},
{
"param": "tagName",
"type": "XML_Char"
},
{
"param": "s",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "parser",
"type": "XML_Parser",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "enc",
"type": "ENCODING",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tagName",
"type": "XML_Char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "s",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e444acb8323ffcb2bdbb8a9d69323cd98d477224 | chinjui/gym_torcs | vtorcs-RL-color/src/libs/txml/xmlparse.c | [
"MIT"
] | C | doCdataSection | null | static
enum XML_Error doCdataSection(XML_Parser parser,
const ENCODING *enc,
const char **startPtr,
const char *end,
const char **nextPtr)
{
const char *s = *startPtr;
const char *dummy;
const char **eventPP;
const char **eventEndPP;
if (enc == encoding) {
eventPP = &eventPtr;
*eventPP = s;
eventEndPP = &eventEndPtr;
}
else
eventPP = eventEndPP = &dummy;
*startPtr = 0;
for (;;) {
const char *next;
int tok = XmlCdataSectionTok(enc, s, end, &next);
*eventEndPP = next;
switch (tok) {
case XML_TOK_CDATA_SECT_CLOSE:
if (characterDataHandler)
characterDataHandler(handlerArg, dataBuf, 0);
else if (defaultHandler)
reportDefault(parser, enc, s, next);
*startPtr = next;
return XML_ERROR_NONE;
case XML_TOK_DATA_NEWLINE:
if (characterDataHandler) {
XML_Char c = XML_T('\n');
characterDataHandler(handlerArg, &c, 1);
}
else if (defaultHandler)
reportDefault(parser, enc, s, next);
break;
case XML_TOK_DATA_CHARS:
if (characterDataHandler) {
if (MUST_CONVERT(enc, s)) {
for (;;) {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
*eventEndPP = next;
characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
if (s == next)
break;
*eventPP = s;
}
}
else
characterDataHandler(handlerArg,
(XML_Char *)s,
(XML_Char *)next - (XML_Char *)s);
}
else if (defaultHandler)
reportDefault(parser, enc, s, next);
break;
case XML_TOK_INVALID:
*eventPP = next;
return XML_ERROR_INVALID_TOKEN;
case XML_TOK_PARTIAL_CHAR:
if (nextPtr) {
*nextPtr = s;
return XML_ERROR_NONE;
}
return XML_ERROR_PARTIAL_CHAR;
case XML_TOK_PARTIAL:
case XML_TOK_NONE:
if (nextPtr) {
*nextPtr = s;
return XML_ERROR_NONE;
}
return XML_ERROR_UNCLOSED_CDATA_SECTION;
default:
abort();
}
*eventPP = s = next;
}
/* not reached */
} | /* startPtr gets set to non-null is the section is closed, and to null if
the section is not yet closed. */ | startPtr gets set to non-null is the section is closed, and to null if
the section is not yet closed. | [
"startPtr",
"gets",
"set",
"to",
"non",
"-",
"null",
"is",
"the",
"section",
"is",
"closed",
"and",
"to",
"null",
"if",
"the",
"section",
"is",
"not",
"yet",
"closed",
"."
] | static
enum XML_Error doCdataSection(XML_Parser parser,
const ENCODING *enc,
const char **startPtr,
const char *end,
const char **nextPtr)
{
const char *s = *startPtr;
const char *dummy;
const char **eventPP;
const char **eventEndPP;
if (enc == encoding) {
eventPP = &eventPtr;
*eventPP = s;
eventEndPP = &eventEndPtr;
}
else
eventPP = eventEndPP = &dummy;
*startPtr = 0;
for (;;) {
const char *next;
int tok = XmlCdataSectionTok(enc, s, end, &next);
*eventEndPP = next;
switch (tok) {
case XML_TOK_CDATA_SECT_CLOSE:
if (characterDataHandler)
characterDataHandler(handlerArg, dataBuf, 0);
else if (defaultHandler)
reportDefault(parser, enc, s, next);
*startPtr = next;
return XML_ERROR_NONE;
case XML_TOK_DATA_NEWLINE:
if (characterDataHandler) {
XML_Char c = XML_T('\n');
characterDataHandler(handlerArg, &c, 1);
}
else if (defaultHandler)
reportDefault(parser, enc, s, next);
break;
case XML_TOK_DATA_CHARS:
if (characterDataHandler) {
if (MUST_CONVERT(enc, s)) {
for (;;) {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
*eventEndPP = next;
characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
if (s == next)
break;
*eventPP = s;
}
}
else
characterDataHandler(handlerArg,
(XML_Char *)s,
(XML_Char *)next - (XML_Char *)s);
}
else if (defaultHandler)
reportDefault(parser, enc, s, next);
break;
case XML_TOK_INVALID:
*eventPP = next;
return XML_ERROR_INVALID_TOKEN;
case XML_TOK_PARTIAL_CHAR:
if (nextPtr) {
*nextPtr = s;
return XML_ERROR_NONE;
}
return XML_ERROR_PARTIAL_CHAR;
case XML_TOK_PARTIAL:
case XML_TOK_NONE:
if (nextPtr) {
*nextPtr = s;
return XML_ERROR_NONE;
}
return XML_ERROR_UNCLOSED_CDATA_SECTION;
default:
abort();
}
*eventPP = s = next;
}
} | [
"static",
"enum",
"XML_Error",
"doCdataSection",
"(",
"XML_Parser",
"parser",
",",
"const",
"ENCODING",
"*",
"enc",
",",
"const",
"char",
"*",
"*",
"startPtr",
",",
"const",
"char",
"*",
"end",
",",
"const",
"char",
"*",
"*",
"nextPtr",
")",
"{",
"const",
"char",
"*",
"s",
"=",
"*",
"startPtr",
";",
"const",
"char",
"*",
"dummy",
";",
"const",
"char",
"*",
"*",
"eventPP",
";",
"const",
"char",
"*",
"*",
"eventEndPP",
";",
"if",
"(",
"enc",
"==",
"encoding",
")",
"{",
"eventPP",
"=",
"&",
"eventPtr",
";",
"*",
"eventPP",
"=",
"s",
";",
"eventEndPP",
"=",
"&",
"eventEndPtr",
";",
"}",
"else",
"eventPP",
"=",
"eventEndPP",
"=",
"&",
"dummy",
";",
"*",
"startPtr",
"=",
"0",
";",
"for",
"(",
";",
";",
")",
"{",
"const",
"char",
"*",
"next",
";",
"int",
"tok",
"=",
"XmlCdataSectionTok",
"(",
"enc",
",",
"s",
",",
"end",
",",
"&",
"next",
")",
";",
"*",
"eventEndPP",
"=",
"next",
";",
"switch",
"(",
"tok",
")",
"{",
"case",
"XML_TOK_CDATA_SECT_CLOSE",
":",
"if",
"(",
"characterDataHandler",
")",
"characterDataHandler",
"(",
"handlerArg",
",",
"dataBuf",
",",
"0",
")",
";",
"else",
"if",
"(",
"defaultHandler",
")",
"reportDefault",
"(",
"parser",
",",
"enc",
",",
"s",
",",
"next",
")",
";",
"*",
"startPtr",
"=",
"next",
";",
"return",
"XML_ERROR_NONE",
";",
"case",
"XML_TOK_DATA_NEWLINE",
":",
"if",
"(",
"characterDataHandler",
")",
"{",
"XML_Char",
"c",
"=",
"XML_T",
"(",
"'",
"\\n",
"'",
")",
";",
"characterDataHandler",
"(",
"handlerArg",
",",
"&",
"c",
",",
"1",
")",
";",
"}",
"else",
"if",
"(",
"defaultHandler",
")",
"reportDefault",
"(",
"parser",
",",
"enc",
",",
"s",
",",
"next",
")",
";",
"break",
";",
"case",
"XML_TOK_DATA_CHARS",
":",
"if",
"(",
"characterDataHandler",
")",
"{",
"if",
"(",
"MUST_CONVERT",
"(",
"enc",
",",
"s",
")",
")",
"{",
"for",
"(",
";",
";",
")",
"{",
"ICHAR",
"*",
"dataPtr",
"=",
"(",
"ICHAR",
"*",
")",
"dataBuf",
";",
"XmlConvert",
"(",
"enc",
",",
"&",
"s",
",",
"next",
",",
"&",
"dataPtr",
",",
"(",
"ICHAR",
"*",
")",
"dataBufEnd",
")",
";",
"*",
"eventEndPP",
"=",
"next",
";",
"characterDataHandler",
"(",
"handlerArg",
",",
"dataBuf",
",",
"dataPtr",
"-",
"(",
"ICHAR",
"*",
")",
"dataBuf",
")",
";",
"if",
"(",
"s",
"==",
"next",
")",
"break",
";",
"*",
"eventPP",
"=",
"s",
";",
"}",
"}",
"else",
"characterDataHandler",
"(",
"handlerArg",
",",
"(",
"XML_Char",
"*",
")",
"s",
",",
"(",
"XML_Char",
"*",
")",
"next",
"-",
"(",
"XML_Char",
"*",
")",
"s",
")",
";",
"}",
"else",
"if",
"(",
"defaultHandler",
")",
"reportDefault",
"(",
"parser",
",",
"enc",
",",
"s",
",",
"next",
")",
";",
"break",
";",
"case",
"XML_TOK_INVALID",
":",
"*",
"eventPP",
"=",
"next",
";",
"return",
"XML_ERROR_INVALID_TOKEN",
";",
"case",
"XML_TOK_PARTIAL_CHAR",
":",
"if",
"(",
"nextPtr",
")",
"{",
"*",
"nextPtr",
"=",
"s",
";",
"return",
"XML_ERROR_NONE",
";",
"}",
"return",
"XML_ERROR_PARTIAL_CHAR",
";",
"case",
"XML_TOK_PARTIAL",
":",
"case",
"XML_TOK_NONE",
":",
"if",
"(",
"nextPtr",
")",
"{",
"*",
"nextPtr",
"=",
"s",
";",
"return",
"XML_ERROR_NONE",
";",
"}",
"return",
"XML_ERROR_UNCLOSED_CDATA_SECTION",
";",
"default",
":",
"abort",
"(",
")",
";",
"}",
"*",
"eventPP",
"=",
"s",
"=",
"next",
";",
"}",
"}"
] | startPtr gets set to non-null is the section is closed, and to null if
the section is not yet closed. | [
"startPtr",
"gets",
"set",
"to",
"non",
"-",
"null",
"is",
"the",
"section",
"is",
"closed",
"and",
"to",
"null",
"if",
"the",
"section",
"is",
"not",
"yet",
"closed",
"."
] | [
"/* not reached */"
] | [
{
"param": "parser",
"type": "XML_Parser"
},
{
"param": "enc",
"type": "ENCODING"
},
{
"param": "startPtr",
"type": "char"
},
{
"param": "end",
"type": "char"
},
{
"param": "nextPtr",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "parser",
"type": "XML_Parser",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "enc",
"type": "ENCODING",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "startPtr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "end",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nextPtr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
e444acb8323ffcb2bdbb8a9d69323cd98d477224 | chinjui/gym_torcs | vtorcs-RL-color/src/libs/txml/xmlparse.c | [
"MIT"
] | C | dtdCopy | int | static int dtdCopy(DTD *newDtd, const DTD *oldDtd)
{
HASH_TABLE_ITER iter;
if (oldDtd->base) {
const XML_Char *tem = poolCopyString(&(newDtd->pool), oldDtd->base);
if (!tem)
return 0;
newDtd->base = tem;
}
hashTableIterInit(&iter, &(oldDtd->attributeIds));
/* Copy the attribute id table. */
for (;;) {
ATTRIBUTE_ID *newA;
const XML_Char *name;
const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter);
if (!oldA)
break;
/* Remember to allocate the scratch byte before the name. */
if (!poolAppendChar(&(newDtd->pool), XML_T('\0')))
return 0;
name = poolCopyString(&(newDtd->pool), oldA->name);
if (!name)
return 0;
++name;
newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID));
if (!newA)
return 0;
newA->maybeTokenized = oldA->maybeTokenized;
}
/* Copy the element type table. */
hashTableIterInit(&iter, &(oldDtd->elementTypes));
for (;;) {
int i;
ELEMENT_TYPE *newE;
const XML_Char *name;
const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter);
if (!oldE)
break;
name = poolCopyString(&(newDtd->pool), oldE->name);
if (!name)
return 0;
newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE));
if (!newE)
return 0;
newE->defaultAtts = (DEFAULT_ATTRIBUTE *)malloc(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
if (!newE->defaultAtts)
return 0;
newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
for (i = 0; i < newE->nDefaultAtts; i++) {
newE->defaultAtts[i].id = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0);
newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
if (oldE->defaultAtts[i].value) {
newE->defaultAtts[i].value = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value);
if (!newE->defaultAtts[i].value)
return 0;
}
else
newE->defaultAtts[i].value = 0;
}
}
/* Copy the entity table. */
hashTableIterInit(&iter, &(oldDtd->generalEntities));
for (;;) {
ENTITY *newE;
const XML_Char *name;
const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter);
if (!oldE)
break;
name = poolCopyString(&(newDtd->pool), oldE->name);
if (!name)
return 0;
newE = (ENTITY *)lookup(&(newDtd->generalEntities), name, sizeof(ENTITY));
if (!newE)
return 0;
if (oldE->systemId) {
const XML_Char *tem = poolCopyString(&(newDtd->pool), oldE->systemId);
if (!tem)
return 0;
newE->systemId = tem;
if (oldE->base) {
if (oldE->base == oldDtd->base)
newE->base = newDtd->base;
tem = poolCopyString(&(newDtd->pool), oldE->base);
if (!tem)
return 0;
newE->base = tem;
}
}
else {
const XML_Char *tem = poolCopyStringN(&(newDtd->pool), oldE->textPtr, oldE->textLen);
if (!tem)
return 0;
newE->textPtr = tem;
newE->textLen = oldE->textLen;
}
if (oldE->notation) {
const XML_Char *tem = poolCopyString(&(newDtd->pool), oldE->notation);
if (!tem)
return 0;
newE->notation = tem;
}
}
newDtd->complete = oldDtd->complete;
newDtd->standalone = oldDtd->standalone;
return 1;
} | /* Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise.
The new DTD has already been initialized. */ | Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise.
The new DTD has already been initialized. | [
"Do",
"a",
"deep",
"copy",
"of",
"the",
"DTD",
".",
"Return",
"0",
"for",
"out",
"of",
"memory",
";",
"non",
"-",
"zero",
"otherwise",
".",
"The",
"new",
"DTD",
"has",
"already",
"been",
"initialized",
"."
] | static int dtdCopy(DTD *newDtd, const DTD *oldDtd)
{
HASH_TABLE_ITER iter;
if (oldDtd->base) {
const XML_Char *tem = poolCopyString(&(newDtd->pool), oldDtd->base);
if (!tem)
return 0;
newDtd->base = tem;
}
hashTableIterInit(&iter, &(oldDtd->attributeIds));
for (;;) {
ATTRIBUTE_ID *newA;
const XML_Char *name;
const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter);
if (!oldA)
break;
if (!poolAppendChar(&(newDtd->pool), XML_T('\0')))
return 0;
name = poolCopyString(&(newDtd->pool), oldA->name);
if (!name)
return 0;
++name;
newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID));
if (!newA)
return 0;
newA->maybeTokenized = oldA->maybeTokenized;
}
hashTableIterInit(&iter, &(oldDtd->elementTypes));
for (;;) {
int i;
ELEMENT_TYPE *newE;
const XML_Char *name;
const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter);
if (!oldE)
break;
name = poolCopyString(&(newDtd->pool), oldE->name);
if (!name)
return 0;
newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE));
if (!newE)
return 0;
newE->defaultAtts = (DEFAULT_ATTRIBUTE *)malloc(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
if (!newE->defaultAtts)
return 0;
newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
for (i = 0; i < newE->nDefaultAtts; i++) {
newE->defaultAtts[i].id = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0);
newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
if (oldE->defaultAtts[i].value) {
newE->defaultAtts[i].value = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value);
if (!newE->defaultAtts[i].value)
return 0;
}
else
newE->defaultAtts[i].value = 0;
}
}
hashTableIterInit(&iter, &(oldDtd->generalEntities));
for (;;) {
ENTITY *newE;
const XML_Char *name;
const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter);
if (!oldE)
break;
name = poolCopyString(&(newDtd->pool), oldE->name);
if (!name)
return 0;
newE = (ENTITY *)lookup(&(newDtd->generalEntities), name, sizeof(ENTITY));
if (!newE)
return 0;
if (oldE->systemId) {
const XML_Char *tem = poolCopyString(&(newDtd->pool), oldE->systemId);
if (!tem)
return 0;
newE->systemId = tem;
if (oldE->base) {
if (oldE->base == oldDtd->base)
newE->base = newDtd->base;
tem = poolCopyString(&(newDtd->pool), oldE->base);
if (!tem)
return 0;
newE->base = tem;
}
}
else {
const XML_Char *tem = poolCopyStringN(&(newDtd->pool), oldE->textPtr, oldE->textLen);
if (!tem)
return 0;
newE->textPtr = tem;
newE->textLen = oldE->textLen;
}
if (oldE->notation) {
const XML_Char *tem = poolCopyString(&(newDtd->pool), oldE->notation);
if (!tem)
return 0;
newE->notation = tem;
}
}
newDtd->complete = oldDtd->complete;
newDtd->standalone = oldDtd->standalone;
return 1;
} | [
"static",
"int",
"dtdCopy",
"(",
"DTD",
"*",
"newDtd",
",",
"const",
"DTD",
"*",
"oldDtd",
")",
"{",
"HASH_TABLE_ITER",
"iter",
";",
"if",
"(",
"oldDtd",
"->",
"base",
")",
"{",
"const",
"XML_Char",
"*",
"tem",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldDtd",
"->",
"base",
")",
";",
"if",
"(",
"!",
"tem",
")",
"return",
"0",
";",
"newDtd",
"->",
"base",
"=",
"tem",
";",
"}",
"hashTableIterInit",
"(",
"&",
"iter",
",",
"&",
"(",
"oldDtd",
"->",
"attributeIds",
")",
")",
";",
"for",
"(",
";",
";",
")",
"{",
"ATTRIBUTE_ID",
"*",
"newA",
";",
"const",
"XML_Char",
"*",
"name",
";",
"const",
"ATTRIBUTE_ID",
"*",
"oldA",
"=",
"(",
"ATTRIBUTE_ID",
"*",
")",
"hashTableIterNext",
"(",
"&",
"iter",
")",
";",
"if",
"(",
"!",
"oldA",
")",
"break",
";",
"if",
"(",
"!",
"poolAppendChar",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"XML_T",
"(",
"'",
"\\0",
"'",
")",
")",
")",
"return",
"0",
";",
"name",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldA",
"->",
"name",
")",
";",
"if",
"(",
"!",
"name",
")",
"return",
"0",
";",
"++",
"name",
";",
"newA",
"=",
"(",
"ATTRIBUTE_ID",
"*",
")",
"lookup",
"(",
"&",
"(",
"newDtd",
"->",
"attributeIds",
")",
",",
"name",
",",
"sizeof",
"(",
"ATTRIBUTE_ID",
")",
")",
";",
"if",
"(",
"!",
"newA",
")",
"return",
"0",
";",
"newA",
"->",
"maybeTokenized",
"=",
"oldA",
"->",
"maybeTokenized",
";",
"}",
"hashTableIterInit",
"(",
"&",
"iter",
",",
"&",
"(",
"oldDtd",
"->",
"elementTypes",
")",
")",
";",
"for",
"(",
";",
";",
")",
"{",
"int",
"i",
";",
"ELEMENT_TYPE",
"*",
"newE",
";",
"const",
"XML_Char",
"*",
"name",
";",
"const",
"ELEMENT_TYPE",
"*",
"oldE",
"=",
"(",
"ELEMENT_TYPE",
"*",
")",
"hashTableIterNext",
"(",
"&",
"iter",
")",
";",
"if",
"(",
"!",
"oldE",
")",
"break",
";",
"name",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldE",
"->",
"name",
")",
";",
"if",
"(",
"!",
"name",
")",
"return",
"0",
";",
"newE",
"=",
"(",
"ELEMENT_TYPE",
"*",
")",
"lookup",
"(",
"&",
"(",
"newDtd",
"->",
"elementTypes",
")",
",",
"name",
",",
"sizeof",
"(",
"ELEMENT_TYPE",
")",
")",
";",
"if",
"(",
"!",
"newE",
")",
"return",
"0",
";",
"newE",
"->",
"defaultAtts",
"=",
"(",
"DEFAULT_ATTRIBUTE",
"*",
")",
"malloc",
"(",
"oldE",
"->",
"nDefaultAtts",
"*",
"sizeof",
"(",
"DEFAULT_ATTRIBUTE",
")",
")",
";",
"if",
"(",
"!",
"newE",
"->",
"defaultAtts",
")",
"return",
"0",
";",
"newE",
"->",
"allocDefaultAtts",
"=",
"newE",
"->",
"nDefaultAtts",
"=",
"oldE",
"->",
"nDefaultAtts",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"newE",
"->",
"nDefaultAtts",
";",
"i",
"++",
")",
"{",
"newE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"id",
"=",
"(",
"ATTRIBUTE_ID",
"*",
")",
"lookup",
"(",
"&",
"(",
"newDtd",
"->",
"attributeIds",
")",
",",
"oldE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"id",
"->",
"name",
",",
"0",
")",
";",
"newE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"isCdata",
"=",
"oldE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"isCdata",
";",
"if",
"(",
"oldE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"value",
")",
"{",
"newE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"value",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"value",
")",
";",
"if",
"(",
"!",
"newE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"value",
")",
"return",
"0",
";",
"}",
"else",
"newE",
"->",
"defaultAtts",
"[",
"i",
"]",
".",
"value",
"=",
"0",
";",
"}",
"}",
"hashTableIterInit",
"(",
"&",
"iter",
",",
"&",
"(",
"oldDtd",
"->",
"generalEntities",
")",
")",
";",
"for",
"(",
";",
";",
")",
"{",
"ENTITY",
"*",
"newE",
";",
"const",
"XML_Char",
"*",
"name",
";",
"const",
"ENTITY",
"*",
"oldE",
"=",
"(",
"ENTITY",
"*",
")",
"hashTableIterNext",
"(",
"&",
"iter",
")",
";",
"if",
"(",
"!",
"oldE",
")",
"break",
";",
"name",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldE",
"->",
"name",
")",
";",
"if",
"(",
"!",
"name",
")",
"return",
"0",
";",
"newE",
"=",
"(",
"ENTITY",
"*",
")",
"lookup",
"(",
"&",
"(",
"newDtd",
"->",
"generalEntities",
")",
",",
"name",
",",
"sizeof",
"(",
"ENTITY",
")",
")",
";",
"if",
"(",
"!",
"newE",
")",
"return",
"0",
";",
"if",
"(",
"oldE",
"->",
"systemId",
")",
"{",
"const",
"XML_Char",
"*",
"tem",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldE",
"->",
"systemId",
")",
";",
"if",
"(",
"!",
"tem",
")",
"return",
"0",
";",
"newE",
"->",
"systemId",
"=",
"tem",
";",
"if",
"(",
"oldE",
"->",
"base",
")",
"{",
"if",
"(",
"oldE",
"->",
"base",
"==",
"oldDtd",
"->",
"base",
")",
"newE",
"->",
"base",
"=",
"newDtd",
"->",
"base",
";",
"tem",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldE",
"->",
"base",
")",
";",
"if",
"(",
"!",
"tem",
")",
"return",
"0",
";",
"newE",
"->",
"base",
"=",
"tem",
";",
"}",
"}",
"else",
"{",
"const",
"XML_Char",
"*",
"tem",
"=",
"poolCopyStringN",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldE",
"->",
"textPtr",
",",
"oldE",
"->",
"textLen",
")",
";",
"if",
"(",
"!",
"tem",
")",
"return",
"0",
";",
"newE",
"->",
"textPtr",
"=",
"tem",
";",
"newE",
"->",
"textLen",
"=",
"oldE",
"->",
"textLen",
";",
"}",
"if",
"(",
"oldE",
"->",
"notation",
")",
"{",
"const",
"XML_Char",
"*",
"tem",
"=",
"poolCopyString",
"(",
"&",
"(",
"newDtd",
"->",
"pool",
")",
",",
"oldE",
"->",
"notation",
")",
";",
"if",
"(",
"!",
"tem",
")",
"return",
"0",
";",
"newE",
"->",
"notation",
"=",
"tem",
";",
"}",
"}",
"newDtd",
"->",
"complete",
"=",
"oldDtd",
"->",
"complete",
";",
"newDtd",
"->",
"standalone",
"=",
"oldDtd",
"->",
"standalone",
";",
"return",
"1",
";",
"}"
] | Do a deep copy of the DTD. | [
"Do",
"a",
"deep",
"copy",
"of",
"the",
"DTD",
"."
] | [
"/* Copy the attribute id table. */",
"/* Remember to allocate the scratch byte before the name. */",
"/* Copy the element type table. */",
"/* Copy the entity table. */"
] | [
{
"param": "newDtd",
"type": "DTD"
},
{
"param": "oldDtd",
"type": "DTD"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "newDtd",
"type": "DTD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "oldDtd",
"type": "DTD",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
374d996caf792c47abfaadc8617b58a15fbbeeb5 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/list2.c | [
"MIT"
] | C | Add_process | void | void Add_process (struct list *List,struct process *proc) {
struct process *temp = List->root;
struct process *temp2 = temp;
if(temp == NULL){
List->root = proc;
List->counter++;
}
else{
while (temp != NULL) {
temp2 = temp; //temp2 will find the last process
temp = temp->next; //temp will always turn out NULL
}
proc->next = NULL;
temp2->next = proc;
List->counter = List->counter + 1;
}
} | //add a process at the end of the list | add a process at the end of the list | [
"add",
"a",
"process",
"at",
"the",
"end",
"of",
"the",
"list"
] | void Add_process (struct list *List,struct process *proc) {
struct process *temp = List->root;
struct process *temp2 = temp;
if(temp == NULL){
List->root = proc;
List->counter++;
}
else{
while (temp != NULL) {
temp2 = temp;
temp = temp->next;
}
proc->next = NULL;
temp2->next = proc;
List->counter = List->counter + 1;
}
} | [
"void",
"Add_process",
"(",
"struct",
"list",
"*",
"List",
",",
"struct",
"process",
"*",
"proc",
")",
"{",
"struct",
"process",
"*",
"temp",
"=",
"List",
"->",
"root",
";",
"struct",
"process",
"*",
"temp2",
"=",
"temp",
";",
"if",
"(",
"temp",
"==",
"NULL",
")",
"{",
"List",
"->",
"root",
"=",
"proc",
";",
"List",
"->",
"counter",
"++",
";",
"}",
"else",
"{",
"while",
"(",
"temp",
"!=",
"NULL",
")",
"{",
"temp2",
"=",
"temp",
";",
"temp",
"=",
"temp",
"->",
"next",
";",
"}",
"proc",
"->",
"next",
"=",
"NULL",
";",
"temp2",
"->",
"next",
"=",
"proc",
";",
"List",
"->",
"counter",
"=",
"List",
"->",
"counter",
"+",
"1",
";",
"}",
"}"
] | add a process at the end of the list | [
"add",
"a",
"process",
"at",
"the",
"end",
"of",
"the",
"list"
] | [
"//temp2 will find the last process",
"//temp will always turn out NULL"
] | [
{
"param": "List",
"type": "struct list"
},
{
"param": "proc",
"type": "struct process"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "List",
"type": "struct list",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "proc",
"type": "struct process",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
374d996caf792c47abfaadc8617b58a15fbbeeb5 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/list2.c | [
"MIT"
] | C | Remove_process | null | struct process* Remove_process (struct list *List) {
struct process *temp = List->root;
if (temp == NULL) return NULL;
if (List->counter == 1){
List->root = NULL;
List->counter--;
return temp;
}
struct process *temp2 = temp->next;
List->root = temp2;
List->counter = List->counter - 1;
return temp;
} | //remove a process from the beginning of the list | remove a process from the beginning of the list | [
"remove",
"a",
"process",
"from",
"the",
"beginning",
"of",
"the",
"list"
] | struct process* Remove_process (struct list *List) {
struct process *temp = List->root;
if (temp == NULL) return NULL;
if (List->counter == 1){
List->root = NULL;
List->counter--;
return temp;
}
struct process *temp2 = temp->next;
List->root = temp2;
List->counter = List->counter - 1;
return temp;
} | [
"struct",
"process",
"*",
"Remove_process",
"(",
"struct",
"list",
"*",
"List",
")",
"{",
"struct",
"process",
"*",
"temp",
"=",
"List",
"->",
"root",
";",
"if",
"(",
"temp",
"==",
"NULL",
")",
"return",
"NULL",
";",
"if",
"(",
"List",
"->",
"counter",
"==",
"1",
")",
"{",
"List",
"->",
"root",
"=",
"NULL",
";",
"List",
"->",
"counter",
"--",
";",
"return",
"temp",
";",
"}",
"struct",
"process",
"*",
"temp2",
"=",
"temp",
"->",
"next",
";",
"List",
"->",
"root",
"=",
"temp2",
";",
"List",
"->",
"counter",
"=",
"List",
"->",
"counter",
"-",
"1",
";",
"return",
"temp",
";",
"}"
] | remove a process from the beginning of the list | [
"remove",
"a",
"process",
"from",
"the",
"beginning",
"of",
"the",
"list"
] | [] | [
{
"param": "List",
"type": "struct list"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "List",
"type": "struct list",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
374d996caf792c47abfaadc8617b58a15fbbeeb5 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/list2.c | [
"MIT"
] | C | Destroy_process | pid_t | pid_t Destroy_process (struct list *List,int id) //FINDS THE PID OF THE PROCCES WITH GIVEN ID
{
struct process *temp = List->root;
if (temp == NULL) return -1;
if (temp->id == id){
List->root = temp->next;
pid_t value = temp->pid;
if(temp->name != NULL)free(temp->name);
free(temp);
return value;
}
struct process *temp2 = temp;
while (temp != NULL && temp->id != id) {
temp2 = temp; //temp2 will find the last process
temp = temp->next; //temp will always turn out NULL
}
if (temp != NULL){
temp2->next=temp->next;
pid_t value = temp->pid;
if(temp->name != NULL)free(temp->name);
free(temp);
return value;
}
else{ return -1;}
} | // Deletes the process from the list and returns its pid | Deletes the process from the list and returns its pid | [
"Deletes",
"the",
"process",
"from",
"the",
"list",
"and",
"returns",
"its",
"pid"
] | pid_t Destroy_process (struct list *List,int id)
{
struct process *temp = List->root;
if (temp == NULL) return -1;
if (temp->id == id){
List->root = temp->next;
pid_t value = temp->pid;
if(temp->name != NULL)free(temp->name);
free(temp);
return value;
}
struct process *temp2 = temp;
while (temp != NULL && temp->id != id) {
temp2 = temp;
temp = temp->next;
}
if (temp != NULL){
temp2->next=temp->next;
pid_t value = temp->pid;
if(temp->name != NULL)free(temp->name);
free(temp);
return value;
}
else{ return -1;}
} | [
"pid_t",
"Destroy_process",
"(",
"struct",
"list",
"*",
"List",
",",
"int",
"id",
")",
"{",
"struct",
"process",
"*",
"temp",
"=",
"List",
"->",
"root",
";",
"if",
"(",
"temp",
"==",
"NULL",
")",
"return",
"-1",
";",
"if",
"(",
"temp",
"->",
"id",
"==",
"id",
")",
"{",
"List",
"->",
"root",
"=",
"temp",
"->",
"next",
";",
"pid_t",
"value",
"=",
"temp",
"->",
"pid",
";",
"if",
"(",
"temp",
"->",
"name",
"!=",
"NULL",
")",
"free",
"(",
"temp",
"->",
"name",
")",
";",
"free",
"(",
"temp",
")",
";",
"return",
"value",
";",
"}",
"struct",
"process",
"*",
"temp2",
"=",
"temp",
";",
"while",
"(",
"temp",
"!=",
"NULL",
"&&",
"temp",
"->",
"id",
"!=",
"id",
")",
"{",
"temp2",
"=",
"temp",
";",
"temp",
"=",
"temp",
"->",
"next",
";",
"}",
"if",
"(",
"temp",
"!=",
"NULL",
")",
"{",
"temp2",
"->",
"next",
"=",
"temp",
"->",
"next",
";",
"pid_t",
"value",
"=",
"temp",
"->",
"pid",
";",
"if",
"(",
"temp",
"->",
"name",
"!=",
"NULL",
")",
"free",
"(",
"temp",
"->",
"name",
")",
";",
"free",
"(",
"temp",
")",
";",
"return",
"value",
";",
"}",
"else",
"{",
"return",
"-1",
";",
"}",
"}"
] | Deletes the process from the list and returns its pid | [
"Deletes",
"the",
"process",
"from",
"the",
"list",
"and",
"returns",
"its",
"pid"
] | [
"//FINDS THE PID OF THE PROCCES WITH GIVEN ID",
"//temp2 will find the last process",
"//temp will always turn out NULL"
] | [
{
"param": "List",
"type": "struct list"
},
{
"param": "id",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "List",
"type": "struct list",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "id",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
732772e8942de1e03ac2dff3f5d83257c1f878b0 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell.c | [
"MIT"
] | C | sched_print_tasks | void | static void sched_print_tasks(void)
{
struct process* temp;
temp = list->root;
if(temp == NULL){
return;
}
printf("\n");
printf("Currently running");
do{
printf("[%s]:with pid %ld and serial_no %d\n\n",temp->name,(long)temp->pid,temp->id);
}while((temp = temp->next) != NULL);
} | // if 0 remove head
/* Print a list of all tasks currently being scheduled. */ | if 0 remove head
Print a list of all tasks currently being scheduled. | [
"if",
"0",
"remove",
"head",
"Print",
"a",
"list",
"of",
"all",
"tasks",
"currently",
"being",
"scheduled",
"."
] | static void sched_print_tasks(void)
{
struct process* temp;
temp = list->root;
if(temp == NULL){
return;
}
printf("\n");
printf("Currently running");
do{
printf("[%s]:with pid %ld and serial_no %d\n\n",temp->name,(long)temp->pid,temp->id);
}while((temp = temp->next) != NULL);
} | [
"static",
"void",
"sched_print_tasks",
"(",
"void",
")",
"{",
"struct",
"process",
"*",
"temp",
";",
"temp",
"=",
"list",
"->",
"root",
";",
"if",
"(",
"temp",
"==",
"NULL",
")",
"{",
"return",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\"",
")",
";",
"do",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"temp",
"->",
"name",
",",
"(",
"long",
")",
"temp",
"->",
"pid",
",",
"temp",
"->",
"id",
")",
";",
"}",
"while",
"(",
"(",
"temp",
"=",
"temp",
"->",
"next",
")",
"!=",
"NULL",
")",
";",
"}"
] | if 0 remove head
Print a list of all tasks currently being scheduled. | [
"if",
"0",
"remove",
"head",
"Print",
"a",
"list",
"of",
"all",
"tasks",
"currently",
"being",
"scheduled",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
732772e8942de1e03ac2dff3f5d83257c1f878b0 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell.c | [
"MIT"
] | C | signals_disable | void | static void
signals_disable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
perror("signals_disable: sigprocmask");
exit(1);
}
} | /* Disable delivery of SIGALRM and SIGCHLD. */ | Disable delivery of SIGALRM and SIGCHLD. | [
"Disable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | static void
signals_disable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
perror("signals_disable: sigprocmask");
exit(1);
}
} | [
"static",
"void",
"signals_disable",
"(",
"void",
")",
"{",
"sigset_t",
"sigset",
";",
"sigemptyset",
"(",
"&",
"sigset",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGALRM",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGCHLD",
")",
";",
"if",
"(",
"sigprocmask",
"(",
"SIG_BLOCK",
",",
"&",
"sigset",
",",
"NULL",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | Disable delivery of SIGALRM and SIGCHLD. | [
"Disable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
732772e8942de1e03ac2dff3f5d83257c1f878b0 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell.c | [
"MIT"
] | C | signals_enable | void | static void
signals_enable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
perror("signals_enable: sigprocmask");
exit(1);
}
} | /* Enable delivery of SIGALRM and SIGCHLD. */ | Enable delivery of SIGALRM and SIGCHLD. | [
"Enable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | static void
signals_enable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
perror("signals_enable: sigprocmask");
exit(1);
}
} | [
"static",
"void",
"signals_enable",
"(",
"void",
")",
"{",
"sigset_t",
"sigset",
";",
"sigemptyset",
"(",
"&",
"sigset",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGALRM",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGCHLD",
")",
";",
"if",
"(",
"sigprocmask",
"(",
"SIG_UNBLOCK",
",",
"&",
"sigset",
",",
"NULL",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | Enable delivery of SIGALRM and SIGCHLD. | [
"Enable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
732772e8942de1e03ac2dff3f5d83257c1f878b0 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell.c | [
"MIT"
] | C | sched_create_shell | void | static void sched_create_shell(char *executable, int *request_fd, int *return_fd)
{
pid_t p;
int pfds_rq[2], pfds_ret[2];
if (pipe(pfds_rq) < 0 || pipe(pfds_ret) < 0) {
perror("pipe");
exit(1);
}
p = fork();
if (p < 0) {
perror("scheduler: fork");
exit(1);
}
if (p == 0) {
/* Child */
close(pfds_rq[0]);
close(pfds_ret[1]);
do_shell(executable, pfds_rq[1], pfds_ret[0]);
assert(0);
}
/* Parent */
close(pfds_rq[1]);
close(pfds_ret[0]);
*request_fd = pfds_rq[0];
*return_fd = pfds_ret[1];
struct process* temp = Create_process(p,current_id);
temp->name = strdup("Shell");
Add_process(list,temp);
current_id++;
} | /* Create a new shell task.
*
* The shell gets special treatment:
* two pipes are created for communication and passed
* as command-line arguments to the executable.
*/ | Create a new shell task.
The shell gets special treatment:
two pipes are created for communication and passed
as command-line arguments to the executable. | [
"Create",
"a",
"new",
"shell",
"task",
".",
"The",
"shell",
"gets",
"special",
"treatment",
":",
"two",
"pipes",
"are",
"created",
"for",
"communication",
"and",
"passed",
"as",
"command",
"-",
"line",
"arguments",
"to",
"the",
"executable",
"."
] | static void sched_create_shell(char *executable, int *request_fd, int *return_fd)
{
pid_t p;
int pfds_rq[2], pfds_ret[2];
if (pipe(pfds_rq) < 0 || pipe(pfds_ret) < 0) {
perror("pipe");
exit(1);
}
p = fork();
if (p < 0) {
perror("scheduler: fork");
exit(1);
}
if (p == 0) {
close(pfds_rq[0]);
close(pfds_ret[1]);
do_shell(executable, pfds_rq[1], pfds_ret[0]);
assert(0);
}
close(pfds_rq[1]);
close(pfds_ret[0]);
*request_fd = pfds_rq[0];
*return_fd = pfds_ret[1];
struct process* temp = Create_process(p,current_id);
temp->name = strdup("Shell");
Add_process(list,temp);
current_id++;
} | [
"static",
"void",
"sched_create_shell",
"(",
"char",
"*",
"executable",
",",
"int",
"*",
"request_fd",
",",
"int",
"*",
"return_fd",
")",
"{",
"pid_t",
"p",
";",
"int",
"pfds_rq",
"[",
"2",
"]",
",",
"pfds_ret",
"[",
"2",
"]",
";",
"if",
"(",
"pipe",
"(",
"pfds_rq",
")",
"<",
"0",
"||",
"pipe",
"(",
"pfds_ret",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"p",
"=",
"fork",
"(",
")",
";",
"if",
"(",
"p",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"if",
"(",
"p",
"==",
"0",
")",
"{",
"close",
"(",
"pfds_rq",
"[",
"0",
"]",
")",
";",
"close",
"(",
"pfds_ret",
"[",
"1",
"]",
")",
";",
"do_shell",
"(",
"executable",
",",
"pfds_rq",
"[",
"1",
"]",
",",
"pfds_ret",
"[",
"0",
"]",
")",
";",
"assert",
"(",
"0",
")",
";",
"}",
"close",
"(",
"pfds_rq",
"[",
"1",
"]",
")",
";",
"close",
"(",
"pfds_ret",
"[",
"0",
"]",
")",
";",
"*",
"request_fd",
"=",
"pfds_rq",
"[",
"0",
"]",
";",
"*",
"return_fd",
"=",
"pfds_ret",
"[",
"1",
"]",
";",
"struct",
"process",
"*",
"temp",
"=",
"Create_process",
"(",
"p",
",",
"current_id",
")",
";",
"temp",
"->",
"name",
"=",
"strdup",
"(",
"\"",
"\"",
")",
";",
"Add_process",
"(",
"list",
",",
"temp",
")",
";",
"current_id",
"++",
";",
"}"
] | Create a new shell task. | [
"Create",
"a",
"new",
"shell",
"task",
"."
] | [
"/* Child */",
"/* Parent */"
] | [
{
"param": "executable",
"type": "char"
},
{
"param": "request_fd",
"type": "int"
},
{
"param": "return_fd",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "executable",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "request_fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "return_fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ea4bccada281218537d2ff1bd0007a720bc891e6 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab3/oslabb30-lab3/mandel.c | [
"MIT"
] | C | compute_mandel_line | void | void compute_mandel_line(int line, int color_val[])
{
/*
* * x and y traverse the complex plane.
* */
double x, y;
int n;
int val;
/* Find out the y value corresponding to this line */
y = ymax - ystep * line;
/* and iterate for all points on this line */
for (x = xmin, n = 0; n < x_chars; x+= xstep, n++) {
/* Compute the point's color value */
val = mandel_iterations_at_point(x, y, MANDEL_MAX_ITERATION);
if (val > 255)
val = 255;
/* And store it in the color_val[] array */
// printf("Color value about to be inserted about is: %d\n", val);
val = xterm_color(val);
color_val[n] = val;
}
} | /*
* * This function computes a line of output
* * as an array of x_char color values.
* */ | This function computes a line of output
as an array of x_char color values. | [
"This",
"function",
"computes",
"a",
"line",
"of",
"output",
"as",
"an",
"array",
"of",
"x_char",
"color",
"values",
"."
] | void compute_mandel_line(int line, int color_val[])
{
double x, y;
int n;
int val;
y = ymax - ystep * line;
for (x = xmin, n = 0; n < x_chars; x+= xstep, n++) {
val = mandel_iterations_at_point(x, y, MANDEL_MAX_ITERATION);
if (val > 255)
val = 255;
val = xterm_color(val);
color_val[n] = val;
}
} | [
"void",
"compute_mandel_line",
"(",
"int",
"line",
",",
"int",
"color_val",
"[",
"]",
")",
"{",
"double",
"x",
",",
"y",
";",
"int",
"n",
";",
"int",
"val",
";",
"y",
"=",
"ymax",
"-",
"ystep",
"*",
"line",
";",
"for",
"(",
"x",
"=",
"xmin",
",",
"n",
"=",
"0",
";",
"n",
"<",
"x_chars",
";",
"x",
"+=",
"xstep",
",",
"n",
"++",
")",
"{",
"val",
"=",
"mandel_iterations_at_point",
"(",
"x",
",",
"y",
",",
"MANDEL_MAX_ITERATION",
")",
";",
"if",
"(",
"val",
">",
"255",
")",
"val",
"=",
"255",
";",
"val",
"=",
"xterm_color",
"(",
"val",
")",
";",
"color_val",
"[",
"n",
"]",
"=",
"val",
";",
"}",
"}"
] | * This function computes a line of output
* as an array of x_char color values. | [
"*",
"This",
"function",
"computes",
"a",
"line",
"of",
"output",
"*",
"as",
"an",
"array",
"of",
"x_char",
"color",
"values",
"."
] | [
"/*\n\t\t * \t * x and y traverse the complex plane.\n\t\t * \t \t */",
"/* Find out the y value corresponding to this line */",
"/* and iterate for all points on this line */",
"/* Compute the point's color value */",
"/* And store it in the color_val[] array */",
"//\t\tprintf(\"Color value about to be inserted about is: %d\\n\", val);"
] | [
{
"param": "line",
"type": "int"
},
{
"param": "color_val",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "line",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "color_val",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ea4bccada281218537d2ff1bd0007a720bc891e6 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab3/oslabb30-lab3/mandel.c | [
"MIT"
] | C | output_mandel_line | void | void output_mandel_line(int fd, int color_val[])
{
int i;
char point ='@';
char newline='\n';
for (i = 0; i < x_chars; i++) {
/* Set the current color, then output the point */
set_xterm_color(fd, color_val[i]);
if (write(fd, &point, 1) != 1) {
perror("compute_and_output_mandel_line: write point");
exit(1);
}
reset_xterm_color(1);
}
/* Now that the line is done, output a newline character */
if (write(fd, &newline, 1) != 1) {
perror("compute_and_output_mandel_line: write newline");
exit(1);
}
} | /*
* This function outputs an array of x_char color values
* to a 256-color xterm.
*/ | This function outputs an array of x_char color values
to a 256-color xterm. | [
"This",
"function",
"outputs",
"an",
"array",
"of",
"x_char",
"color",
"values",
"to",
"a",
"256",
"-",
"color",
"xterm",
"."
] | void output_mandel_line(int fd, int color_val[])
{
int i;
char point ='@';
char newline='\n';
for (i = 0; i < x_chars; i++) {
set_xterm_color(fd, color_val[i]);
if (write(fd, &point, 1) != 1) {
perror("compute_and_output_mandel_line: write point");
exit(1);
}
reset_xterm_color(1);
}
if (write(fd, &newline, 1) != 1) {
perror("compute_and_output_mandel_line: write newline");
exit(1);
}
} | [
"void",
"output_mandel_line",
"(",
"int",
"fd",
",",
"int",
"color_val",
"[",
"]",
")",
"{",
"int",
"i",
";",
"char",
"point",
"=",
"'",
"'",
";",
"char",
"newline",
"=",
"'",
"\\n",
"'",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"x_chars",
";",
"i",
"++",
")",
"{",
"set_xterm_color",
"(",
"fd",
",",
"color_val",
"[",
"i",
"]",
")",
";",
"if",
"(",
"write",
"(",
"fd",
",",
"&",
"point",
",",
"1",
")",
"!=",
"1",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"reset_xterm_color",
"(",
"1",
")",
";",
"}",
"if",
"(",
"write",
"(",
"fd",
",",
"&",
"newline",
",",
"1",
")",
"!=",
"1",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | This function outputs an array of x_char color values
to a 256-color xterm. | [
"This",
"function",
"outputs",
"an",
"array",
"of",
"x_char",
"color",
"values",
"to",
"a",
"256",
"-",
"color",
"xterm",
"."
] | [
"/* Set the current color, then output the point */",
"/* Now that the line is done, output a newline character */"
] | [
{
"param": "fd",
"type": "int"
},
{
"param": "color_val",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "color_val",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
207abcb79d896254e5b68468487ff5928b5c9911 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler.c | [
"MIT"
] | C | install_signal_handlers | void | static void install_signal_handlers(void)
{
sigset_t sigset;
struct sigaction sa;
sa.sa_handler = sigchld_handler;
sa.sa_flags = SA_RESTART;
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGALRM);
sa.sa_mask = sigset;
if (sigaction(SIGCHLD, &sa, NULL) < 0) {
perror("Sigchld");
exit(1);
}
sa.sa_handler = sigalrm_handler;
if (sigaction(SIGALRM, &sa, NULL) < 0) {
perror("Sigalrm");
exit(1);
}
/*
* Ignore SIGPIPE, so that write()s to pipes
* with no reader do not result in us being killed,
* and write() returns EPIPE instead.
*/
if (signal(SIGPIPE, SIG_IGN) < 0) {
perror("Sigpipe");
exit(1);
}
} | /* Install two signal handlers.
* One for SIGCHLD, one for SIGALRM.
* Make sure both signals are masked when one of them is running.
*/ | Install two signal handlers.
One for SIGCHLD, one for SIGALRM.
Make sure both signals are masked when one of them is running. | [
"Install",
"two",
"signal",
"handlers",
".",
"One",
"for",
"SIGCHLD",
"one",
"for",
"SIGALRM",
".",
"Make",
"sure",
"both",
"signals",
"are",
"masked",
"when",
"one",
"of",
"them",
"is",
"running",
"."
] | static void install_signal_handlers(void)
{
sigset_t sigset;
struct sigaction sa;
sa.sa_handler = sigchld_handler;
sa.sa_flags = SA_RESTART;
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGALRM);
sa.sa_mask = sigset;
if (sigaction(SIGCHLD, &sa, NULL) < 0) {
perror("Sigchld");
exit(1);
}
sa.sa_handler = sigalrm_handler;
if (sigaction(SIGALRM, &sa, NULL) < 0) {
perror("Sigalrm");
exit(1);
}
if (signal(SIGPIPE, SIG_IGN) < 0) {
perror("Sigpipe");
exit(1);
}
} | [
"static",
"void",
"install_signal_handlers",
"(",
"void",
")",
"{",
"sigset_t",
"sigset",
";",
"struct",
"sigaction",
"sa",
";",
"sa",
".",
"sa_handler",
"=",
"sigchld_handler",
";",
"sa",
".",
"sa_flags",
"=",
"SA_RESTART",
";",
"sigemptyset",
"(",
"&",
"sigset",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGCHLD",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGALRM",
")",
";",
"sa",
".",
"sa_mask",
"=",
"sigset",
";",
"if",
"(",
"sigaction",
"(",
"SIGCHLD",
",",
"&",
"sa",
",",
"NULL",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"sa",
".",
"sa_handler",
"=",
"sigalrm_handler",
";",
"if",
"(",
"sigaction",
"(",
"SIGALRM",
",",
"&",
"sa",
",",
"NULL",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"if",
"(",
"signal",
"(",
"SIGPIPE",
",",
"SIG_IGN",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | Install two signal handlers. | [
"Install",
"two",
"signal",
"handlers",
"."
] | [
"/*\n\t\t * Ignore SIGPIPE, so that write()s to pipes\n\t\t * with no reader do not result in us being killed,\n\t\t * and write() returns EPIPE instead.\n\t\t */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
10e827df73c4969b3f45008019f16eb2008d22b3 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell2.c | [
"MIT"
] | C | process_request | int | static int process_request(struct request_struct *rq)
{
switch (rq->request_no) {
case REQ_PRINT_TASKS:
sched_print_tasks();
return 0;
case REQ_KILL_TASK:
return sched_kill_task_by_id(rq->task_arg);
case REQ_EXEC_TASK:
sched_create_task(rq->exec_task_arg);
return 0;
case REQ_HIGH_TASK:
return sched_high_task_by_id(rq->task_arg);
case REQ_LOW_TASK:
return sched_low_task_by_id(rq->task_arg);
default:
return -ENOSYS;
}
} | /* Process requests by the shell. */ | Process requests by the shell. | [
"Process",
"requests",
"by",
"the",
"shell",
"."
] | static int process_request(struct request_struct *rq)
{
switch (rq->request_no) {
case REQ_PRINT_TASKS:
sched_print_tasks();
return 0;
case REQ_KILL_TASK:
return sched_kill_task_by_id(rq->task_arg);
case REQ_EXEC_TASK:
sched_create_task(rq->exec_task_arg);
return 0;
case REQ_HIGH_TASK:
return sched_high_task_by_id(rq->task_arg);
case REQ_LOW_TASK:
return sched_low_task_by_id(rq->task_arg);
default:
return -ENOSYS;
}
} | [
"static",
"int",
"process_request",
"(",
"struct",
"request_struct",
"*",
"rq",
")",
"{",
"switch",
"(",
"rq",
"->",
"request_no",
")",
"{",
"case",
"REQ_PRINT_TASKS",
":",
"sched_print_tasks",
"(",
")",
";",
"return",
"0",
";",
"case",
"REQ_KILL_TASK",
":",
"return",
"sched_kill_task_by_id",
"(",
"rq",
"->",
"task_arg",
")",
";",
"case",
"REQ_EXEC_TASK",
":",
"sched_create_task",
"(",
"rq",
"->",
"exec_task_arg",
")",
";",
"return",
"0",
";",
"case",
"REQ_HIGH_TASK",
":",
"return",
"sched_high_task_by_id",
"(",
"rq",
"->",
"task_arg",
")",
";",
"case",
"REQ_LOW_TASK",
":",
"return",
"sched_low_task_by_id",
"(",
"rq",
"->",
"task_arg",
")",
";",
"default",
":",
"return",
"-",
"ENOSYS",
";",
"}",
"}"
] | Process requests by the shell. | [
"Process",
"requests",
"by",
"the",
"shell",
"."
] | [] | [
{
"param": "rq",
"type": "struct request_struct"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rq",
"type": "struct request_struct",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
10e827df73c4969b3f45008019f16eb2008d22b3 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell2.c | [
"MIT"
] | C | signals_disable | void | static void signals_disable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
perror("signals_disable: sigprocmask");
exit(1);
}
} | /* Disable delivery of SIGALRM and SIGCHLD. */ | Disable delivery of SIGALRM and SIGCHLD. | [
"Disable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | static void signals_disable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
perror("signals_disable: sigprocmask");
exit(1);
}
} | [
"static",
"void",
"signals_disable",
"(",
"void",
")",
"{",
"sigset_t",
"sigset",
";",
"sigemptyset",
"(",
"&",
"sigset",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGALRM",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGCHLD",
")",
";",
"if",
"(",
"sigprocmask",
"(",
"SIG_BLOCK",
",",
"&",
"sigset",
",",
"NULL",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | Disable delivery of SIGALRM and SIGCHLD. | [
"Disable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
10e827df73c4969b3f45008019f16eb2008d22b3 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell2.c | [
"MIT"
] | C | signals_enable | void | static void signals_enable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
perror("signals_enable: sigprocmask");
exit(1);
}
} | /* Enable delivery of SIGALRM and SIGCHLD. */ | Enable delivery of SIGALRM and SIGCHLD. | [
"Enable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | static void signals_enable(void)
{
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigaddset(&sigset, SIGCHLD);
if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
perror("signals_enable: sigprocmask");
exit(1);
}
} | [
"static",
"void",
"signals_enable",
"(",
"void",
")",
"{",
"sigset_t",
"sigset",
";",
"sigemptyset",
"(",
"&",
"sigset",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGALRM",
")",
";",
"sigaddset",
"(",
"&",
"sigset",
",",
"SIGCHLD",
")",
";",
"if",
"(",
"sigprocmask",
"(",
"SIG_UNBLOCK",
",",
"&",
"sigset",
",",
"NULL",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | Enable delivery of SIGALRM and SIGCHLD. | [
"Enable",
"delivery",
"of",
"SIGALRM",
"and",
"SIGCHLD",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
10e827df73c4969b3f45008019f16eb2008d22b3 | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/scheduler-shell2.c | [
"MIT"
] | C | sched_create_shell | void | static void sched_create_shell(char *executable, int *request_fd, int *return_fd)
{
pid_t p;
int pfds_rq[2], pfds_ret[2];
if (pipe(pfds_rq) < 0 || pipe(pfds_ret) < 0) {
perror("PIPE");
exit(1);
}
p = fork();
if (p < 0) {
perror("FORK");
exit(1);
}
if (p == 0) {
/* Child */
close(pfds_rq[0]);
close(pfds_ret[1]);
do_shell(executable, pfds_rq[1], pfds_ret[0]);
assert(0);
}
/* Parent */
close(pfds_rq[1]);
close(pfds_ret[0]);
*request_fd = pfds_rq[0];
*return_fd = pfds_ret[1];
struct process* temp = Create_process(p,current_id);
temp->name = strdup("Shell");
Add_process(list,temp);
current_id++;
} | /* Create a new shell task.
*
* The shell gets special treatment:
* two pipes are created for communication and passed
* as command-line arguments to the executable.
*/ | Create a new shell task.
The shell gets special treatment:
two pipes are created for communication and passed
as command-line arguments to the executable. | [
"Create",
"a",
"new",
"shell",
"task",
".",
"The",
"shell",
"gets",
"special",
"treatment",
":",
"two",
"pipes",
"are",
"created",
"for",
"communication",
"and",
"passed",
"as",
"command",
"-",
"line",
"arguments",
"to",
"the",
"executable",
"."
] | static void sched_create_shell(char *executable, int *request_fd, int *return_fd)
{
pid_t p;
int pfds_rq[2], pfds_ret[2];
if (pipe(pfds_rq) < 0 || pipe(pfds_ret) < 0) {
perror("PIPE");
exit(1);
}
p = fork();
if (p < 0) {
perror("FORK");
exit(1);
}
if (p == 0) {
close(pfds_rq[0]);
close(pfds_ret[1]);
do_shell(executable, pfds_rq[1], pfds_ret[0]);
assert(0);
}
close(pfds_rq[1]);
close(pfds_ret[0]);
*request_fd = pfds_rq[0];
*return_fd = pfds_ret[1];
struct process* temp = Create_process(p,current_id);
temp->name = strdup("Shell");
Add_process(list,temp);
current_id++;
} | [
"static",
"void",
"sched_create_shell",
"(",
"char",
"*",
"executable",
",",
"int",
"*",
"request_fd",
",",
"int",
"*",
"return_fd",
")",
"{",
"pid_t",
"p",
";",
"int",
"pfds_rq",
"[",
"2",
"]",
",",
"pfds_ret",
"[",
"2",
"]",
";",
"if",
"(",
"pipe",
"(",
"pfds_rq",
")",
"<",
"0",
"||",
"pipe",
"(",
"pfds_ret",
")",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"p",
"=",
"fork",
"(",
")",
";",
"if",
"(",
"p",
"<",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"if",
"(",
"p",
"==",
"0",
")",
"{",
"close",
"(",
"pfds_rq",
"[",
"0",
"]",
")",
";",
"close",
"(",
"pfds_ret",
"[",
"1",
"]",
")",
";",
"do_shell",
"(",
"executable",
",",
"pfds_rq",
"[",
"1",
"]",
",",
"pfds_ret",
"[",
"0",
"]",
")",
";",
"assert",
"(",
"0",
")",
";",
"}",
"close",
"(",
"pfds_rq",
"[",
"1",
"]",
")",
";",
"close",
"(",
"pfds_ret",
"[",
"0",
"]",
")",
";",
"*",
"request_fd",
"=",
"pfds_rq",
"[",
"0",
"]",
";",
"*",
"return_fd",
"=",
"pfds_ret",
"[",
"1",
"]",
";",
"struct",
"process",
"*",
"temp",
"=",
"Create_process",
"(",
"p",
",",
"current_id",
")",
";",
"temp",
"->",
"name",
"=",
"strdup",
"(",
"\"",
"\"",
")",
";",
"Add_process",
"(",
"list",
",",
"temp",
")",
";",
"current_id",
"++",
";",
"}"
] | Create a new shell task. | [
"Create",
"a",
"new",
"shell",
"task",
"."
] | [
"/* Child */",
"/* Parent */"
] | [
{
"param": "executable",
"type": "char"
},
{
"param": "request_fd",
"type": "int"
},
{
"param": "return_fd",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "executable",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "request_fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "return_fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
461eb69e6ddd0f138534de4fde4425402e0fb30f | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/list.c | [
"MIT"
] | C | Add_process | void | void Add_process (struct list *List,struct process *proc) {
struct process *temp = List->root;
struct process *temp2 = temp;
if(temp == NULL){
List->root = proc;
List->counter = List->counter + 1;
}
else{
while (temp != NULL) {
//printf("trww kark atermono\n");
temp2 = temp; //temp2 will find the last process
temp = temp->next; //temp will always turn out NULL
}
proc->next = NULL;
temp2->next = proc;
List->counter = List->counter + 1;
}
} | //add a process at the end of the list | add a process at the end of the list | [
"add",
"a",
"process",
"at",
"the",
"end",
"of",
"the",
"list"
] | void Add_process (struct list *List,struct process *proc) {
struct process *temp = List->root;
struct process *temp2 = temp;
if(temp == NULL){
List->root = proc;
List->counter = List->counter + 1;
}
else{
while (temp != NULL) {
temp2 = temp;
temp = temp->next;
}
proc->next = NULL;
temp2->next = proc;
List->counter = List->counter + 1;
}
} | [
"void",
"Add_process",
"(",
"struct",
"list",
"*",
"List",
",",
"struct",
"process",
"*",
"proc",
")",
"{",
"struct",
"process",
"*",
"temp",
"=",
"List",
"->",
"root",
";",
"struct",
"process",
"*",
"temp2",
"=",
"temp",
";",
"if",
"(",
"temp",
"==",
"NULL",
")",
"{",
"List",
"->",
"root",
"=",
"proc",
";",
"List",
"->",
"counter",
"=",
"List",
"->",
"counter",
"+",
"1",
";",
"}",
"else",
"{",
"while",
"(",
"temp",
"!=",
"NULL",
")",
"{",
"temp2",
"=",
"temp",
";",
"temp",
"=",
"temp",
"->",
"next",
";",
"}",
"proc",
"->",
"next",
"=",
"NULL",
";",
"temp2",
"->",
"next",
"=",
"proc",
";",
"List",
"->",
"counter",
"=",
"List",
"->",
"counter",
"+",
"1",
";",
"}",
"}"
] | add a process at the end of the list | [
"add",
"a",
"process",
"at",
"the",
"end",
"of",
"the",
"list"
] | [
"//printf(\"trww kark atermono\\n\");",
"//temp2 will find the last process",
"//temp will always turn out NULL"
] | [
{
"param": "List",
"type": "struct list"
},
{
"param": "proc",
"type": "struct process"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "List",
"type": "struct list",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "proc",
"type": "struct process",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
461eb69e6ddd0f138534de4fde4425402e0fb30f | panoszvg/NTUA-Assignments | Operating Systems/oslabb30-03117034-03117804/lab4/oslabb30-lab4/list.c | [
"MIT"
] | C | Cycle_process | null | struct process* Cycle_process (struct list *List) {
struct process *temp = List->root;
if (temp == NULL) return NULL;
if (List->counter == 1){
List->root = NULL;
List->counter--;
return temp;
}
struct process *temp2 = temp->next;
List->root = temp2;
List->counter = List->counter - 1;
return temp;
} | //remove a process from the beginning of the list | remove a process from the beginning of the list | [
"remove",
"a",
"process",
"from",
"the",
"beginning",
"of",
"the",
"list"
] | struct process* Cycle_process (struct list *List) {
struct process *temp = List->root;
if (temp == NULL) return NULL;
if (List->counter == 1){
List->root = NULL;
List->counter--;
return temp;
}
struct process *temp2 = temp->next;
List->root = temp2;
List->counter = List->counter - 1;
return temp;
} | [
"struct",
"process",
"*",
"Cycle_process",
"(",
"struct",
"list",
"*",
"List",
")",
"{",
"struct",
"process",
"*",
"temp",
"=",
"List",
"->",
"root",
";",
"if",
"(",
"temp",
"==",
"NULL",
")",
"return",
"NULL",
";",
"if",
"(",
"List",
"->",
"counter",
"==",
"1",
")",
"{",
"List",
"->",
"root",
"=",
"NULL",
";",
"List",
"->",
"counter",
"--",
";",
"return",
"temp",
";",
"}",
"struct",
"process",
"*",
"temp2",
"=",
"temp",
"->",
"next",
";",
"List",
"->",
"root",
"=",
"temp2",
";",
"List",
"->",
"counter",
"=",
"List",
"->",
"counter",
"-",
"1",
";",
"return",
"temp",
";",
"}"
] | remove a process from the beginning of the list | [
"remove",
"a",
"process",
"from",
"the",
"beginning",
"of",
"the",
"list"
] | [] | [
{
"param": "List",
"type": "struct list"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "List",
"type": "struct list",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | VM_Test | void | void VM_Test(int page, int page_frame, int window, int *string, int string_length, FILE *outfile){
/*
* for fixed allocation
* int *mark: to save information for replacement
* int *mem: to save page no. which are in the page frame
*
* for variable allocation
* int *page_mark: to save loaded time of page
*
* all initialized as -1
*/
int *mark = (int *)malloc(sizeof(int) * page_frame);
int *mem = (int *)malloc(sizeof(int) * page_frame);
int *page_mark = (int *)malloc(sizeof(int) * page);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
mem_init(page_mark, page);
// test each algorithm and initialize the array
MIN_test(mark, mem, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
FIFO_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
LRU_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
LFU_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
Clock_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
WS_test(page, window, page_mark, string, string_length, outfile);
free(mark);
free(mem);
free(page_mark);
} | /**
* create int pointer array using dynamic memory allocation
* call test functions for each algorithm
*
* input:
* int page: the no. of page
* int page_frame: the no. of page frame allocated to the process
* int window: window size (for working set)
* int *string: int array that contains page reference string
* int string_length: length of *string
*
* output:
* print residence set and no. of fault for each algorithm
*/ | create int pointer array using dynamic memory allocation
call test functions for each algorithm
int page: the no. of page
int page_frame: the no. of page frame allocated to the process
int window: window size (for working set)
int *string: int array that contains page reference string
int string_length: length of *string
print residence set and no. of fault for each algorithm | [
"create",
"int",
"pointer",
"array",
"using",
"dynamic",
"memory",
"allocation",
"call",
"test",
"functions",
"for",
"each",
"algorithm",
"int",
"page",
":",
"the",
"no",
".",
"of",
"page",
"int",
"page_frame",
":",
"the",
"no",
".",
"of",
"page",
"frame",
"allocated",
"to",
"the",
"process",
"int",
"window",
":",
"window",
"size",
"(",
"for",
"working",
"set",
")",
"int",
"*",
"string",
":",
"int",
"array",
"that",
"contains",
"page",
"reference",
"string",
"int",
"string_length",
":",
"length",
"of",
"*",
"string",
"print",
"residence",
"set",
"and",
"no",
".",
"of",
"fault",
"for",
"each",
"algorithm"
] | void VM_Test(int page, int page_frame, int window, int *string, int string_length, FILE *outfile){
int *mark = (int *)malloc(sizeof(int) * page_frame);
int *mem = (int *)malloc(sizeof(int) * page_frame);
int *page_mark = (int *)malloc(sizeof(int) * page);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
mem_init(page_mark, page);
MIN_test(mark, mem, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
FIFO_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
LRU_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
LFU_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
Clock_test(mem, mark, page_frame, string, string_length, outfile);
mem_init(mark, page_frame);
mem_init(mem, page_frame);
WS_test(page, window, page_mark, string, string_length, outfile);
free(mark);
free(mem);
free(page_mark);
} | [
"void",
"VM_Test",
"(",
"int",
"page",
",",
"int",
"page_frame",
",",
"int",
"window",
",",
"int",
"*",
"string",
",",
"int",
"string_length",
",",
"FILE",
"*",
"outfile",
")",
"{",
"int",
"*",
"mark",
"=",
"(",
"int",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"int",
")",
"*",
"page_frame",
")",
";",
"int",
"*",
"mem",
"=",
"(",
"int",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"int",
")",
"*",
"page_frame",
")",
";",
"int",
"*",
"page_mark",
"=",
"(",
"int",
"*",
")",
"malloc",
"(",
"sizeof",
"(",
"int",
")",
"*",
"page",
")",
";",
"mem_init",
"(",
"mark",
",",
"page_frame",
")",
";",
"mem_init",
"(",
"mem",
",",
"page_frame",
")",
";",
"mem_init",
"(",
"page_mark",
",",
"page",
")",
";",
"MIN_test",
"(",
"mark",
",",
"mem",
",",
"page_frame",
",",
"string",
",",
"string_length",
",",
"outfile",
")",
";",
"mem_init",
"(",
"mark",
",",
"page_frame",
")",
";",
"mem_init",
"(",
"mem",
",",
"page_frame",
")",
";",
"FIFO_test",
"(",
"mem",
",",
"mark",
",",
"page_frame",
",",
"string",
",",
"string_length",
",",
"outfile",
")",
";",
"mem_init",
"(",
"mark",
",",
"page_frame",
")",
";",
"mem_init",
"(",
"mem",
",",
"page_frame",
")",
";",
"LRU_test",
"(",
"mem",
",",
"mark",
",",
"page_frame",
",",
"string",
",",
"string_length",
",",
"outfile",
")",
";",
"mem_init",
"(",
"mark",
",",
"page_frame",
")",
";",
"mem_init",
"(",
"mem",
",",
"page_frame",
")",
";",
"LFU_test",
"(",
"mem",
",",
"mark",
",",
"page_frame",
",",
"string",
",",
"string_length",
",",
"outfile",
")",
";",
"mem_init",
"(",
"mark",
",",
"page_frame",
")",
";",
"mem_init",
"(",
"mem",
",",
"page_frame",
")",
";",
"Clock_test",
"(",
"mem",
",",
"mark",
",",
"page_frame",
",",
"string",
",",
"string_length",
",",
"outfile",
")",
";",
"mem_init",
"(",
"mark",
",",
"page_frame",
")",
";",
"mem_init",
"(",
"mem",
",",
"page_frame",
")",
";",
"WS_test",
"(",
"page",
",",
"window",
",",
"page_mark",
",",
"string",
",",
"string_length",
",",
"outfile",
")",
";",
"free",
"(",
"mark",
")",
";",
"free",
"(",
"mem",
")",
";",
"free",
"(",
"page_mark",
")",
";",
"}"
] | create int pointer array using dynamic memory allocation
call test functions for each algorithm | [
"create",
"int",
"pointer",
"array",
"using",
"dynamic",
"memory",
"allocation",
"call",
"test",
"functions",
"for",
"each",
"algorithm"
] | [
"/*\r\n * for fixed allocation\r\n * int *mark: to save information for replacement\r\n * int *mem: to save page no. which are in the page frame\r\n *\r\n * for variable allocation\r\n * int *page_mark: to save loaded time of page\r\n *\r\n * all initialized as -1\r\n */",
"// test each algorithm and initialize the array\r"
] | [
{
"param": "page",
"type": "int"
},
{
"param": "page_frame",
"type": "int"
},
{
"param": "window",
"type": "int"
},
{
"param": "string",
"type": "int"
},
{
"param": "string_length",
"type": "int"
},
{
"param": "outfile",
"type": "FILE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "page",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "page_frame",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "window",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "string",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "string_length",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "outfile",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | mem_init | void | void mem_init(int *mem, int page_frame){
if(mem == NULL){
printf("[Error] Dynamic memory allocation failed\n");
exit(-3);
}
for(int i = 0; i < page_frame; i++){
mem[i] = -1;
}
} | /**
* initialize pointer array
* check if there is error in dynamic memory allocation
*
* input:
* int page_frame: the no. of page frame allocated to the process
*
* in/output:
* int *mem: pointer array that is initialized as -1.
*/ | initialize pointer array
check if there is error in dynamic memory allocation
int page_frame: the no. of page frame allocated to the process
in/output:
int *mem: pointer array that is initialized as -1. | [
"initialize",
"pointer",
"array",
"check",
"if",
"there",
"is",
"error",
"in",
"dynamic",
"memory",
"allocation",
"int",
"page_frame",
":",
"the",
"no",
".",
"of",
"page",
"frame",
"allocated",
"to",
"the",
"process",
"in",
"/",
"output",
":",
"int",
"*",
"mem",
":",
"pointer",
"array",
"that",
"is",
"initialized",
"as",
"-",
"1",
"."
] | void mem_init(int *mem, int page_frame){
if(mem == NULL){
printf("[Error] Dynamic memory allocation failed\n");
exit(-3);
}
for(int i = 0; i < page_frame; i++){
mem[i] = -1;
}
} | [
"void",
"mem_init",
"(",
"int",
"*",
"mem",
",",
"int",
"page_frame",
")",
"{",
"if",
"(",
"mem",
"==",
"NULL",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"exit",
"(",
"-3",
")",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"page_frame",
";",
"i",
"++",
")",
"{",
"mem",
"[",
"i",
"]",
"=",
"-1",
";",
"}",
"}"
] | initialize pointer array
check if there is error in dynamic memory allocation | [
"initialize",
"pointer",
"array",
"check",
"if",
"there",
"is",
"error",
"in",
"dynamic",
"memory",
"allocation"
] | [] | [
{
"param": "mem",
"type": "int"
},
{
"param": "page_frame",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "page_frame",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | MIN_replace | int | int MIN_replace(int *mark, int *mem, int page_frame, int *string, int string_length, int time){
int change = 0;
for(int i = 0; i < page_frame; i++){
for(int j = time; j < string_length; j++){
// if the page is referred again in the future, save forward distance
if(string[j] == mem[i]){
mark[i] = j - time;
change = 1;
break;
}
}
// if the page is not referred again, save string_length(infinity)
// since max forward distance = string_length - 1
if(change != 1){
mark[i] = string_length;
}
change = 0;
}
// find page that has maximum forward distance
int max = mark[0];
int max_no = 0;
for(int i = 0; i < page_frame; i++){
if(max < mark[i]){
max = mark[i];
max_no = i;
}
}
return max_no;
} | /**
* find index to be replaced following MIN algorithm
*
* input:
* int *mem: array to save page no. which are in the page frame
* int page_frame: no. of page frame allocated, size of mem, mark
* int *string: array that contains reference string
* int string_length: size of string
* int time: time of the system, same as index of string + 1
*
* output:
* return int index to be replaced
*
* in/output:
* int *mark: save forward distance of page
*/ | find index to be replaced following MIN algorithm
int *mem: array to save page no. which are in the page frame
int page_frame: no. of page frame allocated, size of mem, mark
int *string: array that contains reference string
int string_length: size of string
int time: time of the system, same as index of string + 1
return int index to be replaced
in/output:
int *mark: save forward distance of page | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"MIN",
"algorithm",
"int",
"*",
"mem",
":",
"array",
"to",
"save",
"page",
"no",
".",
"which",
"are",
"in",
"the",
"page",
"frame",
"int",
"page_frame",
":",
"no",
".",
"of",
"page",
"frame",
"allocated",
"size",
"of",
"mem",
"mark",
"int",
"*",
"string",
":",
"array",
"that",
"contains",
"reference",
"string",
"int",
"string_length",
":",
"size",
"of",
"string",
"int",
"time",
":",
"time",
"of",
"the",
"system",
"same",
"as",
"index",
"of",
"string",
"+",
"1",
"return",
"int",
"index",
"to",
"be",
"replaced",
"in",
"/",
"output",
":",
"int",
"*",
"mark",
":",
"save",
"forward",
"distance",
"of",
"page"
] | int MIN_replace(int *mark, int *mem, int page_frame, int *string, int string_length, int time){
int change = 0;
for(int i = 0; i < page_frame; i++){
for(int j = time; j < string_length; j++){
if(string[j] == mem[i]){
mark[i] = j - time;
change = 1;
break;
}
}
if(change != 1){
mark[i] = string_length;
}
change = 0;
}
int max = mark[0];
int max_no = 0;
for(int i = 0; i < page_frame; i++){
if(max < mark[i]){
max = mark[i];
max_no = i;
}
}
return max_no;
} | [
"int",
"MIN_replace",
"(",
"int",
"*",
"mark",
",",
"int",
"*",
"mem",
",",
"int",
"page_frame",
",",
"int",
"*",
"string",
",",
"int",
"string_length",
",",
"int",
"time",
")",
"{",
"int",
"change",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"page_frame",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"time",
";",
"j",
"<",
"string_length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"string",
"[",
"j",
"]",
"==",
"mem",
"[",
"i",
"]",
")",
"{",
"mark",
"[",
"i",
"]",
"=",
"j",
"-",
"time",
";",
"change",
"=",
"1",
";",
"break",
";",
"}",
"}",
"if",
"(",
"change",
"!=",
"1",
")",
"{",
"mark",
"[",
"i",
"]",
"=",
"string_length",
";",
"}",
"change",
"=",
"0",
";",
"}",
"int",
"max",
"=",
"mark",
"[",
"0",
"]",
";",
"int",
"max_no",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"page_frame",
";",
"i",
"++",
")",
"{",
"if",
"(",
"max",
"<",
"mark",
"[",
"i",
"]",
")",
"{",
"max",
"=",
"mark",
"[",
"i",
"]",
";",
"max_no",
"=",
"i",
";",
"}",
"}",
"return",
"max_no",
";",
"}"
] | find index to be replaced following MIN algorithm | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"MIN",
"algorithm"
] | [
"// if the page is referred again in the future, save forward distance\r",
"// if the page is not referred again, save string_length(infinity)\r",
"// since max forward distance = string_length - 1\r",
"// find page that has maximum forward distance\r"
] | [
{
"param": "mark",
"type": "int"
},
{
"param": "mem",
"type": "int"
},
{
"param": "page_frame",
"type": "int"
},
{
"param": "string",
"type": "int"
},
{
"param": "string_length",
"type": "int"
},
{
"param": "time",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mark",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mem",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "page_frame",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "string",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "string_length",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "time",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | FIFO_replace | int | int FIFO_replace(int *mem, int *mark, int page_frame){
int min = mark[0];
int min_no = 0;
for(int i = 0; i < page_frame; i++){
if(min > mark[i]){
min = mark[i];
min_no = i;
}
}
return min_no;
} | /**
* find index to be replaced following FIFO algorithm
*
* input:
* int *mem: array to save page no. which are in the page frame
* int *mark: array that has arrival time of pages in the memory
* int page_frame: no. of page frame allocated, size of mem, mark
*
* output:
* return int index to be replaced(index that has minimum arrival time)
*/ | find index to be replaced following FIFO algorithm
int *mem: array to save page no. which are in the page frame
int *mark: array that has arrival time of pages in the memory
int page_frame: no. of page frame allocated, size of mem, mark
return int index to be replaced(index that has minimum arrival time) | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"FIFO",
"algorithm",
"int",
"*",
"mem",
":",
"array",
"to",
"save",
"page",
"no",
".",
"which",
"are",
"in",
"the",
"page",
"frame",
"int",
"*",
"mark",
":",
"array",
"that",
"has",
"arrival",
"time",
"of",
"pages",
"in",
"the",
"memory",
"int",
"page_frame",
":",
"no",
".",
"of",
"page",
"frame",
"allocated",
"size",
"of",
"mem",
"mark",
"return",
"int",
"index",
"to",
"be",
"replaced",
"(",
"index",
"that",
"has",
"minimum",
"arrival",
"time",
")"
] | int FIFO_replace(int *mem, int *mark, int page_frame){
int min = mark[0];
int min_no = 0;
for(int i = 0; i < page_frame; i++){
if(min > mark[i]){
min = mark[i];
min_no = i;
}
}
return min_no;
} | [
"int",
"FIFO_replace",
"(",
"int",
"*",
"mem",
",",
"int",
"*",
"mark",
",",
"int",
"page_frame",
")",
"{",
"int",
"min",
"=",
"mark",
"[",
"0",
"]",
";",
"int",
"min_no",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"page_frame",
";",
"i",
"++",
")",
"{",
"if",
"(",
"min",
">",
"mark",
"[",
"i",
"]",
")",
"{",
"min",
"=",
"mark",
"[",
"i",
"]",
";",
"min_no",
"=",
"i",
";",
"}",
"}",
"return",
"min_no",
";",
"}"
] | find index to be replaced following FIFO algorithm | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"FIFO",
"algorithm"
] | [] | [
{
"param": "mem",
"type": "int"
},
{
"param": "mark",
"type": "int"
},
{
"param": "page_frame",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mark",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "page_frame",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | LRU_replace | int | int LRU_replace(int *mem, int *mark, int page_frame){
int min = mark[0];
int min_no = 0;
for(int i = 0; i < page_frame; i++){
if(min > mark[i]){
min = mark[i];
min_no = i;
}
}
return min_no;
} | /**
* find index to be replaced following LRU algorithm
*
* input:
* int *mem: array to save page no. which are in the page frame
* int *mark: array that has arrival time of pages in the memory
* int page_frame: no. of page frame allocated, size of mem, mark
*
* output:
* return int index to be replaced(index that has minimum used time)
*/ | find index to be replaced following LRU algorithm
int *mem: array to save page no. which are in the page frame
int *mark: array that has arrival time of pages in the memory
int page_frame: no. of page frame allocated, size of mem, mark
return int index to be replaced(index that has minimum used time) | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"LRU",
"algorithm",
"int",
"*",
"mem",
":",
"array",
"to",
"save",
"page",
"no",
".",
"which",
"are",
"in",
"the",
"page",
"frame",
"int",
"*",
"mark",
":",
"array",
"that",
"has",
"arrival",
"time",
"of",
"pages",
"in",
"the",
"memory",
"int",
"page_frame",
":",
"no",
".",
"of",
"page",
"frame",
"allocated",
"size",
"of",
"mem",
"mark",
"return",
"int",
"index",
"to",
"be",
"replaced",
"(",
"index",
"that",
"has",
"minimum",
"used",
"time",
")"
] | int LRU_replace(int *mem, int *mark, int page_frame){
int min = mark[0];
int min_no = 0;
for(int i = 0; i < page_frame; i++){
if(min > mark[i]){
min = mark[i];
min_no = i;
}
}
return min_no;
} | [
"int",
"LRU_replace",
"(",
"int",
"*",
"mem",
",",
"int",
"*",
"mark",
",",
"int",
"page_frame",
")",
"{",
"int",
"min",
"=",
"mark",
"[",
"0",
"]",
";",
"int",
"min_no",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"page_frame",
";",
"i",
"++",
")",
"{",
"if",
"(",
"min",
">",
"mark",
"[",
"i",
"]",
")",
"{",
"min",
"=",
"mark",
"[",
"i",
"]",
";",
"min_no",
"=",
"i",
";",
"}",
"}",
"return",
"min_no",
";",
"}"
] | find index to be replaced following LRU algorithm | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"LRU",
"algorithm"
] | [] | [
{
"param": "mem",
"type": "int"
},
{
"param": "mark",
"type": "int"
},
{
"param": "page_frame",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mark",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "page_frame",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | LFU_replace | int | int LFU_replace(int *mem, int *mark, int *tie_break, int page_frame){
int min = mark[0];
int min_no = 0;
for(int i = 0; i < page_frame; i++){
if(min > mark[i]){
min = mark[i];
}
}
int tie_min = tie_break[0];
// if the page has same used count with minimum value, tie_break by LRU
for(int i = 0; i < page_frame; i++){
if(mark[i] == min){
if(tie_min > tie_break[i]){
tie_min = tie_break[i];
min_no = i;
}
}
}
return min_no;
} | /**
* find index to be replaced following LFU algorithm
*
* input:
* int *mem: array to save page no. which are in the page frame
* int *mark: array that has used count of pages in the memory
* int *tie_break: array that has used time of pages in the memory
* int page_frame: no. of page frame allocated, size of mem, mark, tie_break
*
* output:
* return int index to be replaced(index that has minimum used count)
*/ | find index to be replaced following LFU algorithm
int *mem: array to save page no. which are in the page frame
int *mark: array that has used count of pages in the memory
int *tie_break: array that has used time of pages in the memory
int page_frame: no. of page frame allocated, size of mem, mark, tie_break
return int index to be replaced(index that has minimum used count) | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"LFU",
"algorithm",
"int",
"*",
"mem",
":",
"array",
"to",
"save",
"page",
"no",
".",
"which",
"are",
"in",
"the",
"page",
"frame",
"int",
"*",
"mark",
":",
"array",
"that",
"has",
"used",
"count",
"of",
"pages",
"in",
"the",
"memory",
"int",
"*",
"tie_break",
":",
"array",
"that",
"has",
"used",
"time",
"of",
"pages",
"in",
"the",
"memory",
"int",
"page_frame",
":",
"no",
".",
"of",
"page",
"frame",
"allocated",
"size",
"of",
"mem",
"mark",
"tie_break",
"return",
"int",
"index",
"to",
"be",
"replaced",
"(",
"index",
"that",
"has",
"minimum",
"used",
"count",
")"
] | int LFU_replace(int *mem, int *mark, int *tie_break, int page_frame){
int min = mark[0];
int min_no = 0;
for(int i = 0; i < page_frame; i++){
if(min > mark[i]){
min = mark[i];
}
}
int tie_min = tie_break[0];
for(int i = 0; i < page_frame; i++){
if(mark[i] == min){
if(tie_min > tie_break[i]){
tie_min = tie_break[i];
min_no = i;
}
}
}
return min_no;
} | [
"int",
"LFU_replace",
"(",
"int",
"*",
"mem",
",",
"int",
"*",
"mark",
",",
"int",
"*",
"tie_break",
",",
"int",
"page_frame",
")",
"{",
"int",
"min",
"=",
"mark",
"[",
"0",
"]",
";",
"int",
"min_no",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"page_frame",
";",
"i",
"++",
")",
"{",
"if",
"(",
"min",
">",
"mark",
"[",
"i",
"]",
")",
"{",
"min",
"=",
"mark",
"[",
"i",
"]",
";",
"}",
"}",
"int",
"tie_min",
"=",
"tie_break",
"[",
"0",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"page_frame",
";",
"i",
"++",
")",
"{",
"if",
"(",
"mark",
"[",
"i",
"]",
"==",
"min",
")",
"{",
"if",
"(",
"tie_min",
">",
"tie_break",
"[",
"i",
"]",
")",
"{",
"tie_min",
"=",
"tie_break",
"[",
"i",
"]",
";",
"min_no",
"=",
"i",
";",
"}",
"}",
"}",
"return",
"min_no",
";",
"}"
] | find index to be replaced following LFU algorithm | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"LFU",
"algorithm"
] | [
"// if the page has same used count with minimum value, tie_break by LRU\r"
] | [
{
"param": "mem",
"type": "int"
},
{
"param": "mark",
"type": "int"
},
{
"param": "tie_break",
"type": "int"
},
{
"param": "page_frame",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mark",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tie_break",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "page_frame",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | Clock_replace | int | int Clock_replace(int *mem, int *mark, int page_frame){
// needle value should be hold for next search -> use static
static int needle = 0;
int replace;
// find page whose reference bit == 0
while(1){
if(mark[needle] == 0){
replace = needle;
needle++;
needle = needle % page_frame;
break;
// if reference bit == 1, change to 0 and examine next page
}else{
mark[needle] = 0;
needle++;
needle = needle % page_frame;
}
}
return replace;
} | /**
* find index to be replaced following Clock algorithm
*
* input:
* int *mem: array to save page no. which are in the page frame
* int *mark: array that has reference bit of pages in the memory
* int page_frame: no. of page frame allocated, size of mem, mark
*
* output:
* return int index to be replaced(index whose reference bit == 0)
*/ | find index to be replaced following Clock algorithm
int *mem: array to save page no. which are in the page frame
int *mark: array that has reference bit of pages in the memory
int page_frame: no. of page frame allocated, size of mem, mark
return int index to be replaced(index whose reference bit == 0) | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"Clock",
"algorithm",
"int",
"*",
"mem",
":",
"array",
"to",
"save",
"page",
"no",
".",
"which",
"are",
"in",
"the",
"page",
"frame",
"int",
"*",
"mark",
":",
"array",
"that",
"has",
"reference",
"bit",
"of",
"pages",
"in",
"the",
"memory",
"int",
"page_frame",
":",
"no",
".",
"of",
"page",
"frame",
"allocated",
"size",
"of",
"mem",
"mark",
"return",
"int",
"index",
"to",
"be",
"replaced",
"(",
"index",
"whose",
"reference",
"bit",
"==",
"0",
")"
] | int Clock_replace(int *mem, int *mark, int page_frame){
static int needle = 0;
int replace;
while(1){
if(mark[needle] == 0){
replace = needle;
needle++;
needle = needle % page_frame;
break;
}else{
mark[needle] = 0;
needle++;
needle = needle % page_frame;
}
}
return replace;
} | [
"int",
"Clock_replace",
"(",
"int",
"*",
"mem",
",",
"int",
"*",
"mark",
",",
"int",
"page_frame",
")",
"{",
"static",
"int",
"needle",
"=",
"0",
";",
"int",
"replace",
";",
"while",
"(",
"1",
")",
"{",
"if",
"(",
"mark",
"[",
"needle",
"]",
"==",
"0",
")",
"{",
"replace",
"=",
"needle",
";",
"needle",
"++",
";",
"needle",
"=",
"needle",
"%",
"page_frame",
";",
"break",
";",
"}",
"else",
"{",
"mark",
"[",
"needle",
"]",
"=",
"0",
";",
"needle",
"++",
";",
"needle",
"=",
"needle",
"%",
"page_frame",
";",
"}",
"}",
"return",
"replace",
";",
"}"
] | find index to be replaced following Clock algorithm | [
"find",
"index",
"to",
"be",
"replaced",
"following",
"Clock",
"algorithm"
] | [
"// needle value should be hold for next search -> use static\r",
"// find page whose reference bit == 0\r",
"// if reference bit == 1, change to 0 and examine next page\r"
] | [
{
"param": "mem",
"type": "int"
},
{
"param": "mark",
"type": "int"
},
{
"param": "page_frame",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mark",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "page_frame",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
0ed570b73165a80a50d8ad1e7f7705791f029b10 | dongwon18/Virtual_Memory_Management | src/virtual_memory_management.c | [
"MIT"
] | C | rand_input | FILE | FILE *rand_input(void){
srand(time(NULL));
int page = rand() % PAGE + 1;
int page_frame = rand() % FRAME + 1;
int window = rand() % WINDOW + 1;
// range: page + 1 ~ S_LEN
int string_length = rand() % (S_LEN - page) + 1 + page;
FILE *infile = fopen("rand_input.txt", "w+");
fprintf(infile, "%d %d %d %d\n", page, page_frame, window, string_length);
for(int i = 0; i < string_length; i++){
fprintf(infile, "%d ", rand() % page);
}
fprintf(infile, "\n");
// set file pointer to the start
fseek(infile, 0, SEEK_SET);
return infile;
} | /**
* create random input
* randomly choose page, page_frame, window, string, string_length within the range
*
* output:
* FILE *infile: file pointer that has randomly chosen values
*/ | create random input
randomly choose page, page_frame, window, string, string_length within the range
FILE *infile: file pointer that has randomly chosen values | [
"create",
"random",
"input",
"randomly",
"choose",
"page",
"page_frame",
"window",
"string",
"string_length",
"within",
"the",
"range",
"FILE",
"*",
"infile",
":",
"file",
"pointer",
"that",
"has",
"randomly",
"chosen",
"values"
] | FILE *rand_input(void){
srand(time(NULL));
int page = rand() % PAGE + 1;
int page_frame = rand() % FRAME + 1;
int window = rand() % WINDOW + 1;
int string_length = rand() % (S_LEN - page) + 1 + page;
FILE *infile = fopen("rand_input.txt", "w+");
fprintf(infile, "%d %d %d %d\n", page, page_frame, window, string_length);
for(int i = 0; i < string_length; i++){
fprintf(infile, "%d ", rand() % page);
}
fprintf(infile, "\n");
fseek(infile, 0, SEEK_SET);
return infile;
} | [
"FILE",
"*",
"rand_input",
"(",
"void",
")",
"{",
"srand",
"(",
"time",
"(",
"NULL",
")",
")",
";",
"int",
"page",
"=",
"rand",
"(",
")",
"%",
"PAGE",
"+",
"1",
";",
"int",
"page_frame",
"=",
"rand",
"(",
")",
"%",
"FRAME",
"+",
"1",
";",
"int",
"window",
"=",
"rand",
"(",
")",
"%",
"WINDOW",
"+",
"1",
";",
"int",
"string_length",
"=",
"rand",
"(",
")",
"%",
"(",
"S_LEN",
"-",
"page",
")",
"+",
"1",
"+",
"page",
";",
"FILE",
"*",
"infile",
"=",
"fopen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"fprintf",
"(",
"infile",
",",
"\"",
"\\n",
"\"",
",",
"page",
",",
"page_frame",
",",
"window",
",",
"string_length",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"string_length",
";",
"i",
"++",
")",
"{",
"fprintf",
"(",
"infile",
",",
"\"",
"\"",
",",
"rand",
"(",
")",
"%",
"page",
")",
";",
"}",
"fprintf",
"(",
"infile",
",",
"\"",
"\\n",
"\"",
")",
";",
"fseek",
"(",
"infile",
",",
"0",
",",
"SEEK_SET",
")",
";",
"return",
"infile",
";",
"}"
] | create random input
randomly choose page, page_frame, window, string, string_length within the range | [
"create",
"random",
"input",
"randomly",
"choose",
"page",
"page_frame",
"window",
"string",
"string_length",
"within",
"the",
"range"
] | [
"// range: page + 1 ~ S_LEN\r",
"// set file pointer to the start\r"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
6bf168ad102525209931f27195d6252ba0ef4e13 | dreamCirno/build_xlua_with_libs | build/ffi/ffi.c | [
"MIT"
] | C | check_enum | int32_t | int32_t check_enum(lua_State* L, int idx, int to_usr, const struct ctype* to_ct)
{
int32_t ret;
switch (lua_type(L, idx)) {
case LUA_TSTRING:
/* lookup string in to_usr to find value */
to_usr = lua_absindex(L, to_usr);
lua_pushvalue(L, idx);
lua_rawget(L, to_usr);
if (lua_isnil(L, -1)) {
goto err;
}
ret = (int32_t) lua_tointeger(L, -1);
lua_pop(L, 1);
return ret;
case LUA_TUSERDATA:
return check_int32(L, idx);
case LUA_TNIL:
return (int32_t) 0;
case LUA_TNUMBER:
return (int32_t) lua_tointeger(L, idx);
default:
goto err;
}
err:
return type_error(L, idx, NULL, to_usr, to_ct);
} | /* to_enum tries to convert a value at idx to the enum type indicated by to_ct
* and uv to_usr. For strings this means it will do a string lookup for the
* enum type. It leaves the stack unchanged. Will throw an error if the type
* at idx can't be conerted.
*/ | to_enum tries to convert a value at idx to the enum type indicated by to_ct
and uv to_usr. For strings this means it will do a string lookup for the
enum type. It leaves the stack unchanged. Will throw an error if the type
at idx can't be conerted. | [
"to_enum",
"tries",
"to",
"convert",
"a",
"value",
"at",
"idx",
"to",
"the",
"enum",
"type",
"indicated",
"by",
"to_ct",
"and",
"uv",
"to_usr",
".",
"For",
"strings",
"this",
"means",
"it",
"will",
"do",
"a",
"string",
"lookup",
"for",
"the",
"enum",
"type",
".",
"It",
"leaves",
"the",
"stack",
"unchanged",
".",
"Will",
"throw",
"an",
"error",
"if",
"the",
"type",
"at",
"idx",
"can",
"'",
"t",
"be",
"conerted",
"."
] | int32_t check_enum(lua_State* L, int idx, int to_usr, const struct ctype* to_ct)
{
int32_t ret;
switch (lua_type(L, idx)) {
case LUA_TSTRING:
to_usr = lua_absindex(L, to_usr);
lua_pushvalue(L, idx);
lua_rawget(L, to_usr);
if (lua_isnil(L, -1)) {
goto err;
}
ret = (int32_t) lua_tointeger(L, -1);
lua_pop(L, 1);
return ret;
case LUA_TUSERDATA:
return check_int32(L, idx);
case LUA_TNIL:
return (int32_t) 0;
case LUA_TNUMBER:
return (int32_t) lua_tointeger(L, idx);
default:
goto err;
}
err:
return type_error(L, idx, NULL, to_usr, to_ct);
} | [
"int32_t",
"check_enum",
"(",
"lua_State",
"*",
"L",
",",
"int",
"idx",
",",
"int",
"to_usr",
",",
"const",
"struct",
"ctype",
"*",
"to_ct",
")",
"{",
"int32_t",
"ret",
";",
"switch",
"(",
"lua_type",
"(",
"L",
",",
"idx",
")",
")",
"{",
"case",
"LUA_TSTRING",
":",
"to_usr",
"=",
"lua_absindex",
"(",
"L",
",",
"to_usr",
")",
";",
"lua_pushvalue",
"(",
"L",
",",
"idx",
")",
";",
"lua_rawget",
"(",
"L",
",",
"to_usr",
")",
";",
"if",
"(",
"lua_isnil",
"(",
"L",
",",
"-1",
")",
")",
"{",
"goto",
"err",
";",
"}",
"ret",
"=",
"(",
"int32_t",
")",
"lua_tointeger",
"(",
"L",
",",
"-1",
")",
";",
"lua_pop",
"(",
"L",
",",
"1",
")",
";",
"return",
"ret",
";",
"case",
"LUA_TUSERDATA",
":",
"return",
"check_int32",
"(",
"L",
",",
"idx",
")",
";",
"case",
"LUA_TNIL",
":",
"return",
"(",
"int32_t",
")",
"0",
";",
"case",
"LUA_TNUMBER",
":",
"return",
"(",
"int32_t",
")",
"lua_tointeger",
"(",
"L",
",",
"idx",
")",
";",
"default",
":",
"goto",
"err",
";",
"}",
"err",
":",
"return",
"type_error",
"(",
"L",
",",
"idx",
",",
"NULL",
",",
"to_usr",
",",
"to_ct",
")",
";",
"}"
] | to_enum tries to convert a value at idx to the enum type indicated by to_ct
and uv to_usr. | [
"to_enum",
"tries",
"to",
"convert",
"a",
"value",
"at",
"idx",
"to",
"the",
"enum",
"type",
"indicated",
"by",
"to_ct",
"and",
"uv",
"to_usr",
"."
] | [
"/* lookup string in to_usr to find value */"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "idx",
"type": "int"
},
{
"param": "to_usr",
"type": "int"
},
{
"param": "to_ct",
"type": "struct ctype"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "idx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "to_usr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "to_ct",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6bf168ad102525209931f27195d6252ba0ef4e13 | dreamCirno/build_xlua_with_libs | build/ffi/ffi.c | [
"MIT"
] | C | check_pointer | void | static void* check_pointer(lua_State* L, int idx, struct ctype* ct)
{
void* p;
memset(ct, 0, sizeof(*ct));
idx = lua_absindex(L, idx);
switch (lua_type(L, idx)) {
case LUA_TNIL:
ct->type = VOID_TYPE;
ct->pointers = 1;
ct->is_null = 1;
lua_pushnil(L);
return NULL;
case LUA_TNUMBER:
ct->type = INTPTR_TYPE;
ct->is_unsigned = 1;
ct->pointers = 0;
lua_pushnil(L);
return (void*) (uintptr_t) lua_tonumber(L, idx); // TODO in Lua 5.3: maybe change to lua_tointeger
case LUA_TLIGHTUSERDATA:
ct->type = VOID_TYPE;
ct->pointers = 1;
lua_pushnil(L);
return lua_touserdata(L, idx);
case LUA_TSTRING:
ct->type = INT8_TYPE;
ct->pointers = 1;
ct->is_unsigned = IS_CHAR_UNSIGNED;
ct->is_array = 1;
ct->base_size = 1;
ct->const_mask = 2;
lua_pushnil(L);
return (void*) lua_tolstring(L, idx, &ct->array_size);
case LUA_TUSERDATA:
p = to_cdata(L, idx, ct);
if (ct->type == INVALID_TYPE) {
/* some other type of user data */
ct->type = VOID_TYPE;
ct->pointers = 1;
return userdata_toptr(L, idx);
} else if (ct->type == STRUCT_TYPE || ct->type == UNION_TYPE) {
return p;
} else {
return (void*) (intptr_t) check_intptr(L, idx, p, ct);
}
break;
}
type_error(L, idx, "pointer", 0, NULL);
return NULL;
} | /* to_pointer tries converts a value at idx to a pointer. It fills out ct and
* pushes the uv of the found type. It will throw a lua error if it can not
* convert the value to a pointer. */ | to_pointer tries converts a value at idx to a pointer. It fills out ct and
pushes the uv of the found type. It will throw a lua error if it can not
convert the value to a pointer. | [
"to_pointer",
"tries",
"converts",
"a",
"value",
"at",
"idx",
"to",
"a",
"pointer",
".",
"It",
"fills",
"out",
"ct",
"and",
"pushes",
"the",
"uv",
"of",
"the",
"found",
"type",
".",
"It",
"will",
"throw",
"a",
"lua",
"error",
"if",
"it",
"can",
"not",
"convert",
"the",
"value",
"to",
"a",
"pointer",
"."
] | static void* check_pointer(lua_State* L, int idx, struct ctype* ct)
{
void* p;
memset(ct, 0, sizeof(*ct));
idx = lua_absindex(L, idx);
switch (lua_type(L, idx)) {
case LUA_TNIL:
ct->type = VOID_TYPE;
ct->pointers = 1;
ct->is_null = 1;
lua_pushnil(L);
return NULL;
case LUA_TNUMBER:
ct->type = INTPTR_TYPE;
ct->is_unsigned = 1;
ct->pointers = 0;
lua_pushnil(L);
return (void*) (uintptr_t) lua_tonumber(L, idx);
case LUA_TLIGHTUSERDATA:
ct->type = VOID_TYPE;
ct->pointers = 1;
lua_pushnil(L);
return lua_touserdata(L, idx);
case LUA_TSTRING:
ct->type = INT8_TYPE;
ct->pointers = 1;
ct->is_unsigned = IS_CHAR_UNSIGNED;
ct->is_array = 1;
ct->base_size = 1;
ct->const_mask = 2;
lua_pushnil(L);
return (void*) lua_tolstring(L, idx, &ct->array_size);
case LUA_TUSERDATA:
p = to_cdata(L, idx, ct);
if (ct->type == INVALID_TYPE) {
ct->type = VOID_TYPE;
ct->pointers = 1;
return userdata_toptr(L, idx);
} else if (ct->type == STRUCT_TYPE || ct->type == UNION_TYPE) {
return p;
} else {
return (void*) (intptr_t) check_intptr(L, idx, p, ct);
}
break;
}
type_error(L, idx, "pointer", 0, NULL);
return NULL;
} | [
"static",
"void",
"*",
"check_pointer",
"(",
"lua_State",
"*",
"L",
",",
"int",
"idx",
",",
"struct",
"ctype",
"*",
"ct",
")",
"{",
"void",
"*",
"p",
";",
"memset",
"(",
"ct",
",",
"0",
",",
"sizeof",
"(",
"*",
"ct",
")",
")",
";",
"idx",
"=",
"lua_absindex",
"(",
"L",
",",
"idx",
")",
";",
"switch",
"(",
"lua_type",
"(",
"L",
",",
"idx",
")",
")",
"{",
"case",
"LUA_TNIL",
":",
"ct",
"->",
"type",
"=",
"VOID_TYPE",
";",
"ct",
"->",
"pointers",
"=",
"1",
";",
"ct",
"->",
"is_null",
"=",
"1",
";",
"lua_pushnil",
"(",
"L",
")",
";",
"return",
"NULL",
";",
"case",
"LUA_TNUMBER",
":",
"ct",
"->",
"type",
"=",
"INTPTR_TYPE",
";",
"ct",
"->",
"is_unsigned",
"=",
"1",
";",
"ct",
"->",
"pointers",
"=",
"0",
";",
"lua_pushnil",
"(",
"L",
")",
";",
"return",
"(",
"void",
"*",
")",
"(",
"uintptr_t",
")",
"lua_tonumber",
"(",
"L",
",",
"idx",
")",
";",
"case",
"LUA_TLIGHTUSERDATA",
":",
"ct",
"->",
"type",
"=",
"VOID_TYPE",
";",
"ct",
"->",
"pointers",
"=",
"1",
";",
"lua_pushnil",
"(",
"L",
")",
";",
"return",
"lua_touserdata",
"(",
"L",
",",
"idx",
")",
";",
"case",
"LUA_TSTRING",
":",
"ct",
"->",
"type",
"=",
"INT8_TYPE",
";",
"ct",
"->",
"pointers",
"=",
"1",
";",
"ct",
"->",
"is_unsigned",
"=",
"IS_CHAR_UNSIGNED",
";",
"ct",
"->",
"is_array",
"=",
"1",
";",
"ct",
"->",
"base_size",
"=",
"1",
";",
"ct",
"->",
"const_mask",
"=",
"2",
";",
"lua_pushnil",
"(",
"L",
")",
";",
"return",
"(",
"void",
"*",
")",
"lua_tolstring",
"(",
"L",
",",
"idx",
",",
"&",
"ct",
"->",
"array_size",
")",
";",
"case",
"LUA_TUSERDATA",
":",
"p",
"=",
"to_cdata",
"(",
"L",
",",
"idx",
",",
"ct",
")",
";",
"if",
"(",
"ct",
"->",
"type",
"==",
"INVALID_TYPE",
")",
"{",
"ct",
"->",
"type",
"=",
"VOID_TYPE",
";",
"ct",
"->",
"pointers",
"=",
"1",
";",
"return",
"userdata_toptr",
"(",
"L",
",",
"idx",
")",
";",
"}",
"else",
"if",
"(",
"ct",
"->",
"type",
"==",
"STRUCT_TYPE",
"||",
"ct",
"->",
"type",
"==",
"UNION_TYPE",
")",
"{",
"return",
"p",
";",
"}",
"else",
"{",
"return",
"(",
"void",
"*",
")",
"(",
"intptr_t",
")",
"check_intptr",
"(",
"L",
",",
"idx",
",",
"p",
",",
"ct",
")",
";",
"}",
"break",
";",
"}",
"type_error",
"(",
"L",
",",
"idx",
",",
"\"",
"\"",
",",
"0",
",",
"NULL",
")",
";",
"return",
"NULL",
";",
"}"
] | to_pointer tries converts a value at idx to a pointer. | [
"to_pointer",
"tries",
"converts",
"a",
"value",
"at",
"idx",
"to",
"a",
"pointer",
"."
] | [
"// TODO in Lua 5.3: maybe change to lua_tointeger",
"/* some other type of user data */"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "idx",
"type": "int"
},
{
"param": "ct",
"type": "struct ctype"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "idx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ct",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6bf168ad102525209931f27195d6252ba0ef4e13 | dreamCirno/build_xlua_with_libs | build/ffi/ffi.c | [
"MIT"
] | C | check_typed_pointer | void | void* check_typed_pointer(lua_State* L, int idx, int to_usr, const struct ctype* tt)
{
struct ctype ft;
void* p;
to_usr = lua_absindex(L, to_usr);
idx = lua_absindex(L, idx);
if (tt->pointers == 1 && (tt->type == STRUCT_TYPE || tt->type == UNION_TYPE) && lua_type(L, idx) == LUA_TTABLE) {
/* need to construct a struct of the target type */
struct ctype ct = *tt;
ct.pointers = ct.is_array = 0;
p = push_cdata(L, to_usr, &ct);
set_struct(L, idx, p, to_usr, &ct, 1);
return p;
}
p = check_pointer(L, idx, &ft);
if (tt->pointers == 1 && ft.pointers == 0 && (ft.type == STRUCT_TYPE || ft.type == UNION_TYPE)) {
/* auto dereference structs */
ft.pointers = 1;
ft.const_mask <<= 1;
}
if (is_void_ptr(tt)) {
/* any pointer can convert to void* */
goto suc;
} else if (is_void_ptr(&ft) && (ft.pointers || ft.is_reference)) {
/* void* can convert to any pointer */
goto suc;
} else if (ft.is_null) {
/* NULL can convert to any pointer */
goto suc;
} else if (!is_same_type(L, to_usr, -1, tt, &ft)) {
/* the base type is different */
goto err;
} else if (tt->pointers != ft.pointers) {
goto err;
} else if (ft.const_mask & ~tt->const_mask) {
/* for every const in from it must be in to, there are further rules
* for const casting (see the c++ spec), but they are hard to test
* quickly */
goto err;
}
suc:
return p;
err:
type_error(L, idx, NULL, to_usr, tt);
return NULL;
} | /* to_typed_pointer converts a value at idx to a type tt with target uv to_usr
* checking all types. May push a temporary value so that it can create
* structs on the fly. */ | to_typed_pointer converts a value at idx to a type tt with target uv to_usr
checking all types. May push a temporary value so that it can create
structs on the fly. | [
"to_typed_pointer",
"converts",
"a",
"value",
"at",
"idx",
"to",
"a",
"type",
"tt",
"with",
"target",
"uv",
"to_usr",
"checking",
"all",
"types",
".",
"May",
"push",
"a",
"temporary",
"value",
"so",
"that",
"it",
"can",
"create",
"structs",
"on",
"the",
"fly",
"."
] | void* check_typed_pointer(lua_State* L, int idx, int to_usr, const struct ctype* tt)
{
struct ctype ft;
void* p;
to_usr = lua_absindex(L, to_usr);
idx = lua_absindex(L, idx);
if (tt->pointers == 1 && (tt->type == STRUCT_TYPE || tt->type == UNION_TYPE) && lua_type(L, idx) == LUA_TTABLE) {
struct ctype ct = *tt;
ct.pointers = ct.is_array = 0;
p = push_cdata(L, to_usr, &ct);
set_struct(L, idx, p, to_usr, &ct, 1);
return p;
}
p = check_pointer(L, idx, &ft);
if (tt->pointers == 1 && ft.pointers == 0 && (ft.type == STRUCT_TYPE || ft.type == UNION_TYPE)) {
ft.pointers = 1;
ft.const_mask <<= 1;
}
if (is_void_ptr(tt)) {
goto suc;
} else if (is_void_ptr(&ft) && (ft.pointers || ft.is_reference)) {
goto suc;
} else if (ft.is_null) {
goto suc;
} else if (!is_same_type(L, to_usr, -1, tt, &ft)) {
goto err;
} else if (tt->pointers != ft.pointers) {
goto err;
} else if (ft.const_mask & ~tt->const_mask) {
goto err;
}
suc:
return p;
err:
type_error(L, idx, NULL, to_usr, tt);
return NULL;
} | [
"void",
"*",
"check_typed_pointer",
"(",
"lua_State",
"*",
"L",
",",
"int",
"idx",
",",
"int",
"to_usr",
",",
"const",
"struct",
"ctype",
"*",
"tt",
")",
"{",
"struct",
"ctype",
"ft",
";",
"void",
"*",
"p",
";",
"to_usr",
"=",
"lua_absindex",
"(",
"L",
",",
"to_usr",
")",
";",
"idx",
"=",
"lua_absindex",
"(",
"L",
",",
"idx",
")",
";",
"if",
"(",
"tt",
"->",
"pointers",
"==",
"1",
"&&",
"(",
"tt",
"->",
"type",
"==",
"STRUCT_TYPE",
"||",
"tt",
"->",
"type",
"==",
"UNION_TYPE",
")",
"&&",
"lua_type",
"(",
"L",
",",
"idx",
")",
"==",
"LUA_TTABLE",
")",
"{",
"struct",
"ctype",
"ct",
"=",
"*",
"tt",
";",
"ct",
".",
"pointers",
"=",
"ct",
".",
"is_array",
"=",
"0",
";",
"p",
"=",
"push_cdata",
"(",
"L",
",",
"to_usr",
",",
"&",
"ct",
")",
";",
"set_struct",
"(",
"L",
",",
"idx",
",",
"p",
",",
"to_usr",
",",
"&",
"ct",
",",
"1",
")",
";",
"return",
"p",
";",
"}",
"p",
"=",
"check_pointer",
"(",
"L",
",",
"idx",
",",
"&",
"ft",
")",
";",
"if",
"(",
"tt",
"->",
"pointers",
"==",
"1",
"&&",
"ft",
".",
"pointers",
"==",
"0",
"&&",
"(",
"ft",
".",
"type",
"==",
"STRUCT_TYPE",
"||",
"ft",
".",
"type",
"==",
"UNION_TYPE",
")",
")",
"{",
"ft",
".",
"pointers",
"=",
"1",
";",
"ft",
".",
"const_mask",
"<<=",
"1",
";",
"}",
"if",
"(",
"is_void_ptr",
"(",
"tt",
")",
")",
"{",
"goto",
"suc",
";",
"}",
"else",
"if",
"(",
"is_void_ptr",
"(",
"&",
"ft",
")",
"&&",
"(",
"ft",
".",
"pointers",
"||",
"ft",
".",
"is_reference",
")",
")",
"{",
"goto",
"suc",
";",
"}",
"else",
"if",
"(",
"ft",
".",
"is_null",
")",
"{",
"goto",
"suc",
";",
"}",
"else",
"if",
"(",
"!",
"is_same_type",
"(",
"L",
",",
"to_usr",
",",
"-1",
",",
"tt",
",",
"&",
"ft",
")",
")",
"{",
"goto",
"err",
";",
"}",
"else",
"if",
"(",
"tt",
"->",
"pointers",
"!=",
"ft",
".",
"pointers",
")",
"{",
"goto",
"err",
";",
"}",
"else",
"if",
"(",
"ft",
".",
"const_mask",
"&",
"~",
"tt",
"->",
"const_mask",
")",
"{",
"goto",
"err",
";",
"}",
"suc",
":",
"return",
"p",
";",
"err",
":",
"type_error",
"(",
"L",
",",
"idx",
",",
"NULL",
",",
"to_usr",
",",
"tt",
")",
";",
"return",
"NULL",
";",
"}"
] | to_typed_pointer converts a value at idx to a type tt with target uv to_usr
checking all types. | [
"to_typed_pointer",
"converts",
"a",
"value",
"at",
"idx",
"to",
"a",
"type",
"tt",
"with",
"target",
"uv",
"to_usr",
"checking",
"all",
"types",
"."
] | [
"/* need to construct a struct of the target type */",
"/* auto dereference structs */",
"/* any pointer can convert to void* */",
"/* void* can convert to any pointer */",
"/* NULL can convert to any pointer */",
"/* the base type is different */",
"/* for every const in from it must be in to, there are further rules\n * for const casting (see the c++ spec), but they are hard to test\n * quickly */"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "idx",
"type": "int"
},
{
"param": "to_usr",
"type": "int"
},
{
"param": "tt",
"type": "struct ctype"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "idx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "to_usr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tt",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6bf168ad102525209931f27195d6252ba0ef4e13 | dreamCirno/build_xlua_with_libs | build/ffi/ffi.c | [
"MIT"
] | C | push_user_mt | int | int push_user_mt(lua_State* L, int ct_usr, const struct ctype* ct)
{
if (ct->type != STRUCT_TYPE && ct->type != UNION_TYPE && !IS_COMPLEX(ct->type)) {
return 0;
}
if (!lua_istable(L, ct_usr)) {
return 0;
}
ct_usr = lua_absindex(L, ct_usr);
lua_pushlightuserdata(L, &user_mt_key);
lua_rawget(L, ct_usr);
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
return 0;
}
return 1;
} | /* push_user_mt returns 1 if the type has a user metatable and pushes it onto
* the stack, otherwise it returns 0 and pushes nothing */ | push_user_mt returns 1 if the type has a user metatable and pushes it onto
the stack, otherwise it returns 0 and pushes nothing | [
"push_user_mt",
"returns",
"1",
"if",
"the",
"type",
"has",
"a",
"user",
"metatable",
"and",
"pushes",
"it",
"onto",
"the",
"stack",
"otherwise",
"it",
"returns",
"0",
"and",
"pushes",
"nothing"
] | int push_user_mt(lua_State* L, int ct_usr, const struct ctype* ct)
{
if (ct->type != STRUCT_TYPE && ct->type != UNION_TYPE && !IS_COMPLEX(ct->type)) {
return 0;
}
if (!lua_istable(L, ct_usr)) {
return 0;
}
ct_usr = lua_absindex(L, ct_usr);
lua_pushlightuserdata(L, &user_mt_key);
lua_rawget(L, ct_usr);
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
return 0;
}
return 1;
} | [
"int",
"push_user_mt",
"(",
"lua_State",
"*",
"L",
",",
"int",
"ct_usr",
",",
"const",
"struct",
"ctype",
"*",
"ct",
")",
"{",
"if",
"(",
"ct",
"->",
"type",
"!=",
"STRUCT_TYPE",
"&&",
"ct",
"->",
"type",
"!=",
"UNION_TYPE",
"&&",
"!",
"IS_COMPLEX",
"(",
"ct",
"->",
"type",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"!",
"lua_istable",
"(",
"L",
",",
"ct_usr",
")",
")",
"{",
"return",
"0",
";",
"}",
"ct_usr",
"=",
"lua_absindex",
"(",
"L",
",",
"ct_usr",
")",
";",
"lua_pushlightuserdata",
"(",
"L",
",",
"&",
"user_mt_key",
")",
";",
"lua_rawget",
"(",
"L",
",",
"ct_usr",
")",
";",
"if",
"(",
"lua_isnil",
"(",
"L",
",",
"-1",
")",
")",
"{",
"lua_pop",
"(",
"L",
",",
"1",
")",
";",
"return",
"0",
";",
"}",
"return",
"1",
";",
"}"
] | push_user_mt returns 1 if the type has a user metatable and pushes it onto
the stack, otherwise it returns 0 and pushes nothing | [
"push_user_mt",
"returns",
"1",
"if",
"the",
"type",
"has",
"a",
"user",
"metatable",
"and",
"pushes",
"it",
"onto",
"the",
"stack",
"otherwise",
"it",
"returns",
"0",
"and",
"pushes",
"nothing"
] | [] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "ct_usr",
"type": "int"
},
{
"param": "ct",
"type": "struct ctype"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ct_usr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ct",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6bf168ad102525209931f27195d6252ba0ef4e13 | dreamCirno/build_xlua_with_libs | build/ffi/ffi.c | [
"MIT"
] | C | lookup_cdata_index | ptrdiff_t | static ptrdiff_t lookup_cdata_index(lua_State* L, int idx, int ct_usr, struct ctype* ct)
{
struct ctype mt;
ptrdiff_t off;
ct_usr = lua_absindex(L, ct_usr);
int type = lua_type(L, idx);
switch (type) {
case LUA_TNUMBER:
case LUA_TUSERDATA:
/* possibilities are array, pointer */
if (!ct->pointers || is_void_ptr(ct)) {
return -1;
}
// unbox cdata
if (type == LUA_TUSERDATA) {
if (!cdata_tointeger(L, idx, &off)) {
return -1;
}
} else {
off = lua_tointeger(L, idx);
}
ct->is_array = 0;
ct->pointers--;
ct->const_mask >>= 1;
ct->is_reference = 0;
lua_pushvalue(L, ct_usr);
return (ct->pointers ? sizeof(void*) : ct->base_size) * off;
case LUA_TSTRING:
/* possibilities are struct/union, pointer to struct/union */
if ((ct->type != STRUCT_TYPE && ct->type != UNION_TYPE) || ct->is_array || ct->pointers > 1) {
return -1;
}
lua_pushvalue(L, idx);
off = get_member(L, ct_usr, ct, &mt);
if (off < 0) {
return -1;
}
*ct = mt;
return off;
default:
return -1;
}
} | /* lookup_cdata_index returns the offset of the found type and user value on
* the stack if valid. Otherwise returns -ve and doesn't touch the stack.
*/ | lookup_cdata_index returns the offset of the found type and user value on
the stack if valid. Otherwise returns -ve and doesn't touch the stack. | [
"lookup_cdata_index",
"returns",
"the",
"offset",
"of",
"the",
"found",
"type",
"and",
"user",
"value",
"on",
"the",
"stack",
"if",
"valid",
".",
"Otherwise",
"returns",
"-",
"ve",
"and",
"doesn",
"'",
"t",
"touch",
"the",
"stack",
"."
] | static ptrdiff_t lookup_cdata_index(lua_State* L, int idx, int ct_usr, struct ctype* ct)
{
struct ctype mt;
ptrdiff_t off;
ct_usr = lua_absindex(L, ct_usr);
int type = lua_type(L, idx);
switch (type) {
case LUA_TNUMBER:
case LUA_TUSERDATA:
if (!ct->pointers || is_void_ptr(ct)) {
return -1;
}
if (type == LUA_TUSERDATA) {
if (!cdata_tointeger(L, idx, &off)) {
return -1;
}
} else {
off = lua_tointeger(L, idx);
}
ct->is_array = 0;
ct->pointers--;
ct->const_mask >>= 1;
ct->is_reference = 0;
lua_pushvalue(L, ct_usr);
return (ct->pointers ? sizeof(void*) : ct->base_size) * off;
case LUA_TSTRING:
if ((ct->type != STRUCT_TYPE && ct->type != UNION_TYPE) || ct->is_array || ct->pointers > 1) {
return -1;
}
lua_pushvalue(L, idx);
off = get_member(L, ct_usr, ct, &mt);
if (off < 0) {
return -1;
}
*ct = mt;
return off;
default:
return -1;
}
} | [
"static",
"ptrdiff_t",
"lookup_cdata_index",
"(",
"lua_State",
"*",
"L",
",",
"int",
"idx",
",",
"int",
"ct_usr",
",",
"struct",
"ctype",
"*",
"ct",
")",
"{",
"struct",
"ctype",
"mt",
";",
"ptrdiff_t",
"off",
";",
"ct_usr",
"=",
"lua_absindex",
"(",
"L",
",",
"ct_usr",
")",
";",
"int",
"type",
"=",
"lua_type",
"(",
"L",
",",
"idx",
")",
";",
"switch",
"(",
"type",
")",
"{",
"case",
"LUA_TNUMBER",
":",
"case",
"LUA_TUSERDATA",
":",
"if",
"(",
"!",
"ct",
"->",
"pointers",
"||",
"is_void_ptr",
"(",
"ct",
")",
")",
"{",
"return",
"-1",
";",
"}",
"if",
"(",
"type",
"==",
"LUA_TUSERDATA",
")",
"{",
"if",
"(",
"!",
"cdata_tointeger",
"(",
"L",
",",
"idx",
",",
"&",
"off",
")",
")",
"{",
"return",
"-1",
";",
"}",
"}",
"else",
"{",
"off",
"=",
"lua_tointeger",
"(",
"L",
",",
"idx",
")",
";",
"}",
"ct",
"->",
"is_array",
"=",
"0",
";",
"ct",
"->",
"pointers",
"--",
";",
"ct",
"->",
"const_mask",
">>=",
"1",
";",
"ct",
"->",
"is_reference",
"=",
"0",
";",
"lua_pushvalue",
"(",
"L",
",",
"ct_usr",
")",
";",
"return",
"(",
"ct",
"->",
"pointers",
"?",
"sizeof",
"(",
"void",
"*",
")",
":",
"ct",
"->",
"base_size",
")",
"*",
"off",
";",
"case",
"LUA_TSTRING",
":",
"if",
"(",
"(",
"ct",
"->",
"type",
"!=",
"STRUCT_TYPE",
"&&",
"ct",
"->",
"type",
"!=",
"UNION_TYPE",
")",
"||",
"ct",
"->",
"is_array",
"||",
"ct",
"->",
"pointers",
">",
"1",
")",
"{",
"return",
"-1",
";",
"}",
"lua_pushvalue",
"(",
"L",
",",
"idx",
")",
";",
"off",
"=",
"get_member",
"(",
"L",
",",
"ct_usr",
",",
"ct",
",",
"&",
"mt",
")",
";",
"if",
"(",
"off",
"<",
"0",
")",
"{",
"return",
"-1",
";",
"}",
"*",
"ct",
"=",
"mt",
";",
"return",
"off",
";",
"default",
":",
"return",
"-1",
";",
"}",
"}"
] | lookup_cdata_index returns the offset of the found type and user value on
the stack if valid. | [
"lookup_cdata_index",
"returns",
"the",
"offset",
"of",
"the",
"found",
"type",
"and",
"user",
"value",
"on",
"the",
"stack",
"if",
"valid",
"."
] | [
"/* possibilities are array, pointer */",
"// unbox cdata",
"/* possibilities are struct/union, pointer to struct/union */"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "idx",
"type": "int"
},
{
"param": "ct_usr",
"type": "int"
},
{
"param": "ct",
"type": "struct ctype"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "idx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ct_usr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ct",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
6bf168ad102525209931f27195d6252ba0ef4e13 | dreamCirno/build_xlua_with_libs | build/ffi/ffi.c | [
"MIT"
] | C | call_user_binop | int | static int call_user_binop(lua_State* L, const char* opfield, int lidx, int lusr, const struct ctype* lt, int ridx, int rusr, const struct ctype* rt)
{
lidx = lua_absindex(L, lidx);
ridx = lua_absindex(L, ridx);
if (push_user_mt(L, lusr, lt)) {
lua_pushstring(L, opfield);
lua_rawget(L, -2);
if (!lua_isnil(L, -1)) {
int top = lua_gettop(L);
lua_pushvalue(L, lidx);
lua_pushvalue(L, ridx);
lua_call(L, 2, LUA_MULTRET);
return lua_gettop(L) - top + 1;
}
lua_pop(L, 2); /* user_mt and user_mt.op */
}
if (push_user_mt(L, rusr, rt)) {
lua_pushstring(L, opfield);
lua_rawget(L, -2);
if (!lua_isnil(L, -1)) {
int top = lua_gettop(L);
lua_pushvalue(L, lidx);
lua_pushvalue(L, ridx);
lua_call(L, 2, LUA_MULTRET);
return lua_gettop(L) - top + 1;
}
lua_pop(L, 2); /* user_mt and user_mt.op */
}
return -1;
} | /* returns -ve if no binop was called otherwise returns the number of return
* arguments */ | ve if no binop was called otherwise returns the number of return
arguments | [
"ve",
"if",
"no",
"binop",
"was",
"called",
"otherwise",
"returns",
"the",
"number",
"of",
"return",
"arguments"
] | static int call_user_binop(lua_State* L, const char* opfield, int lidx, int lusr, const struct ctype* lt, int ridx, int rusr, const struct ctype* rt)
{
lidx = lua_absindex(L, lidx);
ridx = lua_absindex(L, ridx);
if (push_user_mt(L, lusr, lt)) {
lua_pushstring(L, opfield);
lua_rawget(L, -2);
if (!lua_isnil(L, -1)) {
int top = lua_gettop(L);
lua_pushvalue(L, lidx);
lua_pushvalue(L, ridx);
lua_call(L, 2, LUA_MULTRET);
return lua_gettop(L) - top + 1;
}
lua_pop(L, 2);
}
if (push_user_mt(L, rusr, rt)) {
lua_pushstring(L, opfield);
lua_rawget(L, -2);
if (!lua_isnil(L, -1)) {
int top = lua_gettop(L);
lua_pushvalue(L, lidx);
lua_pushvalue(L, ridx);
lua_call(L, 2, LUA_MULTRET);
return lua_gettop(L) - top + 1;
}
lua_pop(L, 2);
}
return -1;
} | [
"static",
"int",
"call_user_binop",
"(",
"lua_State",
"*",
"L",
",",
"const",
"char",
"*",
"opfield",
",",
"int",
"lidx",
",",
"int",
"lusr",
",",
"const",
"struct",
"ctype",
"*",
"lt",
",",
"int",
"ridx",
",",
"int",
"rusr",
",",
"const",
"struct",
"ctype",
"*",
"rt",
")",
"{",
"lidx",
"=",
"lua_absindex",
"(",
"L",
",",
"lidx",
")",
";",
"ridx",
"=",
"lua_absindex",
"(",
"L",
",",
"ridx",
")",
";",
"if",
"(",
"push_user_mt",
"(",
"L",
",",
"lusr",
",",
"lt",
")",
")",
"{",
"lua_pushstring",
"(",
"L",
",",
"opfield",
")",
";",
"lua_rawget",
"(",
"L",
",",
"-2",
")",
";",
"if",
"(",
"!",
"lua_isnil",
"(",
"L",
",",
"-1",
")",
")",
"{",
"int",
"top",
"=",
"lua_gettop",
"(",
"L",
")",
";",
"lua_pushvalue",
"(",
"L",
",",
"lidx",
")",
";",
"lua_pushvalue",
"(",
"L",
",",
"ridx",
")",
";",
"lua_call",
"(",
"L",
",",
"2",
",",
"LUA_MULTRET",
")",
";",
"return",
"lua_gettop",
"(",
"L",
")",
"-",
"top",
"+",
"1",
";",
"}",
"lua_pop",
"(",
"L",
",",
"2",
")",
";",
"}",
"if",
"(",
"push_user_mt",
"(",
"L",
",",
"rusr",
",",
"rt",
")",
")",
"{",
"lua_pushstring",
"(",
"L",
",",
"opfield",
")",
";",
"lua_rawget",
"(",
"L",
",",
"-2",
")",
";",
"if",
"(",
"!",
"lua_isnil",
"(",
"L",
",",
"-1",
")",
")",
"{",
"int",
"top",
"=",
"lua_gettop",
"(",
"L",
")",
";",
"lua_pushvalue",
"(",
"L",
",",
"lidx",
")",
";",
"lua_pushvalue",
"(",
"L",
",",
"ridx",
")",
";",
"lua_call",
"(",
"L",
",",
"2",
",",
"LUA_MULTRET",
")",
";",
"return",
"lua_gettop",
"(",
"L",
")",
"-",
"top",
"+",
"1",
";",
"}",
"lua_pop",
"(",
"L",
",",
"2",
")",
";",
"}",
"return",
"-1",
";",
"}"
] | returns -ve if no binop was called otherwise returns the number of return
arguments | [
"returns",
"-",
"ve",
"if",
"no",
"binop",
"was",
"called",
"otherwise",
"returns",
"the",
"number",
"of",
"return",
"arguments"
] | [
"/* user_mt and user_mt.op */",
"/* user_mt and user_mt.op */"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "opfield",
"type": "char"
},
{
"param": "lidx",
"type": "int"
},
{
"param": "lusr",
"type": "int"
},
{
"param": "lt",
"type": "struct ctype"
},
{
"param": "ridx",
"type": "int"
},
{
"param": "rusr",
"type": "int"
},
{
"param": "rt",
"type": "struct ctype"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "opfield",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "lidx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "lusr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "lt",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ridx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rusr",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rt",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
dec199f2b433592294bfcef0649a8c2bee11e8f2 | dreamCirno/build_xlua_with_libs | build/ffi/ctype.c | [
"MIT"
] | C | to_cdata | void | void* to_cdata(lua_State* L, int idx, struct ctype* ct)
{
struct cdata* cd;
memset(ct, 0, sizeof(struct ctype));
if (!lua_isuserdata(L, idx) || !lua_getmetatable(L, idx)) {
lua_pushnil(L);
return NULL;
}
if (!equals_upval(L, -1, &cdata_mt_key)) {
lua_pop(L, 1); /* mt */
lua_pushnil(L);
return NULL;
}
lua_pop(L, 1); /* mt */
cd = (struct cdata*) lua_touserdata(L, idx);
*ct = cd->type;
lua_getuservalue(L, idx);
if (ct->is_reference) {
return *(void**) (cd+1);
} else if (ct->pointers && !ct->is_array) {
return *(void**) (cd+1);
} else {
return cd + 1;
}
} | /* to_cdata returns the struct cdata* and pushes the user value onto the
* stack. If the index is not a ctype then ct is set to the zero value such
* that ct->type is INVALID_TYPE, a nil is pushed, and NULL is returned. */ | to_cdata returns the struct cdata* and pushes the user value onto the
stack. If the index is not a ctype then ct is set to the zero value such
that ct->type is INVALID_TYPE, a nil is pushed, and NULL is returned. | [
"to_cdata",
"returns",
"the",
"struct",
"cdata",
"*",
"and",
"pushes",
"the",
"user",
"value",
"onto",
"the",
"stack",
".",
"If",
"the",
"index",
"is",
"not",
"a",
"ctype",
"then",
"ct",
"is",
"set",
"to",
"the",
"zero",
"value",
"such",
"that",
"ct",
"-",
">",
"type",
"is",
"INVALID_TYPE",
"a",
"nil",
"is",
"pushed",
"and",
"NULL",
"is",
"returned",
"."
] | void* to_cdata(lua_State* L, int idx, struct ctype* ct)
{
struct cdata* cd;
memset(ct, 0, sizeof(struct ctype));
if (!lua_isuserdata(L, idx) || !lua_getmetatable(L, idx)) {
lua_pushnil(L);
return NULL;
}
if (!equals_upval(L, -1, &cdata_mt_key)) {
lua_pop(L, 1);
lua_pushnil(L);
return NULL;
}
lua_pop(L, 1);
cd = (struct cdata*) lua_touserdata(L, idx);
*ct = cd->type;
lua_getuservalue(L, idx);
if (ct->is_reference) {
return *(void**) (cd+1);
} else if (ct->pointers && !ct->is_array) {
return *(void**) (cd+1);
} else {
return cd + 1;
}
} | [
"void",
"*",
"to_cdata",
"(",
"lua_State",
"*",
"L",
",",
"int",
"idx",
",",
"struct",
"ctype",
"*",
"ct",
")",
"{",
"struct",
"cdata",
"*",
"cd",
";",
"memset",
"(",
"ct",
",",
"0",
",",
"sizeof",
"(",
"struct",
"ctype",
")",
")",
";",
"if",
"(",
"!",
"lua_isuserdata",
"(",
"L",
",",
"idx",
")",
"||",
"!",
"lua_getmetatable",
"(",
"L",
",",
"idx",
")",
")",
"{",
"lua_pushnil",
"(",
"L",
")",
";",
"return",
"NULL",
";",
"}",
"if",
"(",
"!",
"equals_upval",
"(",
"L",
",",
"-1",
",",
"&",
"cdata_mt_key",
")",
")",
"{",
"lua_pop",
"(",
"L",
",",
"1",
")",
";",
"lua_pushnil",
"(",
"L",
")",
";",
"return",
"NULL",
";",
"}",
"lua_pop",
"(",
"L",
",",
"1",
")",
";",
"cd",
"=",
"(",
"struct",
"cdata",
"*",
")",
"lua_touserdata",
"(",
"L",
",",
"idx",
")",
";",
"*",
"ct",
"=",
"cd",
"->",
"type",
";",
"lua_getuservalue",
"(",
"L",
",",
"idx",
")",
";",
"if",
"(",
"ct",
"->",
"is_reference",
")",
"{",
"return",
"*",
"(",
"void",
"*",
"*",
")",
"(",
"cd",
"+",
"1",
")",
";",
"}",
"else",
"if",
"(",
"ct",
"->",
"pointers",
"&&",
"!",
"ct",
"->",
"is_array",
")",
"{",
"return",
"*",
"(",
"void",
"*",
"*",
")",
"(",
"cd",
"+",
"1",
")",
";",
"}",
"else",
"{",
"return",
"cd",
"+",
"1",
";",
"}",
"}"
] | to_cdata returns the struct cdata* and pushes the user value onto the
stack. | [
"to_cdata",
"returns",
"the",
"struct",
"cdata",
"*",
"and",
"pushes",
"the",
"user",
"value",
"onto",
"the",
"stack",
"."
] | [
"/* mt */",
"/* mt */"
] | [
{
"param": "L",
"type": "lua_State"
},
{
"param": "idx",
"type": "int"
},
{
"param": "ct",
"type": "struct ctype"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "L",
"type": "lua_State",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "idx",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ct",
"type": "struct ctype",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
68f91af290bc320bd4e4ede9d7ddff6c77448662 | dobrichev/testgc | src/puzzle.h | [
"BSD-3-Clause"
] | C | N_Fixes | int | static int N_Fixes(const char * pg, int el) {
int n = 0;
for(int i = 0; i < 9; i++)
if(pg[cellsInGroup[el][i]] - '0')
n++;
return n;
} | //! Get valued cell count in the house <code>el</code>
| Get valued cell count in the house el | [
"Get",
"valued",
"cell",
"count",
"in",
"the",
"house",
"el"
] | static int N_Fixes(const char * pg, int el) {
int n = 0;
for(int i = 0; i < 9; i++)
if(pg[cellsInGroup[el][i]] - '0')
n++;
return n;
} | [
"static",
"int",
"N_Fixes",
"(",
"const",
"char",
"*",
"pg",
",",
"int",
"el",
")",
"{",
"int",
"n",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"9",
";",
"i",
"++",
")",
"if",
"(",
"pg",
"[",
"cellsInGroup",
"[",
"el",
"]",
"[",
"i",
"]",
"]",
"-",
"'",
"'",
")",
"n",
"++",
";",
"return",
"n",
";",
"}"
] | Get valued cell count in the house <code>el</code> | [
"Get",
"valued",
"cell",
"count",
"in",
"the",
"house",
"<code",
">",
"el<",
"/",
"code",
">"
] | [] | [
{
"param": "pg",
"type": "char"
},
{
"param": "el",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pg",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "el",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
68f91af290bc320bd4e4ede9d7ddff6c77448662 | dobrichev/testgc | src/puzzle.h | [
"BSD-3-Clause"
] | C | Init | void | void Init()
{
ncand=9; // 9 candidates on
cand.f=0x1ff; // all bits on
typ=0; // free
} | //! Initialize the cell as free with all candidates On
| Initialize the cell as free with all candidates On | [
"Initialize",
"the",
"cell",
"as",
"free",
"with",
"all",
"candidates",
"On"
] | void Init()
{
ncand=9;
cand.f=0x1ff;
typ=0;
} | [
"void",
"Init",
"(",
")",
"{",
"ncand",
"=",
"9",
";",
"cand",
".",
"f",
"=",
"0x1ff",
";",
"typ",
"=",
"0",
";",
"}"
] | Initialize the cell as free with all candidates On | [
"Initialize",
"the",
"cell",
"as",
"free",
"with",
"all",
"candidates",
"On"
] | [
"// 9 candidates on\r",
"// all bits on\r",
"// free\r"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
68f91af290bc320bd4e4ede9d7ddff6c77448662 | dobrichev/testgc | src/puzzle.h | [
"BSD-3-Clause"
] | C | Clear | int | inline int Clear (int i) {
if(cand.On(i))
{
ncand--; // one candidate less
cand.f ^= (1<<i); // clear bit
return 1;
}
return 0;
} | //! Clear a candidate for this cell
/** \return 0 if the candidate was already Off */ | Clear a candidate for this cell
\return 0 if the candidate was already Off | [
"Clear",
"a",
"candidate",
"for",
"this",
"cell",
"\\",
"return",
"0",
"if",
"the",
"candidate",
"was",
"already",
"Off"
] | inline int Clear (int i) {
if(cand.On(i))
{
ncand--;
cand.f ^= (1<<i);
return 1;
}
return 0;
} | [
"inline",
"int",
"Clear",
"(",
"int",
"i",
")",
"{",
"if",
"(",
"cand",
".",
"On",
"(",
"i",
")",
")",
"{",
"ncand",
"--",
";",
"cand",
".",
"f",
"^=",
"(",
"1",
"<<",
"i",
")",
";",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Clear a candidate for this cell
\return 0 if the candidate was already Off | [
"Clear",
"a",
"candidate",
"for",
"this",
"cell",
"\\",
"return",
"0",
"if",
"the",
"candidate",
"was",
"already",
"Off"
] | [
"// one candidate less\r",
"// clear bit\r"
] | [
{
"param": "i",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "i",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3ba6cf59f6778e0d2ecbf0f4c4c0f05d25fca939 | osvaldsson/nsd | configlexer.c | [
"BSD-3-Clause"
] | C | yy_get_previous_state | yy_state_type | static yy_state_type yy_get_previous_state (void)
{
yy_state_type yy_current_state;
char *yy_cp;
yy_current_state = (yy_start);
for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
{
YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] )
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 775 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
}
return yy_current_state;
} | /* yy_get_previous_state - get the state just before the EOB char was reached */ | get the state just before the EOB char was reached | [
"get",
"the",
"state",
"just",
"before",
"the",
"EOB",
"char",
"was",
"reached"
] | static yy_state_type yy_get_previous_state (void)
{
yy_state_type yy_current_state;
char *yy_cp;
yy_current_state = (yy_start);
for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
{
YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] )
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 775 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
}
return yy_current_state;
} | [
"static",
"yy_state_type",
"yy_get_previous_state",
"(",
"void",
")",
"{",
"yy_state_type",
"yy_current_state",
";",
"char",
"*",
"yy_cp",
";",
"yy_current_state",
"=",
"(",
"yy_start",
")",
";",
"for",
"(",
"yy_cp",
"=",
"(",
"yytext_ptr",
")",
"+",
"YY_MORE_ADJ",
";",
"yy_cp",
"<",
"(",
"yy_c_buf_p",
")",
";",
"++",
"yy_cp",
")",
"{",
"YY_CHAR",
"yy_c",
"=",
"(",
"*",
"yy_cp",
"?",
"yy_ec",
"[",
"YY_SC_TO_UI",
"(",
"*",
"yy_cp",
")",
"]",
":",
"1",
")",
";",
"if",
"(",
"yy_accept",
"[",
"yy_current_state",
"]",
")",
"{",
"(",
"yy_last_accepting_state",
")",
"=",
"yy_current_state",
";",
"(",
"yy_last_accepting_cpos",
")",
"=",
"yy_cp",
";",
"}",
"while",
"(",
"yy_chk",
"[",
"yy_base",
"[",
"yy_current_state",
"]",
"+",
"yy_c",
"]",
"!=",
"yy_current_state",
")",
"{",
"yy_current_state",
"=",
"(",
"int",
")",
"yy_def",
"[",
"yy_current_state",
"]",
";",
"if",
"(",
"yy_current_state",
">=",
"775",
")",
"yy_c",
"=",
"yy_meta",
"[",
"(",
"unsigned",
"int",
")",
"yy_c",
"]",
";",
"}",
"yy_current_state",
"=",
"yy_nxt",
"[",
"yy_base",
"[",
"yy_current_state",
"]",
"+",
"(",
"unsigned",
"int",
")",
"yy_c",
"]",
";",
"}",
"return",
"yy_current_state",
";",
"}"
] | yy_get_previous_state - get the state just before the EOB char was reached | [
"yy_get_previous_state",
"-",
"get",
"the",
"state",
"just",
"before",
"the",
"EOB",
"char",
"was",
"reached"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
3c071098a4c9b9e9423e65fc04f87d249c83d210 | paolo-losi/libextratrees | src/simplerandom.c | [
"MIT"
] | C | simplerandom_mwc2_seed | void | void simplerandom_mwc2_seed(SimpleRandomMWC2_t * p_mwc, uint32_t seed_upper, uint32_t seed_lower)
{
if ((seed_upper == 0) || (seed_upper == UINT32_C(0x9068FFFF)))
{
seed_upper = UINT32_C(0xFFFFFFFF);
}
if ((seed_lower == 0) || (seed_lower == UINT32_C(0x464FFFFF) * 1u) ||
(seed_lower == UINT32_C(0x464FFFFF) * 2u) ||
(seed_lower == UINT32_C(0x464FFFFF) * 3u))
{
seed_lower = UINT32_C(0xFFFFFFFF);
}
p_mwc->mwc_upper = seed_upper;
p_mwc->mwc_lower = seed_lower;
} | /* There are some bad seed values. See:
* http://eprint.iacr.org/2011/007.pdf
*
* Of course 0 is bad for either part.
*
* For upper part, seed value 0x9068FFFF is bad. That
* is, 36969 * 0x10000 - 1.
*
* For lower part, seed value 0x464FFFFF, or any multiple,
* is bad. That is, 18000 * 0x10000 - 1.
*/ | There are some bad seed values.
Of course 0 is bad for either part.
For upper part, seed value 0x9068FFFF is bad.
For lower part, seed value 0x464FFFFF, or any multiple,
is bad. | [
"There",
"are",
"some",
"bad",
"seed",
"values",
".",
"Of",
"course",
"0",
"is",
"bad",
"for",
"either",
"part",
".",
"For",
"upper",
"part",
"seed",
"value",
"0x9068FFFF",
"is",
"bad",
".",
"For",
"lower",
"part",
"seed",
"value",
"0x464FFFFF",
"or",
"any",
"multiple",
"is",
"bad",
"."
] | void simplerandom_mwc2_seed(SimpleRandomMWC2_t * p_mwc, uint32_t seed_upper, uint32_t seed_lower)
{
if ((seed_upper == 0) || (seed_upper == UINT32_C(0x9068FFFF)))
{
seed_upper = UINT32_C(0xFFFFFFFF);
}
if ((seed_lower == 0) || (seed_lower == UINT32_C(0x464FFFFF) * 1u) ||
(seed_lower == UINT32_C(0x464FFFFF) * 2u) ||
(seed_lower == UINT32_C(0x464FFFFF) * 3u))
{
seed_lower = UINT32_C(0xFFFFFFFF);
}
p_mwc->mwc_upper = seed_upper;
p_mwc->mwc_lower = seed_lower;
} | [
"void",
"simplerandom_mwc2_seed",
"(",
"SimpleRandomMWC2_t",
"*",
"p_mwc",
",",
"uint32_t",
"seed_upper",
",",
"uint32_t",
"seed_lower",
")",
"{",
"if",
"(",
"(",
"seed_upper",
"==",
"0",
")",
"||",
"(",
"seed_upper",
"==",
"UINT32_C",
"(",
"0x9068FFFF",
")",
")",
")",
"{",
"seed_upper",
"=",
"UINT32_C",
"(",
"0xFFFFFFFF",
")",
";",
"}",
"if",
"(",
"(",
"seed_lower",
"==",
"0",
")",
"||",
"(",
"seed_lower",
"==",
"UINT32_C",
"(",
"0x464FFFFF",
")",
"*",
"1u",
")",
"||",
"(",
"seed_lower",
"==",
"UINT32_C",
"(",
"0x464FFFFF",
")",
"*",
"2u",
")",
"||",
"(",
"seed_lower",
"==",
"UINT32_C",
"(",
"0x464FFFFF",
")",
"*",
"3u",
")",
")",
"{",
"seed_lower",
"=",
"UINT32_C",
"(",
"0xFFFFFFFF",
")",
";",
"}",
"p_mwc",
"->",
"mwc_upper",
"=",
"seed_upper",
";",
"p_mwc",
"->",
"mwc_lower",
"=",
"seed_lower",
";",
"}"
] | There are some bad seed values. | [
"There",
"are",
"some",
"bad",
"seed",
"values",
"."
] | [] | [
{
"param": "p_mwc",
"type": "SimpleRandomMWC2_t"
},
{
"param": "seed_upper",
"type": "uint32_t"
},
{
"param": "seed_lower",
"type": "uint32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p_mwc",
"type": "SimpleRandomMWC2_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "seed_upper",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "seed_lower",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3c071098a4c9b9e9423e65fc04f87d249c83d210 | paolo-losi/libextratrees | src/simplerandom.c | [
"MIT"
] | C | simplerandom_mwc2_next | uint32_t | uint32_t simplerandom_mwc2_next(SimpleRandomMWC2_t * p_mwc)
{
p_mwc->mwc_upper = 36969u * (p_mwc->mwc_upper & 0xFFFFu) + (p_mwc->mwc_upper >> 16u);
p_mwc->mwc_lower = 18000u * (p_mwc->mwc_lower & 0xFFFFu) + (p_mwc->mwc_lower >> 16u);
return (p_mwc->mwc_upper << 16u) + (p_mwc->mwc_upper >> 16u) + p_mwc->mwc_lower;
} | /*
* This is almost identical to simplerandom_mwc1_next(), except that when
* combining the upper and lower values in the last step, the upper 16 bits of
* mwc_upper are added in too, instead of just being discarded.
*/ | This is almost identical to simplerandom_mwc1_next(), except that when
combining the upper and lower values in the last step, the upper 16 bits of
mwc_upper are added in too, instead of just being discarded. | [
"This",
"is",
"almost",
"identical",
"to",
"simplerandom_mwc1_next",
"()",
"except",
"that",
"when",
"combining",
"the",
"upper",
"and",
"lower",
"values",
"in",
"the",
"last",
"step",
"the",
"upper",
"16",
"bits",
"of",
"mwc_upper",
"are",
"added",
"in",
"too",
"instead",
"of",
"just",
"being",
"discarded",
"."
] | uint32_t simplerandom_mwc2_next(SimpleRandomMWC2_t * p_mwc)
{
p_mwc->mwc_upper = 36969u * (p_mwc->mwc_upper & 0xFFFFu) + (p_mwc->mwc_upper >> 16u);
p_mwc->mwc_lower = 18000u * (p_mwc->mwc_lower & 0xFFFFu) + (p_mwc->mwc_lower >> 16u);
return (p_mwc->mwc_upper << 16u) + (p_mwc->mwc_upper >> 16u) + p_mwc->mwc_lower;
} | [
"uint32_t",
"simplerandom_mwc2_next",
"(",
"SimpleRandomMWC2_t",
"*",
"p_mwc",
")",
"{",
"p_mwc",
"->",
"mwc_upper",
"=",
"36969u",
"*",
"(",
"p_mwc",
"->",
"mwc_upper",
"&",
"0xFFFFu",
")",
"+",
"(",
"p_mwc",
"->",
"mwc_upper",
">>",
"16u",
")",
";",
"p_mwc",
"->",
"mwc_lower",
"=",
"18000u",
"*",
"(",
"p_mwc",
"->",
"mwc_lower",
"&",
"0xFFFFu",
")",
"+",
"(",
"p_mwc",
"->",
"mwc_lower",
">>",
"16u",
")",
";",
"return",
"(",
"p_mwc",
"->",
"mwc_upper",
"<<",
"16u",
")",
"+",
"(",
"p_mwc",
"->",
"mwc_upper",
">>",
"16u",
")",
"+",
"p_mwc",
"->",
"mwc_lower",
";",
"}"
] | This is almost identical to simplerandom_mwc1_next(), except that when
combining the upper and lower values in the last step, the upper 16 bits of
mwc_upper are added in too, instead of just being discarded. | [
"This",
"is",
"almost",
"identical",
"to",
"simplerandom_mwc1_next",
"()",
"except",
"that",
"when",
"combining",
"the",
"upper",
"and",
"lower",
"values",
"in",
"the",
"last",
"step",
"the",
"upper",
"16",
"bits",
"of",
"mwc_upper",
"are",
"added",
"in",
"too",
"instead",
"of",
"just",
"being",
"discarded",
"."
] | [] | [
{
"param": "p_mwc",
"type": "SimpleRandomMWC2_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p_mwc",
"type": "SimpleRandomMWC2_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3c071098a4c9b9e9423e65fc04f87d249c83d210 | paolo-losi/libextratrees | src/simplerandom.c | [
"MIT"
] | C | simplerandom_mwc64_seed | void | void simplerandom_mwc64_seed(SimpleRandomMWC64_t * p_mwc, uint32_t seed_upper, uint32_t seed_lower)
{
uint64_t seed64;
seed64 = ((uint64_t)seed_upper << 32u) + seed_lower;
if ((seed64 % UINT64_C(0x29A65EACFFFFFFFF)) == 0)
{
seed_upper = UINT32_C(0xFFFFFFFF);
seed_lower = UINT32_C(0xFFFFFFFF);
}
p_mwc->mwc_upper = seed_upper;
p_mwc->mwc_lower = seed_lower;
} | /* There are some bad seed values. See notes for MWC.
*
* For MWC64, a seed that is any multiple of
* 0x29A65EACFFFFFFFF is bad.
* That is, 698769069 * 0x100000000 - 1.
*/ | There are some bad seed values. See notes for MWC.
For MWC64, a seed that is any multiple of
0x29A65EACFFFFFFFF is bad. | [
"There",
"are",
"some",
"bad",
"seed",
"values",
".",
"See",
"notes",
"for",
"MWC",
".",
"For",
"MWC64",
"a",
"seed",
"that",
"is",
"any",
"multiple",
"of",
"0x29A65EACFFFFFFFF",
"is",
"bad",
"."
] | void simplerandom_mwc64_seed(SimpleRandomMWC64_t * p_mwc, uint32_t seed_upper, uint32_t seed_lower)
{
uint64_t seed64;
seed64 = ((uint64_t)seed_upper << 32u) + seed_lower;
if ((seed64 % UINT64_C(0x29A65EACFFFFFFFF)) == 0)
{
seed_upper = UINT32_C(0xFFFFFFFF);
seed_lower = UINT32_C(0xFFFFFFFF);
}
p_mwc->mwc_upper = seed_upper;
p_mwc->mwc_lower = seed_lower;
} | [
"void",
"simplerandom_mwc64_seed",
"(",
"SimpleRandomMWC64_t",
"*",
"p_mwc",
",",
"uint32_t",
"seed_upper",
",",
"uint32_t",
"seed_lower",
")",
"{",
"uint64_t",
"seed64",
";",
"seed64",
"=",
"(",
"(",
"uint64_t",
")",
"seed_upper",
"<<",
"32u",
")",
"+",
"seed_lower",
";",
"if",
"(",
"(",
"seed64",
"%",
"UINT64_C",
"(",
"0x29A65EACFFFFFFFF",
")",
")",
"==",
"0",
")",
"{",
"seed_upper",
"=",
"UINT32_C",
"(",
"0xFFFFFFFF",
")",
";",
"seed_lower",
"=",
"UINT32_C",
"(",
"0xFFFFFFFF",
")",
";",
"}",
"p_mwc",
"->",
"mwc_upper",
"=",
"seed_upper",
";",
"p_mwc",
"->",
"mwc_lower",
"=",
"seed_lower",
";",
"}"
] | There are some bad seed values. | [
"There",
"are",
"some",
"bad",
"seed",
"values",
"."
] | [] | [
{
"param": "p_mwc",
"type": "SimpleRandomMWC64_t"
},
{
"param": "seed_upper",
"type": "uint32_t"
},
{
"param": "seed_lower",
"type": "uint32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p_mwc",
"type": "SimpleRandomMWC64_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "seed_upper",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "seed_lower",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2a1331cbfca3bc1e06e0525a67775fbc815c1f88 | jonathanmetzman/AFLplusplus | qemu_mode/patches/afl-qemu-cpu-inl.h | [
"Apache-2.0"
] | C | afl_setup | void | static void afl_setup(void) {
char *id_str = getenv(SHM_ENV_VAR), *inst_r = getenv("AFL_INST_RATIO");
int shm_id;
if (inst_r) {
unsigned int r;
r = atoi(inst_r);
if (r > 100) r = 100;
if (!r) r = 1;
afl_inst_rms = MAP_SIZE * r / 100;
}
if (id_str) {
shm_id = atoi(id_str);
afl_area_ptr = shmat(shm_id, NULL, 0);
if (afl_area_ptr == (void *)-1) exit(1);
/* With AFL_INST_RATIO set to a low value, we want to touch the bitmap
so that the parent doesn't give up on us. */
if (inst_r) afl_area_ptr[0] = 1;
}
if (getenv("AFL_INST_LIBS")) {
afl_start_code = 0;
afl_end_code = (abi_ulong)-1;
}
/* Maintain for compatibility */
if (getenv("AFL_QEMU_COMPCOV")) { afl_compcov_level = 1; }
if (getenv("AFL_COMPCOV_LEVEL")) {
afl_compcov_level = atoi(getenv("AFL_COMPCOV_LEVEL"));
}
/* pthread_atfork() seems somewhat broken in util/rcu.c, and I'm
not entirely sure what is the cause. This disables that
behaviour, and seems to work alright? */
rcu_disable_atfork();
} | /* Set up SHM region and initialize other stuff. */ | Set up SHM region and initialize other stuff. | [
"Set",
"up",
"SHM",
"region",
"and",
"initialize",
"other",
"stuff",
"."
] | static void afl_setup(void) {
char *id_str = getenv(SHM_ENV_VAR), *inst_r = getenv("AFL_INST_RATIO");
int shm_id;
if (inst_r) {
unsigned int r;
r = atoi(inst_r);
if (r > 100) r = 100;
if (!r) r = 1;
afl_inst_rms = MAP_SIZE * r / 100;
}
if (id_str) {
shm_id = atoi(id_str);
afl_area_ptr = shmat(shm_id, NULL, 0);
if (afl_area_ptr == (void *)-1) exit(1);
if (inst_r) afl_area_ptr[0] = 1;
}
if (getenv("AFL_INST_LIBS")) {
afl_start_code = 0;
afl_end_code = (abi_ulong)-1;
}
if (getenv("AFL_QEMU_COMPCOV")) { afl_compcov_level = 1; }
if (getenv("AFL_COMPCOV_LEVEL")) {
afl_compcov_level = atoi(getenv("AFL_COMPCOV_LEVEL"));
}
rcu_disable_atfork();
} | [
"static",
"void",
"afl_setup",
"(",
"void",
")",
"{",
"char",
"*",
"id_str",
"=",
"getenv",
"(",
"SHM_ENV_VAR",
")",
",",
"*",
"inst_r",
"=",
"getenv",
"(",
"\"",
"\"",
")",
";",
"int",
"shm_id",
";",
"if",
"(",
"inst_r",
")",
"{",
"unsigned",
"int",
"r",
";",
"r",
"=",
"atoi",
"(",
"inst_r",
")",
";",
"if",
"(",
"r",
">",
"100",
")",
"r",
"=",
"100",
";",
"if",
"(",
"!",
"r",
")",
"r",
"=",
"1",
";",
"afl_inst_rms",
"=",
"MAP_SIZE",
"*",
"r",
"/",
"100",
";",
"}",
"if",
"(",
"id_str",
")",
"{",
"shm_id",
"=",
"atoi",
"(",
"id_str",
")",
";",
"afl_area_ptr",
"=",
"shmat",
"(",
"shm_id",
",",
"NULL",
",",
"0",
")",
";",
"if",
"(",
"afl_area_ptr",
"==",
"(",
"void",
"*",
")",
"-1",
")",
"exit",
"(",
"1",
")",
";",
"if",
"(",
"inst_r",
")",
"afl_area_ptr",
"[",
"0",
"]",
"=",
"1",
";",
"}",
"if",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
"{",
"afl_start_code",
"=",
"0",
";",
"afl_end_code",
"=",
"(",
"abi_ulong",
")",
"-",
"1",
";",
"}",
"if",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
"{",
"afl_compcov_level",
"=",
"1",
";",
"}",
"if",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
"{",
"afl_compcov_level",
"=",
"atoi",
"(",
"getenv",
"(",
"\"",
"\"",
")",
")",
";",
"}",
"rcu_disable_atfork",
"(",
")",
";",
"}"
] | Set up SHM region and initialize other stuff. | [
"Set",
"up",
"SHM",
"region",
"and",
"initialize",
"other",
"stuff",
"."
] | [
"/* With AFL_INST_RATIO set to a low value, we want to touch the bitmap\n so that the parent doesn't give up on us. */",
"/* Maintain for compatibility */",
"/* pthread_atfork() seems somewhat broken in util/rcu.c, and I'm\n not entirely sure what is the cause. This disables that\n behaviour, and seems to work alright? */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
2a1331cbfca3bc1e06e0525a67775fbc815c1f88 | jonathanmetzman/AFLplusplus | qemu_mode/patches/afl-qemu-cpu-inl.h | [
"Apache-2.0"
] | C | afl_forkserver | void | static void afl_forkserver(CPUState *cpu) {
static unsigned char tmp[4];
if (forkserver_installed == 1) return;
forkserver_installed = 1;
// if (!afl_area_ptr) return; // not necessary because of fixed dummy buffer
/* Tell the parent that we're alive. If the parent doesn't want
to talk, assume that we're not running in forkserver mode. */
if (write(FORKSRV_FD + 1, tmp, 4) != 4) return;
afl_forksrv_pid = getpid();
/* All right, let's await orders... */
while (1) {
pid_t child_pid;
int status, t_fd[2];
/* Whoops, parent dead? */
if (read(FORKSRV_FD, tmp, 4) != 4) exit(2);
/* Establish a channel with child to grab translation commands. We'll
read from t_fd[0], child will write to TSL_FD. */
if (pipe(t_fd) || dup2(t_fd[1], TSL_FD) < 0) exit(3);
close(t_fd[1]);
child_pid = fork();
if (child_pid < 0) exit(4);
if (!child_pid) {
/* Child process. Close descriptors and run free. */
afl_fork_child = 1;
close(FORKSRV_FD);
close(FORKSRV_FD + 1);
close(t_fd[0]);
return;
}
/* Parent. */
close(TSL_FD);
if (write(FORKSRV_FD + 1, &child_pid, 4) != 4) exit(5);
/* Collect translation requests until child dies and closes the pipe. */
afl_wait_tsl(cpu, t_fd[0]);
/* Get and relay exit status to parent. */
if (waitpid(child_pid, &status, 0) < 0) exit(6);
if (write(FORKSRV_FD + 1, &status, 4) != 4) exit(7);
}
} | /* Fork server logic, invoked once we hit _start. */ | Fork server logic, invoked once we hit _start. | [
"Fork",
"server",
"logic",
"invoked",
"once",
"we",
"hit",
"_start",
"."
] | static void afl_forkserver(CPUState *cpu) {
static unsigned char tmp[4];
if (forkserver_installed == 1) return;
forkserver_installed = 1;
if (write(FORKSRV_FD + 1, tmp, 4) != 4) return;
afl_forksrv_pid = getpid();
while (1) {
pid_t child_pid;
int status, t_fd[2];
if (read(FORKSRV_FD, tmp, 4) != 4) exit(2);
if (pipe(t_fd) || dup2(t_fd[1], TSL_FD) < 0) exit(3);
close(t_fd[1]);
child_pid = fork();
if (child_pid < 0) exit(4);
if (!child_pid) {
afl_fork_child = 1;
close(FORKSRV_FD);
close(FORKSRV_FD + 1);
close(t_fd[0]);
return;
}
close(TSL_FD);
if (write(FORKSRV_FD + 1, &child_pid, 4) != 4) exit(5);
afl_wait_tsl(cpu, t_fd[0]);
if (waitpid(child_pid, &status, 0) < 0) exit(6);
if (write(FORKSRV_FD + 1, &status, 4) != 4) exit(7);
}
} | [
"static",
"void",
"afl_forkserver",
"(",
"CPUState",
"*",
"cpu",
")",
"{",
"static",
"unsigned",
"char",
"tmp",
"[",
"4",
"]",
";",
"if",
"(",
"forkserver_installed",
"==",
"1",
")",
"return",
";",
"forkserver_installed",
"=",
"1",
";",
"if",
"(",
"write",
"(",
"FORKSRV_FD",
"+",
"1",
",",
"tmp",
",",
"4",
")",
"!=",
"4",
")",
"return",
";",
"afl_forksrv_pid",
"=",
"getpid",
"(",
")",
";",
"while",
"(",
"1",
")",
"{",
"pid_t",
"child_pid",
";",
"int",
"status",
",",
"t_fd",
"[",
"2",
"]",
";",
"if",
"(",
"read",
"(",
"FORKSRV_FD",
",",
"tmp",
",",
"4",
")",
"!=",
"4",
")",
"exit",
"(",
"2",
")",
";",
"if",
"(",
"pipe",
"(",
"t_fd",
")",
"||",
"dup2",
"(",
"t_fd",
"[",
"1",
"]",
",",
"TSL_FD",
")",
"<",
"0",
")",
"exit",
"(",
"3",
")",
";",
"close",
"(",
"t_fd",
"[",
"1",
"]",
")",
";",
"child_pid",
"=",
"fork",
"(",
")",
";",
"if",
"(",
"child_pid",
"<",
"0",
")",
"exit",
"(",
"4",
")",
";",
"if",
"(",
"!",
"child_pid",
")",
"{",
"afl_fork_child",
"=",
"1",
";",
"close",
"(",
"FORKSRV_FD",
")",
";",
"close",
"(",
"FORKSRV_FD",
"+",
"1",
")",
";",
"close",
"(",
"t_fd",
"[",
"0",
"]",
")",
";",
"return",
";",
"}",
"close",
"(",
"TSL_FD",
")",
";",
"if",
"(",
"write",
"(",
"FORKSRV_FD",
"+",
"1",
",",
"&",
"child_pid",
",",
"4",
")",
"!=",
"4",
")",
"exit",
"(",
"5",
")",
";",
"afl_wait_tsl",
"(",
"cpu",
",",
"t_fd",
"[",
"0",
"]",
")",
";",
"if",
"(",
"waitpid",
"(",
"child_pid",
",",
"&",
"status",
",",
"0",
")",
"<",
"0",
")",
"exit",
"(",
"6",
")",
";",
"if",
"(",
"write",
"(",
"FORKSRV_FD",
"+",
"1",
",",
"&",
"status",
",",
"4",
")",
"!=",
"4",
")",
"exit",
"(",
"7",
")",
";",
"}",
"}"
] | Fork server logic, invoked once we hit _start. | [
"Fork",
"server",
"logic",
"invoked",
"once",
"we",
"hit",
"_start",
"."
] | [
"// if (!afl_area_ptr) return; // not necessary because of fixed dummy buffer",
"/* Tell the parent that we're alive. If the parent doesn't want\n to talk, assume that we're not running in forkserver mode. */",
"/* All right, let's await orders... */",
"/* Whoops, parent dead? */",
"/* Establish a channel with child to grab translation commands. We'll\n read from t_fd[0], child will write to TSL_FD. */",
"/* Child process. Close descriptors and run free. */",
"/* Parent. */",
"/* Collect translation requests until child dies and closes the pipe. */",
"/* Get and relay exit status to parent. */"
] | [
{
"param": "cpu",
"type": "CPUState"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpu",
"type": "CPUState",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2a1331cbfca3bc1e06e0525a67775fbc815c1f88 | jonathanmetzman/AFLplusplus | qemu_mode/patches/afl-qemu-cpu-inl.h | [
"Apache-2.0"
] | C | afl_request_tsl | void | static void afl_request_tsl(target_ulong pc, target_ulong cb, uint32_t flags,
uint32_t cf_mask, TranslationBlock *last_tb,
int tb_exit) {
struct afl_tsl t;
struct afl_chain c;
if (!afl_fork_child) return;
t.tb.pc = pc;
t.tb.cs_base = cb;
t.tb.flags = flags;
t.tb.cf_mask = cf_mask;
t.is_chain = (last_tb != NULL);
if (write(TSL_FD, &t, sizeof(struct afl_tsl)) != sizeof(struct afl_tsl))
return;
if (t.is_chain) {
c.last_tb.pc = last_tb->pc;
c.last_tb.cs_base = last_tb->cs_base;
c.last_tb.flags = last_tb->flags;
c.cf_mask = cf_mask;
c.tb_exit = tb_exit;
if (write(TSL_FD, &c, sizeof(struct afl_chain)) != sizeof(struct afl_chain))
return;
}
} | /* This code is invoked whenever QEMU decides that it doesn't have a
translation of a particular block and needs to compute it, or when it
decides to chain two TBs together. When this happens, we tell the parent to
mirror the operation, so that the next fork() has a cached copy. */ | This code is invoked whenever QEMU decides that it doesn't have a
translation of a particular block and needs to compute it, or when it
decides to chain two TBs together. When this happens, we tell the parent to
mirror the operation, so that the next fork() has a cached copy. | [
"This",
"code",
"is",
"invoked",
"whenever",
"QEMU",
"decides",
"that",
"it",
"doesn",
"'",
"t",
"have",
"a",
"translation",
"of",
"a",
"particular",
"block",
"and",
"needs",
"to",
"compute",
"it",
"or",
"when",
"it",
"decides",
"to",
"chain",
"two",
"TBs",
"together",
".",
"When",
"this",
"happens",
"we",
"tell",
"the",
"parent",
"to",
"mirror",
"the",
"operation",
"so",
"that",
"the",
"next",
"fork",
"()",
"has",
"a",
"cached",
"copy",
"."
] | static void afl_request_tsl(target_ulong pc, target_ulong cb, uint32_t flags,
uint32_t cf_mask, TranslationBlock *last_tb,
int tb_exit) {
struct afl_tsl t;
struct afl_chain c;
if (!afl_fork_child) return;
t.tb.pc = pc;
t.tb.cs_base = cb;
t.tb.flags = flags;
t.tb.cf_mask = cf_mask;
t.is_chain = (last_tb != NULL);
if (write(TSL_FD, &t, sizeof(struct afl_tsl)) != sizeof(struct afl_tsl))
return;
if (t.is_chain) {
c.last_tb.pc = last_tb->pc;
c.last_tb.cs_base = last_tb->cs_base;
c.last_tb.flags = last_tb->flags;
c.cf_mask = cf_mask;
c.tb_exit = tb_exit;
if (write(TSL_FD, &c, sizeof(struct afl_chain)) != sizeof(struct afl_chain))
return;
}
} | [
"static",
"void",
"afl_request_tsl",
"(",
"target_ulong",
"pc",
",",
"target_ulong",
"cb",
",",
"uint32_t",
"flags",
",",
"uint32_t",
"cf_mask",
",",
"TranslationBlock",
"*",
"last_tb",
",",
"int",
"tb_exit",
")",
"{",
"struct",
"afl_tsl",
"t",
";",
"struct",
"afl_chain",
"c",
";",
"if",
"(",
"!",
"afl_fork_child",
")",
"return",
";",
"t",
".",
"tb",
".",
"pc",
"=",
"pc",
";",
"t",
".",
"tb",
".",
"cs_base",
"=",
"cb",
";",
"t",
".",
"tb",
".",
"flags",
"=",
"flags",
";",
"t",
".",
"tb",
".",
"cf_mask",
"=",
"cf_mask",
";",
"t",
".",
"is_chain",
"=",
"(",
"last_tb",
"!=",
"NULL",
")",
";",
"if",
"(",
"write",
"(",
"TSL_FD",
",",
"&",
"t",
",",
"sizeof",
"(",
"struct",
"afl_tsl",
")",
")",
"!=",
"sizeof",
"(",
"struct",
"afl_tsl",
")",
")",
"return",
";",
"if",
"(",
"t",
".",
"is_chain",
")",
"{",
"c",
".",
"last_tb",
".",
"pc",
"=",
"last_tb",
"->",
"pc",
";",
"c",
".",
"last_tb",
".",
"cs_base",
"=",
"last_tb",
"->",
"cs_base",
";",
"c",
".",
"last_tb",
".",
"flags",
"=",
"last_tb",
"->",
"flags",
";",
"c",
".",
"cf_mask",
"=",
"cf_mask",
";",
"c",
".",
"tb_exit",
"=",
"tb_exit",
";",
"if",
"(",
"write",
"(",
"TSL_FD",
",",
"&",
"c",
",",
"sizeof",
"(",
"struct",
"afl_chain",
")",
")",
"!=",
"sizeof",
"(",
"struct",
"afl_chain",
")",
")",
"return",
";",
"}",
"}"
] | This code is invoked whenever QEMU decides that it doesn't have a
translation of a particular block and needs to compute it, or when it
decides to chain two TBs together. | [
"This",
"code",
"is",
"invoked",
"whenever",
"QEMU",
"decides",
"that",
"it",
"doesn",
"'",
"t",
"have",
"a",
"translation",
"of",
"a",
"particular",
"block",
"and",
"needs",
"to",
"compute",
"it",
"or",
"when",
"it",
"decides",
"to",
"chain",
"two",
"TBs",
"together",
"."
] | [] | [
{
"param": "pc",
"type": "target_ulong"
},
{
"param": "cb",
"type": "target_ulong"
},
{
"param": "flags",
"type": "uint32_t"
},
{
"param": "cf_mask",
"type": "uint32_t"
},
{
"param": "last_tb",
"type": "TranslationBlock"
},
{
"param": "tb_exit",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "pc",
"type": "target_ulong",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cb",
"type": "target_ulong",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "flags",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cf_mask",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "last_tb",
"type": "TranslationBlock",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tb_exit",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2a1331cbfca3bc1e06e0525a67775fbc815c1f88 | jonathanmetzman/AFLplusplus | qemu_mode/patches/afl-qemu-cpu-inl.h | [
"Apache-2.0"
] | C | is_valid_addr | int | static inline int is_valid_addr(target_ulong addr) {
int l, flags;
target_ulong page;
void * p;
page = addr & TARGET_PAGE_MASK;
l = (page + TARGET_PAGE_SIZE) - addr;
flags = page_get_flags(page);
if (!(flags & PAGE_VALID) || !(flags & PAGE_READ)) return 0;
return 1;
} | /* Check if an address is valid in the current mapping */ | Check if an address is valid in the current mapping | [
"Check",
"if",
"an",
"address",
"is",
"valid",
"in",
"the",
"current",
"mapping"
] | static inline int is_valid_addr(target_ulong addr) {
int l, flags;
target_ulong page;
void * p;
page = addr & TARGET_PAGE_MASK;
l = (page + TARGET_PAGE_SIZE) - addr;
flags = page_get_flags(page);
if (!(flags & PAGE_VALID) || !(flags & PAGE_READ)) return 0;
return 1;
} | [
"static",
"inline",
"int",
"is_valid_addr",
"(",
"target_ulong",
"addr",
")",
"{",
"int",
"l",
",",
"flags",
";",
"target_ulong",
"page",
";",
"void",
"*",
"p",
";",
"page",
"=",
"addr",
"&",
"TARGET_PAGE_MASK",
";",
"l",
"=",
"(",
"page",
"+",
"TARGET_PAGE_SIZE",
")",
"-",
"addr",
";",
"flags",
"=",
"page_get_flags",
"(",
"page",
")",
";",
"if",
"(",
"!",
"(",
"flags",
"&",
"PAGE_VALID",
")",
"||",
"!",
"(",
"flags",
"&",
"PAGE_READ",
")",
")",
"return",
"0",
";",
"return",
"1",
";",
"}"
] | Check if an address is valid in the current mapping | [
"Check",
"if",
"an",
"address",
"is",
"valid",
"in",
"the",
"current",
"mapping"
] | [] | [
{
"param": "addr",
"type": "target_ulong"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "addr",
"type": "target_ulong",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
2a1331cbfca3bc1e06e0525a67775fbc815c1f88 | jonathanmetzman/AFLplusplus | qemu_mode/patches/afl-qemu-cpu-inl.h | [
"Apache-2.0"
] | C | afl_wait_tsl | void | static void afl_wait_tsl(CPUState *cpu, int fd) {
struct afl_tsl t;
struct afl_chain c;
TranslationBlock *tb, *last_tb;
while (1) {
u8 invalid_pc = 0;
/* Broken pipe means it's time to return to the fork server routine. */
if (read(fd, &t, sizeof(struct afl_tsl)) != sizeof(struct afl_tsl)) break;
tb = tb_htable_lookup(cpu, t.tb.pc, t.tb.cs_base, t.tb.flags, t.tb.cf_mask);
if (!tb) {
/* The child may request to transate a block of memory that is not
mapped in the parent (e.g. jitted code or dlopened code).
This causes a SIGSEV in gen_intermediate_code() and associated
subroutines. We simply avoid caching of such blocks. */
if (is_valid_addr(t.tb.pc)) {
mmap_lock();
tb = tb_gen_code(cpu, t.tb.pc, t.tb.cs_base, t.tb.flags, t.tb.cf_mask);
mmap_unlock();
} else {
invalid_pc = 1;
}
}
if (t.is_chain) {
if (read(fd, &c, sizeof(struct afl_chain)) != sizeof(struct afl_chain))
break;
if (!invalid_pc) {
last_tb = tb_htable_lookup(cpu, c.last_tb.pc, c.last_tb.cs_base,
c.last_tb.flags, c.cf_mask);
if (last_tb) { tb_add_jump(last_tb, c.tb_exit, tb); }
}
}
}
close(fd);
} | /* This is the other side of the same channel. Since timeouts are handled by
afl-fuzz simply killing the child, we can just wait until the pipe breaks. */ | This is the other side of the same channel. Since timeouts are handled by
afl-fuzz simply killing the child, we can just wait until the pipe breaks. | [
"This",
"is",
"the",
"other",
"side",
"of",
"the",
"same",
"channel",
".",
"Since",
"timeouts",
"are",
"handled",
"by",
"afl",
"-",
"fuzz",
"simply",
"killing",
"the",
"child",
"we",
"can",
"just",
"wait",
"until",
"the",
"pipe",
"breaks",
"."
] | static void afl_wait_tsl(CPUState *cpu, int fd) {
struct afl_tsl t;
struct afl_chain c;
TranslationBlock *tb, *last_tb;
while (1) {
u8 invalid_pc = 0;
if (read(fd, &t, sizeof(struct afl_tsl)) != sizeof(struct afl_tsl)) break;
tb = tb_htable_lookup(cpu, t.tb.pc, t.tb.cs_base, t.tb.flags, t.tb.cf_mask);
if (!tb) {
if (is_valid_addr(t.tb.pc)) {
mmap_lock();
tb = tb_gen_code(cpu, t.tb.pc, t.tb.cs_base, t.tb.flags, t.tb.cf_mask);
mmap_unlock();
} else {
invalid_pc = 1;
}
}
if (t.is_chain) {
if (read(fd, &c, sizeof(struct afl_chain)) != sizeof(struct afl_chain))
break;
if (!invalid_pc) {
last_tb = tb_htable_lookup(cpu, c.last_tb.pc, c.last_tb.cs_base,
c.last_tb.flags, c.cf_mask);
if (last_tb) { tb_add_jump(last_tb, c.tb_exit, tb); }
}
}
}
close(fd);
} | [
"static",
"void",
"afl_wait_tsl",
"(",
"CPUState",
"*",
"cpu",
",",
"int",
"fd",
")",
"{",
"struct",
"afl_tsl",
"t",
";",
"struct",
"afl_chain",
"c",
";",
"TranslationBlock",
"*",
"tb",
",",
"*",
"last_tb",
";",
"while",
"(",
"1",
")",
"{",
"u8",
"invalid_pc",
"=",
"0",
";",
"if",
"(",
"read",
"(",
"fd",
",",
"&",
"t",
",",
"sizeof",
"(",
"struct",
"afl_tsl",
")",
")",
"!=",
"sizeof",
"(",
"struct",
"afl_tsl",
")",
")",
"break",
";",
"tb",
"=",
"tb_htable_lookup",
"(",
"cpu",
",",
"t",
".",
"tb",
".",
"pc",
",",
"t",
".",
"tb",
".",
"cs_base",
",",
"t",
".",
"tb",
".",
"flags",
",",
"t",
".",
"tb",
".",
"cf_mask",
")",
";",
"if",
"(",
"!",
"tb",
")",
"{",
"if",
"(",
"is_valid_addr",
"(",
"t",
".",
"tb",
".",
"pc",
")",
")",
"{",
"mmap_lock",
"(",
")",
";",
"tb",
"=",
"tb_gen_code",
"(",
"cpu",
",",
"t",
".",
"tb",
".",
"pc",
",",
"t",
".",
"tb",
".",
"cs_base",
",",
"t",
".",
"tb",
".",
"flags",
",",
"t",
".",
"tb",
".",
"cf_mask",
")",
";",
"mmap_unlock",
"(",
")",
";",
"}",
"else",
"{",
"invalid_pc",
"=",
"1",
";",
"}",
"}",
"if",
"(",
"t",
".",
"is_chain",
")",
"{",
"if",
"(",
"read",
"(",
"fd",
",",
"&",
"c",
",",
"sizeof",
"(",
"struct",
"afl_chain",
")",
")",
"!=",
"sizeof",
"(",
"struct",
"afl_chain",
")",
")",
"break",
";",
"if",
"(",
"!",
"invalid_pc",
")",
"{",
"last_tb",
"=",
"tb_htable_lookup",
"(",
"cpu",
",",
"c",
".",
"last_tb",
".",
"pc",
",",
"c",
".",
"last_tb",
".",
"cs_base",
",",
"c",
".",
"last_tb",
".",
"flags",
",",
"c",
".",
"cf_mask",
")",
";",
"if",
"(",
"last_tb",
")",
"{",
"tb_add_jump",
"(",
"last_tb",
",",
"c",
".",
"tb_exit",
",",
"tb",
")",
";",
"}",
"}",
"}",
"}",
"close",
"(",
"fd",
")",
";",
"}"
] | This is the other side of the same channel. | [
"This",
"is",
"the",
"other",
"side",
"of",
"the",
"same",
"channel",
"."
] | [
"/* Broken pipe means it's time to return to the fork server routine. */",
"/* The child may request to transate a block of memory that is not\n mapped in the parent (e.g. jitted code or dlopened code).\n This causes a SIGSEV in gen_intermediate_code() and associated\n subroutines. We simply avoid caching of such blocks. */"
] | [
{
"param": "cpu",
"type": "CPUState"
},
{
"param": "fd",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cpu",
"type": "CPUState",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "fd",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
611beb53422c6eb05be87d458b8c8c2928d68f59 | Fryguy/slp | ext/slp/slp.c | [
"MIT"
] | C | slp_check | void | static void
slp_check(SLPError err, char *method) {
if (err != SLP_OK) {
rb_raise(rb_eSLPError, "%s.%s (errcode=%d)", class_name, method, err);
}
} | /*
* Check the slplib return code and raise a Ruby exception,
* with descriptive text, if there was an error.
*/ | Check the slplib return code and raise a Ruby exception,
with descriptive text, if there was an error. | [
"Check",
"the",
"slplib",
"return",
"code",
"and",
"raise",
"a",
"Ruby",
"exception",
"with",
"descriptive",
"text",
"if",
"there",
"was",
"an",
"error",
"."
] | static void
slp_check(SLPError err, char *method) {
if (err != SLP_OK) {
rb_raise(rb_eSLPError, "%s.%s (errcode=%d)", class_name, method, err);
}
} | [
"static",
"void",
"slp_check",
"(",
"SLPError",
"err",
",",
"char",
"*",
"method",
")",
"{",
"if",
"(",
"err",
"!=",
"SLP_OK",
")",
"{",
"rb_raise",
"(",
"rb_eSLPError",
",",
"\"",
"\"",
",",
"class_name",
",",
"method",
",",
"err",
")",
";",
"}",
"}"
] | Check the slplib return code and raise a Ruby exception,
with descriptive text, if there was an error. | [
"Check",
"the",
"slplib",
"return",
"code",
"and",
"raise",
"a",
"Ruby",
"exception",
"with",
"descriptive",
"text",
"if",
"there",
"was",
"an",
"error",
"."
] | [] | [
{
"param": "err",
"type": "SLPError"
},
{
"param": "method",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "err",
"type": "SLPError",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "method",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | writeRegister | int | int writeRegister(void *ap, int position)
{
struct DogType *dato;
dato = ap;
FILE *f;
f = fopen("dataDogs.dat", "ab");
int d = fseek(f, position * sizeof(struct DogType), SEEK_SET);
if (f == NULL)
{
perror("Could not open a file");
exit(-1);
}
int r = fwrite(dato, sizeof(struct DogType), 1, f);
if (r == 0)
{
perror("Could not write Struct");
exit(-1);
}
fclose(f);
return 0;
} | //funcion para escribir un nuevo registro en el archivo | funcion para escribir un nuevo registro en el archivo | [
"funcion",
"para",
"escribir",
"un",
"nuevo",
"registro",
"en",
"el",
"archivo"
] | int writeRegister(void *ap, int position)
{
struct DogType *dato;
dato = ap;
FILE *f;
f = fopen("dataDogs.dat", "ab");
int d = fseek(f, position * sizeof(struct DogType), SEEK_SET);
if (f == NULL)
{
perror("Could not open a file");
exit(-1);
}
int r = fwrite(dato, sizeof(struct DogType), 1, f);
if (r == 0)
{
perror("Could not write Struct");
exit(-1);
}
fclose(f);
return 0;
} | [
"int",
"writeRegister",
"(",
"void",
"*",
"ap",
",",
"int",
"position",
")",
"{",
"struct",
"DogType",
"*",
"dato",
";",
"dato",
"=",
"ap",
";",
"FILE",
"*",
"f",
";",
"f",
"=",
"fopen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"int",
"d",
"=",
"fseek",
"(",
"f",
",",
"position",
"*",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"SEEK_SET",
")",
";",
"if",
"(",
"f",
"==",
"NULL",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"int",
"r",
"=",
"fwrite",
"(",
"dato",
",",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"1",
",",
"f",
")",
";",
"if",
"(",
"r",
"==",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"fclose",
"(",
"f",
")",
";",
"return",
"0",
";",
"}"
] | funcion para escribir un nuevo registro en el archivo | [
"funcion",
"para",
"escribir",
"un",
"nuevo",
"registro",
"en",
"el",
"archivo"
] | [] | [
{
"param": "ap",
"type": "void"
},
{
"param": "position",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ap",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "position",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | findByIndex | void | void findByIndex(struct DogType *ap, int index, FILE *f)
{
struct DogType reg;
int d = fseek(f, index * sizeof(struct DogType), SEEK_SET);
if (d == -1)
{
printf("error al mover al index\n");
}
int r = fread(®, sizeof(struct DogType), 1, f);
if (r == 0)
{
perror("Could no read structure");
exit(-1);
}
strcpy(ap->name, reg.name);
strcpy(ap->type, reg.type);
ap->age = reg.age;
strcpy(ap->breed, reg.breed);
ap->height = reg.height;
ap->weight = reg.weight;
ap->sex = reg.sex;
ap->deleted = reg.deleted;
ap->index = reg.index;
ap->prevHashIndex = reg.prevHashIndex;
ap->medicalHistoryID = reg.medicalHistoryID;
} | //funcion que nos permite buscar una estructura dada su posicion en la tabla | funcion que nos permite buscar una estructura dada su posicion en la tabla | [
"funcion",
"que",
"nos",
"permite",
"buscar",
"una",
"estructura",
"dada",
"su",
"posicion",
"en",
"la",
"tabla"
] | void findByIndex(struct DogType *ap, int index, FILE *f)
{
struct DogType reg;
int d = fseek(f, index * sizeof(struct DogType), SEEK_SET);
if (d == -1)
{
printf("error al mover al index\n");
}
int r = fread(®, sizeof(struct DogType), 1, f);
if (r == 0)
{
perror("Could no read structure");
exit(-1);
}
strcpy(ap->name, reg.name);
strcpy(ap->type, reg.type);
ap->age = reg.age;
strcpy(ap->breed, reg.breed);
ap->height = reg.height;
ap->weight = reg.weight;
ap->sex = reg.sex;
ap->deleted = reg.deleted;
ap->index = reg.index;
ap->prevHashIndex = reg.prevHashIndex;
ap->medicalHistoryID = reg.medicalHistoryID;
} | [
"void",
"findByIndex",
"(",
"struct",
"DogType",
"*",
"ap",
",",
"int",
"index",
",",
"FILE",
"*",
"f",
")",
"{",
"struct",
"DogType",
"reg",
";",
"int",
"d",
"=",
"fseek",
"(",
"f",
",",
"index",
"*",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"SEEK_SET",
")",
";",
"if",
"(",
"d",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"int",
"r",
"=",
"fread",
"(",
"&",
"reg",
",",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"1",
",",
"f",
")",
";",
"if",
"(",
"r",
"==",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"strcpy",
"(",
"ap",
"->",
"name",
",",
"reg",
".",
"name",
")",
";",
"strcpy",
"(",
"ap",
"->",
"type",
",",
"reg",
".",
"type",
")",
";",
"ap",
"->",
"age",
"=",
"reg",
".",
"age",
";",
"strcpy",
"(",
"ap",
"->",
"breed",
",",
"reg",
".",
"breed",
")",
";",
"ap",
"->",
"height",
"=",
"reg",
".",
"height",
";",
"ap",
"->",
"weight",
"=",
"reg",
".",
"weight",
";",
"ap",
"->",
"sex",
"=",
"reg",
".",
"sex",
";",
"ap",
"->",
"deleted",
"=",
"reg",
".",
"deleted",
";",
"ap",
"->",
"index",
"=",
"reg",
".",
"index",
";",
"ap",
"->",
"prevHashIndex",
"=",
"reg",
".",
"prevHashIndex",
";",
"ap",
"->",
"medicalHistoryID",
"=",
"reg",
".",
"medicalHistoryID",
";",
"}"
] | funcion que nos permite buscar una estructura dada su posicion en la tabla | [
"funcion",
"que",
"nos",
"permite",
"buscar",
"una",
"estructura",
"dada",
"su",
"posicion",
"en",
"la",
"tabla"
] | [] | [
{
"param": "ap",
"type": "struct DogType"
},
{
"param": "index",
"type": "int"
},
{
"param": "f",
"type": "FILE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ap",
"type": "struct DogType",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "index",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "f",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | countRecords | int | int countRecords(FILE *f)
{
int r;
r = fseek(f, 0 * sizeof(struct DogType), SEEK_SET);
if (r == -1)
{
printf("error al mover al index\n");
}
struct DogType perro = {"", "", 0, "", 0, 0.0, 'f', 0, 0};
int count = 0;
while (fread(&perro, sizeof(struct DogType), 1, f) != 0)
{
count++;
}
return count;
} | //funcion para contar la cantidad de registros | funcion para contar la cantidad de registros | [
"funcion",
"para",
"contar",
"la",
"cantidad",
"de",
"registros"
] | int countRecords(FILE *f)
{
int r;
r = fseek(f, 0 * sizeof(struct DogType), SEEK_SET);
if (r == -1)
{
printf("error al mover al index\n");
}
struct DogType perro = {"", "", 0, "", 0, 0.0, 'f', 0, 0};
int count = 0;
while (fread(&perro, sizeof(struct DogType), 1, f) != 0)
{
count++;
}
return count;
} | [
"int",
"countRecords",
"(",
"FILE",
"*",
"f",
")",
"{",
"int",
"r",
";",
"r",
"=",
"fseek",
"(",
"f",
",",
"0",
"*",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"SEEK_SET",
")",
";",
"if",
"(",
"r",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"struct",
"DogType",
"perro",
"=",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"0",
",",
"\"",
"\"",
",",
"0",
",",
"0.0",
",",
"'",
"'",
",",
"0",
",",
"0",
"}",
";",
"int",
"count",
"=",
"0",
";",
"while",
"(",
"fread",
"(",
"&",
"perro",
",",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"1",
",",
"f",
")",
"!=",
"0",
")",
"{",
"count",
"++",
";",
"}",
"return",
"count",
";",
"}"
] | funcion para contar la cantidad de registros | [
"funcion",
"para",
"contar",
"la",
"cantidad",
"de",
"registros"
] | [] | [
{
"param": "f",
"type": "FILE"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "f",
"type": "FILE",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | calculateHash | null | unsigned int calculateHash(const char *word)
{
unsigned int hash = 0, c;
for (size_t i = 0; word[i] != '\0'; i++)
{
c = (unsigned char)word[i];
hash = (hash << 3) + (hash >> (sizeof(hash) * CHAR_BIT - 3)) + c;
}
return hash % HASHSIZE;
} | //funcion para calcular el has de un string | funcion para calcular el has de un string | [
"funcion",
"para",
"calcular",
"el",
"has",
"de",
"un",
"string"
] | unsigned int calculateHash(const char *word)
{
unsigned int hash = 0, c;
for (size_t i = 0; word[i] != '\0'; i++)
{
c = (unsigned char)word[i];
hash = (hash << 3) + (hash >> (sizeof(hash) * CHAR_BIT - 3)) + c;
}
return hash % HASHSIZE;
} | [
"unsigned",
"int",
"calculateHash",
"(",
"const",
"char",
"*",
"word",
")",
"{",
"unsigned",
"int",
"hash",
"=",
"0",
",",
"c",
";",
"for",
"(",
"size_t",
"i",
"=",
"0",
";",
"word",
"[",
"i",
"]",
"!=",
"'",
"\\0",
"'",
";",
"i",
"++",
")",
"{",
"c",
"=",
"(",
"unsigned",
"char",
")",
"word",
"[",
"i",
"]",
";",
"hash",
"=",
"(",
"hash",
"<<",
"3",
")",
"+",
"(",
"hash",
">>",
"(",
"sizeof",
"(",
"hash",
")",
"*",
"CHAR_BIT",
"-",
"3",
")",
")",
"+",
"c",
";",
"}",
"return",
"hash",
"%",
"HASHSIZE",
";",
"}"
] | funcion para calcular el has de un string | [
"funcion",
"para",
"calcular",
"el",
"has",
"de",
"un",
"string"
] | [] | [
{
"param": "word",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "word",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | writeHash | void | void writeHash()
{
int status = remove("hash.dat");
if (status == 0)
{
printf("Hash file deleted\n");
}
FILE *f;
f = fopen("hash.dat", "ab+");
if (f == NULL)
{
perror("Could not open file");
exit(-1);
}
int r = fwrite(lastHashIndex, sizeof(lastHashIndex), 1, f);
if (r == 0)
{
perror("Could not write Struct");
exit(-1);
}
fclose(f);
} | //funcion para grabar el hash en disco | funcion para grabar el hash en disco | [
"funcion",
"para",
"grabar",
"el",
"hash",
"en",
"disco"
] | void writeHash()
{
int status = remove("hash.dat");
if (status == 0)
{
printf("Hash file deleted\n");
}
FILE *f;
f = fopen("hash.dat", "ab+");
if (f == NULL)
{
perror("Could not open file");
exit(-1);
}
int r = fwrite(lastHashIndex, sizeof(lastHashIndex), 1, f);
if (r == 0)
{
perror("Could not write Struct");
exit(-1);
}
fclose(f);
} | [
"void",
"writeHash",
"(",
")",
"{",
"int",
"status",
"=",
"remove",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"status",
"==",
"0",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"FILE",
"*",
"f",
";",
"f",
"=",
"fopen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"f",
"==",
"NULL",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"int",
"r",
"=",
"fwrite",
"(",
"lastHashIndex",
",",
"sizeof",
"(",
"lastHashIndex",
")",
",",
"1",
",",
"f",
")",
";",
"if",
"(",
"r",
"==",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"fclose",
"(",
"f",
")",
";",
"}"
] | funcion para grabar el hash en disco | [
"funcion",
"para",
"grabar",
"el",
"hash",
"en",
"disco"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | readHash | void | void readHash()
{
FILE *f;
f = fopen("hash.dat", "rb");
int d = fseek(f, 0 * sizeof(struct DogType), SEEK_SET);
if (d == -1)
{
printf("error al mover al index\n");
}
if (f == NULL)
{
perror("Could not open file");
exit(-1);
}
int r = fread(lastHashIndex, sizeof(lastHashIndex), 1, f);
if (r == 0)
{
perror("Could not read Struct hash");
exit(-1);
}
fclose(f);
} | //funcion para leer el hash desde el archivo | funcion para leer el hash desde el archivo | [
"funcion",
"para",
"leer",
"el",
"hash",
"desde",
"el",
"archivo"
] | void readHash()
{
FILE *f;
f = fopen("hash.dat", "rb");
int d = fseek(f, 0 * sizeof(struct DogType), SEEK_SET);
if (d == -1)
{
printf("error al mover al index\n");
}
if (f == NULL)
{
perror("Could not open file");
exit(-1);
}
int r = fread(lastHashIndex, sizeof(lastHashIndex), 1, f);
if (r == 0)
{
perror("Could not read Struct hash");
exit(-1);
}
fclose(f);
} | [
"void",
"readHash",
"(",
")",
"{",
"FILE",
"*",
"f",
";",
"f",
"=",
"fopen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"int",
"d",
"=",
"fseek",
"(",
"f",
",",
"0",
"*",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"SEEK_SET",
")",
";",
"if",
"(",
"d",
"==",
"-1",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"if",
"(",
"f",
"==",
"NULL",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"int",
"r",
"=",
"fread",
"(",
"lastHashIndex",
",",
"sizeof",
"(",
"lastHashIndex",
")",
",",
"1",
",",
"f",
")",
";",
"if",
"(",
"r",
"==",
"0",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"fclose",
"(",
"f",
")",
";",
"}"
] | funcion para leer el hash desde el archivo | [
"funcion",
"para",
"leer",
"el",
"hash",
"desde",
"el",
"archivo"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | validateRegValue | int | int validateRegValue(int type, char input[MAXINPUT])
{
switch (type)
{
case 1:
if (strlen(input) <= 32)
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 2:
if (strlen(input) <= 32)
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 3:
if (validateInteger(input))
{
int value;
sscanf(input, "%d", &value);
if (value < 2147483648 && value >= 0)
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 4:
if (strlen(input) <= 16)
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 5:
if (validateInteger(input))
{
int value;
sscanf(input, "%d", &value);
if (value < 2147483648 && value >= 0)
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 6:
if (validateFloat(input))
{
float value = strtof(input, NULL);
if (value < 3.40282e+38 && value >= 0.0)
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 7:
if (strlen(input) == 1 && (strcmp(input, "H") == 0 || strcmp(input, "M") == 0))
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
default:
return 1;
break;
}
} | // funcion que valida los datos ingresados por el usuario al insertar registro | funcion que valida los datos ingresados por el usuario al insertar registro | [
"funcion",
"que",
"valida",
"los",
"datos",
"ingresados",
"por",
"el",
"usuario",
"al",
"insertar",
"registro"
] | int validateRegValue(int type, char input[MAXINPUT])
{
switch (type)
{
case 1:
if (strlen(input) <= 32)
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 2:
if (strlen(input) <= 32)
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 3:
if (validateInteger(input))
{
int value;
sscanf(input, "%d", &value);
if (value < 2147483648 && value >= 0)
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 4:
if (strlen(input) <= 16)
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 5:
if (validateInteger(input))
{
int value;
sscanf(input, "%d", &value);
if (value < 2147483648 && value >= 0)
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 6:
if (validateFloat(input))
{
float value = strtof(input, NULL);
if (value < 3.40282e+38 && value >= 0.0)
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
case 7:
if (strlen(input) == 1 && (strcmp(input, "H") == 0 || strcmp(input, "M") == 0))
{
return 1;
}
else
{
printf("El dato ingresado no es valido\n\n");
return 0;
}
break;
default:
return 1;
break;
}
} | [
"int",
"validateRegValue",
"(",
"int",
"type",
",",
"char",
"input",
"[",
"MAXINPUT",
"]",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"1",
":",
"if",
"(",
"strlen",
"(",
"input",
")",
"<=",
"32",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"return",
"0",
";",
"}",
"break",
";",
"case",
"2",
":",
"if",
"(",
"strlen",
"(",
"input",
")",
"<=",
"32",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"return",
"0",
";",
"}",
"break",
";",
"case",
"3",
":",
"if",
"(",
"validateInteger",
"(",
"input",
")",
")",
"{",
"int",
"value",
";",
"sscanf",
"(",
"input",
",",
"\"",
"\"",
",",
"&",
"value",
")",
";",
"if",
"(",
"value",
"<",
"2147483648",
"&&",
"value",
">=",
"0",
")",
"return",
"1",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"return",
"0",
";",
"}",
"break",
";",
"case",
"4",
":",
"if",
"(",
"strlen",
"(",
"input",
")",
"<=",
"16",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"return",
"0",
";",
"}",
"break",
";",
"case",
"5",
":",
"if",
"(",
"validateInteger",
"(",
"input",
")",
")",
"{",
"int",
"value",
";",
"sscanf",
"(",
"input",
",",
"\"",
"\"",
",",
"&",
"value",
")",
";",
"if",
"(",
"value",
"<",
"2147483648",
"&&",
"value",
">=",
"0",
")",
"return",
"1",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"return",
"0",
";",
"}",
"break",
";",
"case",
"6",
":",
"if",
"(",
"validateFloat",
"(",
"input",
")",
")",
"{",
"float",
"value",
"=",
"strtof",
"(",
"input",
",",
"NULL",
")",
";",
"if",
"(",
"value",
"<",
"3.40282e+38",
"&&",
"value",
">=",
"0.0",
")",
"return",
"1",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"return",
"0",
";",
"}",
"break",
";",
"case",
"7",
":",
"if",
"(",
"strlen",
"(",
"input",
")",
"==",
"1",
"&&",
"(",
"strcmp",
"(",
"input",
",",
"\"",
"\"",
")",
"==",
"0",
"||",
"strcmp",
"(",
"input",
",",
"\"",
"\"",
")",
"==",
"0",
")",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
";",
"return",
"0",
";",
"}",
"break",
";",
"default",
":",
"return",
"1",
";",
"break",
";",
"}",
"}"
] | funcion que valida los datos ingresados por el usuario al insertar registro | [
"funcion",
"que",
"valida",
"los",
"datos",
"ingresados",
"por",
"el",
"usuario",
"al",
"insertar",
"registro"
] | [] | [
{
"param": "type",
"type": "int"
},
{
"param": "input",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "type",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "input",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5995abf4ba350ad3c282cc4589a9f0fe50f977c | FernandoMorantes/Practica_SO_Linux | p1-dogProgram.c | [
"Apache-2.0"
] | C | eraseFunction | int | int eraseFunction(int sizeOfRegisters, int indexToDelete)
{
FILE *f;
FILE *fp2;
for (int i = 0; i < 2000; i++)
{
lastHashIndex[i] = -1;
}
struct DogType reg;
fp2 = fopen("dataDogsCopy.dat", "ab+");
if (fp2 == NULL)
{
perror("Could not open a file");
exit(-1);
}
f = fopen("dataDogs.dat", "ab+");
if (f == NULL)
{
perror("Could not open a file");
exit(-1);
}
///BORRADO DE HISTORIA MEDICA
struct DogType aux;
findByIndex(&aux, indexToDelete, f);
int iDMedical = aux.medicalHistoryID;
char fileNameNumber[256];
char path[256] = "Historias_clinicas/";
sprintf(fileNameNumber, "%d", iDMedical);
strcat(path, fileNameNumber);
strcat(path, ".txt");
int yt = fseek(f, 0, SEEK_SET);
for (int i = 0; i < indexToDelete; i++)
{
int g = fread(®, sizeof(struct DogType), 1, f);
reg.index = i;
int hash = calculateHash(reg.name);
reg.prevHashIndex = lastHashIndex[hash];
lastHashIndex[hash] = i;
int gg = fwrite(®, sizeof(struct DogType), 1, fp2);
int seek = fseek(f, 0, SEEK_CUR);
}
if (fp2 == NULL)
{
perror("Could not open a file");
exit(-1);
}
if (!(indexToDelete == (sizeOfRegisters - 1)))
{
int seek = fseek(f, ((indexToDelete + 1) * sizeof(struct DogType)), SEEK_SET);
for (int j = (indexToDelete + 1); j < sizeOfRegisters; j++)
{
int g = fread(®, sizeof(struct DogType), 1, f);
reg.index = (j - 1);
int hash = calculateHash(reg.name);
reg.prevHashIndex = lastHashIndex[hash];
lastHashIndex[hash] = (j - 1);
int gg = fwrite(®, sizeof(struct DogType), 1, fp2);
}
}
fclose(f);
fclose(fp2);
clearScreen();
if (remove("dataDogs.dat") == 0)
{
printf("---------------------------------------------------------------------------\n");
printf("EL REGISTRO FUE ELIMINADO CORRECTAMENTE\n");
printf("---------------------------------------------------------------------------\n");
}
else
{
printf("---------------------------------------------------------------------------\n");
printf("ERROR: NO SE PUDO ELIMINAR EL REGISTRO\n");
printf("---------------------------------------------------------------------------\n");
}
if (remove(path) == 0)
{
printf("LA HISTORIA CLINICA FUE ELIMINADA CORRECTAMENTE\n");
printf("---------------------------------------------------------------------------\n");
}
else
{
printf("NO SE ENCONTRO HISTORIA CLINICA\n");
printf("---------------------------------------------------------------------------\n");
}
int err = rename("dataDogsCopy.dat", "dataDogs.dat");
if (err == -1)
{
puts("Error al renombrar el archivo");
}
writeHash();
readHash();
REGISTROS--;
return 0;
} | //funcion para elimiinar un registro dada la cantidad total de registros y la posicion del elemento que se desea eiminar del archivo | funcion para elimiinar un registro dada la cantidad total de registros y la posicion del elemento que se desea eiminar del archivo | [
"funcion",
"para",
"elimiinar",
"un",
"registro",
"dada",
"la",
"cantidad",
"total",
"de",
"registros",
"y",
"la",
"posicion",
"del",
"elemento",
"que",
"se",
"desea",
"eiminar",
"del",
"archivo"
] | int eraseFunction(int sizeOfRegisters, int indexToDelete)
{
FILE *f;
FILE *fp2;
for (int i = 0; i < 2000; i++)
{
lastHashIndex[i] = -1;
}
struct DogType reg;
fp2 = fopen("dataDogsCopy.dat", "ab+");
if (fp2 == NULL)
{
perror("Could not open a file");
exit(-1);
}
f = fopen("dataDogs.dat", "ab+");
if (f == NULL)
{
perror("Could not open a file");
exit(-1);
}
struct DogType aux;
findByIndex(&aux, indexToDelete, f);
int iDMedical = aux.medicalHistoryID;
char fileNameNumber[256];
char path[256] = "Historias_clinicas/";
sprintf(fileNameNumber, "%d", iDMedical);
strcat(path, fileNameNumber);
strcat(path, ".txt");
int yt = fseek(f, 0, SEEK_SET);
for (int i = 0; i < indexToDelete; i++)
{
int g = fread(®, sizeof(struct DogType), 1, f);
reg.index = i;
int hash = calculateHash(reg.name);
reg.prevHashIndex = lastHashIndex[hash];
lastHashIndex[hash] = i;
int gg = fwrite(®, sizeof(struct DogType), 1, fp2);
int seek = fseek(f, 0, SEEK_CUR);
}
if (fp2 == NULL)
{
perror("Could not open a file");
exit(-1);
}
if (!(indexToDelete == (sizeOfRegisters - 1)))
{
int seek = fseek(f, ((indexToDelete + 1) * sizeof(struct DogType)), SEEK_SET);
for (int j = (indexToDelete + 1); j < sizeOfRegisters; j++)
{
int g = fread(®, sizeof(struct DogType), 1, f);
reg.index = (j - 1);
int hash = calculateHash(reg.name);
reg.prevHashIndex = lastHashIndex[hash];
lastHashIndex[hash] = (j - 1);
int gg = fwrite(®, sizeof(struct DogType), 1, fp2);
}
}
fclose(f);
fclose(fp2);
clearScreen();
if (remove("dataDogs.dat") == 0)
{
printf("---------------------------------------------------------------------------\n");
printf("EL REGISTRO FUE ELIMINADO CORRECTAMENTE\n");
printf("---------------------------------------------------------------------------\n");
}
else
{
printf("---------------------------------------------------------------------------\n");
printf("ERROR: NO SE PUDO ELIMINAR EL REGISTRO\n");
printf("---------------------------------------------------------------------------\n");
}
if (remove(path) == 0)
{
printf("LA HISTORIA CLINICA FUE ELIMINADA CORRECTAMENTE\n");
printf("---------------------------------------------------------------------------\n");
}
else
{
printf("NO SE ENCONTRO HISTORIA CLINICA\n");
printf("---------------------------------------------------------------------------\n");
}
int err = rename("dataDogsCopy.dat", "dataDogs.dat");
if (err == -1)
{
puts("Error al renombrar el archivo");
}
writeHash();
readHash();
REGISTROS--;
return 0;
} | [
"int",
"eraseFunction",
"(",
"int",
"sizeOfRegisters",
",",
"int",
"indexToDelete",
")",
"{",
"FILE",
"*",
"f",
";",
"FILE",
"*",
"fp2",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"2000",
";",
"i",
"++",
")",
"{",
"lastHashIndex",
"[",
"i",
"]",
"=",
"-1",
";",
"}",
"struct",
"DogType",
"reg",
";",
"fp2",
"=",
"fopen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"fp2",
"==",
"NULL",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"f",
"=",
"fopen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"f",
"==",
"NULL",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"struct",
"DogType",
"aux",
";",
"findByIndex",
"(",
"&",
"aux",
",",
"indexToDelete",
",",
"f",
")",
";",
"int",
"iDMedical",
"=",
"aux",
".",
"medicalHistoryID",
";",
"char",
"fileNameNumber",
"[",
"256",
"]",
";",
"char",
"path",
"[",
"256",
"]",
"=",
"\"",
"\"",
";",
"sprintf",
"(",
"fileNameNumber",
",",
"\"",
"\"",
",",
"iDMedical",
")",
";",
"strcat",
"(",
"path",
",",
"fileNameNumber",
")",
";",
"strcat",
"(",
"path",
",",
"\"",
"\"",
")",
";",
"int",
"yt",
"=",
"fseek",
"(",
"f",
",",
"0",
",",
"SEEK_SET",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"indexToDelete",
";",
"i",
"++",
")",
"{",
"int",
"g",
"=",
"fread",
"(",
"&",
"reg",
",",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"1",
",",
"f",
")",
";",
"reg",
".",
"index",
"=",
"i",
";",
"int",
"hash",
"=",
"calculateHash",
"(",
"reg",
".",
"name",
")",
";",
"reg",
".",
"prevHashIndex",
"=",
"lastHashIndex",
"[",
"hash",
"]",
";",
"lastHashIndex",
"[",
"hash",
"]",
"=",
"i",
";",
"int",
"gg",
"=",
"fwrite",
"(",
"&",
"reg",
",",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"1",
",",
"fp2",
")",
";",
"int",
"seek",
"=",
"fseek",
"(",
"f",
",",
"0",
",",
"SEEK_CUR",
")",
";",
"}",
"if",
"(",
"fp2",
"==",
"NULL",
")",
"{",
"perror",
"(",
"\"",
"\"",
")",
";",
"exit",
"(",
"-1",
")",
";",
"}",
"if",
"(",
"!",
"(",
"indexToDelete",
"==",
"(",
"sizeOfRegisters",
"-",
"1",
")",
")",
")",
"{",
"int",
"seek",
"=",
"fseek",
"(",
"f",
",",
"(",
"(",
"indexToDelete",
"+",
"1",
")",
"*",
"sizeof",
"(",
"struct",
"DogType",
")",
")",
",",
"SEEK_SET",
")",
";",
"for",
"(",
"int",
"j",
"=",
"(",
"indexToDelete",
"+",
"1",
")",
";",
"j",
"<",
"sizeOfRegisters",
";",
"j",
"++",
")",
"{",
"int",
"g",
"=",
"fread",
"(",
"&",
"reg",
",",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"1",
",",
"f",
")",
";",
"reg",
".",
"index",
"=",
"(",
"j",
"-",
"1",
")",
";",
"int",
"hash",
"=",
"calculateHash",
"(",
"reg",
".",
"name",
")",
";",
"reg",
".",
"prevHashIndex",
"=",
"lastHashIndex",
"[",
"hash",
"]",
";",
"lastHashIndex",
"[",
"hash",
"]",
"=",
"(",
"j",
"-",
"1",
")",
";",
"int",
"gg",
"=",
"fwrite",
"(",
"&",
"reg",
",",
"sizeof",
"(",
"struct",
"DogType",
")",
",",
"1",
",",
"fp2",
")",
";",
"}",
"}",
"fclose",
"(",
"f",
")",
";",
"fclose",
"(",
"fp2",
")",
";",
"clearScreen",
"(",
")",
";",
"if",
"(",
"remove",
"(",
"\"",
"\"",
")",
"==",
"0",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"if",
"(",
"remove",
"(",
"path",
")",
"==",
"0",
")",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"else",
"{",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
")",
";",
"}",
"int",
"err",
"=",
"rename",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"if",
"(",
"err",
"==",
"-1",
")",
"{",
"puts",
"(",
"\"",
"\"",
")",
";",
"}",
"writeHash",
"(",
")",
";",
"readHash",
"(",
")",
";",
"REGISTROS",
"--",
";",
"return",
"0",
";",
"}"
] | funcion para elimiinar un registro dada la cantidad total de registros y la posicion del elemento que se desea eiminar del archivo | [
"funcion",
"para",
"elimiinar",
"un",
"registro",
"dada",
"la",
"cantidad",
"total",
"de",
"registros",
"y",
"la",
"posicion",
"del",
"elemento",
"que",
"se",
"desea",
"eiminar",
"del",
"archivo"
] | [
"///BORRADO DE HISTORIA MEDICA"
] | [
{
"param": "sizeOfRegisters",
"type": "int"
},
{
"param": "indexToDelete",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "sizeOfRegisters",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "indexToDelete",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
cc1b4868b979c31f78163582b3bb6568e3e1eda0 | ViditGoel/ComputerGraphics | openGL_codes/FILL_ALGORITHM/Fill_Boundary.c | [
"MIT"
] | C | init | void | void init() {
glClearColor(1.0, 1.0, 1.0, 0.0); // Black Color
glColor3f(0.0, 0.0, 0.0); // White Color
glPointSize(1.0); // Specify the point size
glMatrixMode(GL_PROJECTION); //Transformation
glLoadIdentity();
gluOrtho2D(0, 700, 0, 700);
} | //......................................................................................//
//Function 1: Initialize the OpenGL environment | Function 1: Initialize the OpenGL environment | [
"Function",
"1",
":",
"Initialize",
"the",
"OpenGL",
"environment"
] | void init() {
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0, 0.0, 0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 700, 0, 700);
} | [
"void",
"init",
"(",
")",
"{",
"glClearColor",
"(",
"1.0",
",",
"1.0",
",",
"1.0",
",",
"0.0",
")",
";",
"glColor3f",
"(",
"0.0",
",",
"0.0",
",",
"0.0",
")",
";",
"glPointSize",
"(",
"1.0",
")",
";",
"glMatrixMode",
"(",
"GL_PROJECTION",
")",
";",
"glLoadIdentity",
"(",
")",
";",
"gluOrtho2D",
"(",
"0",
",",
"700",
",",
"0",
",",
"700",
")",
";",
"}"
] | ......................................................................................
Function 1: Initialize the OpenGL environment | [
"......................................................................................",
"Function",
"1",
":",
"Initialize",
"the",
"OpenGL",
"environment"
] | [
"// Black Color",
"// White Color",
"// Specify the point size",
"//Transformation"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |