mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 16:08:38 +01:00
Dev/server malloc check (#1023)
* usleep in communication to actually relay the err message of memory allocation to the client (weird but test for now), function in server to handle memory allcoation issues (updates mess, ret and sendsit to the client and returns prior from function implementatin, setting fnum in client for the speicific functions that send to detector each argument separtely, they need to remember the fnum else they throw with the incorrect fnum * server: every malloc must check if it succeeded, rearranging so that the free is clear as well (only in funcs so far) * fixed malloc checks in other places other than funcs.c
This commit is contained in:
@@ -46,17 +46,27 @@ int Beb_deactivated_left_datastream = 1;
|
||||
int Beb_deactivated_right_datastream = 1;
|
||||
int Beb_deactivated_num_destinations = 1;
|
||||
|
||||
void Beb_Beb() {
|
||||
int Beb_Beb() {
|
||||
Beb_send_ndata = 0;
|
||||
Beb_send_buffer_size = 1026;
|
||||
|
||||
Beb_send_data_raw =
|
||||
malloc((Beb_send_buffer_size + 1) * sizeof(unsigned int));
|
||||
if (Beb_send_data_raw == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for beb (send_data_raw)\n"));
|
||||
return 0;
|
||||
}
|
||||
Beb_send_data = &Beb_send_data_raw[1];
|
||||
|
||||
Beb_recv_ndata = 0;
|
||||
Beb_recv_buffer_size = 1026;
|
||||
|
||||
Beb_recv_data_raw =
|
||||
malloc((Beb_recv_buffer_size + 1) * sizeof(unsigned int));
|
||||
if (Beb_recv_data_raw == NULL) {
|
||||
LOG(logERROR, ("Could not allocate memory for beb (recv_data_raw)\n"));
|
||||
return 0;
|
||||
}
|
||||
Beb_recv_data = &Beb_recv_data_raw[1];
|
||||
|
||||
udp_header = (struct udp_header_type){
|
||||
@@ -83,6 +93,7 @@ void Beb_Beb() {
|
||||
Beb_ClearHeaderData(1);
|
||||
|
||||
Beb_bit_mode = 4;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Beb_ClearHeaderData(int ten_gig) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "slsDetectorServer_defs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void Beb_Beb();
|
||||
int Beb_Beb();
|
||||
void Beb_ClearHeaderData(int ten_gig);
|
||||
int Beb_SetUpUDPHeader(unsigned int header_number, int ten_gig,
|
||||
uint64_t src_mac, uint32_t src_ip, uint16_t src_port,
|
||||
|
||||
@@ -57,11 +57,19 @@ int Feb_Control_FebControl(int normal) {
|
||||
Feb_Control_externalEnableMode = 0;
|
||||
Feb_Control_subFrameMode = 0;
|
||||
Feb_Control_trimbit_size = 263680;
|
||||
|
||||
Feb_Control_last_downloaded_trimbits =
|
||||
malloc(Feb_Control_trimbit_size * sizeof(int));
|
||||
if (Feb_Control_last_downloaded_trimbits == NULL) {
|
||||
LOG(logERROR,
|
||||
("Could not allocate memory for last downloaded trimbits\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Feb_Control_normal = normal;
|
||||
Feb_Interface_SetAddress(Feb_Control_rightAddress, Feb_Control_leftAddress);
|
||||
if (!Feb_Interface_SetAddress(Feb_Control_rightAddress,
|
||||
Feb_Control_leftAddress))
|
||||
return 0;
|
||||
if (Feb_Control_activated) {
|
||||
return Feb_Interface_SetByteOrder();
|
||||
}
|
||||
|
||||
@@ -22,34 +22,57 @@ unsigned int Feb_Interface_recv_buffer_size;
|
||||
unsigned int *Feb_Interface_recv_data_raw;
|
||||
unsigned int *Feb_Interface_recv_data;
|
||||
|
||||
void Feb_Interface_FebInterface() {
|
||||
int Feb_Interface_FebInterface() {
|
||||
ll = &ll_local;
|
||||
Feb_Interface_nfebs = 0;
|
||||
Feb_Interface_feb_numb = 0;
|
||||
|
||||
Feb_Interface_send_ndata = 0;
|
||||
Feb_Interface_send_buffer_size = 1026;
|
||||
|
||||
Feb_Interface_send_data_raw =
|
||||
malloc((Feb_Interface_send_buffer_size + 1) * sizeof(unsigned int));
|
||||
if (Feb_Interface_send_data_raw == NULL) {
|
||||
LOG(logERROR,
|
||||
("Could not allocate memory for feb interface (send_data_raw)\n"));
|
||||
return 0;
|
||||
}
|
||||
Feb_Interface_send_data = &Feb_Interface_send_data_raw[1];
|
||||
|
||||
Feb_Interface_recv_ndata = 0;
|
||||
Feb_Interface_recv_buffer_size = 1026;
|
||||
|
||||
Feb_Interface_recv_data_raw =
|
||||
malloc((Feb_Interface_recv_buffer_size + 1) * sizeof(unsigned int));
|
||||
if (Feb_Interface_recv_data_raw == NULL) {
|
||||
LOG(logERROR,
|
||||
("Could not allocate memory for feb interface (recv_data_raw)\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Feb_Interface_recv_data = &Feb_Interface_recv_data_raw[1];
|
||||
|
||||
Local_LocalLinkInterface(
|
||||
ll, XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr) {
|
||||
if (Feb_Interface_feb_numb)
|
||||
free(Feb_Interface_feb_numb);
|
||||
int Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr) {
|
||||
free(Feb_Interface_feb_numb);
|
||||
Feb_Interface_nfebs = 2;
|
||||
|
||||
Feb_Interface_feb_numb = malloc(2 * sizeof(unsigned int));
|
||||
if (Feb_Interface_feb_numb == NULL) {
|
||||
LOG(logERROR,
|
||||
("Could not allocate memory for feb interface (feb_numb)\n"));
|
||||
Feb_Interface_nfebs = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Feb_Interface_feb_numb[0] = leftAddr;
|
||||
Feb_Interface_feb_numb[1] = rightAddr;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Feb_Interface_WriteTo(unsigned int ch) {
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
int Feb_Interface_WriteTo(unsigned int ch);
|
||||
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys);
|
||||
void Feb_Interface_FebInterface();
|
||||
void Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr);
|
||||
int Feb_Interface_FebInterface();
|
||||
int Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr);
|
||||
int Feb_Interface_SetByteOrder();
|
||||
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,
|
||||
unsigned int *value_read);
|
||||
|
||||
@@ -662,7 +662,15 @@ int checkCommandLineConfiguration() {
|
||||
#ifndef VIRTUAL
|
||||
void setupFebBeb() {
|
||||
sharedMemory_lockLocalLink();
|
||||
Feb_Interface_FebInterface();
|
||||
if (!Feb_Interface_FebInterface()) {
|
||||
initError = FAIL;
|
||||
sprintf(initErrorMessage,
|
||||
"Could not intitalize eiger detector sever: feb interface\n");
|
||||
LOG(logERROR, (initErrorMessage));
|
||||
initCheckDone = 1;
|
||||
sharedMemory_unlockLocalLink();
|
||||
return;
|
||||
}
|
||||
if (!Feb_Control_FebControl(normal)) {
|
||||
initError = FAIL;
|
||||
sprintf(initErrorMessage,
|
||||
@@ -686,7 +694,14 @@ void setupFebBeb() {
|
||||
LOG(logDEBUG1, ("%s server: FEB Initialization done\n",
|
||||
isControlServer ? "Control" : "Stop"));
|
||||
Beb_SetTopVariable(top);
|
||||
Beb_Beb();
|
||||
if (!Beb_Beb()) {
|
||||
initError = FAIL;
|
||||
sprintf(initErrorMessage,
|
||||
"Could not intitalize eiger detector sever: beb\n");
|
||||
LOG(logERROR, (initErrorMessage));
|
||||
initCheckDone = 1;
|
||||
return;
|
||||
}
|
||||
LOG(logDEBUG1, ("%s server: BEB Initialization done\n",
|
||||
isControlServer ? "Control" : "Stop"));
|
||||
|
||||
@@ -724,17 +739,23 @@ void setupFebBeb() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void allocateDetectorStructureMemory() {
|
||||
LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
|
||||
|
||||
// Allocation of memory
|
||||
int allocateDetectorStructureMemory() {
|
||||
detectorModules = malloc(sizeof(sls_detector_module));
|
||||
detectorChans = malloc(NCHIP * NCHAN * sizeof(int));
|
||||
detectorDacs = malloc(NDAC * sizeof(int));
|
||||
if (detectorModules == NULL || detectorChans == NULL ||
|
||||
detectorDacs == NULL) {
|
||||
initError = FAIL;
|
||||
strcpy(initErrorMessage,
|
||||
"Could not allocate memory for dacs or channels in detector\n");
|
||||
LOG(logERROR, (initErrorMessage));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1,
|
||||
("modules from 0x%x to 0x%x\n", detectorModules, detectorModules));
|
||||
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans));
|
||||
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs));
|
||||
|
||||
detectorModules->dacs = detectorDacs;
|
||||
detectorModules->chanregs = detectorChans;
|
||||
detectorModules->ndac = NDAC;
|
||||
@@ -748,14 +769,21 @@ void allocateDetectorStructureMemory() {
|
||||
detectorModules->eV[2] = -1;
|
||||
thisSettings = UNINITIALIZED;
|
||||
|
||||
// if trimval requested, should return -1 to acknowledge unknown
|
||||
// initialize (trimbits at -1 for unknown)
|
||||
for (int idac = 0; idac < (detectorModules)->ndac; ++idac) {
|
||||
detectorDacs[idac] = 0;
|
||||
}
|
||||
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
|
||||
*((detectorModules->chanregs) + ichan) = -1;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
void setupDetector() {
|
||||
allocateDetectorStructureMemory();
|
||||
LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
|
||||
|
||||
if (allocateDetectorStructureMemory() == FAIL)
|
||||
return;
|
||||
|
||||
// force top or master if in config file
|
||||
if (readConfigFile() == FAIL)
|
||||
|
||||
Reference in New Issue
Block a user