mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-13 22:23:45 +00:00
genode_c_api: errors on socket/nic_client init
Prevent uncaught exceptiosn in (NIC-client) initialization but report as errors from genode_socket_init() / genode_nic_client_create().
This commit is contained in:
parent
14cfc765c6
commit
1f181f6ce3
@ -88,7 +88,7 @@ struct Main
|
||||
};
|
||||
|
||||
|
||||
void genode_socket_init(struct genode_env *_env,
|
||||
bool genode_socket_init(struct genode_env *_env,
|
||||
struct genode_socket_io_progress *io_progress,
|
||||
char const *label)
|
||||
{
|
||||
@ -108,4 +108,6 @@ void genode_socket_init(struct genode_env *_env,
|
||||
|
||||
/* wait to finish initialization before returning to callee */
|
||||
lx_emul_execute_kernel_until(lx_user_startup_complete, nullptr);
|
||||
|
||||
return lx_nic_client_initialized();
|
||||
}
|
||||
|
@ -188,6 +188,10 @@ static int rx_task_function(void *arg)
|
||||
}
|
||||
|
||||
|
||||
static bool initialized;
|
||||
|
||||
bool lx_nic_client_initialized() { return initialized; }
|
||||
|
||||
static int __init virtio_net_driver_init(void)
|
||||
{
|
||||
struct net_device *dev;
|
||||
@ -232,6 +236,7 @@ static int __init virtio_net_driver_init(void)
|
||||
|
||||
nic_rx_task_struct_ptr = find_task_by_pid_ns(pid, NULL);
|
||||
|
||||
initialized = true;
|
||||
return 0;
|
||||
|
||||
out_nic:
|
||||
|
@ -23,6 +23,7 @@ extern "C" {
|
||||
struct task_struct *lx_nic_client_rx_task(void);
|
||||
bool lx_nic_client_link_state(void);
|
||||
bool lx_nic_client_update_link_state(void);
|
||||
bool lx_nic_client_initialized(void);
|
||||
|
||||
/* socket.cc */
|
||||
void socket_schedule_peer(void);
|
||||
|
@ -215,7 +215,10 @@ struct genode_netif_handle *lwip_genode_netif_init(char const *label)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->nic_handle = genode_nic_client_create(label);
|
||||
handle->nic_handle = genode_nic_client_create(label);
|
||||
if (handle->nic_handle == NULL)
|
||||
return NULL;
|
||||
|
||||
handle->netif = net;
|
||||
handle->address_valid = false;
|
||||
handle->address_configured = false;
|
||||
|
@ -38,6 +38,8 @@ struct Statics
|
||||
genode_socket_io_progress *io_progress;
|
||||
Genode::Heap *heap;
|
||||
Genode::Env *env;
|
||||
|
||||
bool initialized() const { return netif_ptr && io_progress && heap && env; }
|
||||
};
|
||||
|
||||
|
||||
@ -343,7 +345,7 @@ void genode_socket_wait_for_progress()
|
||||
}
|
||||
|
||||
|
||||
void genode_socket_init(struct genode_env *_env,
|
||||
bool genode_socket_init(struct genode_env *_env,
|
||||
struct genode_socket_io_progress *io_progress,
|
||||
char const *label)
|
||||
{
|
||||
@ -353,6 +355,8 @@ void genode_socket_init(struct genode_env *_env,
|
||||
statics().io_progress = io_progress;
|
||||
|
||||
static Socket::Main main { env, label };
|
||||
|
||||
return statics().initialized();
|
||||
}
|
||||
|
||||
|
||||
|
@ -155,7 +155,7 @@ struct genode_socket_io_progress
|
||||
};
|
||||
|
||||
|
||||
void genode_socket_init(struct genode_env *env,
|
||||
bool genode_socket_init(struct genode_env *env,
|
||||
struct genode_socket_io_progress *,
|
||||
char const *label);
|
||||
|
||||
|
@ -249,11 +249,13 @@ struct genode_nic_client *genode_nic_client_create(char const *label)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new (*statics().alloc_ptr)
|
||||
Registered<genode_nic_client>(statics().nic_clients, *statics().env_ptr,
|
||||
*statics().alloc_ptr,
|
||||
statics().sigh, statics().link_sigh,
|
||||
Session_label(label));
|
||||
try {
|
||||
return new (*statics().alloc_ptr)
|
||||
Registered<genode_nic_client>(statics().nic_clients, *statics().env_ptr,
|
||||
*statics().alloc_ptr,
|
||||
statics().sigh, statics().link_sigh,
|
||||
Session_label(label));
|
||||
} catch (...) { return nullptr; }
|
||||
}
|
||||
|
||||
|
||||
|
@ -1998,10 +1998,12 @@ struct Ip_factory : Vfs::File_system_factory
|
||||
|
||||
using Label = Genode::String<Genode::Session_label::capacity()>;
|
||||
|
||||
genode_socket_init(genode_env_ptr(env.env()), &io_progress,
|
||||
config.attribute_value("label", Label("")).string());
|
||||
if (genode_socket_init(genode_env_ptr(env.env()), &io_progress,
|
||||
config.attribute_value("label", Label("")).string()))
|
||||
return new (env.alloc()) Vfs::Ip_file_system(env, config);
|
||||
|
||||
return new (env.alloc()) Vfs::Ip_file_system(env, config);
|
||||
struct Socket_init_failed { };
|
||||
throw Socket_init_failed();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user