Skip to content

Commit

Permalink
* environ.cc (known): Add preload keyword.
Browse files Browse the repository at this point in the history
* external.cc: Include new callout.h header.
(cygwin_internal): Initial implementation of CW_CALLOUT and CW_CYGHEAP_MALLOC.
(dll_preload): Handle CYGWIN=preload:foo.dll.
(dummy_callout): Default NULL callout function.
* globals.cc: Include new callout.h header.
(callout): Declare/define.
* uname.cc (uname): Initial implementation of callout handling.
* winsup.h (dll_preload): Declare.
* include/cygwin/version.h: Bump API minor number to 269.
* include/sys/cygwin.h: Define CW_CALLOUT, CW_CYGHEAP_MALLOC.
  • Loading branch information
Christopher Faylor committed Jul 31, 2013
1 parent 309eaeb commit 4f756d6
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 2 deletions.
15 changes: 15 additions & 0 deletions winsup/cygwin/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2013-07-31 Christopher Faylor <me.cygwin2013@cgf.cx>

* environ.cc (known): Add preload keyword.
* external.cc: Include new callout.h header.
(cygwin_internal): Initial implementation of CW_CALLOUT and
CW_CYGHEAP_MALLOC.
(dll_preload): Handle CYGWIN=preload:foo.dll.
(dummy_callout): Default NULL callout function.
* globals.cc: Include new callout.h header.
(callout): Declare/define.
* uname.cc (uname): Initial implementation of callout handling.
* winsup.h (dll_preload): Declare.
* include/cygwin/version.h: Bump API minor number to 269.
* include/sys/cygwin.h: Define CW_CALLOUT, CW_CYGHEAP_MALLOC.

2013-07-31 Christopher Faylor <me.cygwin2013@cgf.cx>

* cygheap.cc (cmalloc): Use size_t for size field.
Expand Down
1 change: 1 addition & 0 deletions winsup/cygwin/environ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static struct parse_thing
{"error_start", {func: error_start_init}, isfunc, NULL, {{0}, {0}}},
{"export", {&export_settings}, setbool, NULL, {{false}, {true}}},
{"glob", {func: glob_init}, isfunc, NULL, {{0}, {s: "normal"}}},
{"preload", {func: dll_preload}, isfunc, NULL, {{0}, {0}}},
{"pipe_byte", {&pipe_byte}, setbool, NULL, {{false}, {true}}},
{"proc_retry", {func: set_proc_retry}, isfunc, NULL, {{0}, {5}}},
{"reset_com", {&reset_com}, setbool, NULL, {{false}, {true}}},
Expand Down
22 changes: 22 additions & 0 deletions winsup/cygwin/external.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ details. */
#include <stdlib.h>
#include <wchar.h>
#include <iptypes.h>
#include <cygwin/callout.h>

child_info *get_cygwin_startup_info ();
static void exit_process (UINT, bool) __attribute__((noreturn));
Expand Down Expand Up @@ -553,9 +554,30 @@ cygwin_internal (cygwin_getinfo_types t, ...)
}
break;

case CW_CALLOUT:
callout = va_arg (arg, cw_callout_function_t);
break;

case CW_CYGHEAP_MALLOC:
res = (uintptr_t) cmalloc (HEAP_USER, va_arg (arg, size_t));
break;

default:
set_errno (ENOSYS);
}
va_end (arg);
return res;
}

extern "C" void
dll_preload (const char *dll)
{
if (!LoadLibrary (dll))
api_fatal ("couldn't load CYGWIN=preload DLL: %s, %E", dll);
}

extern "C" cw_callout_return_t
dummy_callout (cw_callout_t, ...)
{
return CO_R_KEEP_GOING;
}
6 changes: 6 additions & 0 deletions winsup/cygwin/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ details. */
#include "thread.h"
#include <malloc.h>
#include <cygwin/version.h>
#include <cygwin/callout.h>

HANDLE NO_COPY hMainThread;
HANDLE NO_COPY hProcToken;
Expand Down Expand Up @@ -75,6 +76,11 @@ bool reset_com;
bool wincmdln;
winsym_t allow_winsymlinks = WSYM_sysfile;

extern "C" {
cw_callout_return_t dummy_callout (cw_callout_t, ...);
cw_callout_function_t callout = dummy_callout;
};

bool NO_COPY in_forkee;

/* Taken from BSD libc:
Expand Down
30 changes: 30 additions & 0 deletions winsup/cygwin/include/cygwin/callout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* callout.h -- Definitions used by Cygwin callout mechanism
Copyright 2013 Red Hat, Inc.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */

#pragma once

extern "C" {
enum cw_callout_t
{
CO_ENV,
CO_SPAWN,
CO_SYMLINK,
CO_UNAME
};

enum cw_callout_return_t
{
CO_R_ERROR,
CO_R_KEEP_GOING,
CO_R_SHORT_CIRCUIT
};

typedef cw_callout_return_t (*cw_callout_function_t) (cw_callout_t, ...);
};
3 changes: 2 additions & 1 deletion winsup/cygwin/include/cygwin/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,13 @@ details. */
arc4random_stir, arc4random_uniform.
267: Export rawmemchr.
268: Export GetCommandLineA, GetCommandLineW
269: Implement Cygwin callout functionality v1
*/

/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */

#define CYGWIN_VERSION_API_MAJOR 0
#define CYGWIN_VERSION_API_MINOR 268
#define CYGWIN_VERSION_API_MINOR 269

/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible
Expand Down
6 changes: 5 additions & 1 deletion winsup/cygwin/include/sys/cygwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ typedef enum
CW_CVT_ENV_TO_WINENV,
CW_ALLOC_DRIVE_MAP,
CW_MAP_DRIVE_MAP,
CW_FREE_DRIVE_MAP
CW_FREE_DRIVE_MAP,
CW_CALLOUT,
CW_CYGHEAP_MALLOC
} cygwin_getinfo_types;

#define CW_LOCK_PINFO CW_LOCK_PINFO
Expand Down Expand Up @@ -194,6 +196,8 @@ typedef enum
#define CW_ALLOC_DRIVE_MAP CW_ALLOC_DRIVE_MAP
#define CW_MAP_DRIVE_MAP CW_MAP_DRIVE_MAP
#define CW_FREE_DRIVE_MAP CW_FREE_DRIVE_MAP
#define CW_CALLOUT CW_CALLOUT
#define CW_CYGHEAP_MALLOC CW_CYGHEAP_MALLOC

/* Token type for CW_SET_EXTERNAL_TOKEN */
enum
Expand Down
8 changes: 8 additions & 0 deletions winsup/cygwin/uname.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ details. */
#include <sys/utsname.h>
#include "cygwin_version.h"
#include "cygtls.h"
#include <cygwin/callout.h>

/* uname: POSIX 4.4.1.1 */
extern "C" int
Expand Down Expand Up @@ -91,5 +92,12 @@ uname (struct utsname *name)
break;
}

switch (callout (CO_UNAME, name))
{
case CO_R_KEEP_GOING:
break;
default:
return -1;
}
return 0;
}
1 change: 1 addition & 0 deletions winsup/cygwin/winsup.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ void __stdcall close_all_files (bool = false);
extern "C" void error_start_init (const char*);
extern "C" int try_to_debug (bool waitloop = 1);

extern "C" void dll_preload (const char*);
void ld_preload ();
const char *find_first_notloaded_dll (class path_conv &);

Expand Down

0 comments on commit 4f756d6

Please sign in to comment.