malloc, DICE and IPC

Tiago Jorge tjpj at lasige.di.fc.ul.pt
Wed Mar 30 15:30:32 CEST 2005


hello...
For my project, i'm now generating IPC stubs using DICE, so that i can i 
have my L4 server beeing call from L4Linux. But just for trying, i'm 
defining the interface, server, library, and a simple client only for 
testing.
Here is my interface:

#####################################################################

typedef struct WOO_Send_Retval_struct{
  int error;
  [string]char *tag;
}WOO_Send_Retval;

typedef struct WOO_Receive_Retval_struct{
  int error;
  [string]char *tag;
}WOO_Receive_Retval;

typedef struct WOO_Decide_Retval_struct{
  int error;
  long order_num;
  char hash[20];
}WOO_Decide_Retval;

interface WOO{
  int init(void);
  WOO_Send_Retval send([in]long long starter_eid, [in, max_is(100), 
size_is(eids_num)]long long eids[], [in]int eids_num, [in]long msg_id, 
[in, string]char *hash);
};

#####################################################################

i've built also a server:

#####################################################################

/*
 * This file is auto generated by Dice-2.2.8.
 *
 * Implement the server templates here.
 * This file is regenerated with every run of 'dice -t ...'.
 * Move it to another location after changing to
 * keep your changes!
 */

#include <stdio.h>
#include <l4/log/l4log.h>
#include <l4/names/libnames.h>
#include <stdlib.h>
#include "WOO-server.h"

char LOG_tag[9]="wooserver";

#ifdef __cplusplus
extern "C" {
#endif


CORBA_int
WOO_init_component(CORBA_Object _dice_corba_obj,
                   CORBA_Server_Environment *_dice_corba_env)
{
    int retval = 232144;

    return retval;
}



WOO_Send_Retval
WOO_send_component(CORBA_Object _dice_corba_obj,
                   CORBA_long_long starter_eid,
                   const CORBA_long_long eids[100],
                   CORBA_int eids_num,
                   CORBA_long msg_id,
                   const_CORBA_char_ptr hash,
                   CORBA_Server_Environment *_dice_corba_env)
{
    WOO_Send_Retval retval;
    LOG("i've got the call:: hash = %s\n", hash);
    retval.error = 34;
    retval.tag = "teststring";

    LOG("return\n");
   
    return retval;
}

int main(void){
        if(names_register("wooserver")==0){
                  printf("Error registering at nameserver\n");
                    return 1;
                    }
            WOO_server_loop(0);
}


#ifdef __cplusplus
}
#endif

#####################################################################

and a libray to call the server:

#####################################################################

#include <l4/names/libnames.h>
#include <l4/log/l4log.h>
#include <l4/env/errno.h>
#include <l4/sys/consts.h>
#include <l4/WOO_ipc/WOO_helper.h>
#include <stdlib.h>

static l4_threadid_t server_id = L4_INVALID_ID;
static CORBA_Object server = &server_id;

//! Request netserver id at nameserver
static int check_server(void){
  if (l4_is_invalid_id(server_id)){
    LOG("inicio do programa\n");
    if (!names_waitfor_name("wooserver",&server_id,10000)){
      LOG("nao ha nome disponivel\n");
      return 1;
    }
  }     
  return 0;
}

//! woo_init
int WOO_init(void){
  CORBA_Environment env = dice_default_environment;
  int retval;
 
  LOG("chamaram o woo_init\n");
  if (check_server()) return -L4_EINVAL;
 
  LOG("fiz o call\n");
  retval = WOO_init_call(server, &env);
  LOG("a call retornou\n");
 
  if(!env._p.ipc_error) return retval;
 
  LOG("ERROR\n");
  return -env._p.ipc_error;
}
//! woo_send

WOO_Send_Retval WOO_send(void){
  CORBA_Environment env = dice_default_environment;
  WOO_Send_Retval retval;
  long long eids[100];
  char tag[20] = "htkilfndtigkmnefktlo";
 
  LOG("call woo send\n");
 
  eids[0] = 213424;
  eids[1] = 2314124;
  eids[2] = 2143441;
 
  if (check_server()){
    retval.error = -L4_EINVAL;
    return retval;
  }

  LOG("do the call\n");
  retval=WOO_send_call(server, 12344512, eids, 3, 453445, tag, &env);
  LOG("call return\n");
  if(!env._p.ipc_error) return retval;
 
  retval.error = -env._p.ipc_error;
  return retval;
}
                                                           
#####################################################################

and a simple client:

#####################################################################

#include <stdio.h>
#include <l4/log/l4log.h>
#include <l4/WOO_ipc/WOO_helper.h>

char LOG_tag[9]="WOOclient";

int main(void){
  int wooinitret;
  WOO_Send_Retval ret;
 
  LOG("client start\n");
  wooinitret = WOO_init();
  LOG("woo_init()\n");
  LOG("WOO init returned %d\n", wooinitret);
 
  LOG("woo_send()\n");
  ret = WOO_send();
  LOG("returned send\n");
  LOG("WOO send tag= %s\n", ret.tag);

  return 0;
}

#####################################################################

all ok, until i get it to run...
There, he gives me an error (page fault) at the stubs, when 
unmarshalling the return value of the woo_send() call, more precisely, 
when allocating the string(tag) inside the return structure. the line is 
the following:

_dice_return.tag = 
(CORBA_char_ptr)(_dice_corba_env->malloc)(_dice_tmp_offset);

i've checked the string size tha comes from the server and it is correct...

So... why is it page faulting??

thanks in advance

Tiago Jorge




More information about the l4-hackers mailing list