Skip to content

Commit

Permalink
[mxio][launchpad] loader-service moves to launchpad
Browse files Browse the repository at this point in the history
This is the logical place for it to live and paves the way to migrate
it away from the soon-to-be-no-more mxio dispatcher.

Tidied up the API, de-mxio'd it, put it behind a common loader_service_
prefix, and broke some swiss-army-knife interfaces into more standalone
pieces, hopefully easier to understand.

Change-Id: I91acd79a44c5dcc72412484bd6e151a54d52c8a1
  • Loading branch information
swetland committed Sep 9, 2017
1 parent fcac280 commit 3e23b10
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 135 deletions.
5 changes: 3 additions & 2 deletions system/core/devmgr/devmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#include <unistd.h>

#include <launchpad/launchpad.h>
#include <launchpad/loader-service.h>
#include <magenta/dlfcn.h>
#include <magenta/process.h>
#include <magenta/processargs.h>
#include <magenta/syscalls.h>
#include <magenta/syscalls/object.h>
#include <magenta/status.h>
#include <mxio/loader-service.h>

#include <mxio/util.h>

#include "devmgr.h"
Expand Down Expand Up @@ -370,7 +371,7 @@ int main(int argc, char** argv) {

// Ensure that devmgr doesn't try to connect to the global
// loader sevice (as this leads to deadlocks in devhost v2)
mxio_force_local_loader_service();
loader_service_force_local();

devmgr_io_init();

Expand Down
12 changes: 6 additions & 6 deletions system/core/devmgr/dmctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include "devcoordinator.h"

#include <magenta/device/dmctl.h>
#include <mxio/loader-service.h>
#include <launchpad/loader-service.h>

static mx_device_t* dmctl_dev;

static mxio_multiloader_t* multiloader;
static loader_service_t* loader_svc;

static mx_status_t dmctl_cmd(uint32_t op, const char* cmd, size_t cmdlen, mx_handle_t h) {
dc_msg_t msg;
Expand Down Expand Up @@ -50,13 +50,13 @@ static mx_status_t dmctl_ioctl(void* ctx, uint32_t op,
if (in_len != 0 || out_buf == NULL || out_len != sizeof(mx_handle_t)) {
return MX_ERR_INVALID_ARGS;
}
if (multiloader == NULL) {
if (loader_svc == NULL) {
// The allocation in dmctl_init() failed.
return MX_ERR_NO_MEMORY;
}
// Create a new channel on the multiloader.
mx_handle_t out_channel;
mx_status_t status = mxio_multiloader_new_service(multiloader, &out_channel);
mx_status_t status = loader_service_connect(loader_svc, &out_channel);
if (status < 0) {
return status;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ mx_status_t dmctl_bind(void* ctx, mx_device_t* parent, void** cookie) {
// Don't try to ioctl to ourselves when this process loads libraries.
// Call this before the device has been created; mxio_loader_service()
// uses the device's presence as an invitation to use it.
mxio_force_local_loader_service();
loader_service_force_local();

device_add_args_t args = {
.version = DEVICE_ADD_ARGS_VERSION,
Expand All @@ -120,7 +120,7 @@ mx_status_t dmctl_bind(void* ctx, mx_device_t* parent, void** cookie) {
}

// Loader service init.
if ((status = mxio_multiloader_create("dmctl-multiloader", &multiloader)) < 0) {
if ((status = loader_service_create("dmctl-multiloader", &loader_svc)) < 0) {
// If this fails, IOCTL_DMCTL_GET_LOADER_SERVICE_CHANNEL will fail
// and processes will fall back to using a local loader.
// TODO: Make this fatal?
Expand Down
2 changes: 1 addition & 1 deletion system/core/devmgr/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ MODULE_SRCS := \

MODULE_STATIC_LIBS := system/ulib/ddk system/ulib/port

MODULE_LIBS := system/ulib/driver system/ulib/mxio system/ulib/magenta system/ulib/c
MODULE_LIBS := system/ulib/driver system/ulib/launchpad system/ulib/mxio system/ulib/magenta system/ulib/c

include make/module.mk
7 changes: 4 additions & 3 deletions system/uapp/launch/launch.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

#include <assert.h>
#include <launchpad/launchpad.h>
#include <launchpad/loader-service.h>
#include <launchpad/vmo.h>
#include <magenta/process.h>
#include <magenta/processargs.h>
#include <magenta/syscalls.h>
#include <magenta/syscalls/object.h>
#include <magenta/syscalls/policy.h>
#include <mxio/loader-service.h>

#include <mxio/io.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down Expand Up @@ -226,7 +227,7 @@ int main(int argc, char** argv) {
bool already_sending = launchpad_send_loader_message(lp, true);
if (!already_sending) {
mx_handle_t loader_svc;
status = mxio_loader_service(NULL, NULL, &loader_svc);
status = loader_service_get_default(&loader_svc);
check("mxio_loader_service", status);
mx_handle_t old = launchpad_use_loader_service(lp, loader_svc);
check("launchpad_use_loader_service", old);
Expand All @@ -240,7 +241,7 @@ int main(int argc, char** argv) {

if (pass_loader_handle) {
mx_handle_t loader_svc;
status = mxio_loader_service(NULL, NULL, &loader_svc);
status = loader_service_get_default(&loader_svc);
check("mxio_loader_service", status);
status = launchpad_add_handle(lp, loader_svc, PA_SVC_LOADER);
check("launchpad_add_handle", status);
Expand Down
67 changes: 67 additions & 0 deletions system/ulib/launchpad/include/launchpad/loader-service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#pragma once

#include <magenta/types.h>
#include <magenta/compiler.h>

__BEGIN_CDECLS

// These routines provide loader service implementations that
// some users of liblaunchpad may need. They are compatible with
// dl_set_loader_service() and are primarily used by devmgr (to
// provide the default system loader service) and clients of
// launchpad that need a specialized variant loader.
//
// Terms:
// "loader service": A channel that speaks the protocol expected by
// dl_set_loader_service(). The service behind the channel receives
// load requests (e.g., "libhid.so") and returns VMOs that contain
// the data associated with that name.
// "local loader service": An in-process loader service.
// "system loader service": A loader service, provided by the system,
// that is shared by multiple processes.

// Type of the hook for loader_service. The first argument is
// the one passed to loader_service_simple(), and the second specifies
// which load service was requested (the opcode from mx_loader_svc_msg_t).
// The remaining arguments' meaning depends on the opcode.
typedef mx_status_t (*loader_service_fn_t)(void* loader_arg, uint32_t load_cmd,
mx_handle_t request_handle, const char* file,
mx_handle_t* out);


// Obtain a handle to the system loader service, if possible
mx_status_t loader_service_get_system(mx_handle_t* out);

// Obtain the default loader service for this process
// Normally it attempts to use the system loader service, and
// if that fails attempts to create a process-local service
// (which depends on the process having filesystem access
// to executables and libraries needing loading)
mx_status_t loader_service_get_default(mx_handle_t* out);

// After this function returns, loader_service_get_default will no
// longer attempt to use the system loader service for the current
// process. Should only be used by the system loader service itself.
void loader_service_force_local(void);


// Create a simple single-threaded loader service, which
// will use the provided service_fn to process load commands
mx_status_t loader_service_simple(loader_service_fn_t loader,
void* loader_arg, mx_handle_t* out);


typedef struct loader_service loader_service_t;

// Create a new file-system backed loader service capable of handling
// any number of clients.
mx_status_t loader_service_create(const char* name, loader_service_t** out);

// Returns a new dl_set_loader_service-compatible loader service channel.
mx_status_t loader_service_connect(loader_service_t* svc, mx_handle_t* out);

__END_CDECLS
4 changes: 2 additions & 2 deletions system/ulib/launchpad/launchpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <magenta/processargs.h>
#include <magenta/stack.h>
#include <magenta/syscalls.h>
#include <mxio/loader-service.h>
#include <launchpad/loader-service.h>
#include <mxio/io.h>
#include <assert.h>
#include <stdatomic.h>
Expand Down Expand Up @@ -475,7 +475,7 @@ static mx_status_t setup_loader_svc(launchpad_t* lp) {
return MX_OK;

mx_handle_t loader_svc;
mx_status_t status = mxio_loader_service(NULL, NULL, &loader_svc);
mx_status_t status = loader_service_get_default(&loader_svc);
if (status < 0)
return status;

Expand Down
Loading

0 comments on commit 3e23b10

Please sign in to comment.